📄 zl5011xtfm.c
字号:
/*******************************************************************************
*
* File name: zl5011xTfm.c
*
* Version: 43
*
* Author: MRC
*
* Date created: 15/02/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains all the functions that will initialise and control
* the TFM block.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 15/02/2002 MRC Creation
* 2 22/02/2002 MRC Added more functions.
* 3 28/02/2002 MRC Checked and quick test
* 4 08/03/2002 MRC Update
* 5 19/03/2002 MRC Update
* 6 26/03/2002 MRC Teardown clears the update bit if set
* 7 09/04/2002 MRC Clear the valid and first bits when assigning
* a new channel
* 8 17/04/2002 MRC Changed the CHECK_.. MRC os to ZL5011X_CHECK_..
* 9 19/04/2002 MRC Added the jitter buffer depth to the device
* structure.
* 10 23/04/2002 MRC Changed the underrun function to use stream
* + channel rather than a channel index
* 11 23/04/2002 MRC Allow a context update from the INIT state.
* 12 24/04/2002 MRC Force a cache init and set the first frame
* bit (if in INIT) when updating a context
* 13 03/05/2002 MRC Added the jitter buffer depth to the device
* structure
* 14 07/05/2002 MRC Check update and teardown now uses the status
* to indicate when the change completes.
* 15 09/05/2002 MRC Update was clearing the context cache every
* time. Should only do it from INIT state.
* 16 14/05/2002 MRC ZL5011X_TRACE now uses \r\n rather than \n.
* 17 07/06/2002 PJE New Enable & DisableInterrupts. ZL5011X_TRACE now uses
* nothing rather than \r\n . Names Initialised.
* 18 07/06/2002 PJE Update
* 19 27/06/2002 MRC Added context switch fn and added packet header
* bits to the update and teardown fns
* 20 03/07/2002 PJE Update Enable & DisableInterrupts after review -
* new structure items.
* 21 09/07/2002 MRC TIF connection mode structure entry changed
* 22 22/07/2002 MRC Update following review.
* 23 31/07/2002 MRC reset the context state in the active structure
* after a teardown
* 24 28/08/2002 PJE clear an interrupt BEFORE enabling it.
* 25 30/09/2002 MRC CheckChan didn't check the active buffer when
* deciding if the channel was free
* 26 03/10/2002 JFE Fixed ZL5011X_TRACE's without : after function name.
* 27 09/10/2002 MRC Added cache 2 clear on context update
* 28 31/10/2002 MRC Added variants + minor fixes
* 29 17/12/2002 JFE Mended bit shifting in context memory issue.
* 30 28/01/2003 PJE intr enable was checking mask without inverting it.
* 31 03/04/2003 MRC Changed interrupt enable to always clear the flags
* even if the mask cannot be changed due to update...
* 32 25/04/2003 MRC Changed the initialisation order for context
* update
* 33 29/07/2003 MRC Fixd init cache function, added cache 1 reset
* 34 04/07/2003 APL Audit action - global rename of PacketToTdmMapping
* 35 04/07/2003 APL Revision history update
* 36 16/02/2004 APL zl5011xTfmGetError clears the error bits after
* reading them.
* 37 23/07/2004 MRC Fixed some compiler warnings
* 38 29/07/2004 MRC Fixed some compiler warnings
* 39 16/11/2004 MRC Added individual stream frequency control
* 40 21/01/2005 MRC Updated first channel function
* 41 04/03/2005 APL Updated first channel function to allow use of
* AUX_CLK where supported
* 42 22/06/2005 MRC Constrained first channel loop to available streams
* 43 24/06/2005 MRC Modified jitter buffer calculation for more range
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011x.h"
#include "zl5011xTfm.h"
#include "zl5011xTfmMap.h"
#include "zl5011xUtilLib.h"
/***************** EXPORTED GLOBAL VARIABLES *****************************/
/***************** STATIC GLOBAL VARIABLES *****************************/
/***************** STATIC FUNCTION DECLARATIONS *****************************/
/*******************************************************************************
Function:
zl5011xTfmInit
Description:
This function initialises the TFM data structure. The TFM should have already
been reset. The operation of the device is represented by two device structures.
current - use for tracking modifications
active - the state of the device after the last update.
By tracking both of these, the API has complete history of the TFM.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xTfmInit(zl5011xParamsS *zl5011xParams)
{
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmInit:", 0, 0, 0, 0, 0, 0);
/* reset the context structures */
for (loop = 0; loop < ZL5011X_MAX_NUMBER_CONTEXTS; loop++)
{
/* reset the current context structure - used to track modifications */
zl5011xParams->wanIf.tfmCurrent.context[loop].state = ZL5011X_STATE_NOT_IN_USE;
zl5011xParams->wanIf.tfmCurrent.context[loop].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;
zl5011xParams->wanIf.tfmCurrent.context[loop].numChannels = 0;
/* reset the active context structure - used to track device operation */
zl5011xParams->wanIf.tfmActive.context[loop].state = ZL5011X_STATE_NOT_IN_USE;
zl5011xParams->wanIf.tfmActive.context[loop].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;
zl5011xParams->wanIf.tfmActive.context[loop].numChannels = 0;
}
/* reset the channel mapping structures */
for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
{
/* reset the current channel structure - used to track modifications */
zl5011xParams->wanIf.tfmCurrent.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
zl5011xParams->wanIf.tfmCurrent.channel[loop].underrunMode = ZL5011X_WAN_USE_LAST_BYTE;
/* reset the active channel structure - used to track device operation */
zl5011xParams->wanIf.tfmActive.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
zl5011xParams->wanIf.tfmActive.channel[loop].underrunMode = ZL5011X_WAN_USE_LAST_BYTE;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xTfmAddChan
Description:
Add a channel to the required context. Checks to see that the channel
is not already in use. The first channel is not tracked when adding channels.
The update of the first channel takes place when the context is updated.
This function should only be called once in unstructured mode. With the one
access made when the context is initialised.
Checking for unstructured accesses is a function of the layer above.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to associate the channel with
tdm stream and channel to add.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xTfmAddChan(zl5011xParamsS *zl5011xParams,
Uint32T context, zl5011xWanChannelS tdm)
{
Uint32T checkContext, chanIndex;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context, "zl5011xTfmAddChan: ctxt %3d, str %2d, ch %3d",
context, tdm.stream, tdm.channel, 0, 0, 0);
status = zl5011xCheckTdm(zl5011xParams, tdm, &chanIndex);
if (status == ZL5011X_OK)
{
status = zl5011xTfmCheckChan(zl5011xParams, &checkContext, chanIndex);
}
if (status == ZL5011X_OK)
{
if ((checkContext != (Uint32T)ZL5011X_INVALID_CONTEXT) && (checkContext != context))
{
status = ZL5011X_CHANNEL_IN_USE;
}
}
if (status == ZL5011X_OK)
{
if (checkContext != context)
{
/* If in unstructured mode, then only one stream can be associated
with a context */
if (zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED)
{
/* unstructured mode, so check that only one channel is attached */
if (zl5011xParams->wanIf.tfmCurrent.context[context].numChannels >= 1)
{
status = ZL5011X_CHANNEL_RANGE;
}
}
if (status == ZL5011X_OK)
{
status = zl5011xTfmAssignChan(zl5011xParams, context, chanIndex);
}
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xTfmRemoveChan
Description:
Removes a channel from the required context, if is already associated with
this context.The first channel is not tracked when adding channels.
The update of the first channel takes place when the context is updated.
This should not be called in unstructured mode, since only one stream is
allowed. Checking for unstructured accesses is in the layer above.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to remove the channel from
tdm stream and channel to remove.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xTfmRemoveChan(zl5011xParamsS *zl5011xParams,
Uint32T context, zl5011xWanChannelS tdm)
{
Uint32T checkContext, chanIndex;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
"zl5011xTfmRemoveChan: ctxt %3d, str %2d, ch %3d",
context, tdm.stream, tdm.channel, 0, 0, 0);
status = zl5011xCheckTdm(zl5011xParams, tdm, &chanIndex);
if (status == ZL5011X_OK)
{
status = zl5011xTfmCheckChan(zl5011xParams, &checkContext, chanIndex);
}
if (status == ZL5011X_OK)
{
if ((checkContext != context))
{
status = ZL5011X_CHANNEL_NOT_IN_CTXT;
}
else
{
status = zl5011xTfmFreeChan(zl5011xParams, context, chanIndex);
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xTfmAssignChan
Description:
Adds the channel to the required context. All checks for validity of
the operation will have been performed outside of this function.
This function accesses the device and maintains the current structures.
The first channel bit is reset when adding a channel, and is not tracked.
The update of the first channel takes place when the context is updated.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to associate the channel with
chanIndex Index used to represent the channel in a linear array.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xTfmAssignChan(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T chanIndex)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context, "zl5011xTfmAssignChan: ctxt %3d, lkup %4X",
context, chanIndex, 0, 0, 0, 0);
zl5011xParams->wanIf.tfmCurrent.context[context].numChannels++;
/* a channel is initialised with the underrun byte set to be the last byte,
this can be changed dynamically, so is not included in this function */
bits = ZL5011X_1BIT_MASK << ZL5011X_TFM_NEW_VALID_CHAN_BIT |
(context << ZL5011X_TFM_LKUP_CTXT_ID_BITS);
status = zl5011xWrite(zl5011xParams,
ZL5011X_TFM_CONTEXT_LOOKUP + (chanIndex * ZL5011X_TFM_LKUP_MEM_SIZE),
bits);
zl5011xParams->wanIf.tfmCurrent.channel[chanIndex].context = context;
return(status);
}
/*******************************************************************************
Function:
zl5011xTfmFreeChan
Description:
Removes the channel from the required context. Checks that a context has at
least one channel, but all other checks for validity of the operation will
have been performed outside of this function.
This function accesses the device and maintains the current structures.
The first channel and valid channel bits are cleared when removing a channel.
The update of the first channel takes place when the context is updated.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to remove the channel from
chanIndex Index used to represent the channel in a linear array.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xTfmFreeChan(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T chanIndex)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits;
Uint32T bitMask;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context, "zl5011xTfmFreeChan: ctxt %3d, lkup %4X",
context, chanIndex, 0, 0, 0, 0);
if (zl5011xParams->wanIf.tfmCurrent.context[context].numChannels <= 1)
{
status = ZL5011X_LAST_CHANNEL_IN_CONTEXT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -