summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-02-19 11:57:56 +0700
committerhathach <[email protected]>2021-02-19 11:57:56 +0700
commit2a04ee68b82d8857fc02974eab2c0557826d9f49 (patch)
treed6aadfff7c54bcf23cf5438e45f33bcb7a18d9cd /src
parentbe9f86ca9e538c7fff9a2347e3f8acbcf61642df (diff)
add TU_FIFO_INIT() to help with tu_fifo declaration
tu_fifo_clear() also reset max_pointer_idx and non_used_index_space
Diffstat (limited to 'src')
-rw-r--r--src/common/tusb_fifo.c2
-rw-r--r--src/common/tusb_fifo.h25
-rw-r--r--src/osal/osal_none.h17
-rw-r--r--src/osal/osal_pico.h15
4 files changed, 25 insertions, 34 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index e3c4d74c7..30629af71 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -598,6 +598,8 @@ bool tu_fifo_clear(tu_fifo_t *f)
{
tu_fifo_lock(f);
f->rd_idx = f->wr_idx = 0;
+ f->max_pointer_idx = 2*f->depth-1;
+ f->non_used_index_space = UINT16_MAX - f->max_pointer_idx;
tu_fifo_unlock(f);
return true;
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index c35b85a49..294378496 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -66,8 +66,8 @@ typedef struct
uint16_t item_size ; ///< size of each item
bool overwritable ;
- uint16_t non_used_index_space ; ///< required for non-power-of-two buffer length
uint16_t max_pointer_idx ; ///< maximum absolute pointer index
+ uint16_t non_used_index_space ; ///< required for non-power-of-two buffer length
volatile uint16_t wr_idx ; ///< write pointer
volatile uint16_t rd_idx ; ///< read pointer
@@ -78,16 +78,19 @@ typedef struct
} tu_fifo_t;
-#define TU_FIFO_DEF(_name, _depth, _type, _overwritable) \
- uint8_t _name##_buf[_depth*sizeof(_type)]; \
- tu_fifo_t _name = { \
- .buffer = _name##_buf, \
- .depth = _depth, \
- .item_size = sizeof(_type), \
- .overwritable = _overwritable, \
- .max_pointer_idx = 2*_depth-1, \
- .non_used_index_space = UINT16_MAX - (2*_depth-1), \
- }
+#define TU_FIFO_INIT(_buffer, _depth, _type, _overwritable) \
+{ \
+ .buffer = _buffer, \
+ .depth = _depth, \
+ .item_size = sizeof(_type), \
+ .overwritable = _overwritable, \
+ .max_pointer_idx = 2*(_depth)-1, \
+ .non_used_index_space = UINT16_MAX - (2*(_depth)-1) \
+}
+
+#define TU_FIFO_DEF(_name, _depth, _type, _overwritable) \
+ uint8_t _name##_buf[_depth*sizeof(_type)]; \
+ tu_fifo_t _name = TU_FIFO_INIT(_name##_buf, _depth, _type, _overwritable)
bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable);
bool tu_fifo_clear(tu_fifo_t *f);
diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h
index 1d170d2fa..ea6818621 100644
--- a/src/osal/osal_none.h
+++ b/src/osal/osal_none.h
@@ -130,18 +130,11 @@ typedef struct
typedef osal_queue_def_t* osal_queue_t;
// role device/host is used by OS NONE for mutex (disable usb isr) only
-#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
- uint8_t _name##_buf[_depth*sizeof(_type)]; \
- osal_queue_def_t _name = { \
- .role = _role, \
- .ff = { \
- .buffer = _name##_buf, \
- .depth = _depth, \
- .item_size = sizeof(_type), \
- .overwritable = false, \
- .max_pointer_idx = (2*(_depth))-1, \
- .non_used_index_space = 0xFFFF-((2*(_depth))-1),\
- }\
+#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
+ uint8_t _name##_buf[_depth*sizeof(_type)]; \
+ osal_queue_def_t _name = { \
+ .role = _role, \
+ .ff = TU_FIFO_INIT(_name##_buf, _depth, _type, false) \
}
// lock queue by disable USB interrupt
diff --git a/src/osal/osal_pico.h b/src/osal/osal_pico.h
index 79054ddfa..de964a7a0 100644
--- a/src/osal/osal_pico.h
+++ b/src/osal/osal_pico.h
@@ -115,17 +115,10 @@ typedef struct
typedef osal_queue_def_t* osal_queue_t;
// role device/host is used by OS NONE for mutex (disable usb isr) only
-#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
- uint8_t _name##_buf[_depth*sizeof(_type)]; \
- osal_queue_def_t _name = { \
- .ff = { \
- .buffer = _name##_buf, \
- .depth = _depth, \
- .item_size = sizeof(_type), \
- .overwritable = false, \
- .max_pointer_idx = 2*_depth-1, \
- .non_used_index_space = UINT16_MAX - (2*_depth-1), \
- }\
+#define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \
+ uint8_t _name##_buf[_depth*sizeof(_type)]; \
+ osal_queue_def_t _name = { \
+ .ff = TU_FIFO_INIT(_name##_buf, _depth, _type, false) \
}
// lock queue by disable USB interrupt