ESPHome 2026.3.0
Loading...
Searching...
No Matches
core.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
2
3#include "core.h"
5#include "esphome/core/hal.h"
8#include "preferences.h"
9
10#include <FreeRTOS.h>
11#include <task.h>
12
13void setup();
14void loop();
15
16namespace esphome {
17
18void HOT yield() { ::yield(); }
19uint32_t IRAM_ATTR HOT millis() { return ::millis(); }
20uint64_t millis_64() { return Millis64Impl::compute(::millis()); }
21uint32_t IRAM_ATTR HOT micros() { return ::micros(); }
22void HOT delay(uint32_t ms) { ::delay(ms); }
23void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { ::delayMicroseconds(us); }
24
25void arch_init() {
27 lt_wdt_enable(10000L);
28#ifdef USE_BK72XX
29 // BK72xx SDK creates the main Arduino task at priority 3, which is lower than
30 // all WiFi (4-5), LwIP (4), and TCP/IP (7) tasks. This causes ~100ms loop
31 // stalls whenever WiFi background processing runs, because the main task
32 // cannot resume until every higher-priority task finishes.
33 //
34 // By contrast, RTL87xx creates the main task at osPriorityRealtime (highest).
35 //
36 // Raise to priority 6: above WiFi/LwIP tasks (4-5) so they don't preempt the
37 // main loop, but below the TCP/IP thread (7) so packet processing keeps priority.
38 // This is safe because ESPHome yields voluntarily via yield_with_select_() and
39 // the Arduino mainTask yield() after each loop() iteration.
40 static constexpr UBaseType_t MAIN_TASK_PRIORITY = 6;
41 static_assert(MAIN_TASK_PRIORITY < configMAX_PRIORITIES, "MAIN_TASK_PRIORITY must be less than configMAX_PRIORITIES");
42 vTaskPrioritySet(nullptr, MAIN_TASK_PRIORITY);
43#endif
44#if LT_GPIO_RECOVER
45 lt_gpio_recover();
46#endif
47}
48
49void arch_restart() {
50 lt_reboot();
51 while (1) {
52 }
53}
54void HOT arch_feed_wdt() { lt_wdt_feed(); }
55uint32_t arch_get_cpu_cycle_count() { return lt_cpu_get_cycle_count(); }
56uint32_t arch_get_cpu_freq_hz() { return lt_cpu_get_freq(); }
57uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
58const char *progmem_read_ptr(const char *const *addr) { return *addr; }
59uint16_t progmem_read_uint16(const uint16_t *addr) { return *addr; }
60
61} // namespace esphome
62
63#endif // USE_LIBRETINY
void setup()
void loop()
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t arch_get_cpu_cycle_count()
Definition core.cpp:59
void arch_init()
Definition core.cpp:39
const char * progmem_read_ptr(const char *const *addr)
Definition core.cpp:57
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:30
void HOT yield()
Definition core.cpp:25
uint32_t arch_get_cpu_freq_hz()
Definition core.cpp:60
uint64_t HOT millis_64()
Definition core.cpp:27
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:29
void HOT arch_feed_wdt()
Definition core.cpp:54
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition core.cpp:58
void HOT delay(uint32_t ms)
Definition core.cpp:28
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:26
void arch_restart()
Definition core.cpp:31
uint8_t progmem_read_byte(const uint8_t *addr)
Definition core.cpp:56
static void uint32_t