summaryrefslogtreecommitdiff
path: root/serial_link/protocol
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-14 17:45:25 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-14 17:45:25 +0200
commita089eaa8682927ea1d21f6dc5ce1d30c78140852 (patch)
tree27ab97a755123da1e1b36ebd7575967e1c0e9306 /serial_link/protocol
parent26537474ae1d65cdf40276299d7e04648474357b (diff)
Add sending of small frames with no zeroes
Diffstat (limited to 'serial_link/protocol')
-rw-r--r--serial_link/protocol/byte_stuffer.c12
-rw-r--r--serial_link/protocol/byte_stuffer.h1
-rw-r--r--serial_link/protocol/physical.h25
3 files changed, 37 insertions, 1 deletions
diff --git a/serial_link/protocol/byte_stuffer.c b/serial_link/protocol/byte_stuffer.c
index f0071b1f77..dfd5942ebc 100644
--- a/serial_link/protocol/byte_stuffer.c
+++ b/serial_link/protocol/byte_stuffer.c
@@ -24,7 +24,7 @@ SOFTWARE.
#include "protocol/byte_stuffer.h"
#include "protocol/frame_validator.h"
-#include <stdio.h>
+#include "protocol/physical.h"
// This implements the "Consistent overhead byte stuffing protocol"
// https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing
@@ -92,3 +92,13 @@ void recv_byte(byte_stuffer_state_t* state, uint8_t data) {
}
}
}
+
+void send_frame(uint8_t* data, uint16_t size) {
+ if (size > 0) {
+ uint8_t numZeroes = size + 1;
+ const uint8_t zero = 0;
+ send_data(&numZeroes, 1);
+ send_data(data, size);
+ send_data(&zero, 1);
+ }
+}
diff --git a/serial_link/protocol/byte_stuffer.h b/serial_link/protocol/byte_stuffer.h
index 9a5551fab5..ea6b8451d4 100644
--- a/serial_link/protocol/byte_stuffer.h
+++ b/serial_link/protocol/byte_stuffer.h
@@ -25,3 +25,4 @@ SOFTWARE.
typedef struct byte_stuffer_state byte_stuffer_state_t;
void init_byte_stuffer_state(byte_stuffer_state_t* state);
void recv_byte(byte_stuffer_state_t* state, uint8_t data);
+void send_frame(uint8_t* data, uint16_t size);
diff --git a/serial_link/protocol/physical.h b/serial_link/protocol/physical.h
new file mode 100644
index 0000000000..73a7855dfb
--- /dev/null
+++ b/serial_link/protocol/physical.h
@@ -0,0 +1,25 @@
+/*
+The MIT License (MIT)
+
+Copyright (c) 2016 Fred Sundvik
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+void send_data(const uint8_t* data, uint16_t size);