summaryrefslogtreecommitdiff
path: root/tests/usb-serial-rs485/ringb.h
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2016-09-26 22:04:02 +0000
committerKarl Palsson <karlp@tweak.net.au>2016-09-26 22:04:02 +0000
commitc0ec94e4c94371d22c334396c5d937d0a682de78 (patch)
tree8fbf2576d64ebc3cb708b08c63e5863fe2c220d2 /tests/usb-serial-rs485/ringb.h
parent19d3225fd66573a2a62ece83158cd5551255f2ad (diff)
downloadolsndot-c0ec94e4c94371d22c334396c5d937d0a682de78.tar.gz
olsndot-c0ec94e4c94371d22c334396c5d937d0a682de78.tar.bz2
olsndot-c0ec94e4c94371d22c334396c5d937d0a682de78.zip
ubs-serial-rs485: First solidly working version.
Needs major refactoring to split out the _actual_ arch dependent pieces. Needs parity and more complete baud rate support. Needs rs485 support.
Diffstat (limited to 'tests/usb-serial-rs485/ringb.h')
-rw-r--r--tests/usb-serial-rs485/ringb.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/usb-serial-rs485/ringb.h b/tests/usb-serial-rs485/ringb.h
new file mode 100644
index 0000000..c3d5356
--- /dev/null
+++ b/tests/usb-serial-rs485/ringb.h
@@ -0,0 +1,60 @@
+/*
+ * Karl Palsson <karlp@tweak.net.au>
+ * Considered to be released under your choice of:
+ * MIT/ISC/Apache2/BSD2Clause/GPLv2
+ * If you're looking for elegant compact performance you've come to the wrong
+ * place hombre.
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct ringb {
+ volatile unsigned int idx_r;
+ volatile unsigned int idx_w;
+ uint8_t *buf;
+ int buf_len;
+};
+
+/**
+ * Load up a ring buffer. Always suceeds
+ * @param ring struct saving state, provided by the user
+ * @param buf where the data will be kept
+ * @param len size of buf in in elements.
+ */
+void ringb_init(struct ringb *ring, uint8_t *buf, int len);
+
+/**
+ * push data in
+ * @param ring
+ * @param c
+ * @return true if space was available
+ */
+bool ringb_put(struct ringb *ring, uint8_t c);
+
+/**
+ * pull data out
+ * @param ring
+ * @return -1 for no data, uint8_t range for valid.
+ */
+int ringb_get(struct ringb *ring);
+
+/**
+ * Toss data and reset to empty
+ * @param ring
+ */
+void ringb_flush(struct ringb *ring);
+
+int ringb_depth(struct ringb *ring);
+
+
+
+#ifdef __cplusplus
+}
+#endif