ESPHome 2026.5.1
Loading...
Searching...
No Matches
core.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32
2
5#include "preferences.h"
6#include <freertos/FreeRTOS.h>
7#include <freertos/task.h>
8
9void setup(); // NOLINT(readability-redundant-declaration)
10
11// Weak stub for initArduino - overridden when the Arduino component is present
12extern "C" __attribute__((weak)) void initArduino() {}
13
14namespace esphome {
15
16// HAL functions live in hal.cpp. This file keeps only the loop task setup.
17TaskHandle_t loop_task_handle = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
18static StaticTask_t loop_task_tcb; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
19static StackType_t
20 loop_task_stack[ESPHOME_LOOP_TASK_STACK_SIZE]; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
21
22void loop_task(void *pv_params) {
23 setup();
24 while (true) {
25 App.loop();
26 }
27}
28
29extern "C" void app_main() {
30 initArduino();
32#if CONFIG_FREERTOS_UNICORE
33 loop_task_handle = xTaskCreateStatic(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1, loop_task_stack,
34 &loop_task_tcb);
35#else
36 loop_task_handle = xTaskCreateStaticPinnedToCore(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1,
37 loop_task_stack, &loop_task_tcb, 1);
38#endif
39}
40
41} // namespace esphome
42
43#endif // USE_ESP32
void ESPHOME_ALWAYS_INLINE loop()
Make a loop iteration. Call this in your loop() function.
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
void setup()
void setup_preferences()
void app_main()
Definition core.cpp:29
TaskHandle_t loop_task_handle
Definition core.cpp:17
Application App
Global storage of Application pointer - only one Application can exist.
void loop_task(void *pv_params)
Definition core.cpp:22