?? zl5011xtdm.c
字號:
/*******************************************************************************
*
* File name: zl5011xTdm.c
*
* Version: 96
*
* Author: MRC
*
* Date created: 03/05/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains the functions required to control the TDM interface.
*
* The convention is that all directions are referenced relative to the
* device. That is Rx is Wan Rx for the device and Tx is Wan Tx for the device.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 03/05/2002 MRC Creation
* 2 14/05/2002 MRC Added more functions
* 3 15/05/2002 MRC Added support for unframed mode
* 4 16/05/2002 MRC Added more functions
* 5 17/05/2002 MRC Added context delete functions
* 6 23/05/2002 MRC Added PAC async functionality
* 7 23/05/2002 MRC TIF changed Rx clock polarity, so changed defaults
* 8 28/05/2002 MRC Mods following seminar
* 9 30/05/2002 MRC Made function naming more consistent
* 10 30/05/2002 MRC Changed the payload function, to take care of
* bit stuffing in frames
* 11 31/05/2002 MRC Added harness defaults to init functions
* 12 06/06/2002 MRC Changed default for async ref to ext primary ref
* 13 11/06/2002 MRC Added harness setups to create context fns
* 14 12/06/2002 MRC Added checks for context teardown in create fns
* 15 17/06/2002 MRC Use number of streams from the structure rather
* than the max #define
* 16 19/06/2002 MRC PAC DPLL changed
* 17 20/06/2002 MRC Changed default DPLL mode to slave
* 18 28/06/2002 MRC Added packet Rx header freeing to the delete
* context fn
* 19 09/07/2002 MRC Added Wan Rx sample point control
* 20 12/07/2002 MRC Rationalised the 2 enums for CPU queues
* 21 18/07/2002 MRC Added Wan to CPU functions
* 22 19/07/2002 MRC Added dynamic alloc for queues
* 23 22/07/2002 MRC Tidied up structure initialisation fns
* 24 01/08/2002 MRC Added queue slip fn and tidied
* 25 14/08/2002 MRC Changed the way that unframed mode was being
* determined in a few fns
* 26 05/09/2002 MRC Determine the Wan Tx switch bit during context
* changes
* 27 12/09/2002 MRC Updated following review
* 28 13/09/2002 MRC Added extra funcs
* 29 19/09/2002 MRC Added extra dpll settings to wan configure fn
* 30 23/09/2002 MRC Added RTP header copy during Wan Rx delete
* 31 02/10/2002 MRC Fixed a couple of function names
* 32 03/10/2002 MRC Clear the first frame field when updating the
* RTP Tx header during a delete
* 33 03/10/2002 MRC added the RTP Tx header fix in another place
* 34 03/10/2002 MRC Fixed a couple of traces using the worng FN_ID
* 35 16/10/2002 PJE zl5011xWanConfigureAsync input clock pol inverted
* 36 17/10/2002 PJE WanConfigureAsync input clock pol invd. properly
* 37 29/10/2002 MRC Added parameter checking
* 38 31/10/2002 MRC Added variants + minor fixes
* 39 04/11/2002 MRC Added fix for context take parameter checks
* 40 04/11/2002 MRC Changed context take parameter checks
* 41 07/11/2002 MRC Added Lan Rx cleanup when deleting a Tx context
* from the INIT state
* 42 07/11/2002 MRC Needed to clean up the packet to TDM mappings
* to allow the PKC matches to be deleted
* 43 19/11/2002 MRC Fixed gotDevice checks
* 44 29/11/2002 MRC Tx queue slip fn checks that queue is active.
* 45 09/12/2002 DJA Header for function zl5011xWanSetAsyncRtpModeStructInit
* modified.
* 46 09/12/2002 DJA Header for function zl5011xWanSetAsyncRtpMode
* fixed up.
* 47 13/12/2002 MRC Added control to allow Wan Tx clock to be sourced
* externally in unframed mode
* 48 06/02/2003 MRC Added DPLL output enable option for operation
* in sync master mode and inband PRS freq fn
* 49 17/02/2003 MRC Added BER functions
* 50 25/03/2003 MRC Added DPLL lock range control
* 51 03/04/2003 MRC Changed default clock polarities for LIU mode
* 52 29/04/2003 MRC Get and Set Tx freq can now be called in sync mode
* 53 27/05/2003 MRC Run for TIF block now takes place in
* WanConfigureSync/WanConfigureAsync
* 54 11/06/2003 MRC Added zl5011xWanRxGetPayloadLength fn and option
* to force the Wan Rx payload to be 64 bit aligned
* 55 26/06/2003 MRC Added function to calculate the payload size for
* unframed contexts
* 56 02/07/2003 MRC Updated structure comments
* 57 21/07/2003 MRC Added queue stats function
* 58 30/07/2003 APL Renamed packetToTdmMapping
* 59 11/08/2003 MRC Added channel combination checking
* 60 28/08/2003 MRC Fixed context create Rx CPU queue problem
* 61 18/11/2003 AMS Update
* 62 06/01/2004 MRC Reverted to revision 60
* 63 29/01/2004 MRC Amended the channel checking rule to check
* that a channel number is not duplicated
* 64 24/03/2004 APL In zl5011xWanTxQueueSlip if the payload size is
* insufficient to slip a whole frame then the return
* error is ZL5011X_PAYLOAD_SIZE_ERROR
* 65 20/04/2004 APL Payload size can be specified in bytes for unframed
* mode
* 66 20/04/2004 APL Added error status check in zl5011xWanRxPayloadConfig
* 67 14/07/2004 MRC Fixed problem deleting Wan Tx contexts that had
* not initialised.
* 68 21/07/2004 MRC Added Wan Tx clock source functions
* 69 26/07/2004 MRC Fixed some compiler warnings
* 70 29/07/2004 MRC Fixed some compiler warnings
* 71 04/08/2004 MRC Comment change for DCO bypass parameter
* 72 19/08/2004 MRC Added limits checking to payload calculation
* 73 25/08/2004 MRC Initialise PW variables on context creation.
* 74 26/08/2004 MRC Update PKC/context mappings on context create
* 75 15/09/2004 APL Offset the DCO on auxiliary stream where this
* exists
* 76 16/09/2004 APL Corrected comment in zl5011xWanRxGetPayloadLength
* 77 17/09/2004 MRC Added min/max statistics to zl5011xWanTxGetQueueStats
* 78 27/09/2004 MRC Added control for TDM_CLKiP freq to configureSync
* 79 20/10/2004 MRC Added PRS variable to async configure struct
* 80 16/11/2004 MRC Added individual stream frequency control
* 81 23/11/2004 APL Changed default behaviour for stream frequency
* 82 24/11/2004 APL Initialise per-stream parameter array properly
* 83 26/11/2004 MRC Use async style per-stream control for sync operation
* 84 16/12/2004 MRC Added clock reference mux function
* 85 17/12/2004 APL Initialise per-stream parameter array (sync mode)
* 86 21/01/2005 MRC zl5011xWanSetTxFreq can change nominal stream freq
* 87 28/01/2005 MRC Added option to use a GPIO pin to force WanTx
* context deletion and current queue length to
* function zl5011xWanTxGetQueueStats
* 88 14/02/2005 APL Previously static API function
* zl5011xUpdateRTPCurrentHeaderRecord is now available
* to other API files.
* 89 19/04/2005 MRC Added context check when forcing Tx teardown
* 90 06/05/2005 APL Added function zl5011xTdmGetCurrentSeqNum
* 91 12/05/2005 APL zl5011xWanSetTxFreq can now set zero frequency
* 92 17/05/2005 MRC Added function to return TDM queue counts and
* reset statistics upon context creation
* 93 08/06/2005 MRC Corrected function header
* 94 04/07/2005 MRC Added StreamClockConfig support for clock only streams
* 95 06/07/2005 MRC Turn on DCO's during configureSync function
* 96 21/07/2005 MRC Relaxed default PLL limits, to match settings used
* during device characterisation.
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011xApi.h"
#include "zl5011xMisc.h"
#include "zl5011xTdm.h"
#include "zl5011xLan.h"
#include "zl5011xTfqMap.h"
/***************** STATIC FUNCTION DECLARATIONS ***************************/
static zlStatusE zl5011xContextSetWanRxHostHeader(zl5011xParamsS *zl5011xParams,
zl5011xContextSetHostQueueS *par);
/***************** STATIC CONSTANTS ***************************/
#define ZL5011X_AUX_CLK_OFFSET 100000 /* +100 ppm for the auxiliary clock */
/***************** EXPORTED FUNCTION DEFINTIONS ***************************/
/*******************************************************************************
Function:
zl5011xContextCreateStructInit
Description:
Initialises structure used by zl5011xContextCreate functions.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items.
See main function
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xContextCreateStructInit(zl5011xParamsS *zl5011xParams, zl5011xContextCreateS *par)
{
zlStatusE status = ZL5011X_OK;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_TDM_FN_ID,
"zl5011xContextCreateStructInit:",
0, 0, 0, 0, 0, 0);
par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;
/* set an invalid default for the flow - the API will choose the
most suitable flow if this is not explicitly specified */
par->flow = (zl5011xFlowTypeE)ZL5011X_INVALID;
par->unframedStream.underrunMode = ZL5011X_WAN_USE_LAST_BYTE;
par->osExclusionEnable = ZL5011X_TRUE;
}
return status;
}
/*******************************************************************************
Function:
zl5011xContextCreateRx
Description:
Function to create a Wan Rx context (that is Wan Rx to the device).
Checks that the context is not currently in use and sets it to the INIT
state. For unframed operation, the context relates directly to the stream
number, so for this instance, also add the first channel (0) for the stream.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items. See below:
Structure inputs:
context context number for creation
flow routing through the device for the context - can be left as value
specified in StructInit function for default operation.
osExclusionEnable ZL5011X_TRUE to enable OS exclusion
Structure outputs:
None
Returns:
zlStatusE
Remarks:
Flows to the CPU are initialised to use CPU queue 3.
*******************************************************************************/
zlStatusE zl5011xContextCreateRx(zl5011xParamsS *zl5011xParams, zl5011xContextCreateS *par)
{
zlStatusE status = ZL5011X_OK;
zl5011xWanChannelS tdm;
zl5011xContextSetHostQueueS contextSetHostQueue;
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
{
/* get access to the device */
status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);
if (status == ZL5011X_OK)
{
gotDevice = ZL5011X_TRUE;
}
}
/* check that the Wan Rx context is valid */
if (status == ZL5011X_OK)
{
status = zl5011xContextCheckRx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_NUMBER);
}
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE_CONTEXT(ZL5011X_TDM_FN_ID, par->context,
"zl5011xContextCreateRx: ctxt %3d",
par->context, 0, 0, 0, 0, 0);
}
if (status == ZL5011X_OK)
{
/* if the context is tearing down, then check to see if it has completed */
if (zl5011xParams->wanIf.plaCurrent.context[par->context].state == ZL5011X_STATE_TEARING_DOWN)
{
status = zl5011xPlaCheckContextTeardown(zl5011xParams, par->context);
/* if the teardown has completed, then reset the error code and
continue */
if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
{
status = ZL5011X_OK;
}
}
}
if (status == ZL5011X_OK)
{
/* check that the context is not currently in use */
if (zl5011xParams->wanIf.plaCurrent.context[par->context].state != ZL5011X_STATE_NOT_IN_USE)
{
status = ZL5011X_CONTEXT_IN_USE;
}
}
if (status == ZL5011X_OK)
{
if (par->flow == (zl5011xFlowTypeE)ZL5011X_INVALID)
{
/* if the flow type has not been specified then set the default
for this direction */
zl5011xParams->wanIf.wanRxFlow[par->context] = ZL5011X_FLOW_WAN_PE_PKT;
}
else
{
zl5011xParams->wanIf.wanRxFlow[par->context] = par->flow;
}
zl5011xParams->wanIf.plaCurrent.context[par->context].state = ZL5011X_STATE_INIT;
/* new configuration so clear out any previous packet Tx header information */
zl5011xParams->packetIf.packetTx.txHeader[par->context].protocolType = ZL5011X_INVALID_PROTOCOL;
zl5011xParams->packetIf.packetTx.txHeader[par->context].highHeader[0].txHighLength = 0;
zl5011xParams->packetIf.packetTx.txHeader[par->context].highHeader[1].txHighLength = 0;
/* Initialise the payload size to exactly 1 frame. */
zl5011xParams->wanIf.plaCurrent.context[par->context].payloadFrames = 1;
zl5011xParams->wanIf.plaCurrent.context[par->context].payloadBytes = 0;
/* update the device structures idea of which is the current header */
status = zl5011xUpdateRTPCurrentHeaderRecord(zl5011xParams, par->context);
}
if (status == ZL5011X_OK)
{
/* reset the RTP statistics - packet Tx */
status = zl5011xRtpInitStatisticsTxEntry(zl5011xParams, par->context);
}
if (status == ZL5011X_OK)
{
/* setup the PLA flow and mpid as required for the flow type */
switch (par->flow)
{
case ZL5011X_FLOW_WAN_CPU :
/* set the CPU queue to queue 3 by default */
status = zl5011xContextSetHostQueueStructInit(zl5011xParams, &contextSetHostQueue);
if (status == ZL5011X_OK)
{
contextSetHostQueue.context = par->context;
contextSetHostQueue.cpuQueue = ZL5011X_QUEUE_0;
contextSetHostQueue.osExclusionEnable = ZL5011X_FALSE;
status = zl5011xContextSetHostQueue(zl5011xParams, &contextSetHostQueue);
}
break;
case ZL5011X_FLOW_WAN_PE_CPU :
/* set the mpid up as the context ID, since the mapping is one to one
into the RTP block */
status = zl5011xPlaSetFlowType(zl5011xParams, par->context, ZL5011X_FLOW_WAN_PE_CPU, par->context);
/* set the CPU queue to queue 3 by default */
if (status == ZL5011X_OK)
{
status = zl5011xContextSetHostQueueStructInit(zl5011xParams, &contextSetHostQueue);
}
if (status == ZL5011X_OK)
{
contextSetHostQueue.context = par->context;
contextSetHostQueue.cpuQueue = ZL5011X_QUEUE_0;
contextSetHostQueue.osExclusionEnable = ZL5011X_FALSE;
status = zl5011xContextSetHostQueue(zl5011xParams, &contextSetHostQueue);
}
break;
default :
status = zl5011xPlaSetFlowType(zl5011xParams, par->context,
zl5011xParams->wanIf.wanRxFlow[par->context], par->context);
}
}
/* if in unframed mode, then need to add the stream to the context now */
if ((status == ZL5011X_OK) && (zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED))
{
tdm.stream = (Uint8T)par->context;
tdm.channel = 0;
status = zl5011xPlaAddChan(zl5011xParams, par->context, tdm);
}
if (gotDevice == ZL5011X_TRUE)
{
if (status == ZL5011X_OK)
{
status = zl5011xReleaseDevice(zl5011xParams);
}
else
{
/* already have an error code, so don't overwrite it */
(void)zl5011xReleaseDevice(zl5011xParams);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -