summaryrefslogtreecommitdiff
path: root/src/common/tusb_fifo.h
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-12-12 21:38:48 +0700
committerhathach <[email protected]>2025-12-12 21:38:48 +0700
commitbb1495966d189dc2fb001bc9f3b7908a02a971bb (patch)
tree63c5044798267aa414a1073f3f7c3976cae65797 /src/common/tusb_fifo.h
parent686e975e4737e668577a66213910841036422752 (diff)
parent02da4e81c77fd7e77ff0b92c616519358c6db4ee (diff)
Merge branch 'refs/heads/master' into audio_open
Diffstat (limited to 'src/common/tusb_fifo.h')
-rw-r--r--src/common/tusb_fifo.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 42f154bca..2e2a0db6f 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -157,8 +157,8 @@ typedef enum {
// Setup API
//--------------------------------------------------------------------+
bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_size, bool overwritable);
-bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);
-bool tu_fifo_clear(tu_fifo_t *f);
+void tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);
+void tu_fifo_clear(tu_fifo_t *f);
#if OSAL_MUTEX_REQUIRED
TU_ATTR_ALWAYS_INLINE static inline
@@ -224,10 +224,11 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_write_n(tu_fifo_t *f, const
//--------------------------------------------------------------------+
// return overflowable count (index difference), which can be used to determine both fifo count and an overflow state
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_ff_overflow_count(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx) {
- if (wr_idx >= rd_idx) {
- return (uint16_t)(wr_idx - rd_idx);
+ const int32_t diff = (int32_t)wr_idx - (int32_t)rd_idx;
+ if (diff >= 0) {
+ return (uint16_t)diff;
} else {
- return (uint16_t)(2 * depth - (rd_idx - wr_idx));
+ return (uint16_t)(2 * depth + diff);
}
}