📄 ixqmgrqaccess.c
字号:
/** * @file IxQMgrQAccess.c * * @author Intel Corporation * @date 30-Oct-2001 * * @brief This file contains functions for putting entries on a queue and * removing entries from a queue. * * * @par * IXP400 SW Release version 2.0 * * -- Copyright Notice -- * * @par * Copyright 2001-2005, Intel Corporation. * All rights reserved. * * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @par * -- End of Copyright Notice --*//* * Inlines are compiled as function when this is defined. * N.B. Must be placed before #include of "IxQMgr.h" */#ifndef IXQMGR_H# define IXQMGRQACCESS_C#else# error#endif/* * System defined include files. *//* * User defined include files. */#include "IxQMgr.h"#include "IxQMgrAqmIf_p.h"#include "IxQMgrQAccess_p.h"#include "IxQMgrQCfg_p.h"#include "IxQMgrDefines_p.h"/* * Global variables and extern definitions */extern IxQMgrQInlinedReadWriteInfo ixQMgrQInlinedReadWriteInfo[];/* * Function definitions. */voidixQMgrQAccessInit (void){ }IX_STATUSixQMgrQReadWithChecks (IxQMgrQId qId, UINT32 *entry){ IxQMgrQEntrySizeInWords entrySizeInWords; IxQMgrQInlinedReadWriteInfo *infoPtr; if (NULL == entry) { return IX_QMGR_PARAMETER_ERROR; } /* Check QId */ if (!ixQMgrQIsConfigured(qId)) { return IX_QMGR_Q_NOT_CONFIGURED; } /* Get the q entry size in words */ entrySizeInWords = ixQMgrQEntrySizeInWordsGet (qId); ixQMgrAqmIfQPop (qId, entrySizeInWords, entry); /* reset the current read count if the counter wrapped around * (unsigned arithmetic) */ infoPtr = &ixQMgrQInlinedReadWriteInfo[qId]; if (infoPtr->qReadCount-- > infoPtr->qSizeInEntries) { infoPtr->qReadCount = 0; } /* Check if underflow occurred on the read */ if (ixQMgrAqmIfUnderflowCheck (qId)) { return IX_QMGR_Q_UNDERFLOW; } return IX_SUCCESS;}/* this function reads the remaining of the q entry * for queues configured with many words. * (the first word of the entry is already read * in the inlined function and the entry pointer already * incremented */IX_STATUSixQMgrQReadMWordsMinus1 (IxQMgrQId qId, UINT32 *entry){ IxQMgrQInlinedReadWriteInfo *infoPtr = &ixQMgrQInlinedReadWriteInfo[qId]; UINT32 entrySize = infoPtr->qEntrySizeInWords; volatile UINT32 *qAccRegAddr = infoPtr->qAccRegAddr; while (--entrySize) { /* read the entry and accumulate the result */ *(++entry) = IX_OSAL_READ_LONG(++qAccRegAddr); } /* underflow is available for lower queues only */ if (qId < IX_QMGR_MIN_QUEUPP_QID) { /* get the queue status */ UINT32 status = IX_OSAL_READ_LONG(infoPtr->qUOStatRegAddr); /* check the underflow status */ if (status & infoPtr->qUflowStatBitMask) { /* the queue is empty * clear the underflow status bit if it was set */ IX_OSAL_WRITE_LONG(infoPtr->qUOStatRegAddr, status & ~infoPtr->qUflowStatBitMask); return IX_QMGR_Q_UNDERFLOW; } } return IX_SUCCESS;}IX_STATUSixQMgrQWriteWithChecks (IxQMgrQId qId, UINT32 *entry){ IxQMgrQEntrySizeInWords entrySizeInWords; IxQMgrQInlinedReadWriteInfo *infoPtr; if (NULL == entry) { return IX_QMGR_PARAMETER_ERROR; } /* Check QId */ if (!ixQMgrQIsConfigured(qId)) { return IX_QMGR_Q_NOT_CONFIGURED; } /* Get the q entry size in words */ entrySizeInWords = ixQMgrQEntrySizeInWordsGet (qId); ixQMgrAqmIfQPush (qId, entrySizeInWords, entry); /* reset the current read count if the counter wrapped around * (unsigned arithmetic) */ infoPtr = &ixQMgrQInlinedReadWriteInfo[qId]; if (infoPtr->qWriteCount++ >= infoPtr->qSizeInEntries) { infoPtr->qWriteCount = infoPtr->qSizeInEntries; } /* Check if overflow occurred on the write*/ if (ixQMgrAqmIfOverflowCheck (qId)) { return IX_QMGR_Q_OVERFLOW; } return IX_SUCCESS;}IX_STATUSixQMgrQPeek (IxQMgrQId qId, unsigned int entryIndex, UINT32 *entry){ unsigned int numEntries;#ifndef NDEBUG if ((NULL == entry) || (entryIndex >= IX_QMGR_Q_SIZE_INVALID)) { return IX_QMGR_PARAMETER_ERROR; } if (!ixQMgrQIsConfigured(qId)) { return IX_QMGR_Q_NOT_CONFIGURED; }#endif if (IX_SUCCESS != ixQMgrQNumEntriesGet (qId, &numEntries)) { return IX_FAIL; } if (entryIndex >= numEntries) /* entryIndex starts at 0 */ { return IX_QMGR_ENTRY_INDEX_OUT_OF_BOUNDS; } return ixQMgrAqmIfQPeek (qId, entryIndex, entry);}IX_STATUSixQMgrQPoke (IxQMgrQId qId, unsigned entryIndex, UINT32 *entry){ unsigned int numEntries;#ifndef NDEBUG if ((NULL == entry) || (entryIndex > 128)) { return IX_QMGR_PARAMETER_ERROR; } if (!ixQMgrQIsConfigured(qId)) { return IX_QMGR_Q_NOT_CONFIGURED; }#endif if (IX_SUCCESS != ixQMgrQNumEntriesGet (qId, &numEntries)) { return IX_FAIL; } if (numEntries < (entryIndex + 1)) /* entryIndex starts at 0 */ { return IX_QMGR_ENTRY_INDEX_OUT_OF_BOUNDS; } return ixQMgrAqmIfQPoke (qId, entryIndex, entry);}IX_STATUSixQMgrQStatusGetWithChecks (IxQMgrQId qId, IxQMgrQStatus *qStatus){ if (NULL == qStatus) { return IX_QMGR_PARAMETER_ERROR; } if (!ixQMgrQIsConfigured (qId)) { return IX_QMGR_Q_NOT_CONFIGURED; } ixQMgrAqmIfQueStatRead (qId, qStatus); return IX_SUCCESS;}IX_STATUSixQMgrQNumEntriesGet (IxQMgrQId qId, unsigned *numEntriesPtr){ UINT32 qPtrs; UINT32 qStatus; unsigned numEntries; IxQMgrQInlinedReadWriteInfo *infoPtr;#ifndef NDEBUG if (NULL == numEntriesPtr) { return IX_QMGR_PARAMETER_ERROR; } /* Check QId */ if (!ixQMgrQIsConfigured(qId)) { return IX_QMGR_Q_NOT_CONFIGURED; }#endif /* get fast access data */ infoPtr = &ixQMgrQInlinedReadWriteInfo[qId]; /* get snapshot */ qPtrs = IX_OSAL_READ_LONG(infoPtr->qConfigRegAddr); /* Mod subtraction of pointers to get number of words in Q. */ numEntries = (qPtrs - (qPtrs >> 7)) & 0x7f; if (numEntries == 0) { /* * Could mean either full or empty queue * so look at status */ ixQMgrAqmIfQueStatRead (qId, &qStatus); if (qId < IX_QMGR_MIN_QUEUPP_QID) { if (qStatus & IX_QMGR_Q_STATUS_E_BIT_MASK) { /* Empty */ *numEntriesPtr = 0; } else if (qStatus & IX_QMGR_Q_STATUS_F_BIT_MASK) { /* Full */ *numEntriesPtr = infoPtr->qSizeInEntries; } else { /* * Queue status and read/write pointers are volatile. * The queue state has changed since we took the * snapshot of the read and write pointers. * Client can retry if they wish */ *numEntriesPtr = 0; return IX_QMGR_WARNING; } } else /* It is an upper queue which does not have an empty status bit maintained */ { if (qStatus & IX_QMGR_Q_STATUS_F_BIT_MASK) { /* The queue is Full at the time of snapshot. */ *numEntriesPtr = infoPtr->qSizeInEntries; } else { /* The queue is either empty, either moving, * Client can retry if they wish */ *numEntriesPtr = 0; return IX_QMGR_WARNING; } } } else { *numEntriesPtr = (numEntries / infoPtr->qEntrySizeInWords) & (infoPtr->qSizeInEntries - 1); } return IX_SUCCESS;}#if defined(__wince) && defined(NO_INLINE_APIS)PUBLIC IX_STATUSixQMgrQRead (IxQMgrQId qId, UINT32 *entryPtr){ extern IxQMgrQInlinedReadWriteInfo ixQMgrQInlinedReadWriteInfo[]; IxQMgrQInlinedReadWriteInfo *infoPtr = &ixQMgrQInlinedReadWriteInfo[qId]; UINT32 entry, entrySize; /* get a new entry */ entrySize = infoPtr->qEntrySizeInWords; entry = IX_OSAL_READ_LONG(infoPtr->qAccRegAddr); if (entrySize != IX_QMGR_Q_ENTRY_SIZE1) { *entryPtr = entry; /* process the remaining part of the entry */ return ixQMgrQReadMWordsMinus1(qId, entryPtr); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -