Commit Graph

113 Commits

Author SHA1 Message Date
Zhou Xiao
aa48bd8f47 fix(esp_timer): prevent restart expiry race 2026-07-27 15:33:44 +03:00
Sudeep Mohanty
958dc8afcf fix(esp_timer): Fix esp_timer task dispatch stall
The task dispatch method for the esp_timer could stall even if it is
armed if ther ISR dispatch alarm triggers close to the task dispatch.
This MR fixes a bug where the esp_timer cleared the incorrect cached
array timer index and subsequently the timer task is never woken up.

Closes https://github.com/espressif/esp-idf/issues/18808
2026-07-20 14:27:01 +03:00
Renz Christian Bagaporo
4e8db0e153 Merge branch 'fix/esptimer_dump' into 'master'
fix(esp_timer): possible heap overflow on info dump

Closes SEC-1134

See merge request espressif/esp-idf!50440
2026-07-15 11:48:11 +08:00
Renz Bagaporo
694032c1b1 fix(esp_timer): avoid dump buffer overflow
print_timer_info advanced the dump cursor by snprintf's return value. When a timer line was truncated, snprintf returned the full would-be length, which could move the cursor past the heap buffer and wrap the remaining size before the next write. Add a bounded append helper that clamps truncation to the end of the buffer while preserving the NUL terminator.
2026-07-13 15:45:00 +09:00
Guillaume Souchere
81fec4bf32 fix(esp_timer): process ISR-dispatch timers in alarm thread on Linux
On real hardware, ESP_TIMER_ISR callbacks run in a hardware interrupt
that preempts any FreeRTOS task. On the Linux simulator, there are no
real ISRs — the alarm is detected by a native pthread but was only
forwarded to the FreeRTOS timer_task via xTaskNotifyGive(). This meant
ISR-dispatch callbacks could be starved by higher-priority FreeRTOS
tasks, breaking components like the task watchdog that rely on
ISR-dispatch timers to detect scheduling starvation.

Move ISR-dispatch timer processing into the alarm pthread itself,
mirroring the hardware ISR path. The FreeRTOS timer_task is only
notified when no ISR-dispatch timer consumed the alarm. This is safe
because the Linux FreeRTOS port already handles vPortEnterCritical()
calls from non-FreeRTOS threads (bumps nesting counter without
blocking on scheduled-task checks).
2026-07-08 09:42:48 +02:00
Konstantin Kondrashov
f6f24af00a feat(esp_timer): Adds support Linux target 2026-06-11 11:59:25 +03:00
Marius Vikhammer
be36c20503 feat(esp_system): add esp_sys_event framework
Introduce a shared esp system event framework and use it
for system init and shutdown.
2026-06-03 15:02:43 +08:00
Marius Vikhammer
4ab44312d4 fix(esp_timer): enable systimer functional clock on ESP32-S31
ESP32-S31 has a separate functional clock gate for the systimer
(reg_systimer_clk_en in HP_SYS_CLKRST) that defaults to off. Without
it, the counter snapshot never completes, hanging execution inside
esp_timer_init_nonos.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-18 11:08:40 +08:00
Chen Chen
eeb24057c4 refactor(hal): graduate systimer hal driver into esp_hal_systimer 2026-02-06 18:08:57 +08:00
Konstantin Kondrashov
8569da1ba8 feat(esp_timer): Adds blocking stop function 2026-01-07 09:26:57 +02:00
Konstantin Kondrashov
3e74ff2b33 refactor(esp_timer): Remove unnecessary nested list lock 2026-01-06 21:52:53 +02:00
Konstantin Kondrashov
0255a7e164 feat(esp_timer): esp_timer_is_active while callback is running 2026-01-06 21:52:53 +02:00
Huelsenfrucht
b3ccc1316d feat(esp_timer): Support absolute timing APIs
Merges https://github.com/espressif/esp-idf/pull/17807
2025-12-09 11:05:40 +02:00
morris
aa1fd9c611 refactor: avoid function calls inside MIN/MAX macros 2025-11-17 22:17:54 +08:00
morris
71cb24caab feat(timg): graduate the hal driver into a single component 2025-09-27 17:33:10 +08:00
Marius Vikhammer
88c9af78a7 Merge branch 'change/allow_esp_timer_init_from_user_code' into 'master'
change(esp_timer): esp_timer_init_os now returns ESP_OK if esp_timer already initialized

Closes IDFGH-8182

See merge request espressif/esp-idf!42069
2025-09-25 10:23:11 +08:00
Marius Vikhammer
16cdbd9f5c change(esp_timer): esp_timer_init_os now returns ESP_OK if already initialized
Previously it would return ESP_ERR_INVALID_STATE, which meant that if called from
user-code before the system tries to initialize the timer then esp-idf would
fail to boot.

This could happen if a user wanted to use esp-timer from a cpp constructor.

Closes https://github.com/espressif/esp-idf/issues/9679
2025-09-22 14:01:56 +08:00
Konstantin Kondrashov
dcf486359e feat(log): Optimize log tag init for bin logging 2025-09-15 15:59:52 +03:00
Marius Vikhammer
b0b76f3792 fix(esp_timer): fixed potential buffer overflow with esp_timer_dump()
esp_timer_dump could overflow when dumping a large amount of timers

Closes https://github.com/espressif/esp-idf/issues/17008
2025-08-14 20:01:55 +08:00
wuzhenghui
f861b7dd65 fix(esp_hw_support): config lact in critical 2025-06-13 20:38:46 +08:00
wuzhenghui
022614b1d3 fix(esp_hw_support): update systimer step immediately when XTAL changes on esp32s2 2025-05-22 13:58:54 +08:00
wuzhenghui
2931aa23b6 fix(esp_hw_support): update LACT clock prescale immediately when APB changes on esp32 2025-05-22 13:58:50 +08:00
Marius Vikhammer
55be8bdc0d feat(esp_timer): added kconfig option for placing IRAM code into flash 2025-03-18 15:23:43 +08:00
Marius Vikhammer
34c7d62855 refactor(hw_support): combine esp_hw_support rtc header to a single file 2024-12-30 10:09:34 +08:00
gaoxu
b240defc75 feat(esp32h21): support esp_system, esp_timer and freertos (stage5) 2024-12-20 22:43:10 +08:00
wanckl
2f9456bf51 fix(esp_timer): fix isr safe when CONFIG_FREERTOS_USE_TICKLESS_IDLE and PM_ENABLE 2024-10-24 12:47:38 +08:00
Konstantin Kondrashov
3081a4ea49 feat(esp_timer): Updates systimer and esp_timer 2024-09-12 14:26:37 +08:00
Alexey Lapshin
ed6e497c6f feat(build): add COMPILER_STATIC_ANALYZER option 2024-06-18 14:25:37 +08:00
Konstantin Kondrashov
a800fcb47e fix(esp_timer): Fix Coverity issue - logically dead code in esp_timer_impl_early_init 2024-05-22 11:20:08 +03:00
wuzhenghui
ad54af74d6 change(esp_hw_support/sleep): improve esp32c3 systimer stall bug workaround 2024-05-13 15:07:40 +08:00
wanlei
a611e91b2f feat(esp32c61): new chip add system and esp_timer support 2024-03-21 11:31:15 +08:00
Konstantin Kondrashov
1253ab6e27 Merge branch 'feature/move_esp_timer_related_inits_into_component' into 'master'
feat(esp_timer): Move esp_timer-related init steps into the component

Closes IDF-8755

See merge request espressif/esp-idf!28664
2024-02-20 16:49:31 +08:00
Konstantin Kondrashov
49ba674fb5 feat(esp_timer): Move esp_timer-related init steps into the component 2024-02-19 19:21:40 +08:00
fl0wl0w
90d1dcfd76 feat(freertos): Introduced new Kconfig option CONFIG_FREERTOS_NUMBER_OF_CORES
This commit replaces the use of portNUM_PROCESSORS and configNUM_CORES
macros in all of ESP-IDF. These macros are needed to realize an SMP
scenario by fetching the number of active cores FreeRTOS is running on.
Instead, a new Kconfig option, CONFIG_FREERTOS_NUMBER_OF_CORES, has been
added as a proxy for the FreeRTOS config option, configNUMBER_OF_CORES.
This new commit is now used to realize an SMP scenario in various places
in ESP-IDF.

[Sudeep Mohanty: Added new Kconfig option CONFIG_FREERTOS_NUMBER_OF_CORES]

Signed-off-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
2024-02-09 09:11:28 +01:00
Marius Vikhammer
77dcb6d46e refactor(system): reformated esp_timer, linux and log comp with astyle 2024-02-04 14:50:54 +08:00
laokaiyao
a48f4760d2 feat(esp32c5): add system related supports 2024-01-02 11:17:11 +08:00
morris
e96491fb1f feat(systimer): support ETM on esp32p4 2023-12-07 18:46:24 +08:00
Ivan Grokhotkov
6046b396ac fix(esp_timer): avoid signed integer overflow in ESP_SYSTEM_INIT_FN
CONFIG_ESP_TIMER_ISR_AFFINITY can be equal to -1, whereas
ESP_SYSTEM_INIT_FN takes an uint16_t argument. To avoid overflow,
move the choice of init mask into source code and set the value
explicitly.
2023-11-27 10:20:51 +01:00
Ivan Grokhotkov
75c92c3a66 refactor(startup): implement registration of core init functions
Similar to how the secondary init functions were already registered
via ESP_SYSTEM_INIT_FN, do the same for the core init functions.
This MR doesn't actually move the init functions into respective
components yet. This has to be carefully done in follow-up MRs.
2023-11-27 10:20:51 +01:00
Konstantin Kondrashov
cbdb799b6f feat(esp_timer): Support systimer for ESP32P4 2023-09-13 19:13:38 +08:00
morris
71cf16ec01 feat(gptimer): use RCC atomic block to enable/reset peripheral 2023-08-22 17:05:35 +08:00
Armando
211c3c0e05 feat(esp_timer): added esp_timer p4 base support 2023-07-25 05:59:10 +00:00
KonstantinKondrashov
5693e0188b refactor(esp_timer): Remove duplicate code and move it to a common file 2023-07-13 15:51:55 +08:00
Alan Fisher
bfcad8d8a2 fix(esp_timer): Fix delay in ISR dispatch callbacks
Set the following alarm before calling the alarm handler.

Closes https://github.com/espressif/esp-idf/pull/11637
Closes https://github.com/espressif/esp-idf/issues/11636
2023-07-12 16:30:45 +08:00
Ivan Grokhotkov
500b5b2103 Merge branch 'contrib/github_pr_11215' into 'master'
improve thread safety in esp_timer (GitHub PR)

Closes IDFGH-9920

See merge request espressif/esp-idf!23295
2023-05-03 02:21:07 +08:00
laokaiyao
bf2a7b2df6 esp32h4: removed esp32h4 related codes 2023-04-23 12:03:07 +00:00
Jens Gutermuth
3ba70490c9 improve thread safety in esp_timer
Inadequate locking in the esp_timer component allowed corruption
of the s_timers linked list:

1. timer_armed(timer) returns false
2. another task arms the timer and adds it to s_timers
3. the list is locked
4. the timer is inserted into s_timers again

The last step results in a loop in the s_timers list, which causes
an infinite loop when iterated. This change always locks the
list before checking if the timer is already armed avoiding
the data race.
2023-04-19 16:59:43 +02:00
KonstantinKondrashov
91fcced0fb esp_timer: Adds IRAM_ATTR for esp_timer_restart and esp_timer_is_active
Closes https://github.com/espressif/esp-idf/issues/10522
Closes https://github.com/espressif/esp-idf/issues/10859
2023-04-19 17:42:38 +08:00
KonstantinKondrashov
449e4bcae7 esp_timer: Adds AFFINITY options for task and ISR
These new settings allow you to balance the load on cores.
Closes: https://github.com/espressif/esp-idf/issues/10457
2023-03-02 20:08:02 +08:00
morris
6c1d98d556 systimer: assign counter and alarm in esp_hw_support 2023-01-10 17:05:49 +08:00