summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2026-03-06 11:59:25 +0100
committerHiFiPhile <[email protected]>2026-03-06 11:59:25 +0100
commitc186063a6387ab6649fcc3e6e450ced854d20d03 (patch)
treeddd40172328355b10da04b84a5f97b5d706fe914 /src/common
parentee6f4f6f2a1f07db7c145551b779ce8cf878c2ac (diff)
parent06a4c6d7190ef83f76b2a65496f2a48a54a8c134 (diff)
Merge remote-tracking branch 'tinyusb/master' into samx7x_update
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_fifo.c19
-rw-r--r--src/common/tusb_fifo.h16
-rw-r--r--src/common/tusb_private.h12
3 files changed, 28 insertions, 19 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 9f188f296..8bd79e56d 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -30,11 +30,6 @@
#define TU_FIFO_DBG 0
-// Suppress IAR warning
-// Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
-#if defined(__ICCARM__)
- #pragma diag_suppress = Pa082
-#endif
#if OSAL_MUTEX_REQUIRED
@@ -496,7 +491,9 @@ uint16_t tu_fifo_peek_n_access_mode(tu_fifo_t *f, void *p_buffer, uint16_t n, ui
// Read n items without removing it from the FIFO, correct read pointer if overflowed
uint16_t tu_fifo_peek_n(tu_fifo_t *f, void *p_buffer, uint16_t n) {
ff_lock(f->mutex_rd);
- const uint16_t ret = tu_fifo_peek_n_access_mode(f, p_buffer, n, f->wr_idx, f->rd_idx, NULL);
+ const uint16_t wr_idx = f->wr_idx;
+ const uint16_t rd_idx = f->rd_idx;
+ const uint16_t ret = tu_fifo_peek_n_access_mode(f, p_buffer, n, wr_idx, rd_idx, NULL);
ff_unlock(f->mutex_rd);
return ret;
}
@@ -506,7 +503,8 @@ uint16_t tu_fifo_read_n_access_mode(tu_fifo_t *f, void *buffer, uint16_t n, cons
ff_lock(f->mutex_rd);
// Peek the data: f->rd_idx might get modified in case of an overflow so we can not use a local variable
- n = tu_fifo_peek_n_access_mode(f, buffer, n, f->wr_idx, f->rd_idx, access_mode);
+ const uint16_t wr_idx = f->wr_idx;
+ n = tu_fifo_peek_n_access_mode(f, buffer, n, wr_idx, f->rd_idx, access_mode);
f->rd_idx = advance_index(f->depth, f->rd_idx, n);
ff_unlock(f->mutex_rd);
@@ -633,7 +631,8 @@ static bool ff_peek_local(tu_fifo_t *f, void *buf, uint16_t wr_idx, uint16_t rd_
bool tu_fifo_read(tu_fifo_t *f, void *buffer) {
// Peek the data
// f->rd_idx might get modified in case of an overflow so we can not use a local variable
- const bool ret = ff_peek_local(f, buffer, f->wr_idx, f->rd_idx);
+ const uint16_t wr_idx = f->wr_idx;
+ const bool ret = ff_peek_local(f, buffer, wr_idx, f->rd_idx);
if (ret) {
ff_lock(f->mutex_rd);
f->rd_idx = advance_index(f->depth, f->rd_idx, 1);
@@ -645,7 +644,9 @@ bool tu_fifo_read(tu_fifo_t *f, void *buffer) {
// Read one item without removing it from the FIFO, correct read index if overflowed
bool tu_fifo_peek(tu_fifo_t *f, void *p_buffer) {
- return ff_peek_local(f, p_buffer, f->wr_idx, f->rd_idx);
+ const uint16_t wr_idx = f->wr_idx;
+ const uint16_t rd_idx = f->rd_idx;
+ return ff_peek_local(f, p_buffer, wr_idx, rd_idx);
}
// Write one element into the buffer
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 86ba59059..b31a0802e 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -120,9 +120,9 @@ typedef struct {
uint8_t *buffer; // buffer pointer
uint16_t depth; // max items
bool overwritable; // overwritable when full
- // 1 byte padding here
+ // 1 byte padding here
- volatile uint16_t wr_idx; // write index TODO maybe can drop volatile
+ volatile uint16_t wr_idx; // write index
volatile uint16_t rd_idx; // read index
#if OSAL_MUTEX_REQUIRED
@@ -291,16 +291,22 @@ TU_ATTR_ALWAYS_INLINE static inline bool tu_fifo_empty(const tu_fifo_t *f) {
// return number of items in fifo, capped to fifo's depth
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_count(const tu_fifo_t *f) {
- return tu_min16(tu_ff_overflow_count(f->depth, f->wr_idx, f->rd_idx), f->depth);
+ const uint16_t wr_idx = f->wr_idx;
+ const uint16_t rd_idx = f->rd_idx;
+ return tu_min16(tu_ff_overflow_count(f->depth, wr_idx, rd_idx), f->depth);
}
// check if fifo is full
TU_ATTR_ALWAYS_INLINE static inline bool tu_fifo_full(const tu_fifo_t *f) {
- return tu_ff_overflow_count(f->depth, f->wr_idx, f->rd_idx) >= f->depth;
+ const uint16_t wr_idx = f->wr_idx;
+ const uint16_t rd_idx = f->rd_idx;
+ return tu_ff_overflow_count(f->depth, wr_idx, rd_idx) >= f->depth;
}
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_remaining(const tu_fifo_t *f) {
- return tu_ff_remaining_local(f->depth, f->wr_idx, f->rd_idx);
+ const uint16_t wr_idx = f->wr_idx;
+ const uint16_t rd_idx = f->rd_idx;
+ return tu_ff_remaining_local(f->depth, wr_idx, rd_idx);
}
#ifdef __cplusplus
diff --git a/src/common/tusb_private.h b/src/common/tusb_private.h
index 43ce7a1df..5a51dfc37 100644
--- a/src/common/tusb_private.h
+++ b/src/common/tusb_private.h
@@ -24,8 +24,8 @@
* This file is part of the TinyUSB stack.
*/
-#ifndef TUSB_PRIVATE_H_
-#define TUSB_PRIVATE_H_
+#ifndef TUSB_PRIVATE_H
+#define TUSB_PRIVATE_H
// Internal Helper used by Host and Device Stack
@@ -33,9 +33,11 @@
extern "C" {
#endif
-//--------------------------------------------------------------------+
-// Configuration
-//--------------------------------------------------------------------+
+typedef void (*tusb_defer_func_t)(uintptr_t param);
+
+ //--------------------------------------------------------------------+
+ // Configuration
+ //--------------------------------------------------------------------+
#define TUP_USBIP_CONTROLLER_NUM 2
extern tusb_role_t _tusb_rhport_role[TUP_USBIP_CONTROLLER_NUM];