Commit graph zephyr/drivers/counter
Author SHA1 Message Date
Andrej Butok
4288af5244 drivers: counter: mcux_ctimer: add reset API support
Implement the counter_api reset callback for the NXP LPC CTimer
driver to zero the timer counter register
while keeping the timer running.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2026-05-08 11:27:43 +02:00
Mathieu Choplain
63da9b5dbf drivers: counter: stm32_rtc: manage EXTI line in a proper manner
Instead of hardcoded EXTI line numbers and raw LL API calls, align the
STM32 RTC Counter driver with its Real-Time Clock counterpart:
- obtain EXTI line number from Devicetree
- use the EXTI INTC API instead of raw LL API calls

Fixes the build issue observed on STM32N6.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-05-07 18:12:51 -05:00
Ryan McClelland
f29a2f11bd drivers: counter: stm32: introduce counter capture api
This introduces APIs for input capture on the STM32.

Rename callback in data to alarm_cb to prevent confusion with other
callbacks.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-05-07 18:02:21 -05:00
Ryan McClelland
1bc5f0543c drivers: counter: introduce counter capture api
This introduces APIs for input capture.

A use case for this would be time stamping a rising and/or falling edge
where precision and lack of jitter is important. The only way to currently
do this in zephyr is to set up a GPIO interrupt and then read the counter
or kernel time... but this can have limitations of software such as the
processor may have a lot going on and can be subject to interrupt
latencies. Having a hardware 'latch' done of the rising and/or falling
edge with respect to a timer can eliminate these imprecisions.

How this is to be used, is that an application is to call
`capture_callback_set` with the configuration of the channel number, flags
(such as falling, rising, or both edges), and then a callback function.
Then the `capture_enable` function is to be called to enable this. The
callback has the timestamp of the edge in ticks and the edge that it
captured (rising or falling).

This also adds a 64 bit tick version for the capture callback.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-05-07 18:02:21 -05:00
Ren Chen
75448eb1f6 drivers: counter: it51xxx: disable alarm before callback
This commit dsiables alarm counter before executing callback
function. Additionally, the alarm counter (external timer 7)
ticks are limited to 3 bytes. Return errno if the configured
value exceeds this range.

Tested with: samples/drivers/counter/alarm

Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
2026-05-06 12:02:47 +01:00
Yuzhuo Liu
07ea4c7f5e drivers: counter: rtc: add Realtek Bee series support
Add counter RTC driver support for Realtek Bee series SoCs,
including RTL87x2G and RTL8752H.

This driver supports:
- Basic counter operations
- Alarm configuration and callbacks

Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
2026-04-16 11:38:00 -05:00
Pisit Sawangvonganan
d08da865be drivers: fix typo in (clock_control, counter, crypto, dai, debug)
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `drivers/clock_control`
- `drivers/counter`
- `drivers/crypto`
- `drivers/dai`
- `drivers/debug`

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-03-27 20:21:24 -04:00
Anas Nashif
4809fb40a6 counter: handlers: include marshalling header
Add missing header, this prevents build issues with llvm.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-03-27 12:35:56 -04:00
Ryan McClelland
748604daec drivers: counter: fix get_pending_int return type mismatch
The counter_api_get_pending_int typedef returns uint32_t, but the
public counter_get_pending_int API, its inline implementation, and
its syscall handler all return int. Several drivers return raw hardware
register bitmasks that can have upper bits set; the implicit cast to
int would make those values appear negative, which callers could
misinterpret as error codes.

Change the public API, inline impl, and syscall handler to return
uint32_t to match the driver API typedef.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-03-27 12:35:39 -04:00
Guillaume Gautier
1ed9563804 drivers: counter: stm32: rtc: adapt rtc driver for stm32 hal2
STM32 HAL2 adopts some new syntaxes so the Counter RTC driver needs to be
updated.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-03-20 20:43:57 +09:00
Sylvio Alves
f671913925 drivers: counter: add esp32c5 lp_timer support
Add ESP32-C5 support to the RTC counter driver. The C5 uses a
different LP timer interrupt status register field
(soc_wakeup_int_st) compared to other SoCs (alarm), requiring a
SoC-specific macro for the interrupt status check.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-03-19 14:53:05 -05:00
Tahsin Mutlugun
8f314d100f drivers: counter: max32_wut: Add runtime power management support
Adds runtime device power management support to MAX32 Wake-up Timer
driver. The suspend routine is intentionally left unimplemented to
allow the Wake-up Timer to continue counting while the device is in
sleep mode.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2026-03-19 17:03:30 +01:00
Aksel Skauge Mellbye
b7d4949013 drivers: counter: silabs: Fix timer counter driver
Fix two bugs in the timer counter driver that prevent tests
from passing.

-EBUSY should be returned from set_top_value() if there are
active alarms, not if the counter has been started.

The ISR should only process interrupts that are currently enabled,
not all pending flags.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2026-03-19 17:01:37 +01:00
sree sreerajatha
12136b4eda drivers: counter: silabs add counter driver support for Silabs xg24 boards
Added Silabs Kconfig support for counter driver and implemented the
counter APIs using protimer underneath.

Signed-off-by: sree sreerajatha <sree.sreerajatha@silabs.com>
2026-03-19 11:36:21 +00:00
Holt Sun
020d465247 drivers: counter: mcux_lptmr: fix unused function warning
When all LPTMR instances are reserved as the system
timer, the counter driver has no instances to create.
The static init and ISR functions become unused,
causing -Werror=unused-function build failures.

Guard the entire driver body with a preprocessor check
that counts usable (non-system-timer) LPTMR instances.
When the count is zero the file compiles to nothing.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-03-18 08:45:36 -05:00
Yuzhuo Liu
66feaaf25f drivers: counter: add Realtek Bee series driver
Add counter timer driver support for Realtek Bee series SoCs,
including RTL87x2G and RTL8752H.

This driver is based on the hardware timer and supports:
- Relative alarm configuration
- Top value configuration

Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
2026-03-18 18:22:17 +09:00
CHEN Xing
a305e6de1d soc: microchip: sam: update for sama7g5 tc
Update MMU and GCLK configurations for tc

Signed-off-by: CHEN Xing <xing.chen@microchip.com>
2026-03-17 18:27:21 -04:00
Holt Sun
bd3076276c drivers: mcux_lptmr: select timer instance via zephyr,system-timer chosen
Replace the single-instance assumption with a zephyr,system-timer chosen
node approach. The timer driver reads its hardware instance directly from
DT_CHOSEN(zephyr_system_timer) instead of assuming instance 0. The
counter driver skips whichever instance is designated as the system timer,
allowing both drivers to coexist on SoCs with multiple LPTMR instances.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-03-17 18:22:50 -04:00
William Markezana
6c2b586f2f drivers: counter: add Bouffalo Lab timer and rtc drivers
Add counter drivers for Bouffalo Lab SoCs:
- GP timer driver with 2 alarm channels, configurable clock source,
  and software cycle tracking for SoCs without hardware counter clear
- RTC counter driver exposing the always-on 32 kHz HBN RTC

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-03-16 08:59:13 +01:00
Ryan McClelland
24e8bf81b7 drivers: counter: run clang-format on counter_handlers.c
run clang-format on counter_handlers.c

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-03-16 08:56:53 +01:00
Ryan McClelland
d179c2b770 drivers: counter: add missing functions in to counter_handlers.c
counter_handlers.c was missing verifier/marshaling coverage for multiple
counter APIs, especially 64-bit helpers.
This change adds the missing z_vrfy handlers and corresponding mrsh
includes so the syscall layer matches the public counter API surface.

Missing functions now covered in drivers/counter/counter_handlers.c:

z_vrfy_counter_get_frequency_64
z_vrfy_counter_us_to_ticks_64
z_vrfy_counter_ticks_to_us_64
z_vrfy_counter_ns_to_ticks
z_vrfy_counter_ns_to_ticks_64
z_vrfy_counter_ticks_to_ns
z_vrfy_counter_ticks_to_ns_64
z_vrfy_counter_reset
z_vrfy_counter_set_value
z_vrfy_counter_set_value_64
z_vrfy_counter_get_max_top_value_64
z_vrfy_counter_set_top_value_64
z_vrfy_counter_set_channel_alarm_64
z_vrfy_counter_get_top_value_64
z_vrfy_counter_get_guard_period_64
z_vrfy_counter_set_guard_period_64

z_vrfy_counter_get_pending_int was removed from the macro as it
returns a uint32_t and not exactly an int.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-03-16 08:56:53 +01:00
Sylvio Alves
c64a74e711 espressif: adapt to hal_espressif IDF master sync
Adapt all Espressif SoC and driver code to the updated
hal_espressif module synced with IDF master branch.

Main changes:
- clock control: delegate peripheral clock gating to HAL
  layer using new clock/reset APIs
- SPI/GDMA: adapt to restructured DMA HAL with new channel
  allocation and configuration interfaces
- ethernet: add RMII clock configuration and PHY management
- GPIO: simplify using direct HAL function calls
- flash: adapt to updated SPI flash HAL interfaces
- linker scripts: update IRAM/DRAM mappings for new HAL
  object files
- DTS: fix ESP32-S2 PSRAM dcache1 address to match actual
  MMU mapping region (0x3f800000 DRAM1 instead of 0x3f500000
  DPORT which lacks 8-bit access capability)
- west.yml: update hal_espressif revision

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-03-13 11:38:18 +01:00
Jan Behrens
86f6c012c2 drivers: counter: rpi_pico_pit: Fixes unwanted running
Fixes the counter running after initialization and the counter running
after calling counter_set_top_value, regardless of previous state.
Also adjusts the tests.

Signed-off-by: Jan Behrens <jan.behrens@navimatix.de>
2026-03-10 17:24:32 +01:00
Raffael Rostagno
14acf0cab1 drivers: counter: rtc: esp32: Add device PM
Add device PM to ESP32 RTC counter driver.

Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
2026-03-10 15:09:30 +01:00
Holt Sun
1b5f4f147e drivers: counter: mcux_rtc_jdp: fix alarm timing with safety window
Replace busy-wait synchronization delay with a safety window mechanism
to prevent missed alarm compares when set too close to current counter
value.

- Remove k_busy_wait(100U) after setting API compare value
- Use MINIMUM_RTCVAL/MINIMUM_APIVAL as safety window thresholds
- Trigger SW-pending interrupts for alarms within safety window
- Fix absolute alarm late-to-set detection using forward distance
- Reduce counter test iterations from 100 to 1

This ensures reliable alarm delivery without blocking delays.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-03-04 14:32:18 +00:00
Hieu Nguyen
de4383a0b5 drivers: counter: Initial support for RZ/A2M
Add Counter driver support for Renesas RZ/A2M

Signed-off-by: Hieu Nguyen <hieu.nguyen.ym@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2026-03-04 11:38:24 +01:00
Tahsin Mutlugun
b3c0247789 drivers: counter: max32: Correctly handle external clock frequency
On MAX32 SoCs, some timer instances can use an external clock input.
This commit ensures that when the external clock is selected as the
source, its frequency is read and used correctly.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2026-03-02 15:59:25 -08:00
Tahsin Mutlugun
2226976c56 drivers: counter: max32: Add pinctrl support for timer I/O signals
MAX32 timers can optionally use external input/output pins.
Enable pinctrl support in the counter driver so these pins
can be properly configured via device tree.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2026-03-02 15:59:25 -08:00
Muhammed Asif
3096cae23f drivers: counter: microchip: Add support for counter using rtc
- Adds the necessary support for counter using rtc peripheral.

Signed-off-by: Muhammed Asif <muhammed.asif@microchip.com>
2026-03-02 10:47:37 +01:00
Hieu Nguyen
f4ce40c8b6 drivers: counter: Update driver for RZ devices
Reduce the complexity of the set-alarm and set-top functions.
Improve the error handling.
Replace IRQ macros with static inline functions to centralize GIC/NVIC
conditional handling.

Signed-off-by: Hieu Nguyen <hieu.nguyen.ym@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2026-03-02 10:46:47 +01:00
Phuc Hoang
868f21f13f drivers: counter: silabs: Add counter driver for timer on Silabs Series 2
Add counter driver for timer on Silicon Labs series 2.
Tested by building and running the sample on realboard
slwrb4180b and xg24_rb4187c.

Signed-off-by: Phuc Hoang <donp172748@gmail.com>
2026-02-26 08:43:59 -06:00
Muhammed Asif
e99a2a9359 drivers: counter: microchip: g1 driver for counter with tc
Adds support for g1 counter driver with tc peripheral

Signed-off-by: Muhammed Asif <muhammed.asif@microchip.com>
2026-02-26 08:42:44 -06:00
James Roy
1698ab3643 drivers: counter: max32: Add counter reset and set_value support
Allow the ADI MAX32 platform use `counter_reset` and `counter_set_value`
- `reset` clears the counter
- `set_value` sets it to a given value

Signed-off-by: James Roy <rruuaanng@outlook.com>
2026-02-25 13:15:25 +01:00
Shontal Biton
4f66943327 drivers: counter: Add counter driver for BURTC in Silabs s2 and s3
Add support for using BURTC as regular counter,
without overriding the sleeptimer.

Signed-off-by: Shontal Biton <shontal1005@gmail.com>
2026-02-23 11:32:26 +00:00
Mathieu Choplain
a11688fab5 drivers: *: stm32: don't check if clock device is ready
If the clock device (i.e., RCC) failed to initialize, we have bigger
problems than trying to call clock_control_{off,on,configure} on it.
Don't bother checking to save some footprint.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-13 18:59:16 +00:00
Guillaume Gautier
f135f10d6c drivers: counter: stm32: replace ll_func_* by ll_*
Replace ll_func_* by ll_* for LL function redefinitions in the STM32
counter driver.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2026-02-12 20:04:25 +01:00
Pieter De Gendt
9d36f4b2ab drivers: counter: Put counter driver API into iterable section
Use DEVICE_API macro to put the API into the correct iterable section.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-10 22:20:25 +01:00
Adrian Bonislawski
9cf26300c9 drivers: counter: ACE: enable 64-bit ticks by default
Select COUNTER_64BITS_TICKS for ACE counters to enable this
functionality by default.
This restores the default state which was disabled by recent commits.

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
2026-02-06 11:21:30 +01:00
Adrian Bonislawski
b446b10d23 drivers: counter: ace_v1x_rtc: fix unused function warning
Wrap counter_ace_v1x_rtc_get_value in #ifdef
to avoid an unused function warning when
64-bit ticks are disabled.

Fixes 7fc848153c

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
2026-02-06 11:21:30 +01:00
Benjamin Cabé
ef79c52871 drivers: counter: use proper essential type in bool variables assignments
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
assigned true/false values, not 1/0.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-02-05 10:20:22 +00:00
Pisit Sawangvonganan
bfff5cf098 drivers: counter: stm32: remove duplicate reset implementation
Drop `counter_stm32_reset_timer`, introduced in PR #94189 (01a00d5),
as it duplicates the existing `counter_stm32_reset` functionality.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-02-04 13:56:29 +01:00
Albort Xue
df3b494c61 drivers: counter: mcux_tpm: Add clock configuration and enable
Add explicit clock configuration and enable calls during driver
initialization.

Note: -ENOSYS is temporarily ignored as not all clock control
drivers currently implement the configure API. This handling
should be removed once all clock drivers support configure.

Signed-off-by: Albort Xue <yao.xue@nxp.com>
2026-02-04 13:55:17 +01:00
Sylvio Alves
4c197048a2 drivers: counter: esp32: fix relative alarm diff calculation
Fix incorrect diff calculation for relative alarms that caused alarm
callbacks to never fire. The original code calculated diff as
(alarm_cfg->ticks - now), which caused unsigned underflow when
now > alarm_cfg->ticks, resulting in a huge diff value that
incorrectly triggered the late alarm path and set callback to NULL.

For relative alarms, the diff should simply be the ticks value since
it already represents the delay from the current time.

Also add channel validation to return -ENOTSUP for chan_id > 0 since
ESP32 timer hardware only supports one alarm comparator per timer.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-02-04 13:54:57 +01:00
Benjamin Cabé
2013be3024 drivers: counter: use proper essential type to initialize boolean variables
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
initialized with true/false, not 1/0.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-02-04 13:52:38 +01:00
Hoang Nguyen
4fbfd12946 drivers: counter: renesas: Initialize p_reg in extended configuration
Initialize p_reg with the register base address from devicetree.

Signed-off-by: Hoang Nguyen <hoang.nguyen.jx@bp.renesas.com>
Signed-off-by: Nhut Nguyen <nhut.nguyen.kc@renesas.com>
2026-02-03 09:29:36 +01:00
Ryan McClelland
7fc848153c drivers: counter: add kconfig for enabling 64b tick api
Add a kconfig to be used as a flag for indicating if it supports 64b
ticks and another flag which will enable the 64b api. The kconfig
indicating that it supports 64b is a dependency of the kconfig that
will enable the api.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-01-27 10:49:43 +00:00
Ryan McClelland
779383e769 drivers: counter: add 64bit apis
Add apis for 64 bits.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-01-27 10:49:43 +00:00
Ryan McClelland
fd72085d9b drivers: counter: add kconfig for enabling 64b frequencies
Some counters, such as those that use fractional adders, tick at
resolutions greater than 4294967295Hz. This changes the freq in the common
info to a uint64_t. This adds a KConfig that can be selected by a driver.

This also has the counter ticks to sec (and vice versa) helper functions
call the get frequency for 64 bits if the kconfig is selected.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-01-27 10:49:43 +00:00
Ryan McClelland
65c2fc6c2f drivers: counter: stm32: implement counter set value api
Implement the counter_set_value api for the STM32.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-01-27 10:49:43 +00:00
Ryan McClelland
01a00d5593 drivers: counter: stm32: add counter reset
Add a reset counter api to set the time back to 0.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2026-01-27 10:49:43 +00:00