From 7b9bc35153128618edb57ee28b6d216085668674 Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Tue, 12 Mar 2024 16:21:50 +0100 Subject: [PATCH 1/6] [robus] Fix some init raising PTP IRQ depending on user config. --- network/robus_network/HAL/STM32F0/robus_hal.c | 5 +++++ network/robus_network/HAL/STM32F4/robus_hal.c | 5 +++++ network/robus_network/HAL/STM32G4/robus_hal.c | 5 +++++ network/robus_network/HAL/STM32L0/robus_hal.c | 5 +++++ network/robus_network/HAL/STM32L4/robus_hal.c | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/network/robus_network/HAL/STM32F0/robus_hal.c b/network/robus_network/HAL/STM32F0/robus_hal.c index 61be2e095..b806995a1 100644 --- a/network/robus_network/HAL/STM32F0/robus_hal.c +++ b/network/robus_network/HAL/STM32F0/robus_hal.c @@ -89,6 +89,8 @@ void RobusHAL_Loop(void) ******************************************************************************/ void RobusHAL_ComInit(uint32_t Baudrate) { + HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ); + HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ); ROBUS_COM_CLOCK_ENABLE(); LL_USART_InitTypeDef USART_InitStruct; @@ -468,6 +470,9 @@ static void RobusHAL_GPIOInit(void) RobusHAL_RegisterPTP(); for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */ { + // Disable IT for PTP + HAL_NVIC_DisableIRQ(PTP[i].IRQ); + HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ); GPIO_InitStruct.Pin = PTP[i].Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; diff --git a/network/robus_network/HAL/STM32F4/robus_hal.c b/network/robus_network/HAL/STM32F4/robus_hal.c index 2846c5671..39fd5aaf5 100644 --- a/network/robus_network/HAL/STM32F4/robus_hal.c +++ b/network/robus_network/HAL/STM32F4/robus_hal.c @@ -90,6 +90,8 @@ void RobusHAL_Loop(void) ******************************************************************************/ void RobusHAL_ComInit(uint32_t Baudrate) { + HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ); + HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ); ROBUS_COM_CLOCK_ENABLE(); LL_USART_InitTypeDef USART_InitStruct; @@ -472,6 +474,9 @@ static void RobusHAL_GPIOInit(void) RobusHAL_RegisterPTP(); for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */ { + // Disable IT for PTP + HAL_NVIC_DisableIRQ(PTP[i].IRQ); + HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ); GPIO_InitStruct.Pin = PTP[i].Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; diff --git a/network/robus_network/HAL/STM32G4/robus_hal.c b/network/robus_network/HAL/STM32G4/robus_hal.c index 448dc0287..6ddc0b427 100644 --- a/network/robus_network/HAL/STM32G4/robus_hal.c +++ b/network/robus_network/HAL/STM32G4/robus_hal.c @@ -91,6 +91,8 @@ void RobusHAL_Loop(void) ******************************************************************************/ void RobusHAL_ComInit(uint32_t Baudrate) { + HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ); + HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ); ROBUS_COM_CLOCK_ENABLE(); LL_USART_InitTypeDef USART_InitStruct; @@ -469,6 +471,9 @@ static void RobusHAL_GPIOInit(void) RobusHAL_RegisterPTP(); for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */ { + // Disable IT for PTP + HAL_NVIC_DisableIRQ(PTP[i].IRQ); + HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ); GPIO_InitStruct.Pin = PTP[i].Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; diff --git a/network/robus_network/HAL/STM32L0/robus_hal.c b/network/robus_network/HAL/STM32L0/robus_hal.c index f03c2bcf7..acefb3a4e 100644 --- a/network/robus_network/HAL/STM32L0/robus_hal.c +++ b/network/robus_network/HAL/STM32L0/robus_hal.c @@ -89,6 +89,8 @@ void RobusHAL_Loop(void) ******************************************************************************/ void RobusHAL_ComInit(uint32_t Baudrate) { + HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ); + HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ); ROBUS_COM_CLOCK_ENABLE(); LL_USART_InitTypeDef USART_InitStruct; @@ -467,6 +469,9 @@ static void RobusHAL_GPIOInit(void) RobusHAL_RegisterPTP(); for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */ { + // Disable IT for PTP + HAL_NVIC_DisableIRQ(PTP[i].IRQ); + HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ); GPIO_InitStruct.Pin = PTP[i].Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; diff --git a/network/robus_network/HAL/STM32L4/robus_hal.c b/network/robus_network/HAL/STM32L4/robus_hal.c index b9c9910e3..cc7dac4c7 100644 --- a/network/robus_network/HAL/STM32L4/robus_hal.c +++ b/network/robus_network/HAL/STM32L4/robus_hal.c @@ -91,6 +91,8 @@ void RobusHAL_Loop(void) ******************************************************************************/ void RobusHAL_ComInit(uint32_t Baudrate) { + HAL_NVIC_DisableIRQ(ROBUS_COM_IRQ); + HAL_NVIC_ClearPendingIRQ(ROBUS_COM_IRQ); ROBUS_COM_CLOCK_ENABLE(); LL_USART_InitTypeDef USART_InitStruct; @@ -469,6 +471,9 @@ static void RobusHAL_GPIOInit(void) RobusHAL_RegisterPTP(); for (uint8_t i = 0; i < NBR_PORT; i++) /*Configure GPIO pins : PTP_Pin */ { + // Disable IT for PTP + HAL_NVIC_DisableIRQ(PTP[i].IRQ); + HAL_NVIC_ClearPendingIRQ(PTP[i].IRQ); GPIO_InitStruct.Pin = PTP[i].Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLDOWN; From 2e42a34cbadafae30a2acda0a92594ba3142a50a Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Tue, 12 Mar 2024 16:20:59 +0100 Subject: [PATCH 2/6] Fix services auto-update by allowing to be removed by sending 0 as period. --- engine/core/src/service.c | 2 +- test/tests_core/test_service/main.c | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/engine/core/src/service.c b/engine/core/src/service.c index 7cab862a7..d321c0d01 100644 --- a/engine/core/src/service.c +++ b/engine/core/src/service.c @@ -136,7 +136,7 @@ uint16_t Service_GetIndex(service_t *service) ******************************************************************************/ void Service_AddAutoUpdateTarget(service_t *service, uint16_t target, uint16_t time_ms) { - LUOS_ASSERT(service && (time_ms > 0) && (target != 0)); + LUOS_ASSERT(service && (target != 0)); for (uint16_t i = 0; i < MAX_AUTO_REFRESH_NUMBER; i++) { if (service_ctx.auto_refresh[i].time_ms == 0) diff --git a/test/tests_core/test_service/main.c b/test/tests_core/test_service/main.c index 36841c895..8e98f600a 100644 --- a/test/tests_core/test_service/main.c +++ b/test/tests_core/test_service/main.c @@ -228,13 +228,6 @@ void unittest_Service_AddAutoUpdateTarget(void) } TEST_ASSERT_TRUE(IS_ASSERT()); END_TRY; - - TRY - { - Service_AddAutoUpdateTarget(&service_ctx.list[0], 1, 0); - } - TEST_ASSERT_TRUE(IS_ASSERT()); - END_TRY; } NEW_TEST_CASE("Test Service_AddAutoUpdateTarget"); { From 784a6ff2f4c57dc5797ab668f021e9ab32574094 Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Tue, 12 Mar 2024 16:23:46 +0100 Subject: [PATCH 3/6] [Gate] Remove auto-updates before setting a new one allowing to keep only one at a time per services. --- tool_services/gate/TinyJSON/convert.c | 7 ++++++- tool_services/gate/data_manager.c | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tool_services/gate/TinyJSON/convert.c b/tool_services/gate/TinyJSON/convert.c index 4f0043c27..9f491aeee 100644 --- a/tool_services/gate/TinyJSON/convert.c +++ b/tool_services/gate/TinyJSON/convert.c @@ -543,7 +543,12 @@ void Convert_JsonToMsg(service_t *service, uint16_t id, luos_type_t type, char * { if (type != GATE_TYPE) { - // this should be a function because it is frequently used + // remove any current updates + time = TimeOD_TimeFrom_s(0); + TimeOD_TimeToMsg(&time, &msg); + msg.header.cmd = UPDATE_PUB; + Luos_SendMsg(service, &msg); + // configure the new update value time = TimeOD_TimeFrom_s((float)json_getReal(jobj)); TimeOD_TimeToMsg(&time, &msg); msg.header.cmd = UPDATE_PUB; diff --git a/tool_services/gate/data_manager.c b/tool_services/gate/data_manager.c index 6c1e74875..abd5e1d3f 100644 --- a/tool_services/gate/data_manager.c +++ b/tool_services/gate/data_manager.c @@ -49,7 +49,13 @@ void DataManager_collect(service_t *service) #endif #else // This service is a sensor so create a msg to enable auto update + // First remove any auto update + time_luos_t reset_time = {.raw = 0}; update_msg.header.target = result.result_table[i]->id; + TimeOD_TimeToMsg(&reset_time, &update_msg); + update_msg.header.cmd = UPDATE_PUB; + Luos_SendMsg(service, &update_msg); + TimeOD_TimeToMsg(&update_time, &update_msg); update_msg.header.cmd = UPDATE_PUB; Luos_SendMsg(service, &update_msg); From 18b2e2df7785e77d178cb8cf0f5033a3b57952ed Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Wed, 13 Mar 2024 11:31:33 +0100 Subject: [PATCH 4/6] [pipe] Fix size calculation if multiple JSON are sent very closely --- tool_services/pipe/SERIAL/serial_protocol.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tool_services/pipe/SERIAL/serial_protocol.h b/tool_services/pipe/SERIAL/serial_protocol.h index d2639e47f..6223a2be7 100644 --- a/tool_services/pipe/SERIAL/serial_protocol.h +++ b/tool_services/pipe/SERIAL/serial_protocol.h @@ -49,8 +49,13 @@ static inline void SerialProtocol_Init(void) static inline void SerialProtocol_CreateTxMsg(void) { + static char *last_data_end = NULL; // Evaluate size - uint16_t size = (Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t)); + // We want to evaluate the size of the last message only. To do that we create a fake StreamChannel with the same properties as the serialTx_StreamChannel but with the sample_ptr pointing to the begining of our message. + streaming_channel_t fake_StreamChannel = *serialTx_StreamChannel; + memcpy(&fake_StreamChannel, serialTx_StreamChannel, sizeof(streaming_channel_t)); + fake_StreamChannel.sample_ptr = size_to_update; // We make it point to the size + uint16_t size = Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 2; // We remove the size bytes from the calculated size. // Update size if ((size_to_update + 2) > (uint8_t *)((int)serialTx_StreamChannel->end_ring_buffer)) { @@ -65,7 +70,7 @@ static inline void SerialProtocol_CreateTxMsg(void) size_to_update[0] = size & 0xFF; size_to_update[1] = size >> 8; } - + last_data_end = (char *)serialTx_StreamChannel->data_ptr; // Write footer and header + size of the next message into the buffer SerialProtocol_t SerialProtocol = { SERIAL_FOOTER, @@ -91,13 +96,17 @@ static inline void SerialProtocol_CreateTxMsg(void) static inline uint16_t SerialProtocol_GetSizeToSend(void) { - if ((Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t)) > Streaming_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel)) + // We want to evaluate the size of the last message only. To do that we create a fake StreamChannel with the same properties as the serialTx_StreamChannel but with the sample_ptr pointing to the begining of our message. + streaming_channel_t fake_StreamChannel = *serialTx_StreamChannel; + memcpy(&fake_StreamChannel, serialTx_StreamChannel, sizeof(streaming_channel_t)); + fake_StreamChannel.data_ptr = size_to_update; // We the end of the data point to the size + if ((Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 1) > Streaming_GetAvailableSampleNBUntilEndBuffer(&fake_StreamChannel)) { - return Streaming_GetAvailableSampleNBUntilEndBuffer(serialTx_StreamChannel); + return Streaming_GetAvailableSampleNBUntilEndBuffer(&fake_StreamChannel); } else { - return Streaming_GetAvailableSampleNB(serialTx_StreamChannel) - sizeof(SerialHeader_t); + return Streaming_GetAvailableSampleNB(&fake_StreamChannel) - 1; } } From 84e13ec4e9a52c4f773960ec4150e668d43b645b Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Tue, 12 Mar 2024 16:22:50 +0100 Subject: [PATCH 5/6] [Gate] Remove the wait period of the Gate --- tool_services/gate/gate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tool_services/gate/gate.c b/tool_services/gate/gate.c index 9a4696155..030d94c82 100644 --- a/tool_services/gate/gate.c +++ b/tool_services/gate/gate.c @@ -53,7 +53,9 @@ void Gate_Init(void) ******************************************************************************/ void Gate_Loop(void) { +#ifndef GATE_POLLING static uint32_t last_time = 0; +#endif // Check the detection status. if (Luos_IsDetected() == false) @@ -68,11 +70,11 @@ void Gate_Loop(void) if (gate_running == RUNNING) { // Manage input and output data + DataManager_Run(gate); +#ifndef GATE_POLLING if ((Luos_GetSystick() - last_time >= TimeOD_TimeTo_ms(update_time)) && (Luos_GetSystick() > last_time)) { last_time = Luos_GetSystick(); - DataManager_Run(gate); -#ifndef GATE_POLLING if (first_conversion == true) { // This is the first time we perform a convertion @@ -95,8 +97,8 @@ void Gate_Loop(void) DataManager_collect(gate); first_conversion = false; } -#endif } +#endif } else { From 189c93c0b1bdb871bf1e9e8b5eb941b1634a5acd Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Tue, 19 Mar 2024 18:34:40 +0100 Subject: [PATCH 6/6] [Pipe] remove a useless variable on the serial TX protocol. --- tool_services/pipe/SERIAL/serial_protocol.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tool_services/pipe/SERIAL/serial_protocol.h b/tool_services/pipe/SERIAL/serial_protocol.h index 6223a2be7..c48bc97f9 100644 --- a/tool_services/pipe/SERIAL/serial_protocol.h +++ b/tool_services/pipe/SERIAL/serial_protocol.h @@ -49,7 +49,6 @@ static inline void SerialProtocol_Init(void) static inline void SerialProtocol_CreateTxMsg(void) { - static char *last_data_end = NULL; // Evaluate size // We want to evaluate the size of the last message only. To do that we create a fake StreamChannel with the same properties as the serialTx_StreamChannel but with the sample_ptr pointing to the begining of our message. streaming_channel_t fake_StreamChannel = *serialTx_StreamChannel; @@ -70,7 +69,6 @@ static inline void SerialProtocol_CreateTxMsg(void) size_to_update[0] = size & 0xFF; size_to_update[1] = size >> 8; } - last_data_end = (char *)serialTx_StreamChannel->data_ptr; // Write footer and header + size of the next message into the buffer SerialProtocol_t SerialProtocol = { SERIAL_FOOTER,