ESPHome
2026.5.0b1
Loading...
Searching...
No Matches
esphome
components
libretiny
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.
13
namespace
esphome::libretiny
{}
// namespace esphome::libretiny
14
15
namespace
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
21
void
arch_init
() {
22
libretiny::setup_preferences
();
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
45
void
arch_restart
() {
46
lt_reboot();
47
while
(1) {
48
}
49
}
50
51
}
// namespace esphome
52
53
#endif
// USE_LIBRETINY
preferences.h
hal.h
core.h
esphome::libretiny
Definition
core.h:7
esphome::libretiny::setup_preferences
void setup_preferences()
Definition
preferences.cpp:166
esphome
Definition
a01nyub.cpp:7
esphome::arch_init
void arch_init()
Definition
hal.cpp:47
esphome::arch_restart
void arch_restart()
Definition
hal.cpp:39
Generated by
1.12.0