rename some fifo functions to be more consistent

This commit is contained in:
hathach 2013-01-16 22:37:10 +07:00
parent 095129887e
commit 53739ccd28
4 changed files with 14 additions and 14 deletions

View File

@ -77,21 +77,21 @@ void test_normal(void)
void test_is_empty(void)
{
TEST_ASSERT_TRUE(fifo_isEmpty(&ff));
TEST_ASSERT_TRUE(fifo_is_empty(&ff));
fifo_write(&ff, 1);
TEST_ASSERT_FALSE(fifo_isEmpty(&ff));
TEST_ASSERT_FALSE(fifo_is_empty(&ff));
}
void test_is_full(void)
{
uint8_t i;
TEST_ASSERT_FALSE(fifo_isFull(&ff));
TEST_ASSERT_FALSE(fifo_is_full(&ff));
for(i=0; i < FIFO_SIZE; i++)
{
fifo_write(&ff, i);
}
TEST_ASSERT_TRUE(fifo_isFull(&ff));
TEST_ASSERT_TRUE(fifo_is_full(&ff));
}

View File

@ -185,7 +185,7 @@ uint16_t tusb_cdc_recv(uint8_t* buffer, uint16_t max)
{
ASSERT(buffer && max, 0);
return fifo_readArray(&ffRX, buffer, max);
return fifo_read_n(&ffRX, buffer, max);
}
// ROM driver bug: cannot hook this to CIC_GetRequest
@ -229,7 +229,7 @@ ErrorCode_t CDC_BulkIn_Hdlr(USBD_HANDLE_T hUsb, void* data, uint32_t event)
uint8_t buffer[CDC_DATA_EP_MAXPACKET_SIZE];
uint16_t count;
count = fifo_readArray(&ffTX, buffer, CDC_DATA_EP_MAXPACKET_SIZE);
count = fifo_read_n(&ffTX, buffer, CDC_DATA_EP_MAXPACKET_SIZE);
USBD_API->hw->WriteEP(hUsb, CDC_DATA_EP_IN, buffer, count); // write data to EP
}

View File

@ -115,7 +115,7 @@ bool fifo_init(fifo_t* f, uint8_t* buffer, uint16_t size, bool overwritable, IRQ
/**************************************************************************/
bool fifo_read(fifo_t* f, uint8_t *data)
{
if (fifo_isEmpty(f))
if (fifo_is_empty(f))
return false;
mutex_lock(f);
@ -143,7 +143,7 @@ bool fifo_read(fifo_t* f, uint8_t *data)
@returns The actual number of bytes read from the FIFO
*/
/**************************************************************************/
uint16_t fifo_readArray(fifo_t* f, uint8_t* rx, uint16_t maxlen)
uint16_t fifo_read_n(fifo_t* f, uint8_t* rx, uint16_t maxlen)
{
uint16_t len = 0;
@ -175,7 +175,7 @@ uint16_t fifo_readArray(fifo_t* f, uint8_t* rx, uint16_t maxlen)
/**************************************************************************/
bool fifo_write(fifo_t* f, uint8_t data)
{
if ( fifo_isFull(f) && f->overwritable == false)
if ( fifo_is_full(f) && f->overwritable == false)
return false;
mutex_lock(f);
@ -183,7 +183,7 @@ bool fifo_write(fifo_t* f, uint8_t data)
f->buf[f->wr_ptr] = data;
f->wr_ptr = (f->wr_ptr + 1) % f->size;
if (fifo_isFull(f))
if (fifo_is_full(f))
{
f->rd_ptr = f->wr_ptr; // keep the full state (rd == wr && len = size)
}else

View File

@ -72,20 +72,20 @@ typedef struct _fifo_t
bool fifo_init(fifo_t* f, uint8_t* buffer, uint16_t size, bool overwritable, IRQn_Type irq);
bool fifo_write(fifo_t* f, uint8_t data);
bool fifo_read(fifo_t* f, uint8_t *data);
uint16_t fifo_readArray(fifo_t* f, uint8_t * rx, uint16_t maxlen);
uint16_t fifo_read_n(fifo_t* f, uint8_t * rx, uint16_t maxlen);
void fifo_clear(fifo_t *f);
static inline bool fifo_isEmpty(fifo_t* f)
static inline bool fifo_is_empty(fifo_t* f)
{
return (f->len == 0);
}
static inline bool fifo_isFull(fifo_t* f)
static inline bool fifo_is_full(fifo_t* f)
{
return (f->len == f->size);
}
static inline uint16_t fifo_getLength(fifo_t* f)
static inline uint16_t fifo_get_length(fifo_t* f)
{
return f->len;
}