mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
update fifo per PanRe review
This commit is contained in:
parent
04a5c03ea8
commit
660343d200
@ -352,9 +352,10 @@ static uint16_t backward_pointer(tu_fifo_t* f, uint16_t p, uint16_t offset)
|
|||||||
return new_p;
|
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)
|
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;
|
while ( idx >= depth ) idx -= depth;
|
||||||
return idx;
|
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)
|
else if (overflowable_count + n >= 2*f->depth)
|
||||||
{
|
{
|
||||||
// Double overflowed
|
// Double overflowed
|
||||||
|
// Index is bigger than the allowed range [0,2*depth)
|
||||||
// re-position write index to have a full fifo after pushed
|
// re-position write index to have a full fifo after pushed
|
||||||
wr_idx = advance_pointer(f, rd_idx, f->depth - n);
|
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
|
// currently deliberately not implemented --> result in incorrect data read back
|
||||||
}else
|
}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
|
// we will correct (re-position) read index later on in fifo_read() function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ extern "C" {
|
|||||||
|
|
||||||
/* Write/Read index is always in the range of:
|
/* Write/Read index is always in the range of:
|
||||||
* 0 .. 2*depth-1
|
* 0 .. 2*depth-1
|
||||||
* The extra window allow us to determine the fifo state of empty or full with only 2 indexes
|
* The extra window allow us to determine the fifo state of empty or full with only 2 indices
|
||||||
* Following are examples with depth = 3
|
* Following are examples with depth = 3
|
||||||
*
|
*
|
||||||
* - empty: W = R
|
* - empty: W = R
|
||||||
@ -86,7 +86,8 @@ extern "C" {
|
|||||||
* -------------------------
|
* -------------------------
|
||||||
* | R | 1 | 2 | 3 | W | 5 |
|
* | R | 1 | 2 | 3 | W | 5 |
|
||||||
*
|
*
|
||||||
* - Double Overflowed: write(3), write(1), write(2)
|
* - Double Overflowed i.e index is out of allowed range [0,2*depth) e.g:
|
||||||
|
* write(3), write(1), write(2)
|
||||||
* Continue to write after overflowed to 2nd overflowed.
|
* Continue to write after overflowed to 2nd overflowed.
|
||||||
* We must prevent 2nd overflowed since it will cause incorrect computed of count, in above example
|
* We must prevent 2nd overflowed since it will cause incorrect computed of count, in above example
|
||||||
* if not handled the fifo will be empty instead of continue-to-be full. Since we must not modify
|
* if not handled the fifo will be empty instead of continue-to-be full. Since we must not modify
|
||||||
@ -94,7 +95,7 @@ extern "C" {
|
|||||||
* after data is written it is a full fifo i.e W = depth - R
|
* after data is written it is a full fifo i.e W = depth - R
|
||||||
*
|
*
|
||||||
* re-position W = 1 before write(2)
|
* re-position W = 1 before write(2)
|
||||||
* Note: we should also move data from mem[4] to read index as well, but deliberately skipped here
|
* Note: we should also move data from mem[3] to read index as well, but deliberately skipped here
|
||||||
* since it is an expensive operation !!!
|
* since it is an expensive operation !!!
|
||||||
* |
|
* |
|
||||||
* -------------------------
|
* -------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user