ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
5#include <cstdint>
6#include <esp_attr.h>
7#include <esp_cpu.h>
8#include <esp_task_wdt.h>
9#include <freertos/FreeRTOS.h>
10#include <freertos/task.h>
11
14
15#ifndef PROGMEM
16#define PROGMEM
17#endif
18
19namespace esphome::esp32 {}
20
21namespace esphome {
22
23// Forward decl from helpers.h (esphome/core/helpers.h) — kept here so this
24// header does not need to pull the rest of helpers.h.
25// NOLINTNEXTLINE(readability-redundant-declaration)
27
29__attribute__((always_inline)) inline bool in_isr_context() { return xPortInIsrContext() != 0; }
30
31// Forward decl from <esp_timer.h>.
32// NOLINTNEXTLINE(readability-redundant-declaration)
33extern "C" int64_t esp_timer_get_time(void);
34
36__attribute__((always_inline)) inline bool is_main_loop_thread() {
37 return xTaskGetCurrentTaskHandle() == esphome_main_task_handle;
38}
39__attribute__((always_inline)) inline void yield() { vPortYield(); }
40__attribute__((always_inline)) inline void delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }
41__attribute__((always_inline)) inline uint32_t micros() { return static_cast<uint32_t>(esp_timer_get_time()); }
43__attribute__((always_inline)) inline uint64_t millis_64() {
44 return micros_to_millis<uint64_t>(static_cast<uint64_t>(esp_timer_get_time()));
45}
46
47// NOLINTNEXTLINE(readability-identifier-naming)
48__attribute__((always_inline)) inline void delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
49__attribute__((always_inline)) inline void arch_feed_wdt() { esp_task_wdt_reset(); }
50__attribute__((always_inline)) inline uint32_t arch_get_cpu_cycle_count() { return esp_cpu_get_cycle_count(); }
51
52void arch_init();
54
55} // namespace esphome
56
57#endif // USE_ESP32
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
void yield(void)
TaskHandle_t esphome_main_task_handle
Main loop task handle and wake helpers — shared between wake.h (C++) and lwip_fast_select....
Definition main_task.c:4
uint32_t arch_get_cpu_cycle_count()
Definition hal.cpp:71
void arch_init()
Definition hal.cpp:44
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
uint32_t arch_get_cpu_freq_hz()
Definition hal.cpp:55
uint64_t millis_64()
Definition hal.cpp:29
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
void delay_microseconds_safe(uint32_t us)
Delay for the given amount of microseconds, possibly yielding to other processes during the wait.
Definition helpers.cpp:889
void arch_feed_wdt()
Definition hal.cpp:58
void HOT delay(uint32_t ms)
Definition hal.cpp:85
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
int64_t esp_timer_get_time(void)
static void uint32_t