/********************************************************************************************************* queue *********************************************************************************************************/ struct queue { uint32_t max_size; uint8_t **pbase; uint32_t front; uint32_t rear; }; static int queue_init(struct queue *queue, int size) { queue->pbase = bios_malloc(sizeof(uint8_t *)*size); if(NULL == queue->pbase) { bios_err(": malloc error "); return -1; } queue->max_size = size; queue->front = 0; queue->rear = 0; return 0; } static int queue_is_empty(struct queue *queue) { if(queue->front == queue->rear) { return 1; } else { return 0; } } static int queue_is_full(struct queue *queue) { if((queue->rear +1)%queue->max_size == queue->front) { return 1; } else { return 0; } } static int queue_in(struct queue *queue, uint8_t *val) { if(queue_is_full(queue)) { bios_log("fe rx queue full "); return 0; } else { //bios_log("queue in %0x ", val); queue->pbase[queue->rear]= val; queue->rear=(queue->rear+1)%queue->max_size; return 1; } } static int queue_out(struct queue *queue, uint8_t **val) { if(queue_is_empty(queue)){ return 0; } else { *val = queue->pbase[queue->front]; //bios_log("queue out %0x ", *val); queue->front=(queue->front+1)%queue->max_size; return 1; } }