rename fifo * to tu_fifo to avoid conflict with other module

This commit is contained in:
hathach 2018-07-04 00:22:15 +07:00
parent ec3227b220
commit 3e66d2d31e
5 changed files with 77 additions and 77 deletions

View File

@ -71,8 +71,8 @@ typedef struct {
CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t _tmp_rx_buf[64];
CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t _tmp_tx_buf[64];
FIFO_DEF(_rx_ff, CFG_TUD_CDC_RX_BUFSIZE, uint8_t, true);
FIFO_DEF(_tx_ff, CFG_TUD_CDC_TX_BUFSIZE, uint8_t, false);
TU_FIFO_DEF(_rx_ff, CFG_TUD_CDC_RX_BUFSIZE, uint8_t, true);
TU_FIFO_DEF(_tx_ff, CFG_TUD_CDC_TX_BUFSIZE, uint8_t, false);
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@ -104,18 +104,18 @@ void tud_n_cdc_get_line_coding (uint8_t rhport, cdc_line_coding_t* coding)
//--------------------------------------------------------------------+
uint32_t tud_n_cdc_available(uint8_t rhport)
{
return fifo_count(&_rx_ff);
return tu_fifo_count(&_rx_ff);
}
int8_t tud_n_cdc_read_char(uint8_t rhport)
{
int8_t ch;
return fifo_read(&_rx_ff, &ch) ? ch : (-1);
return tu_fifo_read(&_rx_ff, &ch) ? ch : (-1);
}
uint32_t tud_n_cdc_read(uint8_t rhport, void* buffer, uint32_t bufsize)
{
return fifo_read_n(&_rx_ff, buffer, bufsize);
return tu_fifo_read_n(&_rx_ff, buffer, bufsize);
}
//--------------------------------------------------------------------+
@ -124,12 +124,12 @@ uint32_t tud_n_cdc_read(uint8_t rhport, void* buffer, uint32_t bufsize)
uint32_t tud_n_cdc_write_char(uint8_t rhport, char ch)
{
return fifo_write(&_tx_ff, &ch) ? 1 : 0;
return tu_fifo_write(&_tx_ff, &ch) ? 1 : 0;
}
uint32_t tud_n_cdc_write(uint8_t rhport, void const* buffer, uint32_t bufsize)
{
return fifo_write_n(&_tx_ff, buffer, bufsize);
return tu_fifo_write_n(&_tx_ff, buffer, bufsize);
}
bool tud_n_cdc_flush (uint8_t rhport)
@ -137,7 +137,7 @@ bool tud_n_cdc_flush (uint8_t rhport)
uint8_t edpt = _cdcd_itf[rhport].ep_in;
VERIFY( !dcd_edpt_busy(rhport, edpt) ); // skip if previous transfer not complete
uint16_t count = fifo_read_n(&_tx_ff, _tmp_tx_buf, sizeof(_tmp_tx_buf));
uint16_t count = tu_fifo_read_n(&_tx_ff, _tmp_tx_buf, sizeof(_tmp_tx_buf));
VERIFY( tud_n_cdc_connected(rhport) ); // fifo is empty if not connected
@ -230,8 +230,8 @@ void cdcd_close(uint8_t rhport)
// no need to close opened pipe, dcd bus reset will put controller's endpoints to default state
memclr_(&_cdcd_itf[rhport], sizeof(cdcd_interface_t));
fifo_clear(&_rx_ff);
fifo_clear(&_tx_ff);
tu_fifo_clear(&_rx_ff);
tu_fifo_clear(&_tx_ff);
}
tusb_error_t cdcd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request)
@ -282,7 +282,7 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
if ( ep_addr == p_cdc->ep_out )
{
fifo_write_n(&_rx_ff, _tmp_rx_buf, xferred_bytes);
tu_fifo_write_n(&_rx_ff, _tmp_rx_buf, xferred_bytes);
// preparing for next
TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, _tmp_rx_buf, sizeof(_tmp_rx_buf)), TUSB_ERROR_DCD_EDPT_XFER );

View File

@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file fifo.c
@file tusb_fifo.c
@author hathach (tinyusb.org)
@section LICENSE
@ -44,8 +44,8 @@
*------------------------------------------------------------------*/
#if CFG_FIFO_MUTEX
#define mutex_lock_if_needed(_ff) if (_ff->mutex) fifo_mutex_lock(_ff->mutex)
#define mutex_unlock_if_needed(_ff) if (_ff->mutex) fifo_mutex_unlock(_ff->mutex)
#define mutex_lock_if_needed(_ff) if (_ff->mutex) tu_fifo_mutex_lock(_ff->mutex)
#define mutex_unlock_if_needed(_ff) if (_ff->mutex) tu_fifo_mutex_unlock(_ff->mutex)
#else
@ -59,13 +59,13 @@ static inline uint16_t min16_of(uint16_t x, uint16_t y)
return (x < y) ? x : y;
}
static inline bool fifo_initalized(fifo_t* f)
static inline bool tu_fifo_initalized(tu_fifo_t* f)
{
return (f->buffer != NULL) && (f->depth > 0) && (f->item_size > 0);
}
void fifo_config(fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
void tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable)
{
mutex_lock_if_needed(f);
@ -96,10 +96,10 @@ void fifo_config(fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bo
@returns TRUE if the queue is not empty
*/
/******************************************************************************/
bool fifo_read(fifo_t* f, void * p_buffer)
bool tu_fifo_read(tu_fifo_t* f, void * p_buffer)
{
if( !fifo_initalized(f) ) return false;
if( fifo_empty(f) ) return false;
if( !tu_fifo_initalized(f) ) return false;
if( tu_fifo_empty(f) ) return false;
mutex_lock_if_needed(f);
@ -130,10 +130,10 @@ bool fifo_read(fifo_t* f, void * p_buffer)
@returns number of items read from the FIFO
*/
/******************************************************************************/
uint16_t fifo_read_n (fifo_t* f, void * p_buffer, uint16_t count)
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count)
{
if( !fifo_initalized(f) ) return 0;
if( fifo_empty(f) ) return 0;
if( !tu_fifo_initalized(f) ) return 0;
if( tu_fifo_empty(f) ) return 0;
/* Limit up to fifo's count */
count = min16_of(count, f->count);
@ -149,7 +149,7 @@ uint16_t fifo_read_n (fifo_t* f, void * p_buffer, uint16_t count)
uint8_t* p_buf = (uint8_t*) p_buffer;
uint16_t len = 0;
while( (len < count) && fifo_read(f, p_buf) )
while( (len < count) && tu_fifo_read(f, p_buf) )
{
len++;
p_buf += f->item_size;
@ -174,9 +174,9 @@ uint16_t fifo_read_n (fifo_t* f, void * p_buffer, uint16_t count)
@returns TRUE if the queue is not empty
*/
/******************************************************************************/
bool fifo_peek_at(fifo_t* f, uint16_t position, void * p_buffer)
bool tu_fifo_peek_at(tu_fifo_t* f, uint16_t position, void * p_buffer)
{
if ( !fifo_initalized(f) ) return false;
if ( !tu_fifo_initalized(f) ) return false;
if ( position >= f->count ) return false;
// rd_idx is position=0
@ -205,12 +205,12 @@ bool fifo_peek_at(fifo_t* f, uint16_t position, void * p_buffer)
FIFO will always return TRUE)
*/
/******************************************************************************/
bool fifo_write(fifo_t* f, void const * p_data)
bool tu_fifo_write(tu_fifo_t* f, void const * p_data)
{
if ( !fifo_initalized(f) ) return false;
if ( !tu_fifo_initalized(f) ) return false;
// if ( fifo_full(f) && !f->overwritable ) return false;
TU_ASSERT( !(fifo_full(f) && !f->overwritable) );
// if ( tu_fifo_full(f) && !f->overwritable ) return false;
TU_ASSERT( !(tu_fifo_full(f) && !f->overwritable) );
mutex_lock_if_needed(f);
@ -220,7 +220,7 @@ bool fifo_write(fifo_t* f, void const * p_data)
f->wr_idx = (f->wr_idx + 1) % f->depth;
if (fifo_full(f))
if (tu_fifo_full(f))
{
f->rd_idx = f->wr_idx; // keep the full state (rd == wr && len = size)
}
@ -249,14 +249,14 @@ bool fifo_write(fifo_t* f, void const * p_data)
@return Number of written elements
*/
/******************************************************************************/
uint16_t fifo_write_n(fifo_t* f, void const * p_data, uint16_t count)
uint16_t tu_fifo_write_n(tu_fifo_t* f, void const * p_data, uint16_t count)
{
if ( count == 0 ) return 0;
uint8_t* p_buf = (uint8_t*) p_data;
uint16_t len = 0;
while( (len < count) && fifo_write(f, p_buf) )
while( (len < count) && tu_fifo_write(f, p_buf) )
{
len++;
p_buf += f->item_size;
@ -273,7 +273,7 @@ uint16_t fifo_write_n(fifo_t* f, void const * p_data, uint16_t count)
Pointer to the FIFO buffer to manipulate
*/
/******************************************************************************/
void fifo_clear(fifo_t *f)
void tu_fifo_clear(tu_fifo_t *f)
{
mutex_lock_if_needed(f);

View File

@ -1,6 +1,6 @@
/**************************************************************************/
/*!
@file fifo.h
@file tusb_fifo.h
@author hathach (tinyusb.org)
@section LICENSE
@ -65,10 +65,10 @@
#define _ff_mutex_def(mutex)
#else
#define fifo_mutex_t struct os_mutex
#define tu_fifo_mutex_t struct os_mutex
#define fifo_mutex_lock(m) os_mutex_pend(m, OS_TIMEOUT_NEVER)
#define fifo_mutex_unlock(m) os_mutex_release(m)
#define tu_fifo_mutex_lock(m) os_mutex_pend(m, OS_TIMEOUT_NEVER)
#define tu_fifo_mutex_unlock(m) os_mutex_release(m)
/* Internal use only */
#define _mutex_declare(m) .mutex = m
@ -82,7 +82,7 @@
#endif
/** \struct fifo_t
/** \struct tu_fifo_t
* \brief Simple Circular FIFO
*/
typedef struct
@ -98,59 +98,59 @@ typedef struct
bool overwritable ;
#if CFG_FIFO_MUTEX
fifo_mutex_t * const mutex;
tu_fifo_mutex_t * const mutex;
#endif
} fifo_t;
} tu_fifo_t;
#define FIFO_DEF(name, ff_depth, type, is_overwritable) /*, irq_mutex)*/ \
uint8_t name##_buffer[ff_depth*sizeof(type)];\
fifo_t name = {\
.buffer = name##_buffer,\
.depth = ff_depth,\
.item_size = sizeof(type),\
.overwritable = is_overwritable,\
#define TU_FIFO_DEF(_name, _depth, _type, _overwritable) /*, irq_mutex)*/ \
uint8_t _name##_buf[_depth*sizeof(_type)];\
tu_fifo_t _name = {\
.buffer = _name##_buf,\
.depth = _depth,\
.item_size = sizeof(_type),\
.overwritable = _overwritable,\
/*.irq = irq_mutex*/\
_mutex_declare(_mutex)\
}
void fifo_clear(fifo_t *f);
void fifo_config(fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
void tu_fifo_clear(tu_fifo_t *f);
void tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_size, bool overwritable);
bool fifo_write (fifo_t* f, void const * p_data);
uint16_t fifo_write_n (fifo_t* f, void const * p_data, uint16_t count);
bool tu_fifo_write (tu_fifo_t* f, void const * p_data);
uint16_t tu_fifo_write_n (tu_fifo_t* f, void const * p_data, uint16_t count);
bool fifo_read (fifo_t* f, void * p_buffer);
uint16_t fifo_read_n (fifo_t* f, void * p_buffer, uint16_t count);
bool tu_fifo_read (tu_fifo_t* f, void * p_buffer);
uint16_t tu_fifo_read_n (tu_fifo_t* f, void * p_buffer, uint16_t count);
bool fifo_peek_at (fifo_t* f, uint16_t position, void * p_buffer);
bool tu_fifo_peek_at (tu_fifo_t* f, uint16_t position, void * p_buffer);
static inline bool fifo_peek(fifo_t* f, void * p_buffer)
static inline bool tu_fifo_peek(tu_fifo_t* f, void * p_buffer)
{
return fifo_peek_at(f, 0, p_buffer);
return tu_fifo_peek_at(f, 0, p_buffer);
}
static inline bool fifo_empty(fifo_t* f)
static inline bool tu_fifo_empty(tu_fifo_t* f)
{
return (f->count == 0);
}
static inline bool fifo_full(fifo_t* f)
static inline bool tu_fifo_full(tu_fifo_t* f)
{
return (f->count == f->depth);
}
static inline uint16_t fifo_count(fifo_t* f)
static inline uint16_t tu_fifo_count(tu_fifo_t* f)
{
return f->count;
}
static inline uint16_t fifo_remaining(fifo_t* f)
static inline uint16_t tu_fifo_remaining(tu_fifo_t* f)
{
return f->depth - f->count;
}
static inline uint16_t fifo_depth(fifo_t* f)
static inline uint16_t tu_fifo_depth(tu_fifo_t* f)
{
return f->depth;
}

View File

@ -130,20 +130,20 @@ static inline osal_task_t osal_task_create(osal_task_def_t* taskdef)
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
#define OSAL_QUEUE_DEF(_name, _depth, _type) FIFO_DEF(_name, _depth, _type, false)
#define OSAL_QUEUE_DEF(_name, _depth, _type) TU_FIFO_DEF(_name, _depth, _type, false)
typedef fifo_t osal_queue_def_t;
typedef fifo_t* osal_queue_t;
typedef tu_fifo_t osal_queue_def_t;
typedef tu_fifo_t* osal_queue_t;
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
{
fifo_clear(qdef);
tu_fifo_clear(qdef);
return (osal_queue_t) qdef;
}
static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data)
{
return fifo_write( (fifo_t*) queue_hdl, data);
return tu_fifo_write( (tu_fifo_t*) queue_hdl, data);
}
#define osal_queue_send osal_queue_send_isr
@ -164,7 +164,7 @@ static inline void osal_queue_flush(osal_queue_t const queue_hdl)
return TUSB_ERROR_OSAL_WAITING; \
} else{ \
/*tusb_hal_int_disable_all();*/ \
fifo_read(queue_hdl, p_data); \
tu_fifo_read(queue_hdl, p_data); \
/*tusb_hal_int_enable_all();*/ \
*(p_error) = TUSB_ERROR_NONE; \
} \

View File

@ -40,11 +40,11 @@
#include "fifo.h"
#define FIFO_SIZE 10
FIFO_DEF(ff, FIFO_SIZE, uint8_t, false);
TU_FIFO_DEF(ff, FIFO_SIZE, uint8_t, false);
void setUp(void)
{
fifo_clear(&ff);
tu_fifo_clear(&ff);
}
void tearDown(void)
@ -57,13 +57,13 @@ void test_normal(void)
for(i=0; i < FIFO_SIZE; i++)
{
fifo_write(&ff, &i);
tu_fifo_write(&ff, &i);
}
for(i=0; i < FIFO_SIZE; i++)
{
uint8_t c;
fifo_read(&ff, &c);
tu_fifo_read(&ff, &c);
TEST_ASSERT_EQUAL(i, c);
}
}
@ -71,21 +71,21 @@ void test_normal(void)
void test_is_empty(void)
{
uint8_t temp;
TEST_ASSERT_TRUE(fifo_is_empty(&ff));
fifo_write(&ff, &temp);
TEST_ASSERT_FALSE(fifo_is_empty(&ff));
TEST_ASSERT_TRUE(tu_fifo_is_empty(&ff));
tu_fifo_write(&ff, &temp);
TEST_ASSERT_FALSE(tu_fifo_is_empty(&ff));
}
void test_is_full(void)
{
uint8_t i;
TEST_ASSERT_FALSE(fifo_is_full(&ff));
TEST_ASSERT_FALSE(tu_fifo_is_full(&ff));
for(i=0; i < FIFO_SIZE; i++)
{
fifo_write(&ff, &i);
tu_fifo_write(&ff, &i);
}
TEST_ASSERT_TRUE(fifo_is_full(&ff));
TEST_ASSERT_TRUE(tu_fifo_is_full(&ff));
}