Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 3a417bf

Browse files
committed
EM-344-mcu-can-enter-a-scheduled-infinite-loop-somewhere-causing-high-power-consumption-no-communication-while-not-triggering-a-watchdog-reset
1 parent bb3531d commit 3a417bf

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

stack/framework/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ FRAMEWORK_HEADER_DEFINE(NUMBER FRAMEWORK_SCHEDULER_MAX_TASKS)
3939
SET(FRAMEWORK_SCHEDULER_LP_MODE "0" CACHE STRING "The low power mode to use. Only change this if you know exactly what you are doing")
4040
FRAMEWORK_HEADER_DEFINE(NUMBER FRAMEWORK_SCHEDULER_LP_MODE)
4141

42+
SET(FRAMEWORK_SCHEDULER_MAX_ACTIVE_TIME "0" CACHE STRING "Defines the maximum time in seconds the scheduler can be active. When this time is exceeded the processor will assert. Set to 0 to disable this feature")
43+
FRAMEWORK_HEADER_DEFINE(NUMBER FRAMEWORK_SCHEDULER_MAX_ACTIVE_TIME)
44+
4245
# when the current platform is using jlink we enable logging by default
4346
IF(JLINK_DEVICE)
4447
SET(FRAMEWORK_LOG_ENABLED "TRUE" CACHE BOOL "Select whether to enable or disable the generation of logs")

stack/framework/components/scheduler/scheduler.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ __LINK_C void scheduler_run()
528528
uint8_t executed_tasks = 0;
529529
watchdog_wakeup = false;
530530
#endif
531-
#if defined FRAMEWORK_USE_POWER_TRACKING
531+
#if (defined FRAMEWORK_USE_POWER_TRACKING || FRAMEWORK_SCHEDULER_MAX_ACTIVE_TIME > 0)
532532
timer_tick_t wakeup_time = timer_get_counter_value();
533533
#endif
534534
while(NG(current_priority) < NUM_PRIORITIES)
@@ -545,15 +545,18 @@ __LINK_C void scheduler_run()
545545
#endif
546546
check_structs_are_valid();
547547
#if defined(FRAMEWORK_LOG_ENABLED) && defined(FRAMEWORK_SCHED_LOG_ENABLED)
548-
timer_tick_t start = timer_get_counter_value();
549-
log_print_string("SCHED start %p at %i", NG(m_info)[id].task, start);
548+
timer_tick_t start = timer_get_counter_value();
549+
log_print_string("SCHED start %p at %i", NG(m_info)[id].task, start);
550550
#endif
551-
current_task_id = id;
552-
NG(m_info)[id].task(NG(m_info)[id].arg);
551+
current_task_id = id;
552+
NG(m_info)[id].task(NG(m_info)[id].arg);
553+
#if FRAMEWORK_SCHEDULER_MAX_ACTIVE_TIME > 0
554+
assert(timer_get_current_time_difference(wakeup_time) < FRAMEWORK_SCHEDULER_MAX_ACTIVE_TIME * TIMER_TICKS_PER_SEC);
555+
#endif
553556
#if defined(FRAMEWORK_LOG_ENABLED) && defined(FRAMEWORK_SCHED_LOG_ENABLED)
554-
timer_tick_t stop = timer_get_counter_value();
555-
timer_tick_t duration = stop - start;
556-
log_print_string("SCHED stop %p at %i took %i", NG(m_info)[id].task, stop, duration);
557+
timer_tick_t stop = timer_get_counter_value();
558+
timer_tick_t duration = stop - start;
559+
log_print_string("SCHED stop %p at %i took %i", NG(m_info)[id].task, stop, duration);
557560
#endif
558561
}
559562
//this needs to be done atomically since otherwise we risk decrementing the current priority

stack/modules/alp/alp_layer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ static void process_async(void* arg)
757757
alp_interface_config_t forward_interface_config;
758758
alp_command_t* resp_command = alp_layer_command_alloc(false, false);
759759
if(resp_command == NULL) {
760-
log_print_error_string("process async: alloc command failed for the response command, retrying later");
761-
fifo_put(&command_fifo, (uint8_t*)&command, sizeof(alp_command_t*));
760+
log_print_error_string("process async: alloc command failed for the response command, dropping command");
761+
free_command(command);
762762
return;
763763
}
764764
static alp_action_t action;

stack/modules/alp/serial_interface.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ static void serial_interface_cmd_handler(fifo_t* cmd_fifo)
6767
end_atomic();
6868

6969
alp_command_t* command = alp_layer_command_alloc(false, false);
70+
if(command == NULL)
71+
{
72+
log_print_error_string("serial_interface_cmd_handler: unable to allocate alp command");
73+
return;
74+
75+
}
7076
command->origin_itf_id = ALP_ITF_ID_SERIAL;
7177
alp_append_interface_status(command, &serial_itf_status);
7278
fifo_put(&command->alp_command_fifo, alp_command, alp_command_len);

0 commit comments

Comments
 (0)