diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/master_posix.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/master_posix.c b/src/master_posix.c index c312757..dc8be7a 100644 --- a/src/master_posix.c +++ b/src/master_posix.c @@ -4,6 +4,7 @@ * Actually, target-specific includes should go in the port folder * This should be specified in the master config file * TODO This file should be moved to the posix port folder + * */ /* FreeRTOS includes. */ @@ -18,7 +19,7 @@ #include <pb_encode.h> #include <pb_decode.h> -/* Project includes. */ +/* (Ideally) platform-agnostic project includes. */ #include "master_posix.h" #include "main.h" #include "devices.h" @@ -46,6 +47,11 @@ #define SET_BIT_FROM_IDX(a, b) a[b>>5]|=(1<<(b%32)) #define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__))) +#define STREAM_INIT(PERIPH, vptr, sptr) \ + sptr.read=&read_##PERIPH; \ + sptr.write=&write_##PERIPH; \ + sptr.props=vptr; + #define BUS_DEVICE_LIMIT 2 device_info_t *device_info[BUS_DEVICE_LIMIT] = {NULL}; @@ -66,7 +72,7 @@ uint32_t data_len_buf[ROUTING_BUFSIZE]; uint32_t data_routing_ptr = 0; /*< Pointer to tail of both data and data index buffers */ uint32_t cmd_routing_ptr = 0; /*< Pointer to tail of cmd and cmd index buffers */ -p_stream_t stream = {&stdio_read, &stdio_write, NULL, NULL}; +p_stream_t stream; static void *handshake_func(void * pvArgs); static void *dataflow_func(void *pvArgs); @@ -96,6 +102,12 @@ bool master_encode_MDR_callback(pb_ostream_t *ostream, const pb_field_t *field, void vStartPOSIXMaster(void *pvParams) { pthread_t handshake_thread, dataflow_thread, routing_thread; + p_stream_t device_streams[2]; + STREAM_INIT(STDIO, NULL, device_streams[0]); + STREAM_INIT(STDIO, NULL, device_streams[1]); + + /* This is the global stream that is being used by handhsake and dataflow */ + STREAM_INIT(STDIO, NULL, stream); pthread_create(&handshake_thread, NULL, handshake_func, NULL); pthread_create(&dataflow_thread, NULL, dataflow_func, NULL); @@ -107,11 +119,6 @@ void vStartPOSIXMaster(void *pvParams) * either in a custom format or in a devicetree format (preferred) * */ - - p_stream_t *device_streams; - device_streams = malloc(sizeof(p_stream_t)*BUS_DEVICE_LIMIT); - - initialize_devices(BUS_DEVICE_LIMIT, device_streams); /* Add device-specific stream/thread declerations here, if needed */ /* ... */ @@ -163,7 +170,6 @@ static void *routing_func(void *pvArgs) /* This function should go into its own file, with a normalized state machine implementation */ hs_status_t handshake(uint32_t i2c_addr) { - /* Handshake variables */ uint8_t hs_sts = IDLE; uint8_t *MDR_buf; @@ -186,7 +192,7 @@ hs_status_t handshake(uint32_t i2c_addr) } else { hs_sts = HS_MDR_ACK; - } + } break; } case (HS_MDR_ACK): @@ -238,7 +244,7 @@ hs_status_t handshake(uint32_t i2c_addr) device_info[dev_idx]->MDR = MDR_res_message; hs_sts = HS_REGISTERED; - } + } } break; } |
