Skip to content

Commit

Permalink
freertos: start scheduler and loop task on header inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
facchinm authored and pennam committed Nov 27, 2024
1 parent 9f0dc38 commit fee8ca9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void unsecure_registers() {
#define str(s) #s

extern "C" void Stacktrace_Handler(void);
extern "C" __attribute__((weak)) void start_freertos_on_header_inclusion() {}

void arduino_main(void)
{
Expand Down Expand Up @@ -111,6 +112,7 @@ void arduino_main(void)
Serial.begin(115200);
#endif
startAgt();
start_freertos_on_header_inclusion();
setup();
while (1)
{
Expand Down
22 changes: 22 additions & 0 deletions libraries/Arduino_FreeRTOS/src/portable/FSP/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ static void prvTaskExitError(void);

#endif

void loop_thread_func(void* arg) {
setup();
while (1)
{
loop();
}
}

static TaskHandle_t loop_task;
void start_freertos_on_header_inclusion() {
xTaskCreate(
(TaskFunction_t)loop_thread_func,
"Loop Thread",
4096 / 4, /* usStackDepth in words */
NULL, /* pvParameters */
4, /* uxPriority */
&loop_task /* pxCreatedTask */
);

vTaskStartScheduler();
}

/* Arduino specific overrides */
void delay(uint32_t ms) {
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
Expand Down

0 comments on commit fee8ca9

Please sign in to comment.