From 205b8cd2adb32384a88db73127be70e7744aa151 Mon Sep 17 00:00:00 2001 From: Hans Christian Olaussen <41271048+klutvott123@users.noreply.github.com> Date: Sat, 16 Apr 2022 16:01:50 +0200 Subject: [PATCH] Initialize tasks data earlier --- src/main/fc/init.c | 4 ++++ src/main/fc/tasks.c | 6 +++++- src/main/fc/tasks.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/fc/init.c b/src/main/fc/init.c index e4ab591cbd..1e5a926232 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -261,6 +261,10 @@ void init(void) systemInit(); + // Initialize task data as soon as possible. Has to be done before tasksInit(), + // and any init code that may try to modify task behaviour before tasksInit(). + tasksInitData(); + // initialize IO (needed for all IO operations) IOInitGlobal(); diff --git a/src/main/fc/tasks.c b/src/main/fc/tasks.c index 4126c3f4f6..a7057eecd9 100644 --- a/src/main/fc/tasks.c +++ b/src/main/fc/tasks.c @@ -438,12 +438,16 @@ task_t *getTask(unsigned taskId) return &tasks[taskId]; } -void tasksInit(void) +// Has to be done before tasksInit() in order to initialize any task data which may be uninitialized at boot +void tasksInitData(void) { for (int i = 0; i < TASK_COUNT; i++) { tasks[i].attribute = &task_attributes[i]; } +} +void tasksInit(void) +{ schedulerInit(); setTaskEnabled(TASK_MAIN, true); diff --git a/src/main/fc/tasks.h b/src/main/fc/tasks.h index b9c3dc1f24..1d6b409ede 100644 --- a/src/main/fc/tasks.h +++ b/src/main/fc/tasks.h @@ -22,6 +22,7 @@ #include "scheduler/scheduler.h" +void tasksInitData(void); void tasksInit(void); task_t *getTask(unsigned taskId);