?? zl5011xrtp.c
字號:
/*******************************************************************************
*
* File name: zl5011xRtp.c
*
* Version: 38
*
* Author: PJE
*
* Date created: 22/05/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description: RTP functions
* The RTP block adds layer 4 and 5 headers, with
* dynamic fields that are relevant to UDP and RTP. If a context does not
* require the layer 4 and 5 headers, then the flow type can be set, so that
* the RTP block is not included in the data path.
*
*
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 24/05/2002 PJE Written easy bits - compiles ok
* 2 29/05/2002 PJE Update
* 3 29/05/2002 PJE added more - still debugging/writing
* 4 30/05/2002 PJE after debugging - not including statistics fns.
* 5 10/06/2002 LCW Update
* 6 10/06/2002 MRC Modified header structure for set header fn
* 7 11/06/2002 MRC Moved header structure and fixed timestamp fns
* 8 11/06/2002 MRC Primary and secondary headers are actually stored
* in banks rather than consecutively
* 9 17/06/2002 MRC CSW bit sense was wrong
* 10 21/06/2002 MRC Improved check on RTP header address
* 11 25/06/2002 LCW Update
* 12 26/06/2002 LCW Minor mods.
* 13 26/06/2002 LCW Fixed compilation error
* 14 28/06/2002 LCW Code review actions
* 15 12/07/2002 MRC Rewrote the statistics functions
* 16 12/07/2002 MRC Statistics addressing fixed
* 17 15/07/2002 MRC Statistics addressing for Init fn fixed
* 18 16/07/2002 PJE correction to zl5011xRtpGetStatisticsAddress
* 19 22/07/2002 MRC Actions following review
* 20 23/07/2002 MRC Added block ID register
* 21 31/07/2002 MRC Timestamp field must be 32 bit aligned for 32 bit
* timestamps, so simplified the get and seed fns
* 22 01/08/2002 MRC Used specific mask for the RTP interrupt period
* 23 16/08/2002 MRC Added control to allow the Tx RTP timestamp to be
* derived from the WAN interface.
* 24 23/08/2002 PJE mod to zl5011xRtpSetHeader - setting CES header
* 25 02/10/2002 PJE multiple define now ZL5011X_ADM_RTP_STATS_INTERRUPT
* 26 25/10/2002 PJE API tidy up
* 27 31/10/2002 MRC Added variants + minor fixes
* 28 09/06/2003 DJA Performed pre-audit actions
* 29 29/07/2003 APL Added support for variants with no TDM
* including using only one header in RTP
* Renamed global wanLimits structure to devLimits
* 30 04/07/2003 APL Removed layer5TimestampFromWan for variants with no TDM
* 31 07/08/2003 APL Audit action - modified comment
* 32 05/09/2003 APL ZL50130 device should use Primary RTP header
* 33 05/09/2003 APL Updated version history
* 34 23/07/2004 MRC Fixed some compiler warnings
* 35 29/07/2004 MRC Fixed some compiler warnings
* 36 16/12/2004 MRC Removed TS increment check when using TS from WAN
* 37 06/05/2005 APL Added function to get last tx sequence number
* 38 17/05/2005 MRC Added functions to reset Rx and Tx statistics and
* fixed endianness of get seq num function
*
*******************************************************************************/
/***************** INCLUDE FILES ******************************************/
#include "zl5011x.h"
#include "zl5011xRtp.h"
#include "zl5011xRtpMap.h"
#include "zl5011xAdm.h"
#include "zl5011xAdmMap.h"
#include "zl5011xUtilLib.h"
/***************** # DEFINES **********************************************/
/***************** STATIC FUNCTION DECLARATIONS ***************************/
/***************** STATIC GLOBAL VARIABLES ********************************/
/***************** EXPORTED GLOBAL VARIABLES ******************************/
/***************** EXPORTED FUNCTION DEFINTIONS ***************************/
/*******************************************************************************
Function:
zl5011xRtpInit
Description:
Called at initialisation time.
Resets the granule timeout to a default value.
Disables reporting.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpInit(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
Uint32T loop;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID, "zl5011xRtpInit:", 0, 0, 0, 0, 0, 0);
/* Reset the granule timeout to a default value. */
status = zl5011xRtpSetGranuleTimeout( zl5011xParams, ZL5011X_RTP_DEFAULT_GRN_TIMEOUT);
/* Disable reporting. */
if (status == ZL5011X_OK)
{
status = zl5011xRtpDisableReporting(zl5011xParams);
}
/* set the block ID. This is only used for debugging TM messages. */
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_RTP_BLOCK_ID,
ZL5011X_RTP_SOURCE_BLOCK_ID);
}
if (status == ZL5011X_OK)
{
for (loop = 0; loop < ZL5011X_PKT_TX_NUM_CONTEXT_HEADERS; loop++)
{
zl5011xParams->packetIf.packetTx.txHeader[loop].protocolType = ZL5011X_INVALID_PROTOCOL;
zl5011xParams->packetIf.packetTx.txHeader[loop].highHeader[0].txHighLength = 0;
zl5011xParams->packetIf.packetTx.txHeader[loop].highHeader[1].txHighLength = 0;
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpConfigure
Description:
Sets up the statistics table base address and the header base address
and initialises the statistics structures.
Inputs:
zl5011xParams Pointer to the structure for this device instance
statistics table base address
header base address
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpConfigure(zl5011xParamsS *zl5011xParams,
Uint32T statsBaseAddr, Uint32T txHeaderBaseAddr)
{
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID, "zl5011xRtpConfigure:", 0, 0, 0, 0, 0, 0);
/* Sets up the statistics table base address */
status = zl5011xRtpSetStatisticsBaseAddress( zl5011xParams, statsBaseAddr);
/* Sets up the Tx per-context data strucure base address */
if (status == ZL5011X_OK)
{
status = zl5011xRtpSetHeaderBaseAddress( zl5011xParams, txHeaderBaseAddr);
}
/* initialises the statistics structures */
if (status == ZL5011X_OK)
{
for (loop = 0; loop < ZL5011X_MAX_NUMBER_CONTEXTS; loop++)
{
status = zl5011xRtpInitStatisticsEntry(zl5011xParams, loop);
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpSetGranuleTimeout
Description:
Enables and sets the granule timeout during the granule request or release
process
Inputs:
zl5011xParams Pointer to the structure for this device instance
timeout The granule timeout in terms of clock cycles
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpSetGranuleTimeout(zl5011xParamsS *zl5011xParams,
Uint32T timeout)
{
zlStatusE status = ZL5011X_OK;
Uint32T rtpAddress=ZL5011X_RTP_CONFIG1;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID, "zl5011xRtpSetGranuleTimeout: value 0x%.8lx",
timeout, 0, 0, 0, 0, 0);
/* Range check for timeout parameter */
if (timeout > ZL5011X_RTP_MAX_GRANULE_TIMEOUT)
{
status = ZL5011X_PARAMETER_INVALID;
}
/* for any non-zero value enable the timeout */
if ((timeout > 0) && (status == ZL5011X_OK))
{
timeout |= ZL5011X_1BIT_MASK<< ZL5011X_RTP_GRN_TIMEOUT_ENABLE;
}
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, rtpAddress, timeout);
}
if (status == ZL5011X_OK)
{
/* update structure */
zl5011xParams->rtp.granuleTimeout= timeout;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpSetStatisticsBaseAddress
Description:
The address is used as the top 13 bits of the external memory address
for accessing the statistics structure.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Uint32T statsBaseAddr
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpSetStatisticsBaseAddress(zl5011xParamsS *zl5011xParams,
Uint32T statsBaseAddr)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits, bitMask;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID,
"zl5011xRtpSetStatisticsBaseAddress: value 0x%.8lx",
statsBaseAddr, 0, 0, 0, 0, 0);
if ((statsBaseAddr & ~(ZL5011X_RTP_MM_RTPS_MASK << ZL5011X_RTP_MM_RTPS_DROP_BITS)) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
bits = statsBaseAddr >> ZL5011X_RTP_MM_RTPS_DROP_BITS;
bitMask = ZL5011X_RTP_MM_RTPS_MASK << ZL5011X_RTP_MM_RTPS_BADDR;
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_RTP_CONFIG0,
bits << ZL5011X_RTP_MM_RTPS_BADDR, bitMask);
/* update structure */
zl5011xParams -> rtp.rtpStatsBaseAddress = statsBaseAddr;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpSetHeaderBaseAddress
Description:
Constructs and sets the header base address.
Inputs:
zl5011xParams Pointer to the structure for this device instance
headerBaseAddr The address to be set in bytes
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpSetHeaderBaseAddress(zl5011xParamsS *zl5011xParams,
Uint32T headerBaseAddr)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits, bitMask;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID,
"zl5011xRtpSetHeaderBaseAddress: value 0x%.8lx",
headerBaseAddr, 0, 0, 0, 0, 0);
if ((headerBaseAddr & ~(ZL5011X_RTP_MM_RTPTX_MASK << ZL5011X_RTP_MM_RTPTX_DROP_BITS)) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
bits = headerBaseAddr >> ZL5011X_RTP_MM_RTPTX_DROP_BITS;
bitMask = ZL5011X_RTP_MM_RTPTX_MASK << ZL5011X_RTP_MM_RTPTX_BADDR;
status = zl5011xReadModWrite(zl5011xParams, ZL5011X_RTP_CONFIG0,
bits << ZL5011X_RTP_MM_RTPTX_BADDR, bitMask);
/* update structure */
zl5011xParams->rtp.rtpTxHeaderBaseAddress = headerBaseAddr;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpGetInterruptStatus
Description:
The RTP block generates an interrupt to indicate that the counters have
rolled over. The rollover is detected by a scanning function inside the
RTP block, which checks for the roll overs. The minimum interval between
the interrupts is set using the function RtpSetInterruptPeriod.
If this is the first interrupt for a context, then the sequence number held
in the interrupt register is the first sequence number. This is stored
straight into the device structure.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
Pcontext The context associated with the interrupt
pRollFlags Flags to indicate counter roll over
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
extern zlStatusE zl5011xRtpGetInterruptStatus(zl5011xParamsS *zl5011xParams,
Uint32T *pContext,
Uint32T *pRollFlags)
{
zlStatusE status = ZL5011X_OK;
Uint32T rtpData;
ZL5011X_TRACE(ZL5011X_RTP_FN_ID,
"zl5011xRtpGetInterruptStatus:",
0, 0, 0, 0, 0, 0);
/* read stats reg */
status = zl5011xRead(zl5011xParams, ZL5011X_RTP_STATS0, &rtpData );
if (status == ZL5011X_OK)
{
/* get context and flags */
*pContext= rtpData & ZL5011X_RTP_INTERRUPT_CTXT_MASK;
*pRollFlags= rtpData & ZL5011X_RTP_ROLLOVER_FLAGS_MASK;
if (*pContext > zl5011xParams->devLimits.numContexts)
{
status = ZL5011X_RTP_INTERRUPT_ERROR;
}
}
if (status == ZL5011X_OK)
{
if (zl5011xParams->rtp.rtpSwCounts[*pContext].rxFirstSequenceNumber == (Uint32T)ZL5011X_INVALID)
{
zl5011xParams->rtp.rtpSwCounts[*pContext].rxFirstSequenceNumber =
(rtpData >> ZL5011X_RTP_FIRST_SEQ_NO_BITS) & ZL5011X_RTP_FIRST_SEQ_NO_MASK;
ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, *pContext,
"zl5011xRtpGetInterruptStatus: ctxt %3d, first packet seq %04X",
*pContext, zl5011xParams->rtp.rtpSwCounts[*pContext].rxFirstSequenceNumber, 0, 0, 0, 0);
}
}
ZL5011X_TRACE_CONTEXT(ZL5011X_RTP_FN_ID, *pContext,
"zl5011xRtpGetInterruptStatus: ctxt %3d, flags 0x%.8lx",
*pContext, *pRollFlags, 0, 0, 0, 0);
return(status);
}
/*******************************************************************************
Function:
zl5011xRtpSetInterruptPeriod
Description:
This sets the interrupt interval and disables the random distribution
function.
Inputs:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -