@@ -319,35 +319,35 @@ static void _ff_pull_n(tu_fifo_t* f, void* app_buf, uint16_t n, uint16_t rel, tu
319
319
320
320
// Advance an absolute index
321
321
// "absolute" index is only in the range of [0..2*depth)
322
- static uint16_t advance_pointer ( tu_fifo_t * f , uint16_t idx , uint16_t offset )
322
+ static uint16_t advance_index ( uint16_t depth , uint16_t idx , uint16_t offset )
323
323
{
324
324
// We limit the index space of p such that a correct wrap around happens
325
325
// Check for a wrap around or if we are in unused index space - This has to be checked first!!
326
326
// We are exploiting the wrap around to the correct index
327
- uint16_t next_p = (uint16_t ) (idx + offset );
328
- if ( (idx > next_p ) || (next_p >= 2 * f -> depth ) )
327
+ uint16_t new_idx = (uint16_t ) (idx + offset );
328
+ if ( (idx > new_idx ) || (new_idx >= 2 * depth ) )
329
329
{
330
- uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * f -> depth - 1 ));
331
- next_p = (uint16_t ) (next_p + non_used_index_space );
330
+ uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * depth - 1 ));
331
+ new_idx = (uint16_t ) (new_idx + non_used_index_space );
332
332
}
333
333
334
- return next_p ;
334
+ return new_idx ;
335
335
}
336
336
337
- // Backward an absolute pointer
338
- static uint16_t backward_pointer ( tu_fifo_t * f , uint16_t p , uint16_t offset )
337
+ // Backward an absolute index
338
+ static uint16_t backward_index ( uint16_t depth , uint16_t idx , uint16_t offset )
339
339
{
340
340
// We limit the index space of p such that a correct wrap around happens
341
341
// Check for a wrap around or if we are in unused index space - This has to be checked first!!
342
342
// We are exploiting the wrap around to the correct index
343
- uint16_t new_p = (uint16_t ) (p - offset );
344
- if ( (p < new_p ) || (new_p >= 2 * f -> depth ) )
343
+ uint16_t new_idx = (uint16_t ) (idx - offset );
344
+ if ( (idx < new_idx ) || (new_idx >= 2 * depth ) )
345
345
{
346
- uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * f -> depth - 1 ));
347
- new_p = (uint16_t ) (new_p - non_used_index_space );
346
+ uint16_t const non_used_index_space = (uint16_t ) (UINT16_MAX - (2 * depth - 1 ));
347
+ new_idx = (uint16_t ) (new_idx - non_used_index_space );
348
348
}
349
349
350
- return new_p ;
350
+ return new_idx ;
351
351
}
352
352
353
353
// index to pointer, simply an modulo with minus.
@@ -394,9 +394,9 @@ uint16_t _ff_remaining(uint16_t depth, uint16_t wr_idx, uint16_t rd_idx)
394
394
// Works on local copies of w
395
395
// For more details see _tu_fifo_overflow()!
396
396
TU_ATTR_ALWAYS_INLINE static inline
397
- void _tu_fifo_correct_read_pointer (tu_fifo_t * f , uint16_t wAbs )
397
+ void _tu_fifo_correct_read_pointer (tu_fifo_t * f , uint16_t wr_idx )
398
398
{
399
- f -> rd_idx = backward_pointer ( f , wAbs , f -> depth );
399
+ f -> rd_idx = backward_index ( f -> depth , wr_idx , f -> depth );
400
400
}
401
401
402
402
// Works on local copies of w and r
@@ -502,7 +502,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
502
502
// Double overflowed
503
503
// Index is bigger than the allowed range [0,2*depth)
504
504
// re-position write index to have a full fifo after pushed
505
- wr_idx = advance_pointer ( f , rd_idx , f -> depth - n );
505
+ wr_idx = advance_index ( f -> depth , rd_idx , f -> depth - n );
506
506
507
507
// TODO we should also shift out n bytes from read index since we avoid changing rd index !!
508
508
// However memmove() is expensive due to actual copying + wrapping consideration.
@@ -528,7 +528,7 @@ static uint16_t _tu_fifo_write_n(tu_fifo_t* f, const void * data, uint16_t n, tu
528
528
_ff_push_n (f , buf8 , n , wr_ptr , copy_mode );
529
529
530
530
// Advance index
531
- f -> wr_idx = advance_pointer ( f , wr_idx , n );
531
+ f -> wr_idx = advance_index ( f -> depth , wr_idx , n );
532
532
533
533
TU_LOG (TU_FIFO_DBG , "\tnew_wr = %u\n" , f -> wr_idx );
534
534
}
@@ -547,7 +547,7 @@ static uint16_t _tu_fifo_read_n(tu_fifo_t* f, void * buffer, uint16_t n, tu_fifo
547
547
n = _tu_fifo_peek_n (f , buffer , n , f -> wr_idx , f -> rd_idx , copy_mode );
548
548
549
549
// Advance read pointer
550
- f -> rd_idx = advance_pointer ( f , f -> rd_idx , n );
550
+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , n );
551
551
552
552
_ff_unlock (f -> mutex_rd );
553
553
return n ;
@@ -690,7 +690,7 @@ bool tu_fifo_read(tu_fifo_t* f, void * buffer)
690
690
bool ret = _tu_fifo_peek (f , buffer , f -> wr_idx , f -> rd_idx );
691
691
692
692
// Advance pointer
693
- f -> rd_idx = advance_pointer ( f , f -> rd_idx , ret );
693
+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , ret );
694
694
695
695
_ff_unlock (f -> mutex_rd );
696
696
return ret ;
@@ -800,7 +800,7 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
800
800
_ff_push (f , data , wr_ptr );
801
801
802
802
// Advance pointer
803
- f -> wr_idx = advance_pointer ( f , wr_idx , 1 );
803
+ f -> wr_idx = advance_index ( f -> depth , wr_idx , 1 );
804
804
805
805
ret = true;
806
806
}
@@ -911,7 +911,7 @@ bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable)
911
911
/******************************************************************************/
912
912
void tu_fifo_advance_write_pointer (tu_fifo_t * f , uint16_t n )
913
913
{
914
- f -> wr_idx = advance_pointer ( f , f -> wr_idx , n );
914
+ f -> wr_idx = advance_index ( f -> depth , f -> wr_idx , n );
915
915
}
916
916
917
917
/******************************************************************************/
@@ -932,7 +932,7 @@ void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n)
932
932
/******************************************************************************/
933
933
void tu_fifo_advance_read_pointer (tu_fifo_t * f , uint16_t n )
934
934
{
935
- f -> rd_idx = advance_pointer ( f , f -> rd_idx , n );
935
+ f -> rd_idx = advance_index ( f -> depth , f -> rd_idx , n );
936
936
}
937
937
938
938
/******************************************************************************/
0 commit comments