diff --git a/AppKit/fifo.c b/AppKit/fifo.c index bb6c94d..b637d23 100644 --- a/AppKit/fifo.c +++ b/AppKit/fifo.c @@ -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; } diff --git a/AppKit/fifo.h b/AppKit/fifo.h index b1f32bc..85a9203 100644 --- a/AppKit/fifo.h +++ b/AppKit/fifo.h @@ -13,7 +13,12 @@ #include #endif /*INCLUDED_OS_MACROS_H*/ +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ +#ifndef OS_CFG_FIFO_DEBUG_ENABLE +#define OS_CFG_FIFO_DEBUG_ENABLE 1 +#endif /* ==================================================================================================== */ /* 类型 */ @@ -24,6 +29,11 @@ typedef struct fifo_t{ os_size_t buffer_size; volatile os_size_t write_idx; volatile os_size_t read_idx; +#if defined(OS_CFG_FIFO_DEBUG_ENABLE) && (OS_CFG_FIFO_DEBUG_ENABLE==1) + volatile os_size_t high_water; /* 顶峰时期使用的字节数 */ + volatile os_size_t overflow_count; /* 请求遇到溢出的次数 */ +#endif + }fifo_t; #define FIFO_INVALID_POS ((os_size_t)(-1u)) diff --git a/Kernel/SingleCore/os_config.h.in b/Kernel/SingleCore/os_config.h.in index aa59c68..fe50dbc 100644 --- a/Kernel/SingleCore/os_config.h.in +++ b/Kernel/SingleCore/os_config.h.in @@ -22,7 +22,7 @@ #cmakedefine OS_CFG_CPU_FPU_PRESENT @OS_CFG_CPU_FPU_PRESENT@ #cmakedefine OS_CFG_CPU_MPU_PRESENT @OS_CFG_CPU_MPU_PRESENT@ - +#cmakedefine OS_CFG_FIFO_DEBUG_ENABLE @OS_CFG_FIFO_DEBUG_ENABLE@ /* ==================================================================================================== */ /* DEFAULT */ @@ -71,5 +71,8 @@ #define OS_CFG_CPU_MPU_PRESENT 0 #endif /* OS_CFG_CPU_MPU_PRESENT */ +#ifndef OS_CFG_FIFO_DEBUG_ENABLE +#define OS_CFG_FIFO_DEBUG_ENABLE 0 +#endif /* OS_CFG_FIFO_DEBUG_ENABLE */ #endif /*INCLUDED_OS_CONFIG_H*/