roundbuf.c
来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 152 行
C
152 行
/****************************************************************
** *
** FILE : RoundBuf.C *
** COPYRIGHT : (c) 2004 .Xiamen Yaxon NetWork CO.LTD *
** *
** *
****************************************************************/
#include "includes.h"
#include "roundbuf.h"
#include "zprint.h"
#include "errtask.h"
void InitRoundBuf(ROUNDBUF_STRUCT *round, INT8U *mem, INT32U memsize, ASMRULE_STRUCT *rule)
{
round->bufsize = memsize;
round->used = 0;
round->bptr = mem;
round->eptr = mem + memsize;
round->wptr = round->rptr = round->bptr;
round->rule = rule;
}
void ResetRoundBuf(ROUNDBUF_STRUCT *round)
{
round->used = 0;
round->rptr = round->wptr = round->bptr;
}
INT8U *RoundBufStartPos(ROUNDBUF_STRUCT *round)
{
return round->bptr;
}
BOOLEAN WriteRoundBuf(ROUNDBUF_STRUCT *round, INT8U data)
{
if(NULL == round) ErrExit(0x5788);
if (round->used >= round->bufsize) return FALSE;
*round->wptr++ = data;
if (round->wptr >= round->eptr) round->wptr = round->bptr;
OS_ENTER_CRITICAL();
round->used++;
OS_EXIT_CRITICAL();
return TRUE;
}
INT32S ReadRoundBuf(ROUNDBUF_STRUCT *round)
{
INT32S ret;
if (round->used == 0) return -1;
ret = *round->rptr++;
if (round->rptr >= round->eptr) round->rptr = round->bptr;
OS_ENTER_CRITICAL();
round->used--;
OS_EXIT_CRITICAL();
return ret;
}
INT32S ReadRoundBufNoMVPtr(ROUNDBUF_STRUCT *round)
{
if (round->used == 0) return -1;
else return *round->rptr;
}
INT32U LeftOfRoundBuf(ROUNDBUF_STRUCT *round)
{
return (round->bufsize - round->used);
}
INT32U UsedOfRoundBuf(ROUNDBUF_STRUCT *round)
{
return round->used;
}
INT32U UsedOfRoundBuf2(ROUNDBUF_STRUCT *round)
{
return round->used;
}
BOOLEAN WriteBlockRoundBuf(ROUNDBUF_STRUCT *round, INT8U *bptr, INT32U blksize)
{
if (blksize > LeftOfRoundBuf(round)) return FALSE;
for (; blksize > 0; blksize--) {
*round->wptr++ = *bptr++;
if (round->wptr >= round->eptr) round->wptr = round->bptr;
OS_ENTER_CRITICAL();
round->used++;
OS_EXIT_CRITICAL();
}
return TRUE;
}
INT32U DeassembleRoundBuf(ROUNDBUF_STRUCT *round, INT8U *dptr, INT32U maxlen)
{
INT8U *rptr;
INT8U cur, pre;
INT32U used, ct;
INT32S rlen;
if (round->rule == NULL) return 0;
rlen = -1;
ct = 0;
rptr = round->rptr;
used = round->used;
while (used > 0) {
cur = *rptr++;
used--;
ct++;
if (rptr >= round->eptr) rptr = round->bptr;
if (rlen == -1) { /* search flags */
if (cur == round->rule->c_flags) {
rlen = 0;
pre = 0;
}
continue;
} else if (rlen == 0) {
if (cur == round->rule->c_flags) continue;
} else {
if (cur == round->rule->c_flags) {
round->rptr = rptr;
round->used -= ct;
return rlen;
}
}
if (pre == round->rule->c_convert0) { /* search convert character */
if (cur == round->rule->c_convert1) /* c_flags = c_convert0 + c_convert1 */
*dptr++ = round->rule->c_flags;
else if (cur == round->rule->c_convert2) /* c_convert0 = c_convert0 + c_convert2 */
*dptr++ = round->rule->c_convert0;
else {
round->rptr = rptr; /* detect error frame! */
round->used -= ct;
rlen = -1;
continue;
}
} else {
if (cur != round->rule->c_convert0) /* search convert character */
*dptr++ = cur;
rlen++;
}
pre = cur;
if (rlen >= maxlen) {
round->rptr = rptr;
round->used -= ct;
rlen = -1;
continue;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?