** QUEUE_EMPTY:无消息 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/ uint8 QueueRead(uint8 *pRet, void *Buf) {
uint8 err; uint16 i;
DataQueue *Queue;
err = NOT_OK;
if (Buf != NULL) /* 队列是否有效 */ { /* 有效 */
Queue = (DataQueue *)Buf;
OS_ENTER_CRITICAL();
if (Queue->nRecNum > 0) /* 队列是否为空 */ { /* 不空 */
for( i = 0; i < Queue->nBytesPerRec; i++ ) *pRet++ = *Queue->pOut++; /* 数据出队 */ /* 调整出队指针 */
if (Queue->pOut >= Queue->pEnd) {
Queue->pOut = Queue->Buf; }
Queue->nRecNum--; /* 数据减少*/ err = QUEUE_OK; } else { /* 空 */
err = QUEUE_EMPTY;
if (Queue->ReadEmpty != NULL) /* 调用用户处理函数 */ {
err = Queue->ReadEmpty(pRet, Queue); } }
OS_EXIT_CRITICAL(); } return err; }
/*********************************************************************************************************
** 函数名称: QueueWrite ** 功能描述: FIFO方式发送数据 ** 输 入: Buf :指向队列的指针 ** pRec:写入记录的首地址 ** 输 出: NOT_OK :参数错误 ** QUEUE_FULL:队列满 ** QUEUE_OK :发送成功 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/ uint8 QueueWrite(void *Buf, uint8* pRec) {
uint8 err; uint16 i;
DataQueue *Queue;
err = NOT_OK;
if (Buf != NULL) /* 队列是否有效 */ {
Queue = (DataQueue *)Buf;
OS_ENTER_CRITICAL();
if (Queue->nRecNum < Queue->nMaxRecNum) /* 队列是否满 */ { /* 不满 */
for( i = 0; i < Queue->nBytesPerRec; i++ ) *Queue->pIn++ = *pRec++; /* 数据入队 */ /* 调整入队指针 */
if (Queue->pIn >= Queue->pEnd) {
Queue->pIn = Queue->Buf; }
Queue->nRecNum++; /* 数据增加 */ err = QUEUE_OK; } else { /* 满 */
err = QUEUE_FULL;
if (Queue->WriteFull != NULL) /* 调用用户处理函数 */ {
err = Queue->WriteFull(Queue, *pRec, Q_WRITE_MODE); } }
OS_EXIT_CRITICAL();
} return err; }
/********************************************************************************************************* ** 函数名称: QueueWriteFront ** 功能描述: LIFO方式发送数据 ** 输 入: Buf:指向队列的指针 ** pRec:写入记录的首地址 ** 输 出: QUEUE_FULL:队列满 ** QUEUE_OK:发送成功 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/
uint8 QueueWriteFront(void *Buf, uint8 *pRec) {
uint8 err; uint16 i;
DataQueue *Queue;
err = NOT_OK;
if (Buf != NULL) /* 队列是否有效 */ {
Queue = (DataQueue *)Buf;
OS_ENTER_CRITICAL();
if (Queue->nRecNum < Queue->nMaxRecNum) /* 队列是否满 */ { /* 不满 */
Queue->pOut--; /* 调整出队指针 */ if (Queue->pOut < Queue->Buf) {
Queue->pOut = Queue->pEnd - 1; }
for( i = 0; i < Queue->nBytesPerRec; i++ ) /* 不满 */
*Queue->pOut-- = *( pRec + Queue->nBytesPerRec - 1 - i ); /* 数据入队 */ Queue->pOut++;
Queue->nRecNum++; /* 数据数目增加 */ err = QUEUE_OK; } else { /* 满 */
err = QUEUE_FULL;
if (Queue->WriteFull != NULL) /* 调用用户处理函数 */ {
err = Queue->WriteFull(Queue, *pRec, Q_WRITE_FRONT_MODE); } }
OS_EXIT_CRITICAL(); } return err; }
/********************************************************************************************************* ** 函数名称: QueueRecNum ** 功能描述: 取得队列中记录数 ** 输 入: Buf:指向队列的指针 ** 输 出: 消息数 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/ uint16 QueueRecNum(void *Buf) {
uint16 temp;
temp = 0; /* 队列无效返回0 */ if (Buf != NULL) {
OS_ENTER_CRITICAL();
temp = ((DataQueue *)Buf)->nRecNum; OS_EXIT_CRITICAL(); }
return temp; }
/********************************************************************************************************* ** 函数名称: QueueMaxRecNum ** 功能描述: 取得队列记录总容量 ** 输 入: Buf:指向队列的指针 ** 输 出: 队列记录总容量 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/ uint16 QueueMaxRecNum(void *Buf)
{
uint16 temp;
temp = 0; /* 队列无效返回0 */ if (Buf != NULL) {
OS_ENTER_CRITICAL();
temp = ((DataQueue *)Buf)->nMaxRecNum; OS_EXIT_CRITICAL(); }
return temp; }
/********************************************************************************************************* ** 函数名称: OSQFlush ** 功能描述: 清空队列 ** 输 入: Buf:指向队列的指针 ** 输 出: 无 ** 全局变量: 无
** 调用模块: OS_ENTER_CRITICAL,OS_EXIT_CRITICAL
********************************************************************************************************/ void QueueFlush(void *Buf) {
DataQueue *Queue;
if (Buf != NULL) /* 队列是否有效 */ { /* 有效*/
Queue = (DataQueue *)Buf; OS_ENTER_CRITICAL(); Queue->pOut = Queue->Buf; Queue->pIn = Queue->Buf;
Queue->nRecNum = 0; /* 数据数目为0 */ OS_EXIT_CRITICAL(); } }