#include "sys.h"
|
#include "gprs_message_queue.h"
|
|
|
|
|
|
// ³õʼ»¯¶ÓÁÐ
|
void initQueue(queue_t * queue_eg, GPRS_SEND_MESSAGE * message_addr)
|
{
|
queue_eg->head = 0; //¶ÓÍ·±ê־λ
|
queue_eg->tail = 0; //¶Óβ±ê־λ
|
queue_eg->queue_num = 0; //¶ÓÁÐÖÐÊý¾Ý¶àÉÙ
|
queue_eg->memory_block = message_addr;
|
}
|
|
//²åÈë¶ÓÁÐ
|
u8 enQueue(queue_t *hq, GPRS_SEND_MESSAGE ins)
|
{
|
int index;
|
u8 * qptr;
|
u8 * ins_ptr;
|
|
|
|
if(hq->queue_num == MESSAGE_NUM)
|
return QUEUE_FULL;
|
|
/**/
|
qptr = (u8 *)&hq->memory_block[hq->head];
|
ins_ptr = (u8 *)&ins;
|
if(hq->head == MESSAGE_NUM)
|
{
|
hq->head = 0;
|
}else
|
{
|
hq->head = hq->head + 1;
|
}
|
hq->queue_num = hq->queue_num + 1;
|
|
/*ÄÚ´æ¿é¸³Öµ*/
|
for(index = 0; index < sizeof(GPRS_SEND_MESSAGE); index ++)
|
{
|
*qptr = *ins_ptr;
|
qptr ++;
|
ins_ptr ++;
|
|
}
|
|
return QUEUE_OK;
|
}
|
|
|
/*´ÓÁÐ¶Ó È¡³öÊý*/
|
u8 outQueue(queue_t * hq, GPRS_SEND_MESSAGE * ins)
|
{
|
u8 * qptr;
|
u8 * ins_ptr;
|
int index;
|
|
|
if(hq->queue_num == 0)
|
return QUEUE_EMPTY;
|
|
|
qptr = (u8 *)&hq->memory_block[hq->tail];
|
ins_ptr = (u8 *)ins;
|
|
if(hq->tail == MESSAGE_NUM)
|
{
|
hq->tail = 0;
|
}else
|
{
|
hq->tail = hq->tail + 1;
|
}
|
|
hq->queue_num --;
|
|
/*ÄÚ´æ¿é¸³Öµ*/
|
for(index = 0; index < sizeof(GPRS_SEND_MESSAGE); index ++)
|
{
|
*ins_ptr = *qptr;
|
qptr ++;
|
ins_ptr ++;
|
|
}
|
|
return QUEUE_OK;
|
|
}
|
|
|
/*Çå³ýÁ´¶ÓÖеÄËùÓÐÔªËØ*/
|
|
void clearQueue(queue_t * hq, GPRS_SEND_MESSAGE * message_addr)
|
{
|
hq->head = 0; //¶ÓÍ·±ê־λ
|
hq->tail = 0; //¶Óβ±ê־λ
|
hq->queue_num = 0; //¶ÓÁÐÖÐÊý¾Ý¶àÉÙ
|
hq->memory_block = message_addr;
|
}
|