📄 zl5011xtfq.c
字号:
}
/*****************************************************************************
Function:
zl5011xTfqGetNextError
Description:
This function is called from the interrupt routine to determine which
context caused the error. The device is then checked, to get the
current state of the interrupt bit.
It is the calling functions responsibility to ensure that there is an
entry on the interrupt queue - this is determined by checking that the
TFQ 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
Remarks:
None
*****************************************************************************/
zlStatusE zl5011xTfqGetNextError(zl5011xParamsS *zl5011xParams,
Uint32T *context, Uint32T *error)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFQ_FN_ID, "zl5011xTfqGetNextError", 0, 0, 0, 0, 0, 0);
status = zl5011xTfqGetErroredContext(zl5011xParams, context);
if (status == ZL5011X_OK)
{
status = zl5011xTfqGetError(zl5011xParams, *context, error);
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqEnableInterrupts
Description:
This function is used to enable the queue interrupt(s) for the given context.
Enable interrupts using this function by setting a ONE in the parameter.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context context to use
intMask interrupt bit= ONE in this parameter to enable interrupt
Outputs:
none
Returns:
zlStatusE
Remarks:
there is also the
*****************************************************************************/
zlStatusE zl5011xTfqEnableInterrupts(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T intMask)
{
zlStatusE status = ZL5011X_OK;
Uint32T regAddress, bitMask;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFQ_FN_ID, context, "zl5011xTfqEnableInterrupts: ctxt %3ld, mask %X",
context, intMask, 0, 0, 0, 0);
regAddress = ZL5011X_TFQ_CTXT_DYNAMIC_SETUP +
(context * ZL5011X_TFQ_CTXT_CONTROL_SIZE);
/* check that only the interrupt bit is set */
if ((intMask & ~(ZL5011X_1BIT_MASK << ZL5011X_TFQ_OVERFLOW_INT_ENABLE)) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* write to the device to enable the interrupt */
status = zl5011xReadModWrite(zl5011xParams, regAddress, 0, intMask);
}
/* record the state in the device structure */
if(status == ZL5011X_OK)
{
status = zl5011xRead(zl5011xParams, regAddress, &bitMask);
zl5011xParams->interruptMasks.wanTxQueueMask[ context] = bitMask;
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqDisableInterrupts
Description:
This function is used to disable the queue interrupt(s) for a given queue.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context context to use
intMask interrupt bit= ONE in this parameter to enable interrupt
Outputs:
none
Returns:
zlStatusE
Remarks:
See: zl5011xTfqEnableInterrupts
*****************************************************************************/
zlStatusE zl5011xTfqDisableInterrupts(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T intMask)
{
zlStatusE status = ZL5011X_OK;
Uint32T regAddress;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFQ_FN_ID, context, "zl5011xTfqDisableInterrupts: ctxt %3ld, mask %X",
context, intMask, 0, 0, 0, 0);
regAddress = ZL5011X_TFQ_CTXT_DYNAMIC_SETUP +
(context * ZL5011X_TFQ_CTXT_CONTROL_SIZE);
/* check that only the interrupt bit is set */
if ((intMask & ~(ZL5011X_1BIT_MASK << ZL5011X_TFQ_OVERFLOW_INT_ENABLE)) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* write to the device to disable the interrupt */
status = zl5011xReadModWrite(zl5011xParams, regAddress,
intMask, intMask);
}
/* record the state in the device structure */
if(status == ZL5011X_OK)
{
status = zl5011xRead(zl5011xParams, regAddress, &intMask);
zl5011xParams->interruptMasks.wanTxQueueMask[ context] = intMask;
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqClearGranuleThresholdIntr
Description:
This function is used to clear the interrupt status using the Acknowledge
reg.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
none
Returns:
zlStatusE
Remarks:
*****************************************************************************/
zlStatusE zl5011xTfqClearGranuleThresholdIntr(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFQ_FN_ID, "zl5011xTfqClearGranuleThresholdIntr: ",
0, 0, 0, 0, 0, 0);
status = zl5011xWrite(zl5011xParams, ZL5011X_TFQ_GRN_THRES_INTR_ACK,
ZL5011X_1BIT_MASK);
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqEnableGranuleThresholdIntr
Description:
This function is used to enable the granule threshold interrupt by setting
a ONE in the appropriate bit of the parameter.
Inputs:
zl5011xParams Pointer to the structure for this device instance
intMask interrupt bit= ONE in this parameter to enable interrupt
Outputs:
none
Returns:
zlStatusE
Remarks:
Active Low
*****************************************************************************/
zlStatusE zl5011xTfqEnableGranuleThresholdIntr(zl5011xParamsS *zl5011xParams,
Uint32T intMask)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFQ_FN_ID,"zl5011xTfqEnableGranuleThresholdIntr:"
"mask 0x%08lx", intMask, 0, 0, 0, 0, 0);
/* check that only the interrupt bit is set */
if ((intMask & ~(ZL5011X_1BIT_MASK << ZL5011X_TFQ_GRN_THRES_INTR_BIT)) > 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* write to the device to enable the interrupt */
status = zl5011xReadModWrite(zl5011xParams,
ZL5011X_TFQ_GRN_THRES_INTR_DISABLE, 0, intMask);
}
/* record the state in the device structure */
if( (status == ZL5011X_OK)&& (intMask > 0 ))
{
zl5011xParams->interruptMasks.TfqGranuleThresInterruptEnabled= ZL5011X_TRUE;
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqDisableGranuleThresholdIntr
Description:
This function is used to disable the granule threshold interrupt by setting
a ONE in the appropriate bit of the parameter.
Inputs:
zl5011xParams Pointer to the structure for this device instance
intMask interrupt bit= ONE in this parameter to disable interrupt
Outputs:
none
Returns:
zlStatusE
Remarks:
Active Low
*****************************************************************************/
zlStatusE zl5011xTfqDisableGranuleThresholdIntr(zl5011xParamsS *zl5011xParams,
Uint32T bits)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_TFQ_FN_ID,"zl5011xTfqDisableGranuleThresholdIntr:"
"bits 0x%08lx", bits, 0, 0, 0, 0, 0);
/* check that only the interrupt bit is set */
if ((bits & ~(ZL5011X_1BIT_MASK << ZL5011X_TFQ_GRN_THRES_INTR_BIT)) > 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* write to the device to disable the interrupt */
status = zl5011xReadModWrite(zl5011xParams,
ZL5011X_TFQ_GRN_THRES_INTR_DISABLE, bits, bits);
}
/* record the state in the device structure */
if( (status == ZL5011X_OK)&& (bits > 0 ))
{
zl5011xParams->interruptMasks.TfqGranuleThresInterruptEnabled= ZL5011X_TRUE;
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqGetReadPointer
Description:
Returns the sequence number for the context, of the packet currently being
played out. For FIFO queues, this is just a count value.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context Context to use
Outputs:
value sequence number
Returns:
zlStatusE
Remarks:
*****************************************************************************/
zlStatusE zl5011xTfqGetReadPointer(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T *value)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFQ_FN_ID, context,
"zl5011xTfqGetReadPointer: ctxt %d",
context, 0, 0, 0, 0, 0);
if(status == ZL5011X_OK)
{
/* read from the device */
status = zl5011xRead(zl5011xParams,
ZL5011X_TFQ_CTXT_READ_POINTER + (context * ZL5011X_TFQ_CTXT_CONTROL_SIZE),
&readValue);
if (zl5011xParams->wanIf.txQueue[context].queueMode == ZL5011X_WAN_TX_QUEUE_RESEQUENCE_8)
{
/* the top 16 bits are rollover, and the bottom 16 bits are the sequence number,
so for 8 bit mode, need to remove the top 8 bits of the bottom 16 bit word */
*value = ((readValue & 0xffff0000)>> 8) | (readValue & 0xff);
}
else
{
*value = readValue;
}
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqGetCurrentLength
Description:
Returns the current queue length for the context.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context Context to use
Outputs:
value queue length
Returns:
zlStatusE
Remarks:
*****************************************************************************/
zlStatusE zl5011xTfqGetCurrentLength(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T *value)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
ZL5011X_TRACE_CONTEXT(ZL5011X_TFQ_FN_ID, context,
"zl5011xTfqGetCurrentLength: ctxt %d",
context, 0, 0, 0, 0, 0);
if(status == ZL5011X_OK)
{
/* read from the device */
status = zl5011xRead(zl5011xParams,
ZL5011X_TFQ_CTXT_STATUS + (context * ZL5011X_TFQ_CTXT_CONTROL_SIZE),
&readValue);
*value = (readValue >> ZL5011X_TFQ_CURR_LENGTH_BITS) & ZL5011X_TFQ_CURR_LENGTH_MASK;
}
return(status);
}
/*****************************************************************************
Function:
zl5011xTfqFormatAvgLength
Description:
Converts the average queue length into an integer and fractional part
in base-10
Inputs:
avgLength The average length value, as returned by zl5011xTfqGetAvgLength
numDP The number of decimal places to convert (range 0-4)
Outputs:
intPart The integer part of the value
fracPart The fractional part of the value
Returns:
Nothing
Remarks:
The input value is in the format 10.16
An example of using this function:
// Get the average length
status = zl5011xTfqGetAvgLength(zl5011xParams, context, &readValue);
if (status == ZL5011X_OK)
{ // Convert to a usable format
Uint32T avgHi, avgLo;
zl5011xTfqFormatAvgLength(readValue, 1 , &avgHi, &avgLo); // One DP precision
printf("Avg len = %4ld.%01ld\n", avgHi, avgLo); // for clarity the second part of the format string
// is "%zero one ell dee". The width of the second part
// should match the selected precision in the line above
}
*****************************************************************************/
void zl5011xTfqFormatAvgLength(Uint32T avgLength, Uint32T numDP, Uint32T *intPart, Uint32T *fracPart)
{
Uint32T roundingValue; /* The amount to add to round to the required number of DP's */
Uint32T multiplier; /* Multiplier to convert fraction into base-10 with the
required number of decimal places. */
/* Algorithm overflows at numDP > 4 so limit the input value */
if (numDP > 4)
{
numDP = 4;
}
roundingValue = (1<<16) / 2;
multiplier = 1;
/* Calculate the multiplier to give the required number of decimal places and the rounding value */
while (numDP>0)
{
multiplier *= 10;
roundingValue /= 10;
numDP--;
}
/* Round up (assuming it will always be a positive number) */
avgLength += roundingValue;
/* Now separate the integer and fractional parts */
*intPart = avgLength >> 16; /* The integer part */
/* The fractional part of the input value is a fraction of 65536. Convert this into a corresponding
fraction of the multiplier */
*fracPart = ((avgLength & 0xFFFF) * multiplier) >> 16; /* The fractional part */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -