ESPHome
2026.11.0b6
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 "
crash_handler.h
"
5
#include "
esphome/core/hal.h
"
6
#include "
preferences.h
"
7
8
#include <FreeRTOS.h>
9
#include <task.h>
10
11
// Empty libretiny namespace block to satisfy ci-custom's lint_namespace check.
12
// HAL functions live in namespace esphome (root) — they are not part of the
13
// libretiny component's API.
14
namespace
esphome::libretiny
{}
// namespace esphome::libretiny
15
16
#if defined(USE_LN882X) && !defined(CLANG_TIDY)
// clang-tidy runs without the PlatformIO flags
17
// Fail the build if the -fshort-enums swap in __init__.py stops working.
18
enum
Ln882xEnumSizeCheck
{
LN882X_ENUM_SIZE_CHECK
};
19
static_assert
(
sizeof
(
Ln882xEnumSizeCheck
) == 1,
"LN882x must build with -fshort-enums to match the SDK"
);
20
#endif
21
22
namespace
esphome
{
23
24
// yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(),
25
// arch_feed_wdt(), arch_get_cpu_cycle_count(), arch_get_cpu_freq_hz()
26
// inlined in components/libretiny/hal.h.
27
28
void
arch_init
() {
29
libretiny::setup_preferences
();
30
lt_wdt_enable
(10000L);
31
#ifdef USE_LIBRETINY_CRASH_HANDLER_VECTOR_PATCH
32
libretiny::crash_handler_install
();
33
#endif
34
#ifdef USE_BK72XX
35
// BK72xx SDK creates the main Arduino task at priority 3, which is lower than
36
// all WiFi (4-5), LwIP (4), and TCP/IP (7) tasks. This causes ~100ms loop
37
// stalls whenever WiFi background processing runs, because the main task
38
// cannot resume until every higher-priority task finishes.
39
//
40
// By contrast, RTL87xx creates the main task at osPriorityRealtime (highest).
41
//
42
// Raise to priority 6: above WiFi/LwIP tasks (4-5) so they don't preempt the
43
// main loop, but below the TCP/IP thread (7) so packet processing keeps priority.
44
// This is safe because ESPHome yields voluntarily via wakeable_delay() and
45
// the Arduino mainTask yield() after each loop() iteration.
46
static
constexpr
UBaseType_t MAIN_TASK_PRIORITY = 6;
47
static_assert
(MAIN_TASK_PRIORITY < configMAX_PRIORITIES,
"MAIN_TASK_PRIORITY must be less than configMAX_PRIORITIES"
);
48
vTaskPrioritySet(
nullptr
, MAIN_TASK_PRIORITY);
49
#endif
50
#if LT_GPIO_RECOVER
51
lt_gpio_recover();
52
#endif
53
}
54
55
void
arch_restart
() {
56
lt_reboot();
57
while
(
true
) {
58
}
59
}
60
61
}
// namespace esphome
62
63
#endif
// USE_LIBRETINY
preferences.h
hal.h
core.h
crash_handler.h
Ln882xEnumSizeCheck
Ln882xEnumSizeCheck
Definition
hal.cpp:18
LN882X_ENUM_SIZE_CHECK
@ LN882X_ENUM_SIZE_CHECK
Definition
hal.cpp:18
esphome::libretiny
Definition
atexit_stubs.cpp:14
esphome::libretiny::lt_wdt_enable
lt_wdt_enable(CRASH_REBOOT_WDT_MS)
esphome::libretiny::crash_handler_install
void crash_handler_install()
Put the crash recorder in front of the SDK's fault handlers.
Definition
crash_handler.cpp:416
esphome::libretiny::setup_preferences
void setup_preferences()
Definition
preferences.cpp:251
esphome
Definition
a01nyub.cpp:7
esphome::arch_init
void arch_init()
Definition
hal.cpp:44
esphome::arch_restart
void arch_restart()
Definition
hal.cpp:36
Generated by
1.12.0