summaryrefslogtreecommitdiff
path: root/libraries/fifo.h
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2020-10-25 12:49:35 +0100
committerxengineering <mail2xengineering@protonmail.com>2020-10-25 12:49:35 +0100
commit9435a85605d7efc75642491c85b0942bd558fcec (patch)
tree56e0c8f5530cac4e5e09aa174edaa170a0120726 /libraries/fifo.h
parentdb0a19edd8c4cd62c6784d8bb1d91c61a6447a2a (diff)
downloadstm32f103c8-examples-9435a85605d7efc75642491c85b0942bd558fcec.tar
stm32f103c8-examples-9435a85605d7efc75642491c85b0942bd558fcec.tar.zst
stm32f103c8-examples-9435a85605d7efc75642491c85b0942bd558fcec.zip
Add usart_irq Code
Diffstat (limited to 'libraries/fifo.h')
-rw-r--r--libraries/fifo.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/libraries/fifo.h b/libraries/fifo.h
new file mode 100644
index 0000000..c56d410
--- /dev/null
+++ b/libraries/fifo.h
@@ -0,0 +1,62 @@
+
+
+/*
+ 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
+*/
+
+
+#ifndef FIFO_H
+#define FIFO_H
+
+
+#include <stdint.h>
+#include <stdlib.h>
+
+
+typedef struct FIFO{
+ uint8_t *buffer_ptr;
+ uint16_t read_index;
+ uint16_t write_index;
+ uint16_t bufferlength;
+} FIFO;
+
+
+void fifo_init(FIFO *fifo, uint16_t bufferlength);
+void fifo_deinit(FIFO *fifo);
+
+uint16_t fifo_get_buffersize(FIFO *fifo);
+
+uint16_t fifo_bytes_available(FIFO *fifo);
+uint16_t fifo_lines_available(FIFO *fifo);
+
+void fifo_move_read_index(FIFO *fifo);
+void fifo_move_write_index(FIFO *fifo);
+
+void fifo_get_byte(FIFO *fifo, uint8_t *data_sink);
+void fifo_put_byte(FIFO *fifo, uint8_t *data_source);
+
+
+#endif /* FIFO_H */