/*
* 写和读的时候分别操作的是不同的指针,因此中断信号的写和程序读互相干扰的情况难发生
*/
//-------------ring buffer definitions------------
#define GPRS_RING_BUF_LEN 256
volatile uint8 gprsDatBuf [GPRS_RING_BUF_LEN];
uint16 gprsDatFirstIdx = 0;
uint16 gprsDatEndIdx = 0; //指向的是最后一个有效数据之后的那块内存
uint8 gprsDatLineBuf[256];
uint16 gprsDatLineLength = 0;
static uint16 inline bytes_in_use() {
if (gprsDatEndIdx >= gprsDatFirstIdx) {
return gprsDatEndIdx - gprsDatFirstIdx;
} else {
return (GPRS_RING_BUF_LEN - gprsDatFirstIdx) + gprsDatEndIdx;
}
}
static boolean inline gprs_buf_append(uint8 c) {
if (bytes_in_use() < GPRS_RING_BUF_LEN - 1) {//Always Keep One Slot Open。见维基百科。
gprsDatEndIdx=(gprsDatEndIdx+1) % GPRS_RING_BUF_LEN;
gprsDatBuf[gprsDatEndIdx] = c;
return TRUE;
}
return FALSE;
}
static boolean inline gprs_buf_pop_head(uint8* c) {
if (bytes_in_use() == 0) {
return FALSE;
}
gprsDatFirstIdx = (gprsDatFirstIdx+1) % GPRS_RING_BUF_LEN;
*c = gprsDatBuf[gprsDatFirstIdx];
return TRUE;
}
* 写和读的时候分别操作的是不同的指针,因此中断信号的写和程序读互相干扰的情况难发生
*/
//-------------ring buffer definitions------------
#define GPRS_RING_BUF_LEN 256
volatile uint8 gprsDatBuf [GPRS_RING_BUF_LEN];
uint16 gprsDatFirstIdx = 0;
uint16 gprsDatEndIdx = 0; //指向的是最后一个有效数据之后的那块内存
uint8 gprsDatLineBuf[256];
uint16 gprsDatLineLength = 0;
static uint16 inline bytes_in_use() {
if (gprsDatEndIdx >= gprsDatFirstIdx) {
return gprsDatEndIdx - gprsDatFirstIdx;
} else {
return (GPRS_RING_BUF_LEN - gprsDatFirstIdx) + gprsDatEndIdx;
}
}
static boolean inline gprs_buf_append(uint8 c) {
if (bytes_in_use() < GPRS_RING_BUF_LEN - 1) {//Always Keep One Slot Open。见维基百科。
gprsDatEndIdx=(gprsDatEndIdx+1) % GPRS_RING_BUF_LEN;
gprsDatBuf[gprsDatEndIdx] = c;
return TRUE;
}
return FALSE;
}
static boolean inline gprs_buf_pop_head(uint8* c) {
if (bytes_in_use() == 0) {
return FALSE;
}
gprsDatFirstIdx = (gprsDatFirstIdx+1) % GPRS_RING_BUF_LEN;
*c = gprsDatBuf[gprsDatFirstIdx];
return TRUE;
}