diff options
author | xengineering <mail2xengineering@protonmail.com> | 2020-10-25 16:52:57 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2020-10-25 16:52:57 +0100 |
commit | 56c268e88a87f708de1824d87fbf7b824d4c1c2a (patch) | |
tree | 0a4ab861b2f03c2fde1de8d7a3b61d2603b4d503 /libraries/fifo.h | |
parent | 58d3787ca563b7d6a2cb4e0a1ab7fdde67fd5557 (diff) | |
download | stm32f103c8-examples-56c268e88a87f708de1824d87fbf7b824d4c1c2a.tar stm32f103c8-examples-56c268e88a87f708de1824d87fbf7b824d4c1c2a.tar.zst stm32f103c8-examples-56c268e88a87f708de1824d87fbf7b824d4c1c2a.zip |
Remove any Heap Allocation
Diffstat (limited to 'libraries/fifo.h')
-rw-r--r-- | libraries/fifo.h | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/libraries/fifo.h b/libraries/fifo.h index c56d410..700d2ec 100644 --- a/libraries/fifo.h +++ b/libraries/fifo.h @@ -1,30 +1,30 @@ -/* - FIFO Ring Buffer uint8_t array ring_buffer (example length is 8) - with data (x) and read and write index: - - --- --- --- --- --- --- --- --- - | | | x | x | x | | | | - --- --- --- --- --- --- --- --- - ^ ^ - | | - read_index | - write_index - - --- --- --- --- --- --- --- --- - | x | x | | | | x | x | x | - --- --- --- --- --- --- --- --- - ^ ^ - | | - write_index | - read_index - - - input data goes to position of write_index - - output data comes from read_index position - - after input/output operation the according index has to be modified - - according to the idea of ring buffers the write_index could be - smaller than the read_index +/* + FIFO Ring Buffer uint8_t array ring_buffer (example length is 8) + with data (x) and read and write index: + + --- --- --- --- --- --- --- --- + | | | x | x | x | | | | + --- --- --- --- --- --- --- --- + ^ ^ + | | + read_index | + write_index + + --- --- --- --- --- --- --- --- + | x | x | | | | x | x | x | + --- --- --- --- --- --- --- --- + ^ ^ + | | + write_index | + read_index + + - input data goes to position of write_index + - output data comes from read_index position + - after input/output operation the according index has to be modified + - according to the idea of ring buffers the write_index could be + smaller than the read_index */ @@ -37,15 +37,14 @@ typedef struct FIFO{ - uint8_t *buffer_ptr; - uint16_t read_index; - uint16_t write_index; - uint16_t bufferlength; + uint8_t *buffer_ptr; + uint16_t bufferlength; + uint16_t read_index; + uint16_t write_index; } FIFO; -void fifo_init(FIFO *fifo, uint16_t bufferlength); -void fifo_deinit(FIFO *fifo); +void fifo_init(FIFO *fifo, uint8_t *buffer, uint16_t bufferlength); uint16_t fifo_get_buffersize(FIFO *fifo); |