Skip to content

Commit 998120d

Browse files
committed
Reproduce freertos crash
Run hello_freertos1 Press Q to quit The worker thread will block the worker task from exiting before the state is cleared in async_context_freertos_deinit. async_context_task will keep running.
1 parent 18b6b37 commit 998120d

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

freertos/hello_freertos/hello_freertos.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828

2929
// Whether to busy wait in the led thread
3030
#ifndef LED_BUSY_WAIT
31-
#define LED_BUSY_WAIT 1
31+
#define LED_BUSY_WAIT 0
3232
#endif
3333

3434
// Delay between led blinking
3535
#define LED_DELAY_MS 2000
3636

3737
// Priorities of our threads - higher numbers are higher priority
38-
#define MAIN_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
39-
#define BLINK_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
40-
#define WORKER_TASK_PRIORITY ( tskIDLE_PRIORITY + 4UL )
38+
#define MAIN_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
39+
#define BLINK_TASK_PRIORITY ( tskIDLE_PRIORITY + 2UL )
40+
#define WORKER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1UL )
4141

4242
// Stack sizes of our threads in words (4 bytes)
4343
#define MAIN_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
@@ -121,6 +121,17 @@ static void do_work(async_context_t *context, async_at_time_worker_t *worker) {
121121
}
122122
async_at_time_worker_t worker_timeout = { .do_work = do_work };
123123

124+
// Note: This is called from an interrupt handler
125+
void key_pressed_func(void *param) {
126+
int key = getchar_timeout_us(0); // get any pending key press but don't wait
127+
if (key == 'q' || key == 'Q') {
128+
bool *exit = (bool*)param;
129+
*exit = true;
130+
}
131+
}
132+
133+
static bool exit = false;
134+
124135
void main_task(__unused void *params) {
125136
async_context_t *context = example_async_context();
126137
// start the worker running
@@ -129,8 +140,9 @@ void main_task(__unused void *params) {
129140
// start the led blinking
130141
xTaskCreate(blink_task, "BlinkThread", BLINK_TASK_STACK_SIZE, NULL, BLINK_TASK_PRIORITY, NULL);
131142
#endif
143+
132144
int count = 0;
133-
while(true) {
145+
while(!exit) {
134146
#if configNUMBER_OF_CORES > 1
135147
static int last_core_id = -1;
136148
if (portGET_CORE_ID() != last_core_id) {
@@ -142,6 +154,7 @@ void main_task(__unused void *params) {
142154
vTaskDelay(3000);
143155
}
144156
async_context_deinit(context);
157+
sleep_ms(1000);
145158
}
146159

147160
void vLaunch( void) {
@@ -161,6 +174,8 @@ int main( void )
161174
{
162175
stdio_init_all();
163176

177+
stdio_set_chars_available_callback(key_pressed_func, &exit);
178+
164179
/* Configure the hardware ready to run the demo. */
165180
const char *rtos_name;
166181
#if (configNUMBER_OF_CORES > 1)

0 commit comments

Comments
 (0)