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/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; 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"); { 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); 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 { diff --git a/tool_services/pipe/SERIAL/serial_protocol.h b/tool_services/pipe/SERIAL/serial_protocol.h index d2639e47f..c48bc97f9 100644 --- a/tool_services/pipe/SERIAL/serial_protocol.h +++ b/tool_services/pipe/SERIAL/serial_protocol.h @@ -50,7 +50,11 @@ static inline void SerialProtocol_Init(void) static inline void SerialProtocol_CreateTxMsg(void) { // 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 +69,6 @@ static inline void SerialProtocol_CreateTxMsg(void) 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, @@ -91,13 +94,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; } }