ESPHome 2026.11.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.
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 // Apply the custom eFuse MAC (if burned and valid) as the base MAC before any
33 // interface (Wi-Fi, Ethernet, Bluetooth, 802.15.4) derives its address from it.
34 // The logger does not exist yet, so only log-free helpers may be used here.
35 uint8_t mac[MAC_ADDRESS_SIZE];
36 if (get_custom_mac_address(mac)) {
37 set_mac_address(mac);
38 }
39 initArduino();
41#if CONFIG_FREERTOS_UNICORE
42 xTaskCreateStatic(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1, loop_task_stack, &loop_task_tcb);
43#else
44 xTaskCreateStaticPinnedToCore(loop_task, "loopTask", ESPHOME_LOOP_TASK_STACK_SIZE, nullptr, 1, loop_task_stack,
45 &loop_task_tcb, 1);
46#endif
47}
48
49} // namespace esphome
50
51#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:45
void setup()
void setup_preferences()
void app_main()
Definition core.cpp:31
void set_mac_address(uint8_t *mac)
Set the MAC address to use from the provided byte array (6 bytes).
Definition helpers.cpp:117
Application App
Global storage of Application pointer - only one Application can exist.
void loop_task(void *pv_params)
Definition core.cpp:24
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