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_RP2
4
5#include <cstdint>
6
7#include <pico/platform.h>
8
10
11#define IRAM_ATTR __attribute__((noinline, long_call, section(".time_critical")))
12#define PROGMEM
13
14// Forward decls from Arduino's <Arduino.h> for the inline wrappers below.
15// NOLINTBEGIN(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
16extern "C" void yield(void);
17extern "C" void delay(unsigned long ms);
18extern "C" unsigned long micros(void);
19extern "C" unsigned long millis(void);
20// NOLINTEND(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
21
22// Forward decls from <pico/time.h> and the pico-sdk / FreeRTOS port for the
23// inline arch_* wrappers below.
24// NOLINTBEGIN(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
25extern "C" uint64_t time_us_64(void);
26extern "C" void watchdog_update(void);
27extern "C" unsigned long ulMainGetRunTimeCounterValue(void);
28// NOLINTEND(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
29
30namespace esphome::rp2 {}
31
32namespace esphome {
33
34// Forward decl from helpers.h.
35// NOLINTNEXTLINE(readability-redundant-declaration)
37
39__attribute__((always_inline)) inline bool in_isr_context() {
40 uint32_t ipsr;
41 __asm__ volatile("mrs %0, ipsr" : "=r"(ipsr));
42 return ipsr != 0;
43}
44
46__attribute__((always_inline)) inline bool is_main_loop_thread() { return !in_isr_context() && get_core_num() == 0; }
47
48__attribute__((always_inline)) inline void yield() { ::yield(); }
49__attribute__((always_inline)) inline void delay(uint32_t ms) { ::delay(ms); }
50__attribute__((always_inline)) inline uint32_t micros() { return static_cast<uint32_t>(::micros()); }
51__attribute__((always_inline)) inline uint32_t millis() { return micros_to_millis(::time_us_64()); }
52__attribute__((always_inline)) inline uint64_t millis_64() { return micros_to_millis<uint64_t>(::time_us_64()); }
53
54// NOLINTNEXTLINE(readability-identifier-naming)
55__attribute__((always_inline)) inline void delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
56__attribute__((always_inline)) inline void arch_feed_wdt() { watchdog_update(); }
57__attribute__((always_inline)) inline uint32_t arch_get_cpu_cycle_count() {
58 return static_cast<uint32_t>(ulMainGetRunTimeCounterValue());
59}
60
61void arch_init();
63
64} // namespace esphome
65
66#endif // USE_RP2
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
unsigned long millis(void)
void delay(unsigned long ms)
unsigned long micros(void)
void yield(void)
void watchdog_update(void)
uint64_t time_us_64(void)
unsigned long ulMainGetRunTimeCounterValue(void)
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
unsigned long ulMainGetRunTimeCounterValue()
static void uint32_t