fifo 支持水位监测和溢出次数统计
This commit is contained in:
+12
-2
@@ -9,18 +9,28 @@
|
||||
|
||||
// 在尾部写入数据
|
||||
os_err_t fifo_put(fifo_t* self, uint8_t data){
|
||||
|
||||
os_size_t write_idx = self->write_idx;
|
||||
|
||||
os_size_t next_write_idx = fifo_next(self, self->write_idx);
|
||||
|
||||
if(next_write_idx == self->read_idx){
|
||||
|
||||
#if defined(OS_CFG_FIFO_DEBUG_ENABLE) && (OS_CFG_FIFO_DEBUG_ENABLE==1)
|
||||
self->overflow_count++;
|
||||
#endif
|
||||
|
||||
return OS_ERR_FULL;
|
||||
}
|
||||
|
||||
self->buffer[write_idx] = data;
|
||||
self->write_idx = next_write_idx;
|
||||
|
||||
#if defined(OS_CFG_FIFO_DEBUG_ENABLE) && (OS_CFG_FIFO_DEBUG_ENABLE==1)
|
||||
os_size_t used = fifo_count(self);
|
||||
if (used > self->high_water) {
|
||||
self->high_water = used;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OS_ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user