refactor osal queue API
This commit is contained in:
@@ -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[])
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user