aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--serial_link.mk3
-rw-r--r--serial_link/protocol/byte_stuffer.c8
-rw-r--r--serial_link/protocol/byte_stuffer.h7
-rw-r--r--serial_link/protocol/frame_router.c5
-rw-r--r--serial_link/protocol/frame_router.h8
-rw-r--r--serial_link/protocol/frame_validator.c7
-rw-r--r--serial_link/protocol/frame_validator.h7
-rw-r--r--serial_link/protocol/physical.h5
-rw-r--r--serial_link/protocol/transport.c20
-rw-r--r--serial_link/protocol/transport.h5
-rw-r--r--serial_link/protocol/triple_buffered_object.c6
-rw-r--r--serial_link/protocol/triple_buffered_object.h2
-rw-r--r--serial_link/system/system.h12
-rw-r--r--serial_link/tests/Makefile2
-rw-r--r--serial_link/tests/byte_stuffer_tests.c8
-rw-r--r--serial_link/tests/frame_router_tests.c8
-rw-r--r--serial_link/tests/frame_validator_tests.c2
-rw-r--r--serial_link/tests/transport_tests.c4
-rw-r--r--serial_link/tests/triple_buffered_object_tests.c2
19 files changed, 79 insertions, 42 deletions
diff --git a/serial_link.mk b/serial_link.mk
index de2364108..e8915a33f 100644
--- a/serial_link.mk
+++ b/serial_link.mk
@@ -20,4 +20,5 @@
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE. 21# SOFTWARE.
22 22
23INC += $(SERIAL_DIR) \ No newline at end of file 23INC += $(SERIAL_DIR)
24SRC += $(wildcard $(SERIAL_DIR)/serial_link/protocol/*.c) \ No newline at end of file
diff --git a/serial_link/protocol/byte_stuffer.c b/serial_link/protocol/byte_stuffer.c
index 8b529667f..fb4c45a8d 100644
--- a/serial_link/protocol/byte_stuffer.c
+++ b/serial_link/protocol/byte_stuffer.c
@@ -22,10 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "protocol/byte_stuffer.h" 25#include "serial_link/protocol/byte_stuffer.h"
26#include "protocol/frame_validator.h" 26#include "serial_link/protocol/frame_validator.h"
27#include "protocol/physical.h" 27#include "serial_link/protocol/physical.h"
28#include <stdio.h> 28#include <stdbool.h>
29 29
30// This implements the "Consistent overhead byte stuffing protocol" 30// This implements the "Consistent overhead byte stuffing protocol"
31// https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing 31// https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing
diff --git a/serial_link/protocol/byte_stuffer.h b/serial_link/protocol/byte_stuffer.h
index 839a876fe..2cc88beb4 100644
--- a/serial_link/protocol/byte_stuffer.h
+++ b/serial_link/protocol/byte_stuffer.h
@@ -22,6 +22,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#ifndef SERIAL_LINK_BYTE_STUFFER_H
26#define SERIAL_LINK_BYTE_STUFFER_H
27
28#include <stdint.h>
29
25void init_byte_stuffer(void); 30void init_byte_stuffer(void);
26void byte_stuffer_recv_byte(uint8_t link, uint8_t data); 31void byte_stuffer_recv_byte(uint8_t link, uint8_t data);
27void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size); 32void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size);
33
34#endif
diff --git a/serial_link/protocol/frame_router.c b/serial_link/protocol/frame_router.c
index 890ebbe9e..04b8c2e75 100644
--- a/serial_link/protocol/frame_router.c
+++ b/serial_link/protocol/frame_router.c
@@ -22,8 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "protocol/frame_router.h" 25#include "serial_link/protocol/frame_router.h"
26#include "protocol/transport.h" 26#include "serial_link/protocol/transport.h"
27#include "serial_link/protocol/frame_validator.h"
27 28
28static bool is_master; 29static bool is_master;
29 30
diff --git a/serial_link/protocol/frame_router.h b/serial_link/protocol/frame_router.h
index 67db3122f..712250ff3 100644
--- a/serial_link/protocol/frame_router.h
+++ b/serial_link/protocol/frame_router.h
@@ -22,9 +22,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#ifndef SERIAL_LINK_FRAME_ROUTER_H
26#define SERIAL_LINK_FRAME_ROUTER_H
27
28#include <stdint.h>
29#include <stdbool.h>
30
25#define UP_LINK 0 31#define UP_LINK 0
26#define DOWN_LINK 1 32#define DOWN_LINK 1
27 33
28void router_set_master(bool master); 34void router_set_master(bool master);
29void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size); 35void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size);
30void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size); 36void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size);
37
38#endif
diff --git a/serial_link/protocol/frame_validator.c b/serial_link/protocol/frame_validator.c
index a3face650..474f80ee8 100644
--- a/serial_link/protocol/frame_validator.c
+++ b/serial_link/protocol/frame_validator.c
@@ -22,9 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "protocol/frame_validator.h" 25#include "serial_link/protocol/frame_validator.h"
26#include "protocol/frame_router.h" 26#include "serial_link/protocol/frame_router.h"
27#include "protocol/byte_stuffer.h" 27#include "serial_link/protocol/byte_stuffer.h"
28#include <string.h>
28 29
29const uint32_t poly8_lookup[256] = 30const uint32_t poly8_lookup[256] =
30{ 31{
diff --git a/serial_link/protocol/frame_validator.h b/serial_link/protocol/frame_validator.h
index c35fc2726..4a910d510 100644
--- a/serial_link/protocol/frame_validator.h
+++ b/serial_link/protocol/frame_validator.h
@@ -22,6 +22,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#ifndef SERIAL_LINK_FRAME_VALIDATOR_H
26#define SERIAL_LINK_FRAME_VALIDATOR_H
27
28#include <stdint.h>
29
25void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size); 30void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size);
26// The buffer pointed to by the data needs 4 additional bytes 31// The buffer pointed to by the data needs 4 additional bytes
27void validator_send_frame(uint8_t link, uint8_t* data, uint16_t size); 32void validator_send_frame(uint8_t link, uint8_t* data, uint16_t size);
33
34#endif
diff --git a/serial_link/protocol/physical.h b/serial_link/protocol/physical.h
index ee5883d36..425e06cdd 100644
--- a/serial_link/protocol/physical.h
+++ b/serial_link/protocol/physical.h
@@ -22,4 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#ifndef SERIAL_LINK_PHYSICAL_H
26#define SERIAL_LINK_PHYSICAL_H
27
25void send_data(uint8_t link, const uint8_t* data, uint16_t size); 28void send_data(uint8_t link, const uint8_t* data, uint16_t size);
29
30#endif
diff --git a/serial_link/protocol/transport.c b/serial_link/protocol/transport.c
index 03f83a806..4542a7a05 100644
--- a/serial_link/protocol/transport.c
+++ b/serial_link/protocol/transport.c
@@ -22,9 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "protocol/transport.h" 25#include "serial_link/protocol/transport.h"
26#include "protocol/frame_router.h" 26#include "serial_link/protocol/frame_router.h"
27#include "protocol/triple_buffered_object.h" 27#include "serial_link/protocol/triple_buffered_object.h"
28#include <string.h>
28 29
29static remote_object_t** remote_objects; 30static remote_object_t** remote_objects;
30static uint32_t num_remote_objects; 31static uint32_t num_remote_objects;
@@ -32,7 +33,7 @@ static uint32_t num_remote_objects;
32void init_transport(remote_object_t** _remote_objects, uint32_t _num_remote_objects) { 33void init_transport(remote_object_t** _remote_objects, uint32_t _num_remote_objects) {
33 remote_objects = _remote_objects; 34 remote_objects = _remote_objects;
34 num_remote_objects = _num_remote_objects; 35 num_remote_objects = _num_remote_objects;
35 int i; 36 unsigned int i;
36 for(i=0;i<num_remote_objects;i++) { 37 for(i=0;i<num_remote_objects;i++) {
37 remote_object_t* obj = remote_objects[i]; 38 remote_object_t* obj = remote_objects[i];
38 if (obj->object_type == MASTER_TO_ALL_SLAVES) { 39 if (obj->object_type == MASTER_TO_ALL_SLAVES) {
@@ -44,7 +45,7 @@ void init_transport(remote_object_t** _remote_objects, uint32_t _num_remote_obje
44 } 45 }
45 else if(obj->object_type == MASTER_TO_SINGLE_SLAVE) { 46 else if(obj->object_type == MASTER_TO_SINGLE_SLAVE) {
46 uint8_t* start = obj->buffer; 47 uint8_t* start = obj->buffer;
47 int j; 48 unsigned int j;
48 for (j=0;j<NUM_SLAVES;j++) { 49 for (j=0;j<NUM_SLAVES;j++) {
49 triple_buffer_object_t* tb = (triple_buffer_object_t*)start; 50 triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
50 triple_buffer_init(tb); 51 triple_buffer_init(tb);
@@ -58,7 +59,7 @@ void init_transport(remote_object_t** _remote_objects, uint32_t _num_remote_obje
58 triple_buffer_object_t* tb = (triple_buffer_object_t*)start; 59 triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
59 triple_buffer_init(tb); 60 triple_buffer_init(tb);
60 start += LOCAL_OBJECT_SIZE(obj->object_size); 61 start += LOCAL_OBJECT_SIZE(obj->object_size);
61 int j; 62 unsigned int j;
62 for (j=0;j<NUM_SLAVES;j++) { 63 for (j=0;j<NUM_SLAVES;j++) {
63 tb = (triple_buffer_object_t*)start; 64 tb = (triple_buffer_object_t*)start;
64 triple_buffer_init(tb); 65 triple_buffer_init(tb);
@@ -88,11 +89,8 @@ void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
88 triple_buffer_end_write_internal(tb); 89 triple_buffer_end_write_internal(tb);
89} 90}
90 91
91uint32_t transport_send_frame(uint8_t to, uint8_t* data, uint16_t size) {
92}
93
94void update_transport(void) { 92void update_transport(void) {
95 int i; 93 unsigned int i;
96 for(i=0;i<num_remote_objects;i++) { 94 for(i=0;i<num_remote_objects;i++) {
97 remote_object_t* obj = remote_objects[i]; 95 remote_object_t* obj = remote_objects[i];
98 if (obj->object_type == MASTER_TO_ALL_SLAVES || obj->object_type == SLAVE_TO_MASTER) { 96 if (obj->object_type == MASTER_TO_ALL_SLAVES || obj->object_type == SLAVE_TO_MASTER) {
@@ -106,7 +104,7 @@ void update_transport(void) {
106 } 104 }
107 else { 105 else {
108 uint8_t* start = obj->buffer; 106 uint8_t* start = obj->buffer;
109 int j; 107 unsigned int j;
110 for (j=0;j<NUM_SLAVES;j++) { 108 for (j=0;j<NUM_SLAVES;j++) {
111 triple_buffer_object_t* tb = (triple_buffer_object_t*)start; 109 triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
112 uint8_t* ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb); 110 uint8_t* ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
diff --git a/serial_link/protocol/transport.h b/serial_link/protocol/transport.h
index a1a83b8f7..9e9e22462 100644
--- a/serial_link/protocol/transport.h
+++ b/serial_link/protocol/transport.h
@@ -25,8 +25,8 @@ SOFTWARE.
25#ifndef SERIAL_LINK_TRANSPORT_H 25#ifndef SERIAL_LINK_TRANSPORT_H
26#define SERIAL_LINK_TRANSPORT_H 26#define SERIAL_LINK_TRANSPORT_H
27 27
28#include "protocol/triple_buffered_object.h" 28#include "serial_link/protocol/triple_buffered_object.h"
29#include "system/system.h" 29#include "serial_link/system/system.h"
30 30
31#define NUM_SLAVES 8 31#define NUM_SLAVES 8
32#define LOCAL_OBJECT_EXTRA 16 32#define LOCAL_OBJECT_EXTRA 16
@@ -146,7 +146,6 @@ typedef struct { \
146 146
147void init_transport(remote_object_t** remote_objects, uint32_t num_remote_objects); 147void init_transport(remote_object_t** remote_objects, uint32_t num_remote_objects);
148void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size); 148void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size);
149uint32_t transport_send_frame(uint8_t to, uint8_t* data, uint16_t size);
150void update_transport(void); 149void update_transport(void);
151 150
152#endif 151#endif
diff --git a/serial_link/protocol/triple_buffered_object.c b/serial_link/protocol/triple_buffered_object.c
index 6b3cf75ad..c6bf28af0 100644
--- a/serial_link/protocol/triple_buffered_object.c
+++ b/serial_link/protocol/triple_buffered_object.c
@@ -22,8 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE. 22SOFTWARE.
23*/ 23*/
24 24
25#include "protocol/triple_buffered_object.h" 25#include "serial_link/protocol/triple_buffered_object.h"
26#include "system/system.h" 26#include "serial_link/system/system.h"
27#include <stdbool.h>
28#include <stddef.h>
27 29
28#define GET_READ_INDEX() object->state & 3 30#define GET_READ_INDEX() object->state & 3
29#define GET_WRITE_INDEX() (object->state >> 2) & 3 31#define GET_WRITE_INDEX() (object->state >> 2) & 3
diff --git a/serial_link/protocol/triple_buffered_object.h b/serial_link/protocol/triple_buffered_object.h
index 03209709c..2e57db3f5 100644
--- a/serial_link/protocol/triple_buffered_object.h
+++ b/serial_link/protocol/triple_buffered_object.h
@@ -25,6 +25,8 @@ SOFTWARE.
25#ifndef SERIAL_LINK_TRIPLE_BUFFERED_OBJECT_H 25#ifndef SERIAL_LINK_TRIPLE_BUFFERED_OBJECT_H
26#define SERIAL_LINK_TRIPLE_BUFFERED_OBJECT_H 26#define SERIAL_LINK_TRIPLE_BUFFERED_OBJECT_H
27 27
28#include <stdint.h>
29
28typedef struct { 30typedef struct {
29 uint8_t state; 31 uint8_t state;
30 uint8_t buffer[] __attribute__((aligned(4))); 32 uint8_t buffer[] __attribute__((aligned(4)));
diff --git a/serial_link/system/system.h b/serial_link/system/system.h
index 163349953..1e4c610b1 100644
--- a/serial_link/system/system.h
+++ b/serial_link/system/system.h
@@ -25,12 +25,18 @@ SOFTWARE.
25#ifndef SERIAL_LINK_SYSTEM_H 25#ifndef SERIAL_LINK_SYSTEM_H
26#define SERIAL_LINK_SYSTEM_H 26#define SERIAL_LINK_SYSTEM_H
27 27
28void serial_link_lock() { 28inline void serial_link_lock(void) {
29} 29}
30 30
31void serial_link_unlock() { 31inline void serial_link_unlock(void) {
32} 32}
33 33
34void signal_data_written(void); 34void singal_data_written(void);
35
36#if defined(PROTOCOL_CHIBIOS)
37
38inline void signal_data_written(void) {
39}
40#endif
35 41
36#endif 42#endif
diff --git a/serial_link/tests/Makefile b/serial_link/tests/Makefile
index 0d8ba4b7b..1b072c6f1 100644
--- a/serial_link/tests/Makefile
+++ b/serial_link/tests/Makefile
@@ -22,7 +22,7 @@
22 22
23CC = gcc 23CC = gcc
24CFLAGS = 24CFLAGS =
25INCLUDES = -I. -I../ 25INCLUDES = -I. -I../../
26LDFLAGS = -L$(BUILDDIR)/cgreen/build-c/src -shared 26LDFLAGS = -L$(BUILDDIR)/cgreen/build-c/src -shared
27LDLIBS = -lcgreen 27LDLIBS = -lcgreen
28UNITOBJ = $(BUILDDIR)/serialtest/unitobj 28UNITOBJ = $(BUILDDIR)/serialtest/unitobj
diff --git a/serial_link/tests/byte_stuffer_tests.c b/serial_link/tests/byte_stuffer_tests.c
index 912c4d321..64b170e8c 100644
--- a/serial_link/tests/byte_stuffer_tests.c
+++ b/serial_link/tests/byte_stuffer_tests.c
@@ -24,10 +24,10 @@ SOFTWARE.
24 24
25#include <cgreen/cgreen.h> 25#include <cgreen/cgreen.h>
26#include <cgreen/mocks.h> 26#include <cgreen/mocks.h>
27#include "protocol/byte_stuffer.h" 27#include "serial_link/protocol/byte_stuffer.h"
28#include "protocol/byte_stuffer.c" 28#include "serial_link/protocol/byte_stuffer.c"
29#include "protocol/frame_validator.h" 29#include "serial_link/protocol/frame_validator.h"
30#include "protocol/physical.h" 30#include "serial_link/protocol/physical.h"
31 31
32static uint8_t sent_data[MAX_FRAME_SIZE*2]; 32static uint8_t sent_data[MAX_FRAME_SIZE*2];
33static uint16_t sent_data_size; 33static uint16_t sent_data_size;
diff --git a/serial_link/tests/frame_router_tests.c b/serial_link/tests/frame_router_tests.c
index 0b0ea6e7f..6c806fa93 100644
--- a/serial_link/tests/frame_router_tests.c
+++ b/serial_link/tests/frame_router_tests.c
@@ -24,10 +24,10 @@ SOFTWARE.
24 24
25#include <cgreen/cgreen.h> 25#include <cgreen/cgreen.h>
26#include <cgreen/mocks.h> 26#include <cgreen/mocks.h>
27#include "protocol/byte_stuffer.c" 27#include "serial_link/protocol/byte_stuffer.c"
28#include "protocol/frame_validator.c" 28#include "serial_link/protocol/frame_validator.c"
29#include "protocol/frame_router.c" 29#include "serial_link/protocol/frame_router.c"
30#include "protocol/transport.h" 30#include "serial_link/protocol/transport.h"
31 31
32static uint8_t received_data[256]; 32static uint8_t received_data[256];
33static uint16_t received_data_size; 33static uint16_t received_data_size;
diff --git a/serial_link/tests/frame_validator_tests.c b/serial_link/tests/frame_validator_tests.c
index f4abd14d1..d20947e2c 100644
--- a/serial_link/tests/frame_validator_tests.c
+++ b/serial_link/tests/frame_validator_tests.c
@@ -24,7 +24,7 @@ SOFTWARE.
24 24
25#include <cgreen/cgreen.h> 25#include <cgreen/cgreen.h>
26#include <cgreen/mocks.h> 26#include <cgreen/mocks.h>
27#include "protocol/frame_validator.c" 27#include "serial_link/protocol/frame_validator.c"
28 28
29void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { 29void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) {
30 mock(data, size); 30 mock(data, size);
diff --git a/serial_link/tests/transport_tests.c b/serial_link/tests/transport_tests.c
index 3fa8eab4a..3e9bffdfa 100644
--- a/serial_link/tests/transport_tests.c
+++ b/serial_link/tests/transport_tests.c
@@ -24,8 +24,8 @@ SOFTWARE.
24 24
25#include <cgreen/cgreen.h> 25#include <cgreen/cgreen.h>
26#include <cgreen/mocks.h> 26#include <cgreen/mocks.h>
27#include "protocol/transport.c" 27#include "serial_link/protocol/transport.c"
28#include "protocol/triple_buffered_object.c" 28#include "serial_link/protocol/triple_buffered_object.c"
29 29
30void signal_data_written(void) { 30void signal_data_written(void) {
31 mock(); 31 mock();
diff --git a/serial_link/tests/triple_buffered_object_tests.c b/serial_link/tests/triple_buffered_object_tests.c
index 1017df8f5..6f7c82b46 100644
--- a/serial_link/tests/triple_buffered_object_tests.c
+++ b/serial_link/tests/triple_buffered_object_tests.c
@@ -23,7 +23,7 @@ SOFTWARE.
23*/ 23*/
24 24
25#include <cgreen/cgreen.h> 25#include <cgreen/cgreen.h>
26#include "protocol/triple_buffered_object.c" 26#include "serial_link/protocol/triple_buffered_object.c"
27 27
28typedef struct { 28typedef struct {
29 uint8_t state; 29 uint8_t state;