Skip to content

Commit c634178

Browse files
committed
Fix exception due to static initialiser in ISR
Non-trivial static variables may require an initialisation routine which is invoked on first call. This happens in the `hwTimerCallback` routine when the `ElapseTimer` constructor is called, but that is unsafe to do from interrupt context. Moving this to a global variable fixes the issue. The exception may vary, but I'm getting: ``` assert failed: xQueueSemaphoreTake queue.c:1718 (!( ( xTaskGetSchedulerState() == ( ( BaseType_t ) 0 ) ) && ( xTicksToWait != 0 ) )) ```
1 parent 3091165 commit c634178

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

samples/Basic_Tasks/app/application.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ constexpr unsigned hwTimerReportInterval{1000000}; //< How often to print hardwa
2020

2121
volatile unsigned hwTimerCount;
2222

23+
ElapseTimer hwTimer(hwTimerReportInterval);
24+
2325
/*
2426
* Analogue reader task
2527
*/
@@ -65,12 +67,11 @@ void IRAM_ATTR hwTimerCallback()
6567
{
6668
++hwTimerCount;
6769

68-
static ElapseTimer timer(hwTimerReportInterval);
69-
if(timer.expired()) {
70+
if(hwTimer.expired()) {
7071
unsigned count = hwTimerCount;
7172
// System.queueCallback([count]() { hwTimerDelegate(count); });
7273
System.queueCallback(hwTimerDelegate, count);
73-
timer.start();
74+
hwTimer.start();
7475
}
7576
}
7677

0 commit comments

Comments
 (0)