summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2020-09-15 20:40:41 +0200
committerReinhard Panhuber <[email protected]>2020-09-15 20:40:41 +0200
commit9dfb78e9d82d0386de555aa291242ddfe835cd18 (patch)
tree9565bb71547a8ff7a11e8fb0323bbbbedd085e0e /src/common
parent349c0f640e7d4532cc96fd28dea2dd11a5d43bde (diff)
Tested, working.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_fifo.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/common/tusb_fifo.c b/src/common/tusb_fifo.c
index 4e274003b..e7a2b469f 100644
--- a/src/common/tusb_fifo.c
+++ b/src/common/tusb_fifo.c
@@ -65,8 +65,8 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
f->item_size = item_size;
f->overwritable = overwritable;
- f->non_used_index_space = ((2^16)-1) % depth;
- f->max_pointer_idx = ((2^16)-1) - f->non_used_index_space;
+ f->non_used_index_space = 0x10000 % depth;
+ f->max_pointer_idx = 0xFFFF - f->non_used_index_space;
f->rd_idx = f->wr_idx = 0;
@@ -78,13 +78,14 @@ bool tu_fifo_config(tu_fifo_t *f, void* buffer, uint16_t depth, uint16_t item_si
// TODO: To be changed!!
static inline uint16_t _ff_mod(uint16_t idx, uint16_t depth)
{
- return (idx < depth) ? idx : (idx-depth);
+// return (idx < depth) ? idx : (idx-depth);
+ return idx % depth;
}
// send one item to FIFO WITHOUT updating write pointer
-static inline void _ff_push(tu_fifo_t* f, void const * data, uint16_t n, uint16_t wRel)
+static inline void _ff_push(tu_fifo_t* f, void const * data, uint16_t wRel)
{
- memcpy(f->buffer + (wRel * f->item_size), data, n*f->item_size);
+ memcpy(f->buffer + (wRel * f->item_size), data, f->item_size);
}
// send n items to FIFO WITHOUT updating write pointer
@@ -107,13 +108,13 @@ static void _ff_push_n(tu_fifo_t* f, void const * data, uint16_t n, uint16_t wRe
}
// get one item from FIFO WITHOUT updating write pointer
-static inline void _ff_pull(tu_fifo_t* f, void const * p_buffer, uint16_t rRel)
+static inline void _ff_pull(tu_fifo_t* f, void * p_buffer, uint16_t rRel)
{
memcpy(p_buffer, f->buffer + (rRel * f->item_size), f->item_size);
}
// get n items from FIFO WITHOUT updating write pointer
-static void _ff_pull_n(tu_fifo_t* f, void const * p_buffer, uint16_t n, uint16_t rRel)
+static void _ff_pull_n(tu_fifo_t* f, void * p_buffer, uint16_t n, uint16_t rRel)
{
if(rRel + n <= f->depth) // Linear mode only
{
@@ -136,7 +137,7 @@ static uint16_t advance_pointer(tu_fifo_t* f, uint16_t p, uint16_t pos)
{
// We limit the index space of p such that a correct wrap around happens
// Check for a wrap around or if we are in unused index space - This has to be checked first!! We are exploiting the wrap around to the correct index
- if ((p > p + pos) || (p + pos >= f->max_pointer_idx))
+ if ((p > p + pos) || (p + pos > f->max_pointer_idx))
{
p = (p + pos) + f->non_used_index_space;
}