summaryrefslogtreecommitdiff
path: root/src/common/tusb_fifo.h
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2020-09-19 11:46:43 +0200
committerReinhard Panhuber <[email protected]>2020-09-19 11:46:43 +0200
commit21299f90faf501422706ce36b6d3bb7c55bb3ecb (patch)
tree2a6ada21761d3e2fd1db2c437720421b42c8d435 /src/common/tusb_fifo.h
parent9dfb78e9d82d0386de555aa291242ddfe835cd18 (diff)
Final cleanup.
Diffstat (limited to 'src/common/tusb_fifo.h')
-rw-r--r--src/common/tusb_fifo.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/common/tusb_fifo.h b/src/common/tusb_fifo.h
index 56491c37b..66888ef19 100644
--- a/src/common/tusb_fifo.h
+++ b/src/common/tusb_fifo.h
@@ -31,6 +31,15 @@
#ifndef _TUSB_FIFO_H_
#define _TUSB_FIFO_H_
+// Due to the use of unmasked pointers, this FIFO does not suffer from loosing
+// one item slice. Furthermore, write and read operations are completely
+// decoupled as write and read functions do not modify a common state. Henceforth,
+// writing or reading from the FIFO within an ISR is safe as long as no other
+// process (thread or ISR) interferes.
+// Also, this FIFO is ready to be used in combination with a DMA as the write and
+// read pointers can be updated from within a DMA ISR. Overflows are detectable
+// within a certain number (see tu_fifo_overflow()).
+
// mutex is only needed for RTOS
// for OS None, we don't get preempted
#define CFG_FIFO_MUTEX (CFG_TUSB_OS != OPT_OS_NONE)
@@ -76,8 +85,8 @@ typedef struct
.depth = _depth, \
.item_size = sizeof(_type), \
.overwritable = _overwritable, \
- .non_used_index_space = (2^16-1) % _depth, \
- .max_pointer_idx = (2^16-1) - ((2^16-1) % _depth), \
+ .non_used_index_space = 0x10000 % _depth, \
+ .max_pointer_idx = 0xFFFF - (0x10000 % _depth), \
}
bool tu_fifo_clear(tu_fifo_t *f);
@@ -100,13 +109,17 @@ bool tu_fifo_peek_at (tu_fifo_t* f, uint16_t pos, void * p_bu
uint16_t tu_fifo_peek_at_n (tu_fifo_t* f, uint16_t pos, void * p_buffer, uint16_t n);
uint16_t tu_fifo_count (tu_fifo_t* f);
-void tu_fifo_correct_read_pointer (tu_fifo_t* f);
bool tu_fifo_empty (tu_fifo_t* f);
bool tu_fifo_full (tu_fifo_t* f);
uint16_t tu_fifo_remaining (tu_fifo_t* f);
bool tu_fifo_overflow (tu_fifo_t* f);
void tu_fifo_correct_read_pointer (tu_fifo_t* f);
+// Pointer modifications intended to be used in combinations with DMAs.
+// USE WITH CARE - NO SAFTY CHECKS CONDUCTED HERE! NOT MUTEX PROTECTED!
+void tu_fifo_advance_write_pointer (tu_fifo_t *f, uint16_t n);
+void tu_fifo_advance_read_pointer (tu_fifo_t *f, uint16_t n);
+
static inline bool tu_fifo_peek(tu_fifo_t* f, void * p_buffer)
{
return tu_fifo_peek_at(f, 0, p_buffer);