From 11bd4ba0dd39654318bd0a3ae495656c2b2187bb Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 12 Mar 2016 19:35:09 +0200 Subject: [PATCH] Remote object callable from many places Change init_transport to add_remote_objects, so that it can be called many times from different places. --- serial_link/protocol/transport.c | 14 +++++++------- serial_link/protocol/transport.h | 2 +- serial_link/system/system.c | 4 ++-- serial_link/tests/transport_tests.c | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/serial_link/protocol/transport.c b/serial_link/protocol/transport.c index 4542a7a050e..fbcb040bf1c 100644 --- a/serial_link/protocol/transport.c +++ b/serial_link/protocol/transport.c @@ -27,15 +27,15 @@ SOFTWARE. #include "serial_link/protocol/triple_buffered_object.h" #include -static remote_object_t** remote_objects; -static uint32_t num_remote_objects; +#define MAX_REMOTE_OBJECTS 16 +static remote_object_t* remote_objects[MAX_REMOTE_OBJECTS]; +static uint32_t num_remote_objects = 0; -void init_transport(remote_object_t** _remote_objects, uint32_t _num_remote_objects) { - remote_objects = _remote_objects; - num_remote_objects = _num_remote_objects; +void add_remote_objects(remote_object_t** _remote_objects, uint32_t _num_remote_objects) { unsigned int i; - for(i=0;iobject_type == MASTER_TO_ALL_SLAVES) { triple_buffer_object_t* tb = (triple_buffer_object_t*)obj->buffer; triple_buffer_init(tb); diff --git a/serial_link/protocol/transport.h b/serial_link/protocol/transport.h index 9e9e22462c7..e518aaa6eb7 100644 --- a/serial_link/protocol/transport.h +++ b/serial_link/protocol/transport.h @@ -144,7 +144,7 @@ typedef struct { \ #define REMOTE_OBJECT(name) (remote_object_t*)&remote_object_##name -void init_transport(remote_object_t** remote_objects, uint32_t num_remote_objects); +void add_remote_objects(remote_object_t** remote_objects, uint32_t num_remote_objects); void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size); void update_transport(void); diff --git a/serial_link/system/system.c b/serial_link/system/system.c index 9cf695a308b..9e4ee5d95e1 100644 --- a/serial_link/system/system.c +++ b/serial_link/system/system.c @@ -120,7 +120,7 @@ static matrix_object_t last_matrix = {}; SLAVE_TO_MASTER_OBJECT(keyboard_matrix, matrix_object_t); MASTER_TO_ALL_SLAVES_OBJECT(serial_link_connected, bool); -remote_object_t* test_remote_objects[] = { +static remote_object_t* remote_objects[] = { REMOTE_OBJECT(serial_link_connected), REMOTE_OBJECT(keyboard_matrix), }; @@ -128,7 +128,7 @@ remote_object_t* test_remote_objects[] = { void init_serial_link(void) { serial_link_connected = false; init_serial_link_hal(); - init_transport(test_remote_objects, sizeof(test_remote_objects)/sizeof(remote_object_t*)); + add_remote_objects(remote_objects, sizeof(remote_objects)/sizeof(remote_object_t*)); init_byte_stuffer(); sdStart(&SD1, &config); sdStart(&SD2, &config); diff --git a/serial_link/tests/transport_tests.c b/serial_link/tests/transport_tests.c index 3e9bffdfa71..02a7a10425b 100644 --- a/serial_link/tests/transport_tests.c +++ b/serial_link/tests/transport_tests.c @@ -53,7 +53,7 @@ MASTER_TO_ALL_SLAVES_OBJECT(master_to_slave, test_object1_t); MASTER_TO_SINGLE_SLAVE_OBJECT(master_to_single_slave, test_object1_t); SLAVE_TO_MASTER_OBJECT(slave_to_master, test_object1_t); -remote_object_t* test_remote_objects[] = { +static remote_object_t* test_remote_objects[] = { REMOTE_OBJECT(master_to_slave), REMOTE_OBJECT(master_to_single_slave), REMOTE_OBJECT(slave_to_master), @@ -61,7 +61,7 @@ remote_object_t* test_remote_objects[] = { Describe(Transport); BeforeEach(Transport) { - init_transport(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*)); + add_remote_objects(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*)); sent_data_size = 0; } AfterEach(Transport) {}