Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stability issues #487

Merged
merged 9 commits into from
May 23, 2024
2 changes: 2 additions & 0 deletions engine/core/src/luos_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ void Luos_JumpToBootloader(void)
******************************************************************************/
_CRITICAL void Luos_assert(char *file, uint32_t line)
{
// Reset phy to avoid locking the phys
Phy_Reset();
// prepare a message as a node.
// To do that we have to reset the service ID and clear PTP states to unlock others.

Expand Down
10 changes: 5 additions & 5 deletions engine/core/src/routing_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ search_result_t *RTFilter_ID(search_result_t *result, uint16_t id)
if (result->result_table[entry_nbr]->id != id)
{
// if we find an other id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1006,7 +1006,7 @@ search_result_t *RTFilter_Type(search_result_t *result, luos_type_t type)
if (result->result_table[entry_nbr]->type != type)
{
// if we find an other type, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1042,7 +1042,7 @@ search_result_t *RTFilter_Node(search_result_t *result, uint16_t node_id)
if (RoutingTB_NodeIDFromID(result->result_table[entry_nbr]->id) != node_id)
{
// if we find an other node_id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1078,7 +1078,7 @@ search_result_t *RTFilter_Alias(search_result_t *result, char *alias)
if (strstr(result->result_table[entry_nbr]->alias, alias) == 0)
{
// if we find an other node_id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down Expand Up @@ -1114,7 +1114,7 @@ search_result_t *RTFilter_Service(search_result_t *result, service_t *service)
if (result->result_table[entry_nbr]->id != service->id)
{
// if we find an other id, erase it from the research table
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr));
memcpy(&result->result_table[entry_nbr], &result->result_table[entry_nbr + 1], sizeof(routing_table_t *) * (result->result_nbr - entry_nbr - 1));
result->result_nbr--;
}
else
Expand Down
21 changes: 16 additions & 5 deletions network/robus_network/HAL/ATSAMD21/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,24 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // clear IT pending
ROBUS_TIMER->COUNT16.TC_INTFLAG = TC_INTFLAG_OVF_Msk; // clear flag
ROBUS_TIMER->COUNT16.TC_CTRLA &= ~TC_CTRLA_ENABLE_Msk;
uint32_t diff;
// We use the end of the timer as trigger.
diff = (0xFFFF - ROBUS_TIMER->COUNT16.TC_COUNT) / timoutclockcnt; // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.TC_CTRLA &= ~TC_CTRLA_ENABLE_Msk; // Disable timer
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending
ROBUS_TIMER->COUNT16.TC_INTFLAG = TC_INTFLAG_OVF_Msk; // clear flag
ROBUS_TIMER->COUNT16.TC_COUNT = 0xFFFF - (timoutclockcnt * DEFAULT_TIMEOUT); // Load the timer with it's default value
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.TC_COUNT = 0xFFFF - (timoutclockcnt * nbrbit); // Load the timer
}
if (nbrbit != 0)
{
ROBUS_TIMER->COUNT16.TC_COUNT = 0xFFFF - (timoutclockcnt * nbrbit);
ROBUS_TIMER->COUNT16.TC_CTRLA |= TC_CTRLA_ENABLE_Msk;
ROBUS_TIMER->COUNT16.TC_CTRLA |= TC_CTRLA_ENABLE_Msk; // Enable timer
}
}
/******************************************************************************
Expand Down
21 changes: 16 additions & 5 deletions network/robus_network/HAL/ATSAMD21_ARDUINO/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,24 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // clear IT pending
ROBUS_TIMER->COUNT16.INTFLAG.bit.OVF = 1;
ROBUS_TIMER->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE;
uint32_t diff;
// We use the end of the timer as trigger.
diff = (0xFFFF - ROBUS_TIMER->COUNT16.COUNT.reg) / timoutclockcnt; // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE; // Disable timer
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending
ROBUS_TIMER->COUNT16.INTFLAG.bit.OVF = 1; // Clear IT flag
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * DEFAULT_TIMEOUT); // Load the timer with it's default value
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * nbrbit); // Load the timer
}
if (nbrbit != 0)
{
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * nbrbit);
ROBUS_TIMER->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE;
ROBUS_TIMER->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE; // Enable timer
}
}
/******************************************************************************
Expand Down
21 changes: 16 additions & 5 deletions network/robus_network/HAL/ATSAMD21_MBED/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,24 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // clear IT pending
ROBUS_TIMER->COUNT16.INTFLAG.bit.OVF = 1;
ROBUS_TIMER->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE;
uint32_t diff;
// We use the end of the timer as trigger.
diff = (0xFFFF - ROBUS_TIMER->COUNT16.COUNT.reg) / timoutclockcnt; // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.CTRLA.reg &= ~TC_CTRLA_ENABLE; // Disable timer
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending
ROBUS_TIMER->COUNT16.INTFLAG.bit.OVF = 1; // Clear IT flag
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * DEFAULT_TIMEOUT); // Load the timer with it's default value
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * nbrbit); // Load the timer
}
if (nbrbit != 0)
{
ROBUS_TIMER->COUNT16.COUNT.reg = 0xFFFF - (timoutclockcnt * nbrbit);
ROBUS_TIMER->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE;
ROBUS_TIMER->COUNT16.CTRLA.reg |= TC_CTRLA_ENABLE; // Enable timer
}
}
/******************************************************************************
Expand Down
29 changes: 23 additions & 6 deletions network/robus_network/HAL/ESP32/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,32 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
// disable Counter
timer_hal_set_counter_value(&timeout_hal_context, 0);
timer_hal_set_counter_enable(&timeout_hal_context, TIMER_PAUSE);
timer_hal_clear_intr_status(&timeout_hal_context);
timer_hal_intr_disable(&timeout_hal_context);
uint64_t arr_val, diff, cnt_val;
timer_get_alarm_value(ROBUS_TIMER_GROUP, ROBUS_TIMER, &arr_val); // Get actual timeout value
timer_get_counter_value(ROBUS_TIMER_GROUP, ROBUS_TIMER, &cnt_val); // Get counter value
diff = arr_val - cnt_val; // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
// disable Counter
timer_hal_set_counter_enable(&timeout_hal_context, TIMER_PAUSE);
timer_hal_clear_intr_status(&timeout_hal_context);
timer_hal_intr_disable(&timeout_hal_context);

timer_hal_set_alarm_value(&timeout_hal_context, DEFAULT_TIMEOUT);
timer_hal_set_counter_value(&timeout_hal_context, 0);
}

if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
// Reset counter
timer_hal_set_alarm_value(&timeout_hal_context, nbrbit);
timer_hal_set_counter_value(&timeout_hal_context, 0);
}

// Reset counter
if (nbrbit != 0)
{
// Start counter
timer_hal_intr_enable(&timeout_hal_context);
timer_hal_set_counter_enable(&timeout_hal_context, TIMER_START);
}
Expand Down
28 changes: 23 additions & 5 deletions network/robus_network/HAL/STM32F0/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,31 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
if (nbrbit != 0)
/* TODO: optimize further by getting rid of the need to reach for the ARR value.
The same result can be achieved by only setting the start value of the counter and letting it count down toward 0.
An IRQ can then be generated when reaching 0. This way diff = counter_value.
*/

uint32_t arr_val, diff;
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value
diff = arr_val - LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);

LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT);
LL_TIM_SetCounter(ROBUS_TIMER, 0);
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
}
if (nbrbit != 0)
{
LL_TIM_EnableCounter(ROBUS_TIMER);
}
}
Expand Down
28 changes: 23 additions & 5 deletions network/robus_network/HAL/STM32F4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,31 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
if (nbrbit != 0)
/* TODO: optimize further by getting rid of the need to reach for the ARR value.
The same result can be achieved by only setting the start value of the counter and letting it count down toward 0.
An IRQ can then be generated when reaching 0. This way diff = counter_value.
*/

uint32_t arr_val, diff;
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value
diff = arr_val - LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);

LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT);
LL_TIM_SetCounter(ROBUS_TIMER, 0);
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
}
if (nbrbit != 0)
{
LL_TIM_EnableCounter(ROBUS_TIMER);
}
}
Expand Down
28 changes: 23 additions & 5 deletions network/robus_network/HAL/STM32G4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,31 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
if (nbrbit != 0)
/* TODO: optimize further by getting rid of the need to reach for the ARR value.
The same result can be achieved by only setting the start value of the counter and letting it count down toward 0.
An IRQ can then be generated when reaching 0. This way diff = counter_value.
*/

uint32_t arr_val, diff;
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value
diff = arr_val - LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);

LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT);
LL_TIM_SetCounter(ROBUS_TIMER, 0);
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
}
if (nbrbit != 0)
{
LL_TIM_EnableCounter(ROBUS_TIMER);
}
}
Expand Down
30 changes: 24 additions & 6 deletions network/robus_network/HAL/STM32L0/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,33 @@ static void RobusHAL_TimeoutInit(void)
* @param None
* @return None
******************************************************************************/
void RobusHAL_ResetTimeout(uint16_t nbrbit)
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
if (nbrbit != 0)
/* TODO: optimize further by getting rid of the need to reach for the ARR value.
The same result can be achieved by only setting the start value of the counter and letting it count down toward 0.
An IRQ can then be generated when reaching 0. This way diff = counter_value.
*/

uint32_t arr_val, diff;
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value
diff = arr_val - LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);

LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT);
LL_TIM_SetCounter(ROBUS_TIMER, 0);
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
}
if (nbrbit != 0)
{
LL_TIM_EnableCounter(ROBUS_TIMER);
}
}
Expand Down
27 changes: 22 additions & 5 deletions network/robus_network/HAL/STM32L4/robus_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,30 @@ static void RobusHAL_TimeoutInit(void)
******************************************************************************/
_CRITICAL void RobusHAL_ResetTimeout(uint16_t nbrbit)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
if (nbrbit != 0)
/* TODO: optimize further by getting rid of the need to reach for the ARR value.
The same result can be achieved by only setting the start value of the counter and letting it count down toward 0.
An IRQ can then be generated when reaching 0. This way diff = counter_value.
*/
uint32_t arr_val, diff;
arr_val = LL_TIM_ReadReg(ROBUS_TIMER, ARR); // Get actual timeout value
diff = arr_val - LL_TIM_ReadReg(ROBUS_TIMER, CNT); // Compute remaining time before timeout

if (diff < DEFAULT_TIMEOUT)
{
LL_TIM_DisableCounter(ROBUS_TIMER);
NVIC_ClearPendingIRQ(ROBUS_TIMER_IRQ); // Clear IT pending NVIC
LL_TIM_ClearFlag_UPDATE(ROBUS_TIMER);

LL_TIM_SetAutoReload(ROBUS_TIMER, DEFAULT_TIMEOUT);
LL_TIM_SetCounter(ROBUS_TIMER, 0);
}
if (nbrbit != 0 && nbrbit != DEFAULT_TIMEOUT)
{
LL_TIM_SetAutoReload(ROBUS_TIMER, nbrbit); // reload value
LL_TIM_SetCounter(ROBUS_TIMER, 0); // Reset counter
}
if (nbrbit != 0)
{
LL_TIM_EnableCounter(ROBUS_TIMER);
}
}
Expand Down
6 changes: 3 additions & 3 deletions network/robus_network/src/robus.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ robus_encaps_t encaps[MAX_MSG_NB]; // Store all the CRC for each msg to transmit
******************************************************************************/
void Robus_Init(void)
{
// Init Reception
Recep_Init();

// Init hal
RobusHAL_Init();

Expand All @@ -49,9 +52,6 @@ void Robus_Init(void)
// Init transmission
Transmit_Init();

// Init Receiption
Recep_Init();

// Instantiate the phy struct
phy_robus = Phy_Create(Robus_JobHandler, Robus_RunTopology, Robus_Reset);
LUOS_ASSERT(phy_robus);
Expand Down
Loading