I try to get rid of 900 lines of code in a main.cpp file.
For that I tried to set up some kind of project directory structure.
The first attempt is in:
But when creating xTaskCreatePinnedToCore() in this code I get an error:
‘NULL’ undeclared (first use in this function)
#include <tasksConfig.h>
#include <createAllTasks.h>
#include <someUsefullName.h>
// #include <task_B.h>
void createAllTasks()
{
// All xTaskCreate… goes here and utilize the macros created
// in taskConfig.h
// Be very carefull about the ordening of tasks because they
// start running as soon as they're created.
xTaskCreatePinnedToCore(
someUsefullName,
"Some Usefull Name",
1024,
NULL, // 'NULL' undeclared (first use in this function)
1,
NULL, // handle
1
);
}
Can/will someone please tell me what went wrong here?
NULL
is a macro defined in stdlib.h
.
Though this project seems to be a weird mixing of C and C++ files without extern "C"
declarations, so linking will fail… Are you sure you don’t want to just write C++ directly and use the builtin nullptr
?
Also I don’t think you should call vTaskStartScheduler like that
the Arduino-ESP32 framework will already do that for you. In fact, as you can see in the code, setup()
and loop()
already run in a FreeRTOS task called "loopTask"
If you vTaskDelete
that task, that will prevent the functions esp_task_wdt_reset()
and serialEventRun()
from running, which will probably mess something up.
I suggest just using all .cpp files in an Arduino-ESP32 project and using #include <FreeRTOS.h>
to pull in the FreeRTOS functions. Your current createAllTasks.c
file also doesn’t do that and results in
src/createAllTasks.c: In function 'createAllTasks':
src/createAllTasks.c:16:5: warning: implicit declaration of function 'xTaskCreatePinnedToCore' [-Wimplicit-function-declaration]
xTaskCreatePinnedToCore(
^
even if you #include <stdlib.h>
; needs #include <FreeRTOS.h>
.
Max,
Thank you, I’ll try your suggestions and what they bring me.
I started out with createAllTasks.cpp but then PlatformIO didn’t recognize xTaskCreatePinnedToCore() at all.
But that’s just due to not doing #include <FreeRTOS.h>
(or more simply #include <Arduino.h>
)
That is a great insight! Thank you.