Fix: lab3 on-board problems

This commit is contained in:
2025-04-01 23:38:06 +08:00
parent 2af52f761c
commit c211d8cde2
7 changed files with 62 additions and 21 deletions

View File

@@ -24,11 +24,11 @@ int ringbuffer_push(ringbuffer_t *buf, uint8_t val)
return ERR_OUT_OF_BOUND;
*buf->write++ = val;
++buf->size;
if (buf->write == buf->data + buf->cap)
buf->write = buf->data;
++buf->size;
return NO_ERROR;
}
@@ -38,10 +38,18 @@ uint8_t ringbuffer_bump(ringbuffer_t *buf)
exit(ERR_INVALID_OP);
uint8_t ret = *buf->read++;
--buf->size;
if (buf->read == buf->data + buf->cap)
buf->read = buf->data;
--buf->size;
return ret;
}
uint8_t ringbuffer_peek(ringbuffer_t *buf)
{
if (buf->size == 0)
exit(ERR_INVALID_OP);
return *buf->read;
}