diff options
| author | hathach <[email protected]> | 2018-02-28 16:45:54 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-02-28 16:45:54 +0700 |
| commit | 30124b9b02e067c967aca642823f3ed4cb7f618d (patch) | |
| tree | 5823eb3dfd498e85420d26b3924057bf272c42b4 /tinyusb/common | |
| parent | c961bb47feee422746f5aa81e48b00a50a4cbf0e (diff) | |
refactor osal queue API
Diffstat (limited to 'tinyusb/common')
| -rw-r--r-- | tinyusb/common/common.h | 6 | ||||
| -rw-r--r-- | tinyusb/common/fifo.c | 8 | ||||
| -rw-r--r-- | tinyusb/common/fifo.h | 20 |
3 files changed, 21 insertions, 13 deletions
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index 6481b33ad..a624b941f 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -109,6 +109,12 @@ #define memclr_(buffer, size) memset((buffer), 0, (size))
+#define memclr(buffer, size) memset(buffer, 0, size)
+#define varclr(_var) memclr(_var, sizeof(*(_var)))
+#define arrclr(_arr) memclr(_arr, sizeof(_arr))
+
+#define arrcount(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
+
static inline uint8_t const * descriptor_next(uint8_t const p_desc[]) ATTR_ALWAYS_INLINE ATTR_PURE;
static inline uint8_t const * descriptor_next(uint8_t const p_desc[])
{
diff --git a/tinyusb/common/fifo.c b/tinyusb/common/fifo.c index dd7a66298..8db3f04ac 100644 --- a/tinyusb/common/fifo.c +++ b/tinyusb/common/fifo.c @@ -83,7 +83,7 @@ static inline bool fifo_initalized(fifo_t* f) bool fifo_read(fifo_t* f, void * p_buffer)
{
if( !fifo_initalized(f) ) return false;
- if( fifo_is_empty(f) ) return false;
+ if( fifo_empty(f) ) return false;
mutex_lock_if_needed(f);
@@ -117,7 +117,7 @@ bool fifo_read(fifo_t* f, void * p_buffer) uint16_t fifo_read_n (fifo_t* f, void * p_buffer, uint16_t count)
{
if( !fifo_initalized(f) ) return false;
- if( fifo_is_empty(f) ) return false;
+ if( fifo_empty(f) ) return false;
/* Limit up to fifo's count */
count = min16_of(count, f->count);
@@ -192,7 +192,7 @@ bool fifo_peek_at(fifo_t* f, uint16_t position, void * p_buffer) bool fifo_write(fifo_t* f, void const * p_data)
{
if ( !fifo_initalized(f) ) return false;
- if ( fifo_is_full(f) && !f->overwritable ) return false;
+ if ( fifo_full(f) && !f->overwritable ) return false;
mutex_lock_if_needed(f);
@@ -202,7 +202,7 @@ bool fifo_write(fifo_t* f, void const * p_data) f->wr_idx = (f->wr_idx + 1) % f->depth;
- if (fifo_is_full(f))
+ if (fifo_full(f))
{
f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
}
diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h index f069c54af..e162b5d5e 100644 --- a/tinyusb/common/fifo.h +++ b/tinyusb/common/fifo.h @@ -78,13 +78,15 @@ */
typedef struct
{
- uint8_t* const buffer ; ///< buffer pointer
- uint16_t const depth ; ///< max items
- uint16_t const item_size ; ///< size of each item
- volatile uint16_t count ; ///< number of items in queue
- volatile uint16_t wr_idx ; ///< write pointer
- volatile uint16_t rd_idx ; ///< read pointer
- bool overwritable ;
+ uint8_t* buffer ; ///< buffer pointer
+ uint16_t depth ; ///< max items
+ uint16_t item_size ; ///< size of each item
+
+ volatile uint16_t count ; ///< number of items in queue
+ volatile uint16_t wr_idx ; ///< write pointer
+ volatile uint16_t rd_idx ; ///< read pointer
+
+ bool overwritable ;
#if CFG_FIFO_MUTEX
fifo_mutex_t * const mutex;
@@ -118,12 +120,12 @@ static inline bool fifo_peek(fifo_t* f, void * p_buffer) return fifo_peek_at(f, 0, p_buffer);
}
-static inline bool fifo_is_empty(fifo_t* f)
+static inline bool fifo_empty(fifo_t* f)
{
return (f->count == 0);
}
-static inline bool fifo_is_full(fifo_t* f)
+static inline bool fifo_full(fifo_t* f)
{
return (f->count == f->depth);
}
|
