📄 zl5011xtfm.c
字号:
zlStatusE zl5011xTfmEnableInterrupts(zl5011xParamsS *zl5011xParams, Uint32T context,
Uint32T intBits)
{
zlStatusE status = ZL5011X_OK;
Uint32T bitMask, temp;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmEnableInterrupts: ctxt %3d, mask %08X",
context, intBits, 0, 0, 0, 0);
bitMask = (ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_INT);
if ((intBits & ~bitMask) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
status = zl5011xRead(zl5011xParams,
ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
&temp);
}
if (status == ZL5011X_OK)
{
/* check against mask (active LOW) */
if ((( ~temp) & intBits) != intBits)
{
/* the interrupt bits are to be changed, so check that neither
update or teardown are pending */
if ((temp & (ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_BIT)) != 0)
{
status = ZL5011X_CONTEXT_IN_UPDATE;
}
if ((temp & (ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_BIT)) != 0)
{
status = ZL5011X_CONTEXT_IN_TEARDOWN;
}
}
/* Clear the error bit which drives the requested interrupt */
if (status == ZL5011X_OK)
{
bitMask = 0;
if( (intBits & (ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_INT)) != 0)
{
bitMask|= ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_ERR;
}
if( (intBits & (ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_INT)) != 0)
{
bitMask|= ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_ERR;
}
if( (intBits & (ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_INT)) != 0)
{
bitMask|= ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_ERR;
}
status = zl5011xWrite(zl5011xParams,
ZL5011X_TFM_CONTEXT_ERROR + (context * ZL5011X_TFM_CTXT_MEM_SIZE), bitMask);
}
if (status == ZL5011X_OK)
{
/* if don't need to change the interrupt bits then don't */
if ((( ~temp) & intBits) != intBits)
{
status = zl5011xWrite(zl5011xParams,
ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
temp & ~intBits);
/* record the state in the device structure */
zl5011xParams->interruptMasks.tfmMask[context] = temp & ~intBits;
}
}
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmGetErroredContext
Description:
This function is called to get a context ID from the interrupt queue.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
context ID from the interrupt queue
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmGetErroredContext(zl5011xParamsS *zl5011xParams,
Uint32T *context)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
status = zl5011xRead(zl5011xParams, ZL5011X_TFM_INT_ERROR_QUEUE,
&readValue);
*context = (readValue >> ZL5011X_TFM_INT_QUEUE_CTXT_BITS) & ZL5011X_TFM_CONTEXT_MASK;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmGetErroredContext: ctxt %3d",
*context, 0, 0, 0, 0, 0);
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmGetError
Description:
Collects the error flags for a context, and resets them.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context which context to collect the
Outputs:
error bits are set to indicate the source of the error
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmGetError(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T *error)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
status = zl5011xRead(zl5011xParams,
ZL5011X_TFM_CONTEXT_ERROR + (context * ZL5011X_TFM_CTXT_ERR_SIZE),
&readValue);
if (status == ZL5011X_OK)
{
/* Isolate the bits we are interested in here */
readValue = readValue & ((ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_ERR) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_ERR) |
(ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_ERR));
/* map from the error bit positions to the interrupt mask positions */
*error = 0;
if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_ERR)) != 0)
{
*error |= ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_INT;
}
if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_ERR)) != 0)
{
*error |= ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_INT;
}
if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_ERR)) != 0)
{
*error |= ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_INT;
}
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmGetError: ctxt %3d, flags %X",
context, *error, 0, 0, 0, 0);
/* clear the error bits by writing to the register */
status = zl5011xWrite(zl5011xParams,
ZL5011X_TFM_CONTEXT_ERROR + (context * ZL5011X_TFM_CTXT_ERR_SIZE),
readValue);
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmGetNextError
Description:
This function is called from the interrupt routine to determine which
context caused the error. The error flags are returned.
It is the calling functions responsibility to ensure that there is an
entry on the interrupt queue - this is determined by checking that the
TFM is issuing an interrupt.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
context context for which interrupt occured
error bits are set to indicate the source of the error
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmGetNextError(zl5011xParamsS *zl5011xParams,
Uint32T *context, Uint32T *error)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmGetNextError:", 0, 0, 0, 0, 0, 0);
status = zl5011xTfmGetErroredContext(zl5011xParams, context);
if (status == ZL5011X_OK)
{
status = zl5011xTfmGetError(zl5011xParams, *context, error);
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmGetNextInfo
Description:
This function is called from the interrupt routine to determine which
context has had a state change.
It is the calling functions responsibility to ensure that there is an
entry on the interrupt queue - this is determined by checking that the
TFM is issuing an interrupt.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
context context for which interrupt occured
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmGetNextInfo(zl5011xParamsS *zl5011xParams,
Uint32T *context)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmGetNextInfo:", 0, 0, 0, 0, 0, 0);
status = zl5011xRead(zl5011xParams, ZL5011X_TFM_INT_INFO_QUEUE,
&readValue);
*context = (readValue >> ZL5011X_TFM_INT_QUEUE_CTXT_BITS) & ZL5011X_TFM_CONTEXT_MASK;
ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmGetNextInfo: ctxt %3d",
*context, 0, 0, 0, 0, 0);
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmSetJitterBufferTime
Description:
The depth is set in bytes for unframed modes, unless bit stuffing is
in use - then it is frames. It is measures in frames for framed modes.
This calculates the jitter buffer setting required for a given time in
us. That is, for a 10ms jitter buffer, the time required would be 10000.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context which context to get the length for.
timeInUs jitter buffer depth in us
Outputs:
None
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmSetJitterBufferTime(zl5011xParamsS *zl5011xParams, Uint32T context,
Uint32T timeInUs)
{
zlStatusE status = ZL5011X_OK;
Uint32T jitterBuffer;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
"zl5011xTfmSetJitterBufferTime: ctxt %3d, time %dus",
context, timeInUs, 0, 0, 0, 0);
if (status == ZL5011X_OK)
{
if ((zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED) &&
(zl5011xParams->wanIf.wanBitStuffingEnabled == ZL5011X_FALSE))
{
/* if unframed and not bit stuffing, then the jitter buffer
depth is measured in bytes.
The calculation is (time_us / 1000000) * (freq / 8) */
jitterBuffer = (timeInUs / 10) * (zl5011xParams->wanIf.clock.async.stream[context].streamFrequency / 8000);
/* now do the final divide by 100 */
jitterBuffer /= 100;
}
else
{
/* the jitter buffer depth is measured in frames. Frames are at 8kHz, so the
sum is (timeInUs / 1000000) x frame rate */
jitterBuffer = timeInUs / 125;
}
status = zl5011xTfmSetJitterBuffer(zl5011xParams, context, jitterBuffer);
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfmSetJitterBuffer
Description:
The depth is set in bytes for unframed modes, unless bit stuffing is
in use - then it is frames. It is measures in frames for framed modes.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context which context to get the length for.
depth jitter buffer depth
Outputs:
None
Returns:
zlStatusE
*****************************************************************************/
zlStatusE zl5011xTfmSetJitterBuffer(zl5011xParamsS *zl5011xParams, Uint32T context,
Uint32T depth)
{
zlStatusE status = ZL5011X_OK;
Uint32T bitMask;
Uint32T bits;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
"zl5011xTfmSetJitterBuffer: ctxt %3d, depth %d",
context, depth, 0, 0, 0, 0);
if ((depth & ~ZL5011X_TFM_JITTER_BUF_MASK) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
bits = depth << ZL5011X_TFM_JITTER_BUF_BITS;
bitMask = ZL5011X_TFM_JITTER_BUF_MASK << ZL5011X_TFM_JITTER_BUF_BITS;
status = zl5011xReadModWrite(zl5011xParams,
ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
bits, bitMask);
if (status == ZL5011X_OK)
{
zl5011xParams->wanIf.tfmCurrent.context[context].jitterDepth = depth;
}
}
return(status);
}
/***************** END ****************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -