Skip to content

Commit 248025b

Browse files
committed
reverse idx2ptr() arguments to be consistent
1 parent 24bd1c9 commit 248025b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/common/tusb_fifo.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ static uint16_t backward_index(uint16_t depth, uint16_t idx, uint16_t offset)
351351
}
352352

353353
// index to pointer, simply an modulo with minus.
354-
static inline uint16_t idx2ptr(uint16_t idx, uint16_t depth)
354+
TU_ATTR_ALWAYS_INLINE static inline
355+
uint16_t idx2ptr(uint16_t depth, uint16_t idx)
355356
{
356357
// Only run at most 3 times since index is limit in the range of [0..2*depth)
357358
while ( idx >= depth ) idx -= depth;
@@ -415,7 +416,7 @@ static bool _tu_fifo_peek(tu_fifo_t* f, void * p_buffer, uint16_t wr_idx, uint16
415416
// Skip beginning of buffer
416417
if (cnt == 0) return false;
417418

418-
uint16_t rd_ptr = idx2ptr(rd_idx, f->depth);
419+
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
419420

420421
// Peek data
421422
_ff_pull(f, p_buffer, rd_ptr);
@@ -443,7 +444,7 @@ static uint16_t _tu_fifo_peek_n(tu_fifo_t* f, void * p_buffer, uint16_t n, uint1
443444
// Check if we can read something at and after offset - if too less is available we read what remains
444445
if (cnt < n) n = cnt;
445446

446-
uint16_t rd_ptr = idx2ptr(rd_idx, f->depth);
447+
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
447448

448449
// Peek data
449450
_ff_pull_n(f, p_buffer, n, rd_ptr, copy_mode);
@@ -520,7 +521,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
520521

521522
if (n)
522523
{
523-
uint16_t wr_ptr = idx2ptr(wr_idx, f->depth);
524+
uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
524525

525526
TU_LOG(TU_FIFO_DBG, "actual_n = %u, wr_ptr = %u", n, wr_ptr);
526527

@@ -794,7 +795,7 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
794795
ret = false;
795796
}else
796797
{
797-
uint16_t wr_ptr = idx2ptr(wr_idx, f->depth);
798+
uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
798799

799800
// Write data
800801
_ff_push(f, data, wr_ptr);
@@ -980,8 +981,8 @@ void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
980981
}
981982

982983
// Get relative pointers
983-
uint16_t wr_ptr = idx2ptr(wr_idx, f->depth);
984-
uint16_t rd_ptr = idx2ptr(rd_idx, f->depth);
984+
uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
985+
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
985986

986987
// Copy pointer to buffer to start reading from
987988
info->ptr_lin = &f->buffer[rd_ptr];
@@ -1034,8 +1035,8 @@ void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
10341035
}
10351036

10361037
// Get relative pointers
1037-
uint16_t wr_ptr = idx2ptr(wr_idx, f->depth);
1038-
uint16_t rd_ptr = idx2ptr(rd_idx, f->depth);
1038+
uint16_t wr_ptr = idx2ptr(f->depth, wr_idx);
1039+
uint16_t rd_ptr = idx2ptr(f->depth, rd_idx);
10391040

10401041
// Copy pointer to buffer to start writing to
10411042
info->ptr_lin = &f->buffer[wr_ptr];

0 commit comments

Comments
 (0)