change tu_fifo_buffer_info_t layout

This commit is contained in:
hathach
2025-11-26 15:26:42 +07:00
parent 1a51a7e159
commit c925277e24
11 changed files with 124 additions and 124 deletions

View File

@ -501,10 +501,10 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
// find backward
uint8_t *ptr;
if (buf_info.len_wrap > 0) {
ptr = buf_info.ptr_wrap + buf_info.len_wrap - 1; // last byte of wrap buffer
} else if (buf_info.len_lin > 0) {
ptr = buf_info.ptr_lin + buf_info.len_lin - 1; // last byte of linear buffer
if (buf_info.wrapped.len > 0) {
ptr = buf_info.wrapped.ptr + buf_info.wrapped.len - 1; // last byte of wrap buffer
} else if (buf_info.linear.len > 0) {
ptr = buf_info.linear.ptr + buf_info.linear.len - 1; // last byte of linear buffer
} else {
ptr = NULL; // no data
}
@ -516,9 +516,9 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
break; // only invoke once per transfer, even if multiple wanted chars are present
}
if (ptr == buf_info.ptr_wrap) {
ptr = buf_info.ptr_lin + buf_info.len_lin - 1; // last byte of linear buffer
} else if (ptr == buf_info.ptr_lin) {
if (ptr == buf_info.wrapped.ptr) {
ptr = buf_info.linear.ptr + buf_info.linear.len - 1; // last byte of linear buffer
} else if (ptr == buf_info.linear.ptr) {
break; // reached the beginning
} else {
ptr--;

View File

@ -82,8 +82,8 @@ bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_si
//--------------------------------------------------------------------+
// Pull & Push
// copy data to/from fifo without updating read/write pointers
//--------------------------------------------------------------------+
#ifdef CFG_TUSB_FIFO_ACCESS_FIXED_ADDR_RW32
// Intended to be used to read from hardware USB FIFO in e.g. STM32 where all data is read from a constant address
// Code adapted from dcd_synopsys.c
@ -216,7 +216,7 @@ static void _ff_push_n(tu_fifo_t *f, const void *app_buf, uint16_t n, uint16_t w
}
// get one item from fifo WITHOUT updating read pointer
TU_ATTR_ALWAYS_INLINE static inline void _ff_pull(tu_fifo_t *f, void *buf, uint16_t ptr) {
TU_ATTR_ALWAYS_INLINE static inline void _ff_pull(const tu_fifo_t *f, void *buf, uint16_t ptr) {
memcpy(buf, f->buffer + (ptr * f->item_size), f->item_size);
}
@ -326,7 +326,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t idx2ptr(uint16_t depth, uint16_t id
// Works on local copies of w
// When an overwritable fifo is overflowed, rd_idx will be re-index so that it forms a full fifo
TU_ATTR_ALWAYS_INLINE static inline uint16_t ff_correct_read_index(tu_fifo_t *f, uint16_t wr_idx) {
TU_ATTR_ALWAYS_INLINE static inline uint16_t correct_read_index(tu_fifo_t *f, uint16_t wr_idx) {
uint16_t rd_idx;
if (wr_idx >= f->depth) {
rd_idx = wr_idx - f->depth;
@ -349,7 +349,7 @@ static bool ff_peek_local(tu_fifo_t *f, void *p_buffer, uint16_t wr_idx, uint16_
// Correct read index if overflow
if (ovf_count > f->depth) {
ff_lock(f->mutex_rd);
rd_idx = ff_correct_read_index(f, wr_idx);
rd_idx = correct_read_index(f, wr_idx);
ff_unlock(f->mutex_rd);
}
@ -373,7 +373,7 @@ uint16_t tu_fifo_peek_n_access(tu_fifo_t *f, void *p_buffer, uint16_t n, uint16_
// Check overflow and correct if required
if (cnt > f->depth) {
rd_idx = ff_correct_read_index(f, wr_idx);
rd_idx = correct_read_index(f, wr_idx);
cnt = f->depth;
}
@ -477,7 +477,7 @@ uint16_t tu_fifo_read_n_access(tu_fifo_t *f, void *buffer, uint16_t n, tu_fifo_a
// Only use in case tu_fifo_overflow() returned true!
void tu_fifo_correct_read_pointer(tu_fifo_t *f) {
ff_lock(f->mutex_rd);
ff_correct_read_index(f, f->wr_idx);
correct_read_index(f, f->wr_idx);
ff_unlock(f->mutex_rd);
}
@ -696,7 +696,7 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info) {
// Check overflow and correct if required - may happen in case a DMA wrote too fast
if (cnt > f->depth) {
ff_lock(f->mutex_rd);
rd_idx = ff_correct_read_index(f, wr_idx);
rd_idx = correct_read_index(f, wr_idx);
ff_unlock(f->mutex_rd);
cnt = f->depth;
@ -704,10 +704,10 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info) {
// Check if fifo is empty
if (cnt == 0) {
info->len_lin = 0;
info->len_wrap = 0;
info->ptr_lin = NULL;
info->ptr_wrap = NULL;
info->linear.len = 0;
info->wrapped.len = 0;
info->linear.ptr = NULL;
info->wrapped.ptr = NULL;
return;
}
@ -716,20 +716,20 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info) {
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
// Copy pointer to buffer to start reading from
info->ptr_lin = &f->buffer[rd_ptr];
info->linear.ptr = &f->buffer[rd_ptr];
// Check if there is a wrap around necessary
if (wr_ptr > rd_ptr) {
// Non wrapping case
info->len_lin = cnt;
info->linear.len = cnt;
info->len_wrap = 0;
info->ptr_wrap = NULL;
info->wrapped.len = 0;
info->wrapped.ptr = NULL;
} else {
info->len_lin = f->depth - rd_ptr; // Also the case if FIFO was full
info->linear.len = f->depth - rd_ptr; // Also the case if FIFO was full
info->len_wrap = cnt - info->len_lin;
info->ptr_wrap = f->buffer;
info->wrapped.len = cnt - info->linear.len;
info->wrapped.ptr = f->buffer;
}
}
@ -754,10 +754,10 @@ void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info) {
uint16_t remain = tu_ff_remaining_local(f->depth, wr_idx, rd_idx);
if (remain == 0) {
info->len_lin = 0;
info->len_wrap = 0;
info->ptr_lin = NULL;
info->ptr_wrap = NULL;
info->linear.len = 0;
info->wrapped.len = 0;
info->linear.ptr = NULL;
info->wrapped.ptr = NULL;
return;
}
@ -766,16 +766,16 @@ void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info) {
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
// Copy pointer to buffer to start writing to
info->ptr_lin = &f->buffer[wr_ptr];
info->linear.ptr = &f->buffer[wr_ptr];
if (wr_ptr < rd_ptr) {
// Non wrapping case
info->len_lin = rd_ptr - wr_ptr;
info->len_wrap = 0;
info->ptr_wrap = NULL;
info->linear.len = rd_ptr - wr_ptr;
info->wrapped.len = 0;
info->wrapped.ptr = NULL;
} else {
info->len_lin = f->depth - wr_ptr;
info->len_wrap = remain - info->len_lin; // Remaining length - n already was limited to remain or FIFO depth
info->ptr_wrap = f->buffer; // Always start of buffer
info->linear.len = f->depth - wr_ptr;
info->wrapped.len = remain - info->linear.len; // Remaining length - n already was limited to remain or FIFO depth
info->wrapped.ptr = f->buffer; // Always start of buffer
}
}

View File

@ -128,10 +128,10 @@ typedef struct {
} tu_fifo_t;
typedef struct {
uint16_t len_lin; ///< linear length in item size
uint16_t len_wrap; ///< wrapped length in item size
uint8_t *ptr_lin; ///< linear part start pointer
uint8_t *ptr_wrap; ///< wrapped part start pointer
struct {
uint16_t len; // length
uint8_t *ptr; // buffer pointer
} linear, wrapped;
} tu_fifo_buffer_info_t;
#define TU_FIFO_INIT(_buffer, _depth, _type, _overwritable) \
@ -198,7 +198,6 @@ TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_fifo_write_n(tu_fifo_t *f, const
return tu_fifo_write_n_access(f, data, n, TU_FIFO_INC_ADDR_RW8);
}
//--------------------------------------------------------------------+
// Index API
//--------------------------------------------------------------------+

View File

@ -523,6 +523,7 @@
//--------------------------------------------------------------------+
#elif TU_CHECK_MCU(OPT_MCU_F1C100S)
#define TUP_DCD_ENDPOINT_MAX 4
#define TUP_DCD_EDPT_CLOSE_API
//--------------------------------------------------------------------+
// WCH

View File

@ -545,19 +545,19 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
tu_fifo_get_write_info(ff, &fifo_info);
}
if ( fifo_info.len_lin >= total_bytes )
if ( fifo_info.linear.len >= total_bytes )
{
// Linear length is enough for this transfer
qtd_init(p_qtd, fifo_info.ptr_lin, total_bytes);
qtd_init(p_qtd, fifo_info.linear.ptr, total_bytes);
}
else
{
// linear part is not enough
// prepare TD up to linear length
qtd_init(p_qtd, fifo_info.ptr_lin, fifo_info.len_lin);
qtd_init(p_qtd, fifo_info.linear.ptr, fifo_info.linear.len);
if ( !tu_offset4k((uint32_t) fifo_info.ptr_wrap) && !tu_offset4k(tu_fifo_depth(ff)) )
if ( !tu_offset4k((uint32_t) fifo_info.wrapped.ptr) && !tu_offset4k(tu_fifo_depth(ff)) )
{
// If buffer is aligned to 4K & buffer size is multiple of 4K
// We can make use of buffer page array to also combine the linear + wrapped length
@ -568,7 +568,7 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
// pick up buffer array where linear ends
if (p_qtd->buffer[i] == 0)
{
p_qtd->buffer[i] = (uint32_t) fifo_info.ptr_wrap + 4096 * page;
p_qtd->buffer[i] = (uint32_t) fifo_info.wrapped.ptr + 4096 * page;
page++;
}
}

View File

@ -221,12 +221,12 @@ static void pipe_read_write_packet_ff(tu_fifo_t *f, volatile void *fifo, unsigne
tu_fifo_buffer_info_t info;
ops[dir].tu_fifo_get_info(f, &info);
unsigned total_len = len;
len = TU_MIN(total_len, info.len_lin);
ops[dir].pipe_read_write(info.ptr_lin, fifo, len);
len = TU_MIN(total_len, info.linear.len);
ops[dir].pipe_read_write(info.linear.ptr, fifo, len);
unsigned rem = total_len - len;
if (rem) {
len = TU_MIN(rem, info.len_wrap);
ops[dir].pipe_read_write(info.ptr_wrap, fifo, len);
len = TU_MIN(rem, info.wrapped.len);
ops[dir].pipe_read_write(info.wrapped.ptr, fifo, len);
rem -= len;
}
ops[dir].tu_fifo_advance(f, total_len - rem);

View File

@ -697,7 +697,7 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
udd_dma_ctrl_wrap |= DEVDMACONTROL_END_TR_IT | DEVDMACONTROL_END_TR_EN;
} else {
tu_fifo_get_read_info(ff, &info);
if(info.len_wrap == 0)
if(info.wrapped.len == 0)
{
udd_dma_ctrl_lin |= DEVDMACONTROL_END_B_EN;
}
@ -705,18 +705,18 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
}
// Clean invalidate cache of linear part
CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.ptr_lin, 4), info.len_lin + 31);
CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.linear.ptr, 4), info.linear.len + 31);
USB_REG->DEVDMA[epnum - 1].DEVDMAADDRESS = (uint32_t)info.ptr_lin;
if (info.len_wrap)
USB_REG->DEVDMA[epnum - 1].DEVDMAADDRESS = (uint32_t)info.linear.ptr;
if (info.wrapped.len)
{
// Clean invalidate cache of wrapped part
CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.ptr_wrap, 4), info.len_wrap + 31);
CleanInValidateCache((uint32_t*) tu_align((uint32_t) info.wrapped.ptr, 4), info.wrapped.len + 31);
dma_desc[epnum - 1].next_desc = 0;
dma_desc[epnum - 1].buff_addr = (uint32_t)info.ptr_wrap;
dma_desc[epnum - 1].buff_addr = (uint32_t)info.wrapped.ptr;
dma_desc[epnum - 1].chnl_ctrl =
udd_dma_ctrl_wrap | (info.len_wrap << DEVDMACONTROL_BUFF_LENGTH_Pos);
udd_dma_ctrl_wrap | (info.wrapped.len << DEVDMACONTROL_BUFF_LENGTH_Pos);
// Clean cache of wrapped DMA descriptor
CleanInValidateCache((uint32_t*)&dma_desc[epnum - 1], sizeof(dma_desc_t));
@ -725,7 +725,7 @@ bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_
} else {
udd_dma_ctrl_lin |= DEVDMACONTROL_END_BUFFIT;
}
udd_dma_ctrl_lin |= (info.len_lin << DEVDMACONTROL_BUFF_LENGTH_Pos);
udd_dma_ctrl_lin |= (info.linear.len << DEVDMACONTROL_BUFF_LENGTH_Pos);
// Disable IRQs to have a short sequence
// between read of EOT_STA and DMA enable
uint32_t irq_state = __get_PRIMASK();

View File

@ -213,13 +213,13 @@ static void pipe_write_packet_ff(rusb2_reg_t * rusb, tu_fifo_t *f, volatile void
tu_fifo_buffer_info_t info;
tu_fifo_get_read_info(f, &info);
uint16_t count = tu_min16(total_len, info.len_lin);
pipe_write_packet(rusb, info.ptr_lin, fifo, count);
uint16_t count = tu_min16(total_len, info.linear.len);
pipe_write_packet(rusb, info.linear.ptr, fifo, count);
uint16_t rem = total_len - count;
if (rem) {
rem = tu_min16(rem, info.len_wrap);
pipe_write_packet(rusb, info.ptr_wrap, fifo, rem);
rem = tu_min16(rem, info.wrapped.len);
pipe_write_packet(rusb, info.wrapped.ptr, fifo, rem);
count += rem;
}
@ -231,13 +231,13 @@ static void pipe_read_packet_ff(rusb2_reg_t * rusb, tu_fifo_t *f, volatile void
tu_fifo_buffer_info_t info;
tu_fifo_get_write_info(f, &info);
uint16_t count = tu_min16(total_len, info.len_lin);
pipe_read_packet(rusb, info.ptr_lin, fifo, count);
uint16_t count = tu_min16(total_len, info.linear.len);
pipe_read_packet(rusb, info.linear.ptr, fifo, count);
uint16_t rem = total_len - count;
if (rem) {
rem = tu_min16(rem, info.len_wrap);
pipe_read_packet(rusb, info.ptr_wrap, fifo, rem);
rem = tu_min16(rem, info.wrapped.len);
pipe_read_packet(rusb, info.wrapped.ptr, fifo, rem);
count += rem;
}

View File

@ -927,15 +927,15 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNB
tu_fifo_buffer_info_t info;
tu_fifo_get_read_info(ff, &info);
uint16_t cnt_lin = tu_min16(wNBytes, info.len_lin);
uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.len_wrap);
uint16_t cnt_lin = tu_min16(wNBytes, info.linear.len);
uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.wrapped.len);
uint16_t const cnt_total = cnt_lin + cnt_wrap;
// We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
// last lin byte will be combined with wrapped part To ensure PMA is always access aligned
uint16_t lin_even = cnt_lin & ~(FSDEV_BUS_SIZE - 1);
uint16_t lin_odd = cnt_lin & (FSDEV_BUS_SIZE - 1);
uint8_t const *src8 = (uint8_t const*) info.ptr_lin;
uint8_t const *src8 = (uint8_t const*) info.linear.ptr;
// write even linear part
dcd_write_packet_memory(dst, src8, lin_even);
@ -943,7 +943,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNB
src8 += lin_even;
if (lin_odd == 0) {
src8 = (uint8_t const*) info.ptr_wrap;
src8 = (uint8_t const*) info.wrapped.ptr;
} else {
// Combine last linear bytes + first wrapped bytes to form fsdev bus width data
fsdev_bus_t temp = 0;
@ -952,7 +952,7 @@ static bool dcd_write_packet_memory_ff(tu_fifo_t *ff, uint16_t dst, uint16_t wNB
temp |= *src8++ << (i * 8);
}
src8 = (uint8_t const*) info.ptr_wrap;
src8 = (uint8_t const*) info.wrapped.ptr;
for(; i < FSDEV_BUS_SIZE && cnt_wrap > 0; i++, cnt_wrap--) {
temp |= *src8++ << (i * 8);
}
@ -977,8 +977,8 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBy
tu_fifo_buffer_info_t info;
tu_fifo_get_write_info(ff, &info); // We want to read from the FIFO
uint16_t cnt_lin = tu_min16(wNBytes, info.len_lin);
uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.len_wrap);
uint16_t cnt_lin = tu_min16(wNBytes, info.linear.len);
uint16_t cnt_wrap = tu_min16(wNBytes - cnt_lin, info.wrapped.len);
uint16_t cnt_total = cnt_lin + cnt_wrap;
// We want to read from the FIFO and write it into the PMA, if LIN part is ODD and has WRAPPED part,
@ -986,7 +986,7 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBy
uint16_t lin_even = cnt_lin & ~(FSDEV_BUS_SIZE - 1);
uint16_t lin_odd = cnt_lin & (FSDEV_BUS_SIZE - 1);
uint8_t *dst8 = (uint8_t *) info.ptr_lin;
uint8_t *dst8 = (uint8_t *) info.linear.ptr;
// read even linear part
dcd_read_packet_memory(dst8, src, lin_even);
@ -994,7 +994,7 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBy
src += lin_even;
if (lin_odd == 0) {
dst8 = (uint8_t *) info.ptr_wrap;
dst8 = (uint8_t *) info.wrapped.ptr;
} else {
// Combine last linear bytes + first wrapped bytes to form fsdev bus width data
fsdev_bus_t temp;
@ -1007,7 +1007,7 @@ static bool dcd_read_packet_memory_ff(tu_fifo_t *ff, uint16_t src, uint16_t wNBy
temp >>= 8;
}
dst8 = (uint8_t *) info.ptr_wrap;
dst8 = (uint8_t *) info.wrapped.ptr;
for (; i < FSDEV_BUS_SIZE && cnt_wrap > 0; i++, cnt_wrap--) {
*dst8++ = (uint8_t) (temp & 0xfful);
temp >>= 8;

View File

@ -535,12 +535,12 @@ static void pipe_read_write_packet_ff(tu_fifo_t *f, volatile void *fifo, unsigne
tu_fifo_buffer_info_t info;
ops[dir].tu_fifo_get_info(f, &info);
unsigned total_len = len;
len = TU_MIN(total_len, info.len_lin);
ops[dir].pipe_read_write(info.ptr_lin, fifo, len);
len = TU_MIN(total_len, info.linear.len);
ops[dir].pipe_read_write(info.linear.ptr, fifo, len);
unsigned rem = total_len - len;
if (rem) {
len = TU_MIN(rem, info.len_wrap);
ops[dir].pipe_read_write(info.ptr_wrap, fifo, len);
len = TU_MIN(rem, info.wrapped.len);
ops[dir].pipe_read_write(info.wrapped.ptr, fifo, len);
rem -= len;
}
ops[dir].tu_fifo_advance(f, total_len - rem);

View File

@ -236,11 +236,11 @@ void test_get_read_info_when_no_wrap() {
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(4, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL(4, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.ptr_lin);
TEST_ASSERT_NULL(info.ptr_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.linear.ptr);
TEST_ASSERT_NULL(info.wrapped.ptr);
}
void test_get_read_info_when_wrapped() {
@ -262,11 +262,11 @@ void test_get_read_info_when_wrapped() {
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(FIFO_SIZE - 6, info.len_lin);
TEST_ASSERT_EQUAL(2, info.len_wrap);
TEST_ASSERT_EQUAL(FIFO_SIZE - 6, info.linear.len);
TEST_ASSERT_EQUAL(2, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 6, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 6, info.linear.ptr);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.wrapped.ptr);
}
void test_get_write_info_when_no_wrap() {
@ -278,12 +278,12 @@ void test_get_write_info_when_no_wrap() {
tu_fifo_get_write_info(ff, &info);
TEST_ASSERT_EQUAL(FIFO_SIZE - 2, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL(FIFO_SIZE - 2, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.linear.ptr);
// application should check len instead of ptr.
// TEST_ASSERT_NULL(info.ptr_wrap);
// TEST_ASSERT_NULL(info.wrapped.ptr);
}
void test_get_write_info_when_wrapped() {
@ -300,11 +300,11 @@ void test_get_write_info_when_wrapped() {
tu_fifo_get_write_info(ff, &info);
TEST_ASSERT_EQUAL(FIFO_SIZE - 6, info.len_lin);
TEST_ASSERT_EQUAL(2, info.len_wrap);
TEST_ASSERT_EQUAL(FIFO_SIZE - 6, info.linear.len);
TEST_ASSERT_EQUAL(2, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 6, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 6, info.linear.ptr);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.wrapped.ptr);
}
void test_empty(void) {
@ -314,21 +314,21 @@ void test_empty(void) {
// read info
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(0, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL(0, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_NULL(info.ptr_lin);
TEST_ASSERT_NULL(info.ptr_wrap);
TEST_ASSERT_NULL(info.linear.ptr);
TEST_ASSERT_NULL(info.wrapped.ptr);
// write info
tu_fifo_get_write_info(ff, &info);
TEST_ASSERT_EQUAL(FIFO_SIZE, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL(FIFO_SIZE, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.linear.ptr);
// application should check len instead of ptr.
// TEST_ASSERT_NULL(info.ptr_wrap);
// TEST_ASSERT_NULL(info.wrapped.ptr);
// write 1 then re-check empty
tu_fifo_write(ff, &temp);
@ -347,12 +347,12 @@ void test_full(void) {
// read info
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(FIFO_SIZE, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL(FIFO_SIZE, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.linear.ptr);
// skip this, application must check len instead of buffer
// TEST_ASSERT_NULL(info.ptr_wrap);
// TEST_ASSERT_NULL(info.wrapped.ptr);
// write info
}
@ -511,18 +511,18 @@ void test_get_read_info_advanced_cases(void) {
ff->wr_idx = 20;
ff->rd_idx = 2;
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(18, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.ptr_lin);
TEST_ASSERT_NULL(info.ptr_wrap);
TEST_ASSERT_EQUAL(18, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 2, info.linear.ptr);
TEST_ASSERT_NULL(info.wrapped.ptr);
ff->wr_idx = 68; // ptr = 4
ff->rd_idx = 56; // ptr = 56
tu_fifo_get_read_info(ff, &info);
TEST_ASSERT_EQUAL(8, info.len_lin);
TEST_ASSERT_EQUAL(4, info.len_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 56, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap);
TEST_ASSERT_EQUAL(8, info.linear.len);
TEST_ASSERT_EQUAL(4, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 56, info.linear.ptr);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.wrapped.ptr);
}
void test_get_write_info_advanced_cases(void) {
@ -531,18 +531,18 @@ void test_get_write_info_advanced_cases(void) {
ff->wr_idx = 10;
ff->rd_idx = 104; // ptr = 40
tu_fifo_get_write_info(ff, &info);
TEST_ASSERT_EQUAL(30, info.len_lin);
TEST_ASSERT_EQUAL(0, info.len_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 10, info.ptr_lin);
TEST_ASSERT_NULL(info.ptr_wrap);
TEST_ASSERT_EQUAL(30, info.linear.len);
TEST_ASSERT_EQUAL(0, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 10, info.linear.ptr);
TEST_ASSERT_NULL(info.wrapped.ptr);
ff->wr_idx = 60;
ff->rd_idx = 20;
tu_fifo_get_write_info(ff, &info);
TEST_ASSERT_EQUAL(4, info.len_lin);
TEST_ASSERT_EQUAL(20, info.len_wrap);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 60, info.ptr_lin);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.ptr_wrap);
TEST_ASSERT_EQUAL(4, info.linear.len);
TEST_ASSERT_EQUAL(20, info.wrapped.len);
TEST_ASSERT_EQUAL_PTR(ff->buffer + 60, info.linear.ptr);
TEST_ASSERT_EQUAL_PTR(ff->buffer, info.wrapped.ptr);
}
void test_correct_read_pointer_cases(void) {