@@ -352,9 +352,10 @@ static uint16_t backward_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset)
352
352
return new_p ;
353
353
}
354
354
355
- // index to pointer, simply an modulo with minus
355
+ // index to pointer, simply an modulo with minus.
356
356
static inline uint16_t idx2ptr (uint16_t idx , uint16_t depth )
357
357
{
358
+ // Only run at most 3 times since index is limit in the range of [0..2*depth)
358
359
while ( idx >= depth ) idx -= depth ;
359
360
return idx ;
360
361
}
@@ -509,6 +510,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
509
510
else if (overflowable_count + n >= 2 * f -> depth )
510
511
{
511
512
// Double overflowed
513
+ // Index is bigger than the allowed range [0,2*depth)
512
514
// re-position write index to have a full fifo after pushed
513
515
wr_idx = advance_pointer (f , rd_idx , f -> depth - n );
514
516
@@ -518,7 +520,9 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
518
520
// currently deliberately not implemented --> result in incorrect data read back
519
521
}else
520
522
{
521
- // normal + single overflowed: just increase write index
523
+ // normal + single overflowed:
524
+ // Index is in the range of [0,2*depth) and thus detect and recoverable. Recovering is handled in read()
525
+ // Therefore we just increase write index
522
526
// we will correct (re-position) read index later on in fifo_read() function
523
527
}
524
528
}
0 commit comments