memring.h 文件
typedef struct _memring MEMRING;
struct _memring
{
int head;
int tail;
int length;
unsigned char *pring;
int (*dataLengthInRing)(struct _memring* );
int (*ringIsEmtpy)(struct _memring* );
int (*ringIsFull)(struct _memring* );
void(*dataPushRing)(struct _memring* ,unsigned char );
unsigned char (*dataPopRing)(struct _memring* );
};
memring.c 文件
#include "memring.h"
#include "2410add.h"
int memDataLengthInRing(struct _memring * memring)
{
unsigned int savereg;
int ret;
//disable all interrupt
savereg=rINTMSK;
rINTMSK=0XFFFFFFFF;
ret=(memring->length + memring->tail-memring->head ) % memring->length;
//recover
rINTMSK=savereg;
return ret;
}
int memRingIsEmpty(struct _memring * memring)
{
unsigned int savereg;
int ret;
//disable all interrupt
savereg=rINTMSK;
rINTMSK=0XFFFFFFFF;
ret=(memring->head == memring->tail);
//recover
rINTMSK=savereg;
return ret;
}
int memRingIsFull(struct _memring * memring)
{
unsigned int savereg;
int ret;
//disable all interrupt
savereg=rINTMSK;
rINTMSK=0XFFFFFFFF;
ret=( ((memring->tail+1) % memring->length ) == memring->head);
//recover
rINTMSK=savereg;
return ret;
}
void memDataPushRing(struct _memring * memring,unsigned char ch)
{
unsigned int savereg;
//disable all interrupt
savereg=rINTMSK;
rINTMSK=0XFFFFFFFF;
memring->pring[memring->tail] = (ch);
memring->tail = ( memring->tail + 1 ) % memring->length;
//recover
rINTMSK=savereg;
}
unsigned char memDataPopRing(struct _memring * memring)
{
unsigned int savereg;
unsigned char ch;
//disable all interrupt
savereg=rINTMSK;
rINTMSK=0XFFFFFFFF;
ch = memring->pring[memring->head];
memring->head = ( memring->head + 1 ) % memring->length;
//recover
rINTMSK=savereg;
return ch;
}
void memringCreat(struct _memring * memring,unsigned char * buff,int length)
{
memring->head = 0;
memring->tail = 0;
memring->length = length;
memring->pring = buff;
memring->dataLengthInRing = memDataLengthInRing;
memring->ringIsEmtpy = memRingIsEmpty;
memring->ringIsFull = memRingIsFull;
memring->dataPushRing = memDataPushRing;
memring->dataPopRing = memDataPopRing;
}
文章评论(0条评论)
登录后参与讨论