?? zl5011xgm.c
字號:
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_GM_GRANULE_TAIL,
index << ZL5011X_GM_GRANULE_TAIL_BITS);
zl5011xParams->packetMemory.granuleTailIndex = index;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmGetTailGranule
Description:
Gets the index number of the tail granule.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
index gets the index number of the tail granule
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmGetTailGranule(zl5011xParamsS *zl5011xParams, Uint32T *index)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmGetTailGranule:", 0, 0, 0, 0, 0, 0);
status = zl5011xRead(zl5011xParams, ZL5011X_GM_GRANULE_TAIL,
&readValue);
if (status == ZL5011X_OK)
{
*index = (readValue >> ZL5011X_GM_GRANULE_TAIL_BITS) & ZL5011X_GM_GRANULE_INDEX_MASK;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmGetTailGranule: index %d", *index, 0, 0, 0, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmSetNumFreeGranules
Description:
Sets the number of available granules.
Inputs:
zl5011xParams Pointer to the structure for this device instance
count sets the total number of granules available
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmSetNumFreeGranules(zl5011xParamsS *zl5011xParams, Uint32T count)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmSetNumFreeGranules: count %d", count, 0, 0, 0, 0, 0);
/* if the count value passed in is a bad number, or does not tie up with the
tail and head pointers, then return an error */
if ((count & ~ZL5011X_GM_GRANULE_COUNT_MASK) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_GM_GRANULE_COUNT,
count << ZL5011X_GM_GRANULE_COUNT_BITS);
zl5011xParams->packetMemory.granuleCount = count;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmGetNumFreeGranules
Description:
Gets the number of available granules.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
count gets the total number of granules available
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmGetNumFreeGranules(zl5011xParamsS *zl5011xParams, Uint32T *count)
{
zlStatusE status = ZL5011X_OK;
Uint32T readValue;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmGetNumFreeGranules: ", 0, 0, 0, 0, 0, 0);
status = zl5011xRead(zl5011xParams, ZL5011X_GM_GRANULE_COUNT,
&readValue);
if (status == ZL5011X_OK)
{
*count = (readValue >> ZL5011X_GM_GRANULE_COUNT_BITS) & ZL5011X_GM_GRANULE_COUNT_MASK;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmGetNumFreeGranules: count %d", *count, 0, 0, 0, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmSetGranuleThreshold
Description:
Sets the granule threshold, which is used to generate an interrupt.
Inputs:
zl5011xParams Pointer to the structure for this device instance
count granule threshold.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmSetGranuleThreshold(zl5011xParamsS *zl5011xParams, Uint32T count)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmSetGranuleThreshold: count %d", count, 0, 0, 0, 0, 0);
/* if the threshold value passed in is a bad number, or is not less than the total
number of granules, then return an error */
if (((count & ~ZL5011X_GM_GRANULE_THRESHOLD_MASK) != 0) ||
(count > (zl5011xParams->packetMemory.granuleTailIndex - zl5011xParams->packetMemory.granuleHeadIndex + 1)))
{
status = ZL5011X_PARAMETER_INVALID;
}
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, ZL5011X_GM_GRANULE_THRESHOLD,
count << ZL5011X_GM_GRANULE_THRESHOLD_BITS);
}
zl5011xParams->packetMemory.granuleThreshold = count;
return(status);
}
/*******************************************************************************
Function:
zl5011xGmCheckGranules
Description:
Checks the granule chain for errors.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
This function can only be run when no granule chain operations are being
performed - that is, the device should be in freeze state.
*******************************************************************************/
zlStatusE zl5011xGmCheckGranules(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
Uint32T headPtr, tailPtr, numGranules;
Uint32T loop;
Uint32T currPtr, address;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmCheckGranules:", 0, 0, 0, 0, 0, 0);
/* get the current granule info from the device */
status = zl5011xGmGetTailGranule(zl5011xParams, &tailPtr);
if (status == ZL5011X_OK)
{
status = zl5011xGmGetHeadGranule(zl5011xParams, &headPtr);
}
if (status == ZL5011X_OK)
{
status = zl5011xGmGetNumFreeGranules(zl5011xParams, &numGranules);
}
/* check that there aren't more free granules than when the device
was initialised */
if (status == ZL5011X_OK)
{
if ((zl5011xParams->packetMemory.granuleTailIndex > zl5011xParams->packetMemory.granuleCount) ||
(zl5011xParams->packetMemory.granuleHeadIndex > zl5011xParams->packetMemory.granuleCount))
{
status = ZL5011X_NUM_FREE_GRANULES_ERROR;
}
}
/* starting at the head of the granule chain, check that the chain
is consistent and that the tail pointer is correct */
currPtr = headPtr;
for (loop = 0; loop < numGranules; loop++)
{
/* check that haven't reached the end of the chain yet */
if ((status != ZL5011X_OK) || (currPtr == tailPtr))
{
break;
}
address = zl5011xParams->packetMemory.granDescBaseAddr +
(currPtr * ZL5011X_GRANULE_DESCRIPTOR_SIZE);
status = zl5011xRead(zl5011xParams, address, &currPtr);
currPtr = (currPtr >> ZL5011X_GRANULE_NEXT_GRN_BITS) & ZL5011X_GRANULE_NEXT_GRN_MASK;
if (currPtr > zl5011xParams->packetMemory.granuleCount + 1)
{
status = ZL5011X_GRANULE_CHAIN_ERROR;
}
}
if (status == ZL5011X_OK)
{
/* the loop been exited on the tail pointer, so check that the loop
had completed i.e. the tail is at the end of the chain */
if ((loop != numGranules) || (currPtr != tailPtr))
{
status = ZL5011X_GRANULE_CHAIN_ERROR;
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmEnableInterrupts
Description:
This function is used to enable granule interrupts.
Inputs:
zl5011xParams Pointer to the structure for this device instance
interruptMask interrupt bit= ONE in this parameter to enable an interrupt
Outputs:
None
Returns:
zlStatusE
Remarks:
clear the intr reg by reading the value back. Assume this is correct method.
*******************************************************************************/
zlStatusE zl5011xGmEnableInterrupts(zl5011xParamsS *zl5011xParams,
Uint32T interruptMask)
{
zlStatusE status = ZL5011X_OK;
Uint32T bitMask, readValue;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmEnableInterrupts: enable %08X", interruptMask, 0, 0, 0, 0, 0);
bitMask = (ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_ERROR_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_OVERRUN_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_THRESHOLD_INT);
if ((interruptMask & ~bitMask) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* read the value back from the register, to clear - I hope */
status = zl5011xRead(zl5011xParams, ZL5011X_GM_INTERRUPT_STATUS, &readValue);
}
if(status == ZL5011X_OK)
{
/* clear the mask bits from the parameter to enable the interrupt */
status = zl5011xReadModWrite(zl5011xParams,
ZL5011X_GM_INTERRUPT_MASK,
0, interruptMask);
}
if(status == ZL5011X_OK)
{
/* read the value back from the register, to save in the device structure */
status = zl5011xRead(zl5011xParams, ZL5011X_GM_INTERRUPT_MASK,
&readValue);
/* mask out the bits that aren't to do with the interrupts */
readValue &= bitMask;
zl5011xParams->interruptMasks.gmMask = readValue;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmDisableInterrupts
Description:
This function is used to disable granule interrupts.
Inputs:
zl5011xParams Pointer to the structure for this device instance
interruptMask interrupt bit= ONE in this parameter to disable an interrupt
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmDisableInterrupts(zl5011xParamsS *zl5011xParams,
Uint32T interruptMask)
{
zlStatusE status = ZL5011X_OK;
Uint32T bitMask, readValue;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmDisableInterrupts: disable %08X", interruptMask, 0, 0, 0, 0, 0);
bitMask = (ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_ERROR_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_OVERRUN_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_THRESHOLD_INT);
if ((interruptMask & ~bitMask) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
if(status == ZL5011X_OK)
{
/* set the mask bits from the parameter to disable the interrupt */
status = zl5011xReadModWrite(zl5011xParams,
ZL5011X_GM_INTERRUPT_MASK,
interruptMask, interruptMask);
}
if(status == ZL5011X_OK)
{
/* read the value back from the register, to save in the device structure */
status = zl5011xRead(zl5011xParams, ZL5011X_GM_INTERRUPT_MASK,
&readValue);
/* mask out the bits that aren't to do with the interrupts */
readValue &= bitMask;
zl5011xParams->interruptMasks.gmMask = readValue;
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGmGetStatus
Description:
Returns the value from the status register
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
gmStatus returns the status of the interrupt bits
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGmGetStatus(zl5011xParamsS *zl5011xParams, Uint32T *gmStatus)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_GM_FN_ID, "zl5011xGmGetStatus:", 0, 0, 0, 0, 0, 0);
status = zl5011xRead(zl5011xParams, ZL5011X_GM_INTERRUPT_STATUS, gmStatus);
*gmStatus &= (ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_ERROR_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_OVERRUN_INT) |
(ZL5011X_1BIT_MASK << ZL5011X_GM_GRANULE_THRESHOLD_INT);
return(status);
}
/***************** END ****************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -