summaryrefslogtreecommitdiff
path: root/src/common/tusb_fifo.c
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-12-16 16:55:25 +0700
committerhathach <[email protected]>2022-12-16 16:55:25 +0700
commit660343d2001c0ee943bf3e24cab6f235d3930b33 (patch)
tree96267833bf47cae3dfea9f150b493e2cccb49f76 /src/common/tusb_fifo.c
parent04a5c03ea8ea70510c332f0fafb44daf0ec7c7fb (diff)
update fifo per PanRe review
Diffstat (limited to 'src/common/tusb_fifo.c')
-rw-r--r--src/common/tusb_fifo.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 70f514df2..bbdd82982 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -352,9 +352,10 @@ static uint16_t backward_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset)
return new_p;
}
-// index to pointer, simply an modulo with minus
+// index to pointer, simply an modulo with minus.
static inline uint16_t idx2ptr(uint16_t idx, uint16_t depth)
{
+ // Only run at most 3 times since index is limit in the range of [0..2*depth)
while ( idx >= depth ) idx -= depth;
return idx;
}
@@ -509,6 +510,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
else if (overflowable_count + n >= 2*f->depth)
{
// Double overflowed
+ // Index is bigger than the allowed range [0,2*depth)
// re-position write index to have a full fifo after pushed
wr_idx = advance_pointer(f, rd_idx, f->depth - n);
@@ -518,7 +520,9 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
// currently deliberately not implemented --> result in incorrect data read back
}else
{
- // normal + single overflowed: just increase write index
+ // normal + single overflowed:
+ // Index is in the range of [0,2*depth) and thus detect and recoverable. Recovering is handled in read()
+ // Therefore we just increase write index
// we will correct (re-position) read index later on in fifo_read() function
}
}