ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
hal.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
2
3#include "core.h"
4#include "esphome/core/hal.h"
5#include "preferences.h"
6
7#include <FreeRTOS.h>
8#include <task.h>
9
10// Empty libretiny namespace block to satisfy ci-custom's lint_namespace check.
11// HAL functions live in namespace esphome (root) — they are not part of the
12// libretiny component's API.
13namespace esphome::libretiny {} // namespace esphome::libretiny
14
15namespace esphome {
16
17// yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(),
18// arch_feed_wdt(), arch_get_cpu_cycle_count(), arch_get_cpu_freq_hz()
19// inlined in components/libretiny/hal.h.
20
21void arch_init() {
23 lt_wdt_enable(10000L);
24#ifdef USE_BK72XX
25 // BK72xx SDK creates the main Arduino task at priority 3, which is lower than
26 // all WiFi (4-5), LwIP (4), and TCP/IP (7) tasks. This causes ~100ms loop
27 // stalls whenever WiFi background processing runs, because the main task
28 // cannot resume until every higher-priority task finishes.
29 //
30 // By contrast, RTL87xx creates the main task at osPriorityRealtime (highest).
31 //
32 // Raise to priority 6: above WiFi/LwIP tasks (4-5) so they don't preempt the
33 // main loop, but below the TCP/IP thread (7) so packet processing keeps priority.
34 // This is safe because ESPHome yields voluntarily via wakeable_delay() and
35 // the Arduino mainTask yield() after each loop() iteration.
36 static constexpr UBaseType_t MAIN_TASK_PRIORITY = 6;
37 static_assert(MAIN_TASK_PRIORITY < configMAX_PRIORITIES, "MAIN_TASK_PRIORITY must be less than configMAX_PRIORITIES");
38 vTaskPrioritySet(nullptr, MAIN_TASK_PRIORITY);
39#endif
40#if LT_GPIO_RECOVER
41 lt_gpio_recover();
42#endif
43}
44
45void arch_restart() {
46 lt_reboot();
47 while (1) {
48 }
49}
50
51} // namespace esphome
52
53#endif // USE_LIBRETINY
void arch_init()
Definition hal.cpp:47
void arch_restart()
Definition hal.cpp:39