summaryrefslogtreecommitdiff
path: root/firmware/src/data_link.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-31 10:33:56 +0200
committerxengineering <me@xengineering.eu>2024-06-01 10:25:12 +0200
commitff3fa235236f2d6d92f7869fb4f55e3655b0502a (patch)
tree8ef09c07efcdfe5194bc17a4debaba18d3286bdd /firmware/src/data_link.c
parentbb029aacf08983ad6c1a6360d988e89394fc4d85 (diff)
downloadiot-core-ff3fa235236f2d6d92f7869fb4f55e3655b0502a.tar
iot-core-ff3fa235236f2d6d92f7869fb4f55e3655b0502a.tar.zst
iot-core-ff3fa235236f2d6d92f7869fb4f55e3655b0502a.zip
firmware: Separate data link related code
Diffstat (limited to 'firmware/src/data_link.c')
-rw-r--r--firmware/src/data_link.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/firmware/src/data_link.c b/firmware/src/data_link.c
new file mode 100644
index 0000000..a6d091a
--- /dev/null
+++ b/firmware/src/data_link.c
@@ -0,0 +1,24 @@
+#include <zephyr/drivers/uart.h>
+
+#include "data_link.h"
+
+void dl_send_frame(const struct device *const uart_dev, uint8_t *buffer,
+ size_t len) {
+ for (size_t i = 0; i < len; i++) {
+ uint8_t octet = *(buffer + i);
+ switch (octet) {
+ case DL_SLIP_END:
+ uart_poll_out(uart_dev, DL_SLIP_ESC);
+ uart_poll_out(uart_dev, DL_SLIP_ESC_END);
+ break;
+ case DL_SLIP_ESC:
+ uart_poll_out(uart_dev, DL_SLIP_ESC);
+ uart_poll_out(uart_dev, DL_SLIP_ESC_ESC);
+ break;
+ default:
+ uart_poll_out(uart_dev, octet);
+ break;
+ }
+ }
+ uart_poll_out(uart_dev, DL_SLIP_END);
+}