Skip to content

Commit

Permalink
Merge pull request #369 from facchinm/freertos_wrap_loop
Browse files Browse the repository at this point in the history
Arduino_FreeRTOS: automatically start loop
  • Loading branch information
pennam authored Nov 28, 2024
2 parents 7c59871 + fee8ca9 commit 428df2a
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 428df2a

Please sign in to comment.