diff options
| author | hathach <[email protected]> | 2023-01-06 10:52:25 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2023-01-06 10:52:25 +0700 |
| commit | b42d298b8162de232b985879732e44d3c86c889f (patch) | |
| tree | 2bacfc31ceb09ea4c540a0f768eaf291cfc67980 /src/common/tusb_fifo.h | |
| parent | 660343d2001c0ee943bf3e24cab6f235d3930b33 (diff) | |
| parent | 6e23c596ccb381aa606103727d2f19247822f3a3 (diff) | |
Merge branch 'master' into fix-fifo-memory-overflow
Diffstat (limited to 'src/common/tusb_fifo.h')
| -rw-r--r-- | src/common/tusb_fifo.h | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h index 972d29d50..f1810e39c 100644 --- a/src/common/tusb_fifo.h +++ b/src/common/tusb_fifo.h @@ -42,15 +42,13 @@ extern "C" { // within a certain number (see tu_fifo_overflow()). #include "common/tusb_common.h" +#include "osal/osal.h" + +#define tu_fifo_mutex_t osal_mutex_t // mutex is only needed for RTOS // for OS None, we don't get preempted -#define CFG_FIFO_MUTEX (CFG_TUSB_OS != OPT_OS_NONE) - -#if CFG_FIFO_MUTEX -#include "osal/osal.h" -#define tu_fifo_mutex_t osal_mutex_t -#endif +#define CFG_FIFO_MUTEX OSAL_MUTEX_REQUIRED /* Write/Read index is always in the range of: * 0 .. 2*depth-1 @@ -122,7 +120,7 @@ typedef struct volatile uint16_t wr_idx ; ///< write index volatile uint16_t rd_idx ; ///< read index -#if CFG_FIFO_MUTEX +#if OSAL_MUTEX_REQUIRED tu_fifo_mutex_t mutex_wr; tu_fifo_mutex_t mutex_rd; #endif @@ -155,13 +153,18 @@ bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable); bool tu_fifo_clear(tu_fifo_t *f); bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable); -#if CFG_FIFO_MUTEX +#if OSAL_MUTEX_REQUIRED TU_ATTR_ALWAYS_INLINE static inline void tu_fifo_config_mutex(tu_fifo_t *f, tu_fifo_mutex_t wr_mutex, tu_fifo_mutex_t rd_mutex) { f->mutex_wr = wr_mutex; f->mutex_rd = rd_mutex; } + +#else + +#define tu_fifo_config_mutex(_f, _wr_mutex, _rd_mutex) + #endif bool tu_fifo_write (tu_fifo_t* f, void const * p_data); |
