diff --git a/examples/projects/Arduino/gate_serialcom/node_config.h b/examples/projects/Arduino/gate_serialcom/node_config.h index cd518cbfe..d6690001d 100644 --- a/examples/projects/Arduino/gate_serialcom/node_config.h +++ b/examples/projects/Arduino/gate_serialcom/node_config.h @@ -93,14 +93,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/Arduino/gate_serialcom/platformio.ini b/examples/projects/Arduino/gate_serialcom/platformio.ini index 0a2a8e3f0..58c5ccd50 100644 --- a/examples/projects/Arduino/gate_serialcom/platformio.ini +++ b/examples/projects/Arduino/gate_serialcom/platformio.ini @@ -28,5 +28,5 @@ lib_extra_dirs = ../../../../../ lib_deps = luos_engine@^2.5.3 - Gate Pipe + Gate diff --git a/examples/projects/Arduino/inspector_serialcom/node_config.h b/examples/projects/Arduino/inspector_serialcom/node_config.h index c83533c53..569098c36 100644 --- a/examples/projects/Arduino/inspector_serialcom/node_config.h +++ b/examples/projects/Arduino/inspector_serialcom/node_config.h @@ -94,13 +94,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-F072RB/gate_serialcom/node_config.h b/examples/projects/NUCLEO-F072RB/gate_serialcom/node_config.h index 1a8800c63..69a37d007 100644 --- a/examples/projects/NUCLEO-F072RB/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-F072RB/gate_serialcom/node_config.h @@ -100,14 +100,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-F401RE/gate_serialcom/node_config.h b/examples/projects/NUCLEO-F401RE/gate_serialcom/node_config.h index 5a72e405c..710205ccd 100644 --- a/examples/projects/NUCLEO-F401RE/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-F401RE/gate_serialcom/node_config.h @@ -129,14 +129,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-F401RE/inspector_serialcom/node_config.h b/examples/projects/NUCLEO-F401RE/inspector_serialcom/node_config.h index 0169d5585..b42db8241 100644 --- a/examples/projects/NUCLEO-F401RE/inspector_serialcom/node_config.h +++ b/examples/projects/NUCLEO-F401RE/inspector_serialcom/node_config.h @@ -128,14 +128,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #define NODETECTION #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-F410RB/gate_serialcom/node_config.h b/examples/projects/NUCLEO-F410RB/gate_serialcom/node_config.h index 4422577ef..1e4d7e535 100644 --- a/examples/projects/NUCLEO-F410RB/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-F410RB/gate_serialcom/node_config.h @@ -128,14 +128,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-F410RB/inspector_serialcom/node_config.h b/examples/projects/NUCLEO-F410RB/inspector_serialcom/node_config.h index cfea88b78..db6d404bf 100644 --- a/examples/projects/NUCLEO-F410RB/inspector_serialcom/node_config.h +++ b/examples/projects/NUCLEO-F410RB/inspector_serialcom/node_config.h @@ -129,13 +129,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-G431KB/gate_serialcom/node_config.h b/examples/projects/NUCLEO-G431KB/gate_serialcom/node_config.h index bb9b0bddb..736a879f1 100644 --- a/examples/projects/NUCLEO-G431KB/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-G431KB/gate_serialcom/node_config.h @@ -100,14 +100,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-G431KB/inspector_serialcom/node_config.h b/examples/projects/NUCLEO-G431KB/inspector_serialcom/node_config.h index 7bc419cf7..df289fe55 100644 --- a/examples/projects/NUCLEO-G431KB/inspector_serialcom/node_config.h +++ b/examples/projects/NUCLEO-G431KB/inspector_serialcom/node_config.h @@ -101,13 +101,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-G474RE/gate_serialcom/node_config.h b/examples/projects/NUCLEO-G474RE/gate_serialcom/node_config.h index bb9b0bddb..736a879f1 100644 --- a/examples/projects/NUCLEO-G474RE/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-G474RE/gate_serialcom/node_config.h @@ -100,14 +100,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-G474RE/inspector_serialcom/node_config.h b/examples/projects/NUCLEO-G474RE/inspector_serialcom/node_config.h index 7bc419cf7..df289fe55 100644 --- a/examples/projects/NUCLEO-G474RE/inspector_serialcom/node_config.h +++ b/examples/projects/NUCLEO-G474RE/inspector_serialcom/node_config.h @@ -101,13 +101,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/NUCLEO-L432KC/gate_serialcom/node_config.h b/examples/projects/NUCLEO-L432KC/gate_serialcom/node_config.h index bb9b0bddb..736a879f1 100644 --- a/examples/projects/NUCLEO-L432KC/gate_serialcom/node_config.h +++ b/examples/projects/NUCLEO-L432KC/gate_serialcom/node_config.h @@ -100,14 +100,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/NUCLEO-L432KC/inspector_serialcom/node_config.h b/examples/projects/NUCLEO-L432KC/inspector_serialcom/node_config.h index 7bc419cf7..df289fe55 100644 --- a/examples/projects/NUCLEO-L432KC/inspector_serialcom/node_config.h +++ b/examples/projects/NUCLEO-L432KC/inspector_serialcom/node_config.h @@ -101,13 +101,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/STM32F4-discovery/gate_serialcom/node_config.h b/examples/projects/STM32F4-discovery/gate_serialcom/node_config.h index b52829598..135ab7868 100644 --- a/examples/projects/STM32F4-discovery/gate_serialcom/node_config.h +++ b/examples/projects/STM32F4-discovery/gate_serialcom/node_config.h @@ -103,14 +103,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/STM32F4-discovery/inspector_serialcom/node_config.h b/examples/projects/STM32F4-discovery/inspector_serialcom/node_config.h index 2f19023aa..89968f35a 100644 --- a/examples/projects/STM32F4-discovery/inspector_serialcom/node_config.h +++ b/examples/projects/STM32F4-discovery/inspector_serialcom/node_config.h @@ -104,13 +104,13 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 #endif /* _NODE_CONFIG_H_ */ diff --git a/examples/projects/l0/gate_serialcom/node_config.h b/examples/projects/l0/gate_serialcom/node_config.h index 672df30fa..c54dbc890 100644 --- a/examples/projects/l0/gate_serialcom/node_config.h +++ b/examples/projects/l0/gate_serialcom/node_config.h @@ -99,14 +99,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size * INIT_TIME | 150 | Wait init time before first detection ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/examples/projects/l0/gate_serialcom/src/main.c b/examples/projects/l0/gate_serialcom/src/main.c index 914077e52..f515c71df 100644 --- a/examples/projects/l0/gate_serialcom/src/main.c +++ b/examples/projects/l0/gate_serialcom/src/main.c @@ -114,9 +114,8 @@ int main(void) */ void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. diff --git a/examples/projects/native/gate_wscom/node_config.h b/examples/projects/native/gate_wscom/node_config.h index 958a636ba..bbb60372e 100644 --- a/examples/projects/native/gate_wscom/node_config.h +++ b/examples/projects/native/gate_wscom/node_config.h @@ -100,14 +100,14 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size * INIT_TIME | 150 | Wait init time before first detection ******************************************************************************/ -#define MAX_RTB_ENTRY 40 -#define GATE_BUFF_SIZE 1024 -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 +#define MAX_RTB_ENTRY 40 +#define GATE_BUFF_SIZE 1024 +#define PIPE_TX_BUFFER_SIZE 1024 +#define PIPE_RX_BUFFER_SIZE 2048 /******************************************************************************* * OTHER GATE PARAMETERS diff --git a/test/_resources/node_config.h b/test/_resources/node_config.h index 61d5541f8..170681ab1 100644 --- a/test/_resources/node_config.h +++ b/test/_resources/node_config.h @@ -93,8 +93,8 @@ * :-------------------------|------------------------------------------------------ * MAX_RTB_ENTRY | 40 | max number entry in routing table * GATE_BUFF_SIZE | 1024 | Json receive buffer size - * PIPE_TO_LUOS_BUFFER_SIZE | 1024 | Receive pipe buffer size - * LUOS_TO_PIPE_BUFFER_SIZE | 2048 | Transmit pipe buffer size + * PIPE_TX_BUFFER_SIZE | 1024 | Receive pipe buffer size + * PIPE_RX_BUFFER_SIZE | 2048 | Transmit pipe buffer size ******************************************************************************/ #endif /* _NODE_CONFIG_H_ */ diff --git a/tool_services/gate/pipe_link.c b/tool_services/gate/pipe_link.c index e0d5f74b6..d094c5347 100644 --- a/tool_services/gate/pipe_link.c +++ b/tool_services/gate/pipe_link.c @@ -12,8 +12,8 @@ /******************************************************************************* * Variables ******************************************************************************/ -uint16_t pipe_id = 0; -void (*PipeDirectPutSample)(uint8_t *data, uint16_t size); +uint16_t pipe_id = 0; +streaming_channel_t *PipeDirectPutSample = NULL; /******************************************************************************* * Function @@ -40,7 +40,7 @@ void PipeLink_Send(service_t *service, void *data, uint32_t size) { // We have a localhost pipe // Copy the data directly into the local streaming channel without passing by Luos. - PipeDirectPutSample(data, size); + Stream_PutSample(PipeDirectPutSample, data, size); // Send a void set_cmd to strat data transmission on pipe. msg.header.size = 0; Luos_SendMsg(service, &msg); diff --git a/tool_services/inspector/pipe_link.c b/tool_services/inspector/pipe_link.c index 168d1648c..d9c62a301 100644 --- a/tool_services/inspector/pipe_link.c +++ b/tool_services/inspector/pipe_link.c @@ -12,8 +12,8 @@ /******************************************************************************* * Variables ******************************************************************************/ -uint16_t pipe_id = 0; -void (*PipeDirectPutSample)(uint8_t *data, uint16_t size); +uint16_t pipe_id = 0; +streaming_channel_t *PipeDirectPutSample = NULL; /******************************************************************************* * Function @@ -41,7 +41,7 @@ void PipeLink_Send(service_t *service, void *data, uint32_t size) msg.header.config = BASE_PROTOCOL; // We have a localhost pipe // Copy the data directly into the local streaming channel without passing by Luos. - PipeDirectPutSample(data, size); + Stream_PutSample(PipeDirectPutSample, data, size); // Send a void set_cmd to strat data transmission on pipe. msg.header.size = 0; Luos_SendMsg(service, &msg); diff --git a/tool_services/pipe/SERIAL/ARDUINO/pipe_com.cpp b/tool_services/pipe/SERIAL/ARDUINO/pipe_com.cpp index edc8face9..06cdec4d0 100644 --- a/tool_services/pipe/SERIAL/ARDUINO/pipe_com.cpp +++ b/tool_services/pipe/SERIAL/ARDUINO/pipe_com.cpp @@ -12,9 +12,8 @@ extern "C" { #endif -#include #include "pipe_com.h" -#include "luos_utils.h" +#include "../serial_protocol.h" #ifdef __cplusplus } @@ -39,55 +38,44 @@ extern "C" void PipeCom_Init(void) { Serial.begin(1000000); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ + SerialProtocol_Init(); +} +/****************************************************************************** + * @brief loop must be call in project loop + * @param None + * @return None + ******************************************************************************/ void PipeCom_Loop(void) { - uint16_t size = 0; - uint8_t data = 0; + uint8_t data = 0; while (Serial.available() > 0) { data = Serial.read(); - Stream_PutSample(get_P2L_StreamChannel(), &data, 1); - } - // Check if we need to transmit - if (PipeCom_SendL2PPending() == false) - { - streaming_channel_t *stream_channel = get_L2P_StreamChannel(); - size = Stream_GetAvailableSampleNB(stream_channel); - if (size != 0) - { - PipeCom_SendL2P((uint8_t *)stream_channel->sample_ptr, size); - Stream_RmvAvailableSampleNB(stream_channel, size); - } + Stream_PutSample(Pipe_GetRxStreamChannel(), &data, 1); } } /****************************************************************************** - * @brief check if pipe is sending - * @param None - * @return true/false - ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) -{ - return false; -} -/****************************************************************************** - * @brief init must be call in project init + * @brief Check if a message is available * @param None * @return None ******************************************************************************/ -void PipeCom_ReceiveP2L(void) +uint8_t PipeCom_Receive(uint16_t *size) { + return SerialProtocol_IsMsgComplete(size); } /****************************************************************************** - * @brief PipeCom_SendL2P + * @brief PipeCom_Send * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) +void PipeCom_Send(void) { - Serial.write(data, size); + SerialProtocol_CreateTxMsg(); + uint16_t size = SerialProtocol_GetSizeToSend(); + while (size > 0) + { + Serial.write(SerialProtocol_GetDataToSend(), size); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size); + size = SerialProtocol_GetSizeToSend(); + } } diff --git a/tool_services/pipe/SERIAL/ARDUINO/pipe_com.h b/tool_services/pipe/SERIAL/ARDUINO/pipe_com.h index 4ba099fa5..d64f79ef3 100644 --- a/tool_services/pipe/SERIAL/ARDUINO/pipe_com.h +++ b/tool_services/pipe/SERIAL/ARDUINO/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" /******************************************************************************* * Definitions @@ -23,10 +22,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_ReceiveP2L(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.c b/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.c index 26c488d09..7241ea405 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.c +++ b/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -78,8 +79,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -88,110 +90,114 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableChannel(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetChannelPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_SYSCFG_SetRemapDMA_USART(P2L_DMA_REQUEST); + LL_DMA_DisableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetChannelPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_SYSCFG_SetRemapDMA_USART(PIPE_RX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_USART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableChannel(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetChannelPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_SYSCFG_SetRemapDMA_USART(L2P_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetChannelPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_SYSCFG_SetRemapDMA_USART(PIPE_TX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); LL_USART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableChannel(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableChannel(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); } /****************************************************************************** * @brief init must be call in project init * @param None * @return None ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } +} +/****************************************************************************** + * @brief RX Serial IRQ handler + * @param None + * @return None + ******************************************************************************/ void PIPE_COM_IRQHANDLER() { - uint16_t size = 0; - uint16_t P2L_PointerPosition = 0; + uint16_t size = 0; + uint16_t RX_PointerPosition = 0; // check if we receive an IDLE on usart3 if (LL_USART_IsActiveFlag_IDLE(PIPE_COM)) { LL_USART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + RX_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + RX_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = RX_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = RX_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -200,23 +206,20 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.h b/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.h index d2700d4f4..996ea8f1f 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.h +++ b/tool_services/pipe/SERIAL/NUCLEO-F0/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32f0xx_hal.h" #include "stm32f0xx_ll_usart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ USART2_IRQn #define PIPE_COM_IRQHANDLER() USART2_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_CHANNEL_5 -#define P2L_DMA_REQUEST LL_SYSCFG_USART2_RMP_DMA1CH54 -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC5(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC5(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_CHANNEL_5 +#define PIPE_RX_DMA_REQUEST LL_SYSCFG_USART2_RMP_DMA1CH54 +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC5(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC5(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_CHANNEL_4 -#define L2P_DMA_REQUEST LL_SYSCFG_USART2_RMP_DMA1CH54 -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC4(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC4(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Channel4_5_6_7_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Channel4_5_6_7_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_CHANNEL_4 +#define PIPE_TX_DMA_REQUEST LL_SYSCFG_USART2_RMP_DMA1CH54 +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Channel4_5_6_7_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Channel4_5_6_7_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.c b/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.c index 94c390818..455fe172b 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.c +++ b/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -78,8 +79,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -88,111 +90,116 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableStream(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetChannelSelection(P2L_DMA, P2L_DMA_CHANNEL, L2P_DMA_REQUEST); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetStreamPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_DisableStream(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetChannelSelection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetStreamPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->DR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->DR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_USART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableStream(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableStream(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_DisableStream(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetChannelSelection(L2P_DMA, L2P_DMA_CHANNEL, L2P_DMA_REQUEST); - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetStreamPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_DisableStream(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetChannelSelection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, PIPE_TX_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetStreamPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->DR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->DR); LL_USART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableStream(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableStream(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); } /****************************************************************************** * @brief init must be call in project init * @param None * @return None ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableStream(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableStream(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } +} + +/****************************************************************************** + * @brief RX Serial IRQ handler + * @param None + * @return None + ******************************************************************************/ void PIPE_COM_IRQHANDLER() { - uint16_t size = 0; - uint16_t P2L_PointerPosition = 0; + uint16_t size = 0; + uint16_t RX_PointerPosition = 0; // check if we receive an IDLE on usart3 if (LL_USART_IsActiveFlag_IDLE(PIPE_COM)) { LL_USART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + RX_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + RX_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = RX_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = RX_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -201,23 +208,20 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.h b/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.h index c48885fc9..9b1df1425 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.h +++ b/tool_services/pipe/SERIAL/NUCLEO-F4/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32f4xx_hal.h" #include "stm32f4xx_ll_usart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ USART2_IRQn #define PIPE_COM_IRQHANDLER() USART2_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_STREAM_5 -#define P2L_DMA_REQUEST LL_DMA_CHANNEL_4 -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC5(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC5(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_STREAM_5 +#define PIPE_RX_DMA_REQUEST LL_DMA_CHANNEL_4 +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC5(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC5(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_STREAM_6 -#define L2P_DMA_REQUEST LL_DMA_CHANNEL_4 -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC6(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC6(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Stream6_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Stream6_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_STREAM_6 +#define PIPE_TX_DMA_REQUEST LL_DMA_CHANNEL_4 +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC6(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC6(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Stream6_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Stream6_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.c b/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.c index d1dbb509d..5b13732dc 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.c +++ b/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -79,8 +80,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -89,110 +91,114 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableChannel(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetChannelPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(P2L_DMA, P2L_DMA_CHANNEL, P2L_DMA_REQUEST); + LL_DMA_DisableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetChannelPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_RX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_USART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableChannel(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetChannelPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(L2P_DMA, L2P_DMA_CHANNEL, L2P_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetChannelPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, PIPE_TX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); LL_USART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableChannel(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableChannel(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); } /****************************************************************************** * @brief init must be call in project init * @param None * @return None ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } +} +/****************************************************************************** + * @brief RX Serial IRQ handler + * @param None + * @return None + ******************************************************************************/ void PIPE_COM_IRQHANDLER() { - uint16_t size = 0; - uint16_t P2L_PointerPosition = 0; + uint16_t size = 0; + uint16_t RX_PointerPosition = 0; // check if we receive an IDLE on usart3 if (LL_USART_IsActiveFlag_IDLE(PIPE_COM)) { LL_USART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + RX_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + RX_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = RX_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = RX_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -201,23 +207,20 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.h b/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.h index b877b2cce..b24805b01 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.h +++ b/tool_services/pipe/SERIAL/NUCLEO-G431/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32g4xx_hal.h" #include "stm32g4xx_ll_usart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ USART2_IRQn #define PIPE_COM_IRQHANDLER() USART2_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_CHANNEL_3 -#define P2L_DMA_REQUEST LL_DMAMUX_REQ_USART2_RX -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC3(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC3(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_CHANNEL_3 +#define PIPE_RX_DMA_REQUEST LL_DMAMUX_REQ_USART2_RX +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC3(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC3(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_CHANNEL_4 -#define L2P_DMA_REQUEST LL_DMAMUX_REQ_USART2_TX -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC4(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC4(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Channel4_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_CHANNEL_4 +#define PIPE_TX_DMA_REQUEST LL_DMAMUX_REQ_USART2_TX +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Channel4_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.c b/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.c index fcb291e9d..878f2fb71 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.c +++ b/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -78,8 +79,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -88,75 +90,79 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableChannel(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetChannelPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(P2L_DMA, P2L_DMA_CHANNEL, P2L_DMA_REQUEST); + LL_DMA_DisableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetChannelPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_RX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_LPUART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableChannel(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetChannelPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(L2P_DMA, L2P_DMA_CHANNEL, L2P_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetChannelPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, PIPE_TX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); LL_LPUART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableChannel(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableChannel(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); +} +/****************************************************************************** + * @brief init must be call in project init + * @param None + * @return None + ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } } /****************************************************************************** * @brief init must be call in project init @@ -172,26 +178,26 @@ void PIPE_COM_IRQHANDLER() if (LL_LPUART_IsActiveFlag_IDLE(PIPE_COM)) { LL_LPUART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + P2L_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + P2L_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = P2L_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = P2L_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -200,23 +206,20 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.h b/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.h index accdece3c..d9d0945ea 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.h +++ b/tool_services/pipe/SERIAL/NUCLEO-G474/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32g4xx_hal.h" #include "stm32g4xx_ll_lpuart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ LPUART1_IRQn #define PIPE_COM_IRQHANDLER() LPUART1_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_CHANNEL_3 -#define P2L_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_RX -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC3(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC3(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_CHANNEL_3 +#define PIPE_RX_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_RX +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC3(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC3(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_CHANNEL_4 -#define L2P_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_TX -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC4(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC4(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Channel4_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_CHANNEL_4 +#define PIPE_TX_DMA_REQUEST LL_DMAMUX_REQ_LPUART1_TX +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC4(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Channel4_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Channel4_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.c b/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.c index c28ea3180..6d4094ee9 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.c +++ b/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -78,8 +79,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -88,75 +90,79 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableChannel(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetChannelPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(P2L_DMA, P2L_DMA_CHANNEL, P2L_DMA_REQUEST); + LL_DMA_DisableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetChannelPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_RX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_USART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableChannel(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetChannelPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_DMA_SetPeriphRequest(L2P_DMA, L2P_DMA_CHANNEL, L2P_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetChannelPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_DMA_SetPeriphRequest(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, PIPE_TX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); LL_USART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableChannel(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableChannel(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); +} +/****************************************************************************** + * @brief init must be call in project init + * @param None + * @return None + ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } } /****************************************************************************** * @brief init must be call in project init @@ -172,26 +178,26 @@ void PIPE_COM_IRQHANDLER() if (LL_USART_IsActiveFlag_IDLE(PIPE_COM)) { LL_USART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + P2L_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + P2L_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = P2L_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = P2L_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -200,24 +206,21 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.h b/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.h index 99965fb1c..cc7ed9384 100644 --- a/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.h +++ b/tool_services/pipe/SERIAL/NUCLEO-L4/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32l4xx_hal.h" #include "stm32l4xx_ll_usart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ USART2_IRQn #define PIPE_COM_IRQHANDLER() USART2_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_CHANNEL_6 -#define P2L_DMA_REQUEST LL_DMA_REQUEST_2 -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC6(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC6(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_CHANNEL_6 +#define PIPE_RX_DMA_REQUEST LL_DMA_REQUEST_2 +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC6(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC6(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_CHANNEL_7 -#define L2P_DMA_REQUEST LL_DMA_REQUEST_2 -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC7(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC7(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Channel7_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Channel7_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE(); +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_CHANNEL_7 +#define PIPE_TX_DMA_REQUEST LL_DMA_REQUEST_2 +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC7(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC7(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Channel7_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Channel7_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/l0/pipe_com.c b/tool_services/pipe/SERIAL/l0/pipe_com.c index 26c488d09..7241ea405 100644 --- a/tool_services/pipe/SERIAL/l0/pipe_com.c +++ b/tool_services/pipe/SERIAL/l0/pipe_com.c @@ -7,6 +7,7 @@ #include #include "pipe_com.h" #include "luos_utils.h" +#include "../serial_protocol.h" /******************************************************************************* * Definitions @@ -15,9 +16,9 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint8_t is_sending = false; -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint8_t is_sending = false; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; /******************************************************************************* * Function ******************************************************************************/ @@ -78,8 +79,9 @@ void PipeCom_Init(void) HAL_NVIC_EnableIRQ(PIPE_COM_IRQ); HAL_NVIC_SetPriority(PIPE_COM_IRQ, 1, 1); - P2L_PrevPointerPosition = 0; + RX_PrevPointerPosition = 0; PipeCom_DMAInit(); + SerialProtocol_Init(); } /****************************************************************************** * @brief init must be call in project init @@ -88,110 +90,114 @@ void PipeCom_Init(void) ******************************************************************************/ static void PipeCom_DMAInit(void) { - P2L_DMA_CLOCK_ENABLE(); - L2P_DMA_CLOCK_ENABLE(); + PIPE_RX_DMA_CLOCK_ENABLE(); + PIPE_TX_DMA_CLOCK_ENABLE(); // Pipe to Luos - LL_DMA_DisableChannel(P2L_DMA, P2L_DMA_CHANNEL); - LL_DMA_SetDataTransferDirection(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); - LL_DMA_SetChannelPriorityLevel(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); - LL_DMA_SetPeriphIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(P2L_DMA, P2L_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_SYSCFG_SetRemapDMA_USART(P2L_DMA_REQUEST); + LL_DMA_DisableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); + LL_DMA_SetDataTransferDirection(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); + LL_DMA_SetChannelPriorityLevel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MODE_CIRCULAR); + LL_DMA_SetPeriphIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_SYSCFG_SetRemapDMA_USART(PIPE_RX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); - LL_DMA_SetDataLength(P2L_DMA, P2L_DMA_CHANNEL, PIPE_TO_LUOS_BUFFER_SIZE); - LL_DMA_SetMemoryAddress(P2L_DMA, P2L_DMA_CHANNEL, (uint32_t)PipeBuffer_GetP2LBuffer()); + LL_DMA_SetPeriphAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)&PIPE_COM->RDR); + LL_DMA_SetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, PIPE_TX_BUFFER_SIZE); + LL_DMA_SetMemoryAddress(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL, (uint32_t)Pipe_GetRxStreamChannel()->ring_buffer); LL_USART_EnableDMAReq_RX(PIPE_COM); - LL_DMA_EnableChannel(P2L_DMA, P2L_DMA_CHANNEL); + LL_DMA_EnableChannel(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); // Luos to Pipe - LL_DMA_SetDataTransferDirection(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); - LL_DMA_SetChannelPriorityLevel(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); - LL_DMA_SetMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MODE_NORMAL); - LL_DMA_SetPeriphIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); - LL_DMA_SetMemoryIncMode(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); - LL_DMA_SetPeriphSize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); - LL_DMA_SetMemorySize(L2P_DMA, L2P_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); - LL_SYSCFG_SetRemapDMA_USART(L2P_DMA_REQUEST); + LL_DMA_SetDataTransferDirection(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); + LL_DMA_SetChannelPriorityLevel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PRIORITY_LOW); + LL_DMA_SetMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MODE_NORMAL); + LL_DMA_SetPeriphIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PERIPH_NOINCREMENT); + LL_DMA_SetMemoryIncMode(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MEMORY_INCREMENT); + LL_DMA_SetPeriphSize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_PDATAALIGN_BYTE); + LL_DMA_SetMemorySize(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, LL_DMA_MDATAALIGN_BYTE); + LL_SYSCFG_SetRemapDMA_USART(PIPE_TX_DMA_REQUEST); // Prepare buffer - LL_DMA_SetPeriphAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); + LL_DMA_SetPeriphAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)&PIPE_COM->TDR); LL_USART_EnableDMAReq_TX(PIPE_COM); - HAL_NVIC_EnableIRQ(L2P_DMA_IRQ); - HAL_NVIC_SetPriority(L2P_DMA_IRQ, 1, 1); + HAL_NVIC_EnableIRQ(PIPE_TX_DMA_IRQ); + HAL_NVIC_SetPriority(PIPE_TX_DMA_IRQ, 1, 1); - LL_DMA_EnableIT_TC(L2P_DMA, L2P_DMA_CHANNEL); + LL_DMA_EnableIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); } /****************************************************************************** - * @brief init must be call in project init + * @brief loop must be call in project loop * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) -{ - LUOS_ASSERT(size > 0); - is_sending = true; - size_to_send = size; - LL_DMA_DisableChannel(L2P_DMA, L2P_DMA_CHANNEL); - LL_DMA_SetMemoryAddress(L2P_DMA, L2P_DMA_CHANNEL, (uint32_t)data); - LL_DMA_SetDataLength(L2P_DMA, L2P_DMA_CHANNEL, size); - LL_DMA_EnableChannel(L2P_DMA, L2P_DMA_CHANNEL); -} /****************************************************************************** - * @brief loop must be call in project loop - * @param None - * @return None - ******************************************************************************/ void PipeCom_Loop(void) { } /****************************************************************************** - * @brief check if pipe is sending + * @brief Check if a message is available * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +uint8_t PipeCom_Receive(uint16_t *size) { - return is_sending; + return SerialProtocol_IsMsgComplete(size); } /****************************************************************************** * @brief init must be call in project init * @param None * @return None ******************************************************************************/ +void PipeCom_Send() +{ + SerialProtocol_CreateTxMsg(); + if (is_sending == false) + { + is_sending = true; + size_to_send = SerialProtocol_GetSizeToSend(); + LL_DMA_DisableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + LL_DMA_SetMemoryAddress(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, (uint32_t)SerialProtocol_GetDataToSend()); + LL_DMA_SetDataLength(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL, size_to_send); + LL_DMA_EnableChannel(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL); + } +} +/****************************************************************************** + * @brief RX Serial IRQ handler + * @param None + * @return None + ******************************************************************************/ void PIPE_COM_IRQHANDLER() { - uint16_t size = 0; - uint16_t P2L_PointerPosition = 0; + uint16_t size = 0; + uint16_t RX_PointerPosition = 0; // check if we receive an IDLE on usart3 if (LL_USART_IsActiveFlag_IDLE(PIPE_COM)) { LL_USART_ClearFlag_IDLE(PIPE_COM); - if (LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL) == 0) + if (LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL) == 0) { return; } - P2L_PointerPosition = PIPE_TO_LUOS_BUFFER_SIZE - LL_DMA_GetDataLength(P2L_DMA, P2L_DMA_CHANNEL); + RX_PointerPosition = PIPE_TX_BUFFER_SIZE - LL_DMA_GetDataLength(PIPE_RX_DMA, PIPE_RX_DMA_CHANNEL); - if (P2L_DMA_TC(P2L_DMA) != RESET) // DMA buffer overflow + if (PIPE_RX_DMA_TC(PIPE_RX_DMA) != RESET) // DMA buffer overflow { - P2L_DMA_CLEAR_TC(P2L_DMA); - size = (PIPE_TO_LUOS_BUFFER_SIZE - P2L_PrevPointerPosition) + P2L_PointerPosition; + PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA); + size = (PIPE_TX_BUFFER_SIZE - RX_PrevPointerPosition) + RX_PointerPosition; } else { - size = P2L_PointerPosition - P2L_PrevPointerPosition; + size = RX_PointerPosition - RX_PrevPointerPosition; } - P2L_PrevPointerPosition = P2L_PointerPosition; + RX_PrevPointerPosition = RX_PointerPosition; if (size != 0) { - Stream_AddAvailableSampleNB(get_P2L_StreamChannel(), size); + Stream_AddAvailableSampleNB(Pipe_GetRxStreamChannel(), size); } } } @@ -200,23 +206,20 @@ void PIPE_COM_IRQHANDLER() * @param None * @return None ******************************************************************************/ -void L2P_DMA_IRQHANDLER() +void PIPE_TX_DMA_IRQHANDLER() { uint16_t size = 0; // check if we receive an IDLE on usart3 - if ((L2P_DMA_TC(L2P_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(L2P_DMA, L2P_DMA_CHANNEL) != RESET)) + if ((PIPE_TX_DMA_TC(PIPE_TX_DMA) != RESET) && (LL_DMA_IsEnabledIT_TC(PIPE_TX_DMA, PIPE_TX_DMA_CHANNEL) != RESET)) { - L2P_DMA_CLEAR_TC(L2P_DMA); + PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA); - Stream_RmvAvailableSampleNB(get_L2P_StreamChannel(), size_to_send); - size = Stream_GetAvailableSampleNBUntilEndBuffer(get_L2P_StreamChannel()); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size_to_send); + size = SerialProtocol_GetSizeToSend(); + is_sending = false; if (size > 0) { - PipeCom_SendL2P(get_L2P_StreamChannel()->sample_ptr, size); - } - else - { - is_sending = false; + PipeCom_Send(); } } } diff --git a/tool_services/pipe/SERIAL/l0/pipe_com.h b/tool_services/pipe/SERIAL/l0/pipe_com.h index 6d17f2aa6..1994e2cd3 100644 --- a/tool_services/pipe/SERIAL/l0/pipe_com.h +++ b/tool_services/pipe/SERIAL/l0/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" #include "stm32f0xx_hal.h" #include "stm32f0xx_ll_usart.h" @@ -35,21 +34,21 @@ #define PIPE_COM_IRQ USART3_4_IRQn #define PIPE_COM_IRQHANDLER() USART3_4_IRQHandler() -#define P2L_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() -#define P2L_DMA DMA1 -#define P2L_DMA_CHANNEL LL_DMA_CHANNEL_6 -#define P2L_DMA_REQUEST LL_SYSCFG_USART3_RMP_DMA1CH67 -#define P2L_DMA_TC(P2L_DMA) LL_DMA_IsActiveFlag_TC6(P2L_DMA) -#define P2L_DMA_CLEAR_TC(P2L_DMA) LL_DMA_ClearFlag_TC6(P2L_DMA) +#define PIPE_RX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() +#define PIPE_RX_DMA DMA1 +#define PIPE_RX_DMA_CHANNEL LL_DMA_CHANNEL_6 +#define PIPE_RX_DMA_REQUEST LL_SYSCFG_USART3_RMP_DMA1CH67 +#define PIPE_RX_DMA_TC(PIPE_RX_DMA) LL_DMA_IsActiveFlag_TC6(PIPE_RX_DMA) +#define PIPE_RX_DMA_CLEAR_TC(PIPE_RX_DMA) LL_DMA_ClearFlag_TC6(PIPE_RX_DMA) -#define L2P_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() -#define L2P_DMA DMA1 -#define L2P_DMA_CHANNEL LL_DMA_CHANNEL_7 -#define L2P_DMA_REQUEST LL_SYSCFG_USART3_RMP_DMA1CH67 -#define L2P_DMA_TC(L2P_DMA) LL_DMA_IsActiveFlag_TC7(L2P_DMA) -#define L2P_DMA_CLEAR_TC(L2P_DMA) LL_DMA_ClearFlag_TC7(L2P_DMA) -#define L2P_DMA_IRQ DMA1_Channel4_5_6_7_IRQn -#define L2P_DMA_IRQHANDLER() DMA1_Channel4_5_6_7_IRQHandler() +#define PIPE_TX_DMA_CLOCK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE() +#define PIPE_TX_DMA DMA1 +#define PIPE_TX_DMA_CHANNEL LL_DMA_CHANNEL_7 +#define PIPE_TX_DMA_REQUEST LL_SYSCFG_USART3_RMP_DMA1CH67 +#define PIPE_TX_DMA_TC(PIPE_TX_DMA) LL_DMA_IsActiveFlag_TC7(PIPE_TX_DMA) +#define PIPE_TX_DMA_CLEAR_TC(PIPE_TX_DMA) LL_DMA_ClearFlag_TC7(PIPE_TX_DMA) +#define PIPE_TX_DMA_IRQ DMA1_Channel4_5_6_7_IRQn +#define PIPE_TX_DMA_IRQHANDLER() DMA1_Channel4_5_6_7_IRQHandler() /******************************************************************************* * Variables @@ -60,9 +59,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/SERIAL/serial_protocol.h b/tool_services/pipe/SERIAL/serial_protocol.h new file mode 100644 index 000000000..13426139c --- /dev/null +++ b/tool_services/pipe/SERIAL/serial_protocol.h @@ -0,0 +1,188 @@ +/****************************************************************************** + * @file serial_protocol.h + * @brief Protocol dedicated to serial communication allowing to catch the completude of the message + * @author Luos + * @version 0.0.0 + ******************************************************************************/ + +#include +#include "_pipe.h" +/******************************************************************************* + * Definitions + ******************************************************************************/ +#define SERIAL_HEADER 0x7E +#define SERIAL_FOOTER 0x81 + +/******************************************************************************* + * Variables + ******************************************************************************/ +typedef struct __attribute__((__packed__)) +{ + uint8_t header; + uint16_t size; +} SerialHeader_t; + +typedef struct __attribute__((__packed__)) +{ + uint8_t footer; + SerialHeader_t header; +} SerialProtocol_t; + +streaming_channel_t *serialTx_StreamChannel = NULL; +uint8_t *size_to_update = NULL; // Size is uint16_t but we use uint8_t* here to avoid memory alignement issues + +static inline void SerialProtocol_Init(void) +{ + // Get tx stream channel + serialTx_StreamChannel = Pipe_GetTxStreamChannel(); + // write header + size into the buffer + SerialHeader_t SerialHeader = { + SERIAL_HEADER, + 0, + }; + Stream_PutSample(serialTx_StreamChannel, &SerialHeader, sizeof(SerialHeader_t)); + // Keep size to update, size are the last 2 bytes of the StreamChannel + size_to_update = (uint8_t *)((int)serialTx_StreamChannel->data_ptr - 2); + // Now we are ready to get data +} + +static inline void SerialProtocol_CreateTxMsg(void) +{ + uint8_t size_at_end_ring_buffer = 0; + // Temporary remove protocol from the stream to evaluate data size + void *sample_ptr_bkp = serialTx_StreamChannel->sample_ptr; + serialTx_StreamChannel->sample_ptr = (void *)((int)serialTx_StreamChannel->sample_ptr + sizeof(SerialHeader_t)); + if (serialTx_StreamChannel->sample_ptr > serialTx_StreamChannel->end_ring_buffer) + { + size_at_end_ring_buffer = 1; + serialTx_StreamChannel->sample_ptr = (void *)((int)serialTx_StreamChannel->ring_buffer + 1); + } + // Evaluate size + uint16_t size = Stream_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel); + // Restore pointer + serialTx_StreamChannel->sample_ptr = sample_ptr_bkp; + // Update size + if (size_at_end_ring_buffer) + { + // Size is 2 bytes and those bytes are splitted, one at the end of the buffer and one at the beginning of the buffer + size_to_update[0] = size & 0xFF; + ((uint8_t *)serialTx_StreamChannel->ring_buffer)[0] = size >> 8; + } + else + { + // Size is not splitted, we can write it directly in the buffer + // We still writing it byte by bytes avoiding memory alignement issues + size_to_update[0] = size & 0xFF; + size_to_update[1] = size >> 8; + } + + // Write footer and header + size of the next message into the buffer + SerialProtocol_t SerialProtocol = { + SERIAL_FOOTER, + {SERIAL_HEADER, + 0} // Size will be updated on the next call of SerialProtocol_CreateTxMsg() + }; + Stream_PutSample(serialTx_StreamChannel, &SerialProtocol, sizeof(SerialProtocol_t)); + + // Keep size to update, size are the last 2 bytes of the StreamChannel + size_to_update = (uint8_t *)((int)serialTx_StreamChannel->data_ptr - 2); +} + +static inline uint16_t SerialProtocol_GetSizeToSend(void) +{ + if ((Stream_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t)) > Stream_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel)) + { + return Stream_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel); + } + else + { + return Stream_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t); + } +} + +static inline char *SerialProtocol_GetDataToSend(void) +{ + return (char *)serialTx_StreamChannel->sample_ptr; +} + +static inline uint8_t SerialProtocol_IsMsgComplete(uint16_t *size) +{ + + streaming_channel_t *serialRx_StreamChannel = Pipe_GetRxStreamChannel(); + uint16_t TotalSize = Stream_GetAvailableSampleNB(serialRx_StreamChannel); + uint16_t SizeUntilEnd = 0; + + if (TotalSize > 4) + { + // We received something + for (uint16_t i = 0; i < TotalSize; i++) + { + if (*((uint8_t *)(serialRx_StreamChannel->sample_ptr)) == SERIAL_HEADER) + { + // The first byte is a header + // Make TotalSize fit the size of remaining datas. + TotalSize = TotalSize - i; + i = 0; + SizeUntilEnd = Stream_GetAvailableSampleNBUntilEndBuffer(serialRx_StreamChannel); + // Make size pointer point to the size data (1 byte after the SERIAL_HEADER 16bits length) + if (SizeUntilEnd > 1) + { + *size = (uint16_t)(*((uint8_t *)((int)serialRx_StreamChannel->sample_ptr + 1))); + if (SizeUntilEnd > 2) + { + *size |= (uint16_t)(*((uint8_t *)((int)serialRx_StreamChannel->sample_ptr + 2)) << 8); + } + else + { + *size |= (uint16_t)(*((uint8_t *)(serialRx_StreamChannel->ring_buffer)) << 8); + } + } + else + { + *size = (uint16_t)(*((uint8_t *)(serialRx_StreamChannel->ring_buffer))); + *size |= (uint16_t)(*((uint8_t *)((int)serialRx_StreamChannel->ring_buffer + 1)) << 8); + } + + if (TotalSize > *size) + { + // We should have a complete message + if (SizeUntilEnd > (*size + 3)) + { + // The message is continuons on the ring buffer + if (*((uint8_t *)((int)serialRx_StreamChannel->sample_ptr + (*size + 3))) == SERIAL_FOOTER) + { + // This is a good message remove the header and size from the available sample keeping only the data + Stream_RmvAvailableSampleNB(serialRx_StreamChannel, 3); + return true; + } + // Else this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte an dcontinue looking for it. + } + else + { + // The message is not continuons on the ring buffer + if (*((uint8_t *)((int)serialRx_StreamChannel->ring_buffer + ((*size + 3) - SizeUntilEnd))) == SERIAL_FOOTER) + { + // This is a good message remove the header and size from the available sample keeping only the data + Stream_RmvAvailableSampleNB(serialRx_StreamChannel, 3); + return true; + } + // Else this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte an dcontinue looking for it. + } + } + else + { + // The message is not complete + // Check if the size make sense, if not this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte and continue looking for it. + if (*size < PIPE_TX_BUFFER_SIZE) + { + // The message sounds good but is just not finished. + return false; + } + } + } + // The first byte is not a good header remove the byte + Stream_RmvAvailableSampleNB(serialRx_StreamChannel, 1); + } + } + return false; +} \ No newline at end of file diff --git a/tool_services/pipe/WS/native/pipe_com.c b/tool_services/pipe/WS/native/pipe_com.c index 8a24a4ebf..6738e3200 100644 --- a/tool_services/pipe/WS/native/pipe_com.c +++ b/tool_services/pipe/WS/native/pipe_com.c @@ -16,8 +16,8 @@ /******************************************************************************* * Variables ******************************************************************************/ -volatile uint16_t size_to_send = 0; -volatile uint16_t P2L_PrevPointerPosition = 0; +volatile uint16_t size_to_send = 0; +volatile uint16_t RX_PrevPointerPosition = 0; static const char *s_listen_on = "ws://localhost:9342"; static struct mg_mgr mgr; // Event manager @@ -54,7 +54,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { // Got websocket frame. Received data is wm->data. save it into the Pipe streaming channel struct mg_ws_message *wm = (struct mg_ws_message *)ev_data; - Stream_PutSample(get_P2L_StreamChannel(), wm->data.ptr, wm->data.len); + Stream_PutSample(Pipe_GetRxStreamChannel(), wm->data.ptr, wm->data.len); } (void)fn_data; } @@ -66,52 +66,67 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) ******************************************************************************/ void PipeCom_Init(void) { + // Initialize the event manager only once + static bool is_init = false; + if (is_init) + { + return; + } + is_init = true; mg_mgr_init(&mgr); // Initialise event manager printf("Starting WS listener on %s/ws\n", s_listen_on); mg_http_listen(&mgr, s_listen_on, fn, NULL); // Create HTTP listener } /****************************************************************************** - * @brief init must be call in project init + * @brief Check if a message is available * @param None * @return None ******************************************************************************/ -void PipeCom_SendL2P(uint8_t *data, uint16_t size) +uint8_t PipeCom_Receive(uint16_t *size) { - LUOS_ASSERT(size > 0); - size_to_send = size; - if (ws_connection != NULL) + *size = Stream_GetAvailableSampleNB(Pipe_GetRxStreamChannel()); + return (*size > 0); +} +/****************************************************************************** + * @brief PipeCom_GetSizeToSend + * @param None + * @return None + ******************************************************************************/ +static uint16_t PipeCom_GetSizeToSend(void) +{ + if ((Stream_GetAvailableSampleNB(Pipe_GetTxStreamChannel())) > Stream_GetAvailableSampleNBUntilEndBuffer(Pipe_GetTxStreamChannel())) + { + return Stream_GetAvailableSampleNBUntilEndBuffer(Pipe_GetTxStreamChannel()); + } + else { - mg_ws_send(ws_connection, (const char *)data, size, WEBSOCKET_OP_BINARY); + return Stream_GetAvailableSampleNB(Pipe_GetTxStreamChannel()); } } /****************************************************************************** - * @brief loop must be call in project loop + * @brief PipeCom_Send * @param None * @return None ******************************************************************************/ -void PipeCom_Loop(void) +void PipeCom_Send(void) { - uint16_t size = 0; - mg_mgr_poll(&mgr, 1000); // Infinite event loop - - // Check if we need to transmit - if (PipeCom_SendL2PPending() == false) + // Make sure the message finish with a '\n' + char end_of_message = '\n'; + Stream_PutSample(Pipe_GetTxStreamChannel(), &end_of_message, 1); + uint16_t size = PipeCom_GetSizeToSend(); + while (size > 0) { - streaming_channel_t *stream_channel = get_L2P_StreamChannel(); - size = Stream_GetAvailableSampleNB(stream_channel); - if (size != 0) - { - PipeCom_SendL2P((uint8_t *)stream_channel->sample_ptr, size); - Stream_RmvAvailableSampleNB(stream_channel, size); - } + mg_ws_send(ws_connection, (const char *)Pipe_GetTxStreamChannel()->sample_ptr, size, WEBSOCKET_OP_BINARY); + Stream_RmvAvailableSampleNB(Pipe_GetTxStreamChannel(), size); + size = PipeCom_GetSizeToSend(); } } /****************************************************************************** - * @brief check if pipe is sending + * @brief loop must be call in project loop * @param None - * @return true/false + * @return None ******************************************************************************/ -volatile uint8_t PipeCom_SendL2PPending(void) +void PipeCom_Loop(void) { - return false; + mg_mgr_poll(&mgr, 1000); // Infinite event loop } \ No newline at end of file diff --git a/tool_services/pipe/WS/native/pipe_com.h b/tool_services/pipe/WS/native/pipe_com.h index 90fac5214..d64f79ef3 100644 --- a/tool_services/pipe/WS/native/pipe_com.h +++ b/tool_services/pipe/WS/native/pipe_com.h @@ -7,8 +7,7 @@ #ifndef PIPE_COM_H #define PIPE_COM_H -#include "pipe_buffer.h" -#include "streaming.h" +#include "_pipe.h" /******************************************************************************* * Definitions @@ -23,9 +22,7 @@ ******************************************************************************/ void PipeCom_Init(void); void PipeCom_Loop(void); -void PipeCom_SendL2P(uint8_t *data, uint16_t size); -volatile uint8_t PipeCom_SendL2PPending(void); -streaming_channel_t *get_L2P_StreamChannel(void); -streaming_channel_t *get_P2L_StreamChannel(void); +uint8_t PipeCom_Receive(uint16_t *size); +void PipeCom_Send(void); #endif /* PIPE_H */ diff --git a/tool_services/pipe/_pipe.h b/tool_services/pipe/_pipe.h new file mode 100644 index 000000000..89e4198cb --- /dev/null +++ b/tool_services/pipe/_pipe.h @@ -0,0 +1,11 @@ +/****************************************************************************** + * @file _pipe + * @brief Private pipe functions + * @author Luos + * @version 0.0.0 + ******************************************************************************/ + +#include "streaming.h" + +streaming_channel_t *Pipe_GetTxStreamChannel(void); +streaming_channel_t *Pipe_GetRxStreamChannel(void); \ No newline at end of file diff --git a/tool_services/pipe/pipe.c b/tool_services/pipe/pipe.c index 373097ca5..f830ac395 100644 --- a/tool_services/pipe/pipe.c +++ b/tool_services/pipe/pipe.c @@ -4,8 +4,8 @@ * @author Luos * @version 0.1.0 ******************************************************************************/ -#include #include "pipe.h" +#include "_pipe.h" #include "pipe_com.h" /******************************************************************************* @@ -15,8 +15,10 @@ /******************************************************************************* * Variables ******************************************************************************/ -streaming_channel_t P2L_StreamChannel; -streaming_channel_t L2P_StreamChannel; +streaming_channel_t rx_StreamChannel; +streaming_channel_t tx_StreamChannel; +uint8_t rx_Buffer[PIPE_TX_BUFFER_SIZE] = {0}; +uint8_t tx_Buffer[PIPE_RX_BUFFER_SIZE] = {0}; /******************************************************************************* * Function @@ -29,11 +31,11 @@ static void Pipe_MsgHandler(service_t *service, msg_t *msg); ******************************************************************************/ void Pipe_Init(void) { - revision_t revision = {.major = 1, .minor = 0, .build = 0}; + rx_StreamChannel = Stream_CreateStreamingChannel(rx_Buffer, PIPE_TX_BUFFER_SIZE, 1); + tx_StreamChannel = Stream_CreateStreamingChannel(tx_Buffer, PIPE_RX_BUFFER_SIZE, 1); PipeCom_Init(); + revision_t revision = {.major = 1, .minor = 0, .build = 0}; Luos_CreateService(Pipe_MsgHandler, PIPE_TYPE, "Pipe", revision); - P2L_StreamChannel = Stream_CreateStreamingChannel(PipeBuffer_GetP2LBuffer(), PIPE_TO_LUOS_BUFFER_SIZE, 1); - L2P_StreamChannel = Stream_CreateStreamingChannel(PipeBuffer_GetL2PBuffer(), LUOS_TO_PIPE_BUFFER_SIZE, 1); } /****************************************************************************** * @brief loop must be call in project loop @@ -52,45 +54,34 @@ void Pipe_Loop(void) ******************************************************************************/ static void Pipe_MsgHandler(service_t *service, msg_t *msg) { - SerialProtocol_t SerialProtocol = {SERIAL_HEADER, 0, SERIAL_FOOTER}; - uint16_t size = 0; - static bool L2P_CompleteMsg = true; + uint16_t size = 0; if (msg->header.cmd == GET_CMD) { - if (true == PipeBuffer_GetP2LMsg(&size)) + if (true == PipeCom_Receive(&size)) { // fill the message infos msg_t pub_msg; pub_msg.header.cmd = SET_CMD; pub_msg.header.target_mode = ID; pub_msg.header.target = msg->header.source; - Luos_SendStreamingSize(service, &pub_msg, &P2L_StreamChannel, size); + Luos_SendStreamingSize(service, &pub_msg, &rx_StreamChannel, size); } } else if (msg->header.cmd == SET_CMD) { if (msg->header.size > 0) { - if (L2P_CompleteMsg == true) - { - L2P_CompleteMsg = false; - SerialProtocol.Size = msg->header.size; - Stream_PutSample(&L2P_StreamChannel, &SerialProtocol, 3); - } - if (Luos_ReceiveStreaming(service, msg, &L2P_StreamChannel) == SUCCEED) + if (Luos_ReceiveStreaming(service, msg, &tx_StreamChannel) == SUCCEED) { - Stream_PutSample(&L2P_StreamChannel, &SerialProtocol.Footer, 1); - L2P_CompleteMsg = true; + // Data reception is complete, we can send it. + PipeCom_Send(); } } - if (PipeCom_SendL2PPending() == false) + else { - size = Stream_GetAvailableSampleNBUntilEndBuffer(&L2P_StreamChannel); - if (size > 0) - { - PipeCom_SendL2P(L2P_StreamChannel.sample_ptr, size); - } + // The source of the data we have to send is localhost and the data is already in the buffer, we just have to send it. + PipeCom_Send(); } } else if (msg->header.cmd == PARAMETERS) @@ -100,31 +91,32 @@ static void Pipe_MsgHandler(service_t *service, msg_t *msg) pub_msg.header.cmd = PARAMETERS; pub_msg.header.target_mode = IDACK; pub_msg.header.target = msg->header.source; - pub_msg.header.size = sizeof(void *); - uintptr_t value = (uintptr_t)&PipeBuffer_SetL2PMsg; - memcpy(pub_msg.data, &value, sizeof(void *)); + pub_msg.header.size = sizeof(uintptr_t); + uintptr_t value = (uintptr_t)&tx_StreamChannel; + memcpy(pub_msg.data, &value, sizeof(uintptr_t)); Luos_SendMsg(service, &pub_msg); } else if (msg->header.cmd == REINIT) { - L2P_StreamChannel.sample_ptr = L2P_StreamChannel.data_ptr; + tx_StreamChannel.sample_ptr = tx_StreamChannel.data_ptr; + PipeCom_Init(); } } /****************************************************************************** - * @brief get Luos to Pipe StreamChannel + * @brief get TX (Luos to outside) StreamChannel * @param None * @return streaming_channel_t* ******************************************************************************/ -streaming_channel_t *get_L2P_StreamChannel(void) +streaming_channel_t *Pipe_GetTxStreamChannel(void) { - return &L2P_StreamChannel; + return &tx_StreamChannel; } /****************************************************************************** - * @brief get Pipe to Luos StreamChannel + * @brief get RX (outside to Luos) StreamChannel * @param None * @return streaming_channel_t* ******************************************************************************/ -streaming_channel_t *get_P2L_StreamChannel(void) +streaming_channel_t *Pipe_GetRxStreamChannel(void) { - return &P2L_StreamChannel; + return &rx_StreamChannel; } diff --git a/tool_services/pipe/pipe.h b/tool_services/pipe/pipe.h index 3cbbcddd4..88ca85e27 100644 --- a/tool_services/pipe/pipe.h +++ b/tool_services/pipe/pipe.h @@ -8,11 +8,15 @@ #define PIPE_H #include "luos_engine.h" -#include /******************************************************************************* * Definitions ******************************************************************************/ - +#ifndef PIPE_TX_BUFFER_SIZE +#define PIPE_TX_BUFFER_SIZE 1024 +#endif +#ifndef PIPE_RX_BUFFER_SIZE +#define PIPE_RX_BUFFER_SIZE 2048 +#endif /******************************************************************************* * Variables ******************************************************************************/ diff --git a/tool_services/pipe/pipe_buffer.c b/tool_services/pipe/pipe_buffer.c deleted file mode 100644 index 96431077c..000000000 --- a/tool_services/pipe/pipe_buffer.c +++ /dev/null @@ -1,142 +0,0 @@ -/****************************************************************************** - * @file pipe_buffer - * @brief communication buffer - * @author Luos - * @version 0.0.0 - ******************************************************************************/ -#include "pipe_com.h" -#include "pipe_buffer.h" -#include - -/******************************************************************************* - * Definitions - ******************************************************************************/ - -/******************************************************************************* - * Variables - ******************************************************************************/ -uint8_t P2L_Buffer[PIPE_TO_LUOS_BUFFER_SIZE] = {0}; -uint8_t L2P_Buffer[LUOS_TO_PIPE_BUFFER_SIZE] = {0}; - -/******************************************************************************* - * Function - ******************************************************************************/ - -/****************************************************************************** - * @brief init must be call in project init - * @param None - * @return None - ******************************************************************************/ -void PipeBuffer_SetL2PMsg(uint8_t *data, uint16_t size) -{ - streaming_channel_t *StreamChannel = get_L2P_StreamChannel(); - SerialProtocol_t SerialProtocol = {SERIAL_HEADER, 0, SERIAL_FOOTER}; - - SerialProtocol.Size = size; - Stream_PutSample(StreamChannel, &SerialProtocol, 3); - Stream_PutSample(StreamChannel, data, size); - Stream_PutSample(StreamChannel, &SerialProtocol.Footer, 1); -} -/****************************************************************************** - * @brief init must be call in project init - * @param None - * @return None - ******************************************************************************/ -uint8_t PipeBuffer_GetP2LMsg(uint16_t *size) -{ - streaming_channel_t *StreamChannel = get_P2L_StreamChannel(); - uint16_t TotalSize = Stream_GetAvailableSampleNB(StreamChannel); - uint16_t SizeUntilEnd = 0; - - if (TotalSize > 0) - { - // We received something - for (uint16_t i = 0; i < TotalSize; i++) - { - if (*((uint8_t *)(StreamChannel->sample_ptr)) == SERIAL_HEADER) - { - // The first byte is a header - // Make TotalSize fit the size of remaining datas. - TotalSize = TotalSize - i; - i = 0; - SizeUntilEnd = Stream_GetAvailableSampleNBUntilEndBuffer(StreamChannel); - // Make size pointer point to the size data (1 byte after the SERIAL_HEADER 16bits length) - if (SizeUntilEnd > 1) - { - *size = (uint16_t)(*((uint8_t *)(StreamChannel->sample_ptr + 1))); - if (SizeUntilEnd > 2) - { - *size |= (uint16_t)(*((uint8_t *)(StreamChannel->sample_ptr + 2)) << 8); - } - else - { - *size |= (uint16_t)(*((uint8_t *)(StreamChannel->ring_buffer)) << 8); - } - } - else - { - *size = (uint16_t)(*((uint8_t *)(StreamChannel->ring_buffer))); - *size |= (uint16_t)(*((uint8_t *)(StreamChannel->ring_buffer + 1)) << 8); - } - - if (TotalSize > *size) - { - // We should have a complete message - if (SizeUntilEnd > (*size + 3)) - { - // The message is continuons on the ring buffer - if (*((uint8_t *)(StreamChannel->sample_ptr + (*size + 3))) == SERIAL_FOOTER) - { - // This is a good message remove the header and size from the available sample keeping only the data - Stream_RmvAvailableSampleNB(StreamChannel, 3); - return true; - } - // Else this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte an dcontinue looking for it. - } - else - { - // The message is not continuons on the ring buffer - if (*((uint8_t *)(StreamChannel->ring_buffer + ((*size + 3) - SizeUntilEnd))) == SERIAL_FOOTER) - { - // This is a good message remove the header and size from the available sample keeping only the data - Stream_RmvAvailableSampleNB(StreamChannel, 3); - return true; - } - // Else this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte an dcontinue looking for it. - } - } - else - { - // The message is not complete - // Check if the size mak sense, if not this is not really a massage begin, so we have to remove the fake SERIAL_HEADER byte an dcontinue looking for it. - if (*size < PIPE_TO_LUOS_BUFFER_SIZE) - { - // The message sounds good but is just not finished. - return false; - } - } - } - // The first byte is not a good header remove the byte - Stream_RmvAvailableSampleNB(StreamChannel, 1); - } - } - return false; -} -/****************************************************************************** - * @brief Get L2P Buffer adresse - * @param None - * @return None - ******************************************************************************/ -uint8_t *PipeBuffer_GetL2PBuffer(void) -{ - return &L2P_Buffer[0]; -} -/****************************************************************************** - * @brief Get P2L Buffer adresse - * @param None - * @return None - ******************************************************************************/ -uint8_t *PipeBuffer_GetP2LBuffer(void) -{ - return &P2L_Buffer[0]; -} diff --git a/tool_services/pipe/pipe_buffer.h b/tool_services/pipe/pipe_buffer.h deleted file mode 100644 index c7317bfd8..000000000 --- a/tool_services/pipe/pipe_buffer.h +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * @file pipe_com - * @brief communication driver - * @author Luos - * @version 0.0.0 - ******************************************************************************/ -#ifndef PIPE_BUFFER_H -#define PIPE_BUFFER_H - -#include -/******************************************************************************* - * Definitions - ******************************************************************************/ -#ifndef PIPE_TO_LUOS_BUFFER_SIZE -#define PIPE_TO_LUOS_BUFFER_SIZE 1024 -#endif -#ifndef LUOS_TO_PIPE_BUFFER_SIZE -#define LUOS_TO_PIPE_BUFFER_SIZE 2048 -#endif - -#define SERIAL_HEADER 0x7E -#define SERIAL_FOOTER 0x81 -/******************************************************************************* - * Variables - ******************************************************************************/ -typedef struct __attribute__((__packed__)) -{ - uint8_t Header; - uint16_t Size; - uint8_t Footer; -} SerialProtocol_t; -/******************************************************************************* - * Function - ******************************************************************************/ -void PipeBuffer_SetL2PMsg(uint8_t *data, uint16_t size); -uint8_t PipeBuffer_GetP2LMsg(uint16_t *size); -uint8_t *PipeBuffer_GetP2LBuffer(void); -uint8_t *PipeBuffer_GetL2PBuffer(void); - -#endif /* PIPE_BUFFER_H */