Skip to content

Arduino_FreeRTOS: automatically start loop #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading