ESPHome 2026.6.0-dev
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.
12// Name must match the Arduino framework's entry point, so the naming check is suppressed.
13// NOLINTNEXTLINE(readability-identifier-naming)
14extern "C" __attribute__((weak)) void initArduino() {}
15
16namespace esphome {
17
18// HAL functions live in hal.cpp. This file keeps only the loop task setup.
19TaskHandle_t loop_task_handle = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
20static StaticTask_t loop_task_tcb; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
21static StackType_t
22 loop_task_stack[ESPHOME_LOOP_TASK_STACK_SIZE]; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
23
24void loop_task(void *pv_params) {
25 setup();
26 while (true) {
27 App.loop();
28 }
29}
30
31extern "C" void app_main() {
32 initArduino();
34#if CONFIG_FREERTOS_UNICORE
35 loop_task_handle = xTaskCreateStatic(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1, loop_task_stack,
36 &loop_task_tcb);
37#else
38 loop_task_handle = xTaskCreateStaticPinnedToCore(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1,
39 loop_task_stack, &loop_task_tcb, 1);
40#endif
41}
42
43} // namespace esphome
44
45#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:31
TaskHandle_t loop_task_handle
Definition core.cpp:19
Application App
Global storage of Application pointer - only one Application can exist.
void loop_task(void *pv_params)
Definition core.cpp:24