ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
core.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32
2
6#include "preferences.h"
7#include <freertos/FreeRTOS.h>
8#include <freertos/task.h>
9
10void setup(); // NOLINT(readability-redundant-declaration)
11
12// Weak stub for initArduino - overridden when the Arduino component is present.
13// Name must match the Arduino framework's entry point, so the naming check is suppressed.
14// NOLINTNEXTLINE(readability-identifier-naming)
15extern "C" __attribute__((weak)) void initArduino() {}
16
17namespace esphome {
18
19// HAL functions live in hal.cpp. This file keeps only the loop task setup.
20TaskHandle_t loop_task_handle = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
21static StaticTask_t loop_task_tcb; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
22static StackType_t
23 loop_task_stack[ESPHOME_LOOP_TASK_STACK_SIZE]; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
24
25void loop_task(void *pv_params) {
26 setup();
27 while (true) {
28 App.loop();
29 }
30}
31
32extern "C" void app_main() {
33 // Apply the custom eFuse MAC (if burned and valid) as the base MAC before any
34 // interface (Wi-Fi, Ethernet, Bluetooth, 802.15.4) derives its address from it.
35 // The logger does not exist yet, so only log-free helpers may be used here.
36 uint8_t mac[MAC_ADDRESS_SIZE];
37 if (get_custom_mac_address(mac)) {
38 set_mac_address(mac);
39 }
40 initArduino();
42#if CONFIG_FREERTOS_UNICORE
43 loop_task_handle = xTaskCreateStatic(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1, loop_task_stack,
44 &loop_task_tcb);
45#else
46 loop_task_handle = xTaskCreateStaticPinnedToCore(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1,
47 loop_task_stack, &loop_task_tcb, 1);
48#endif
49}
50
51} // namespace esphome
52
53#endif // USE_ESP32
void ESPHOME_ALWAYS_INLINE loop()
Make a loop iteration. Call this in your loop() function.
struct @66::@67 __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:32
void set_mac_address(uint8_t *mac)
Set the MAC address to use from the provided byte array (6 bytes).
Definition helpers.cpp:117
TaskHandle_t loop_task_handle
Definition core.cpp:20
Application App
Global storage of Application pointer - only one Application can exist.
void loop_task(void *pv_params)
Definition core.cpp:25
bool get_custom_mac_address(uint8_t *mac)
Read the custom MAC address from eFuse into the provided byte array (6 bytes).
Definition helpers.cpp:75