Commit 49e4b33b authored by Rafal Babski's avatar Rafal Babski

msp430_serial_minimal driver - Support for multiple sporadic interfaces

parent a1c99f03
Pipeline #1568 failed with stage
in 8 minutes and 17 seconds
...@@ -326,21 +326,20 @@ enum PACKET_STATE ...@@ -326,21 +326,20 @@ enum PACKET_STATE
void process_packet(uint8_t* data, int length) void process_packet(uint8_t* data, int length)
{ {
struct Message msg; if(length > 4)
if(length > 0)
{ {
msg.m_port = 0; struct Message msg;
msg.m_length = length;
memcpy(msg.m_data, data, length); memcpy(&msg.m_port, data, sizeof(uint32_t));
memcpy(msg.m_data, data + sizeof(uint32_t), length - sizeof(uint32_t));
msg.m_length = length - sizeof(uint32_t);
process_incomming_message(&msg);
} }
else else
{ {
msg.m_port = 0; // the packet does not contain valid Message
msg.m_length = 0;
} }
process_incomming_message(&msg);
} }
int serial_total_received_characters = 0; int serial_total_received_characters = 0;
...@@ -416,7 +415,7 @@ void spg_serial_msp430_minimal_poller(void* param) ...@@ -416,7 +415,7 @@ void spg_serial_msp430_minimal_poller(void* param)
static SemaphoreHandle_t sender_semaphore; static SemaphoreHandle_t sender_semaphore;
static StaticSemaphore_t sender_semaphore_buffer; static StaticSemaphore_t sender_semaphore_buffer;
void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length) void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length, uint32_t port)
{ {
xSemaphoreTake(sender_semaphore, portMAX_DELAY); xSemaphoreTake(sender_semaphore, portMAX_DELAY);
...@@ -424,6 +423,18 @@ void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length) ...@@ -424,6 +423,18 @@ void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length)
uint32_t iter; uint32_t iter;
for(iter = 0; iter < 4; ++iter)
{
uint8_t packet_byte = ((uint8_t*)(&port))[iter];
if(packet_byte == PACKET_START_BYTE || packet_byte == PACKET_STOP_BYTE || packet_byte == PACKET_ESCAPE_BYTE)
{
uart_putc(PACKET_ESCAPE_BYTE);
}
uart_putc(packet_byte);
}
for(iter = 0; iter < length; ++iter) for(iter = 0; iter < length; ++iter)
{ {
uint8_t packet_byte = data[iter]; uint8_t packet_byte = data[iter];
......
...@@ -34,6 +34,6 @@ ...@@ -34,6 +34,6 @@
void spg_serial_msp430_minimal_init(void); void spg_serial_msp430_minimal_init(void);
void spg_serial_msp430_minimal_poller(void* param); void spg_serial_msp430_minimal_poller(void* param);
void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length); void spg_serial_msp430_minimal_sender(uint8_t* data, uint32_t length, uint32_t port);
#endif #endif
...@@ -34,20 +34,25 @@ ...@@ -34,20 +34,25 @@
#include <msp430.h> #include <msp430.h>
#include <string.h> #include <string.h>
// use header genrated by ocarina for port identyfication
#include <deployment.h>
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "queue.h" #include "queue.h"
#include "semphr.h" #include "semphr.h"
@@IF@@ @_In_Port_Names_@ /= "" AND @_Out_Port_Names_@ /= "" @@IF@@ @_In_Port_Names_@ /= "" AND @_Out_Port_Names_@ /= ""
static RemoteTransportFuncPtr remote_transport_func = NULL; __attribute__ ((persistent)) static RemoteTransportFuncPtr remote_transport_func = NULL;
void register_remote_transport_func(RemoteTransportFuncPtr fn) void register_remote_transport_func(RemoteTransportFuncPtr fn)
{ {
remote_transport_func = fn; remote_transport_func = fn;
} }
// in future, this should be table @@TABLE@@
extern QueueHandle_t @_In_Port_Thread_Name_@_global_queue; extern QueueHandle_t @_In_Port_Thread_Name_@_global_queue;
@@END_TABLE@@
void process_incomming_message(struct Message* msg) void process_incomming_message(struct Message* msg)
{ {
...@@ -62,9 +67,17 @@ void process_incomming_message(struct Message* msg) ...@@ -62,9 +67,17 @@ void process_incomming_message(struct Message* msg)
request.m_length = 0; request.m_length = 0;
} }
xQueueSend(@_In_Port_Thread_Name_@_global_queue, switch(msg->m_port)
&request, {
0); @@TABLE@@
case @_LOWER:In_Port_Thread_Name_@_global_inport_@_LOWER:In_Port_Names_@:
xQueueSend(@_In_Port_Thread_Name_@_global_queue,
&request,
0);
break;
@@END_TABLE@@
}
} }
@@END_IF@@ @@END_IF@@
...@@ -74,7 +87,9 @@ void deliver_to_@_Out_Port_Remote_Function_@_@_Out_Port_Remote_Port_Name_@(struc ...@@ -74,7 +87,9 @@ void deliver_to_@_Out_Port_Remote_Function_@_@_Out_Port_Remote_Port_Name_@(struc
{ {
if(remote_transport_func != NULL) if(remote_transport_func != NULL)
{ {
remote_transport_func(task->m_data, task->m_length); remote_transport_func(task->m_data,
task->m_length,
(uint32_t) @_LOWER:Out_Port_Remote_Function_@_@_LOWER:Out_Port_Remote_Port_Name_@_global_inport_@_LOWER:Out_Port_Remote_Port_Name_@);
} }
} }
@@END_TABLE@@ @@END_TABLE@@
......
...@@ -54,7 +54,7 @@ struct Message ...@@ -54,7 +54,7 @@ struct Message
void process_incomming_message(struct Message* msg); void process_incomming_message(struct Message* msg);
typedef void (*RemoteTransportFuncPtr)(uint8_t* data, uint32_t length); typedef void (*RemoteTransportFuncPtr)(uint8_t* data, uint32_t length, uint32_t port);
void register_remote_transport_func(RemoteTransportFuncPtr fn); void register_remote_transport_func(RemoteTransportFuncPtr fn);
@@TABLE@@ @@TABLE@@
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment