Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/releases/migration-guide-4.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ Comparator
and :c:macro:`NRF_COMP_AIN_VDDH_DIV5` represents VDDH/5.
The old ``string`` properties type is deprecated.

Counter
=======

* Drivers that support 64-bit ticks now can use the new KConfig
:kconfig:option:`CONFIG_COUNTER_64BITS` to enable this feature. The drivers that support
this feature are :dtcompatible:`intel,ace-art-counter`,
:dtcompatible:`intel,ace-rtc-counter`, :dtcompatible:`ti,cc23x0-rtc`,
:dtcompatible:`espressif,esp32-counter`, and the :dtcompatible:`st,stm32-rtc` if
:kconfig:option:`CONFIG_COUNTER_RTC_STM32_SUBSECONDS` is enabled. This moves the ``uint32_t``
previously used for ticks to a typedef :c:type:`counter_ticks_t` that is ``uint64_t`` when 64-bit
ticks are enabled and ``uint32_t`` otherwise. The API functions that use ticks have been
updated to use this typedef. This change is backward compatible as long as the application
does not enable 64-bit ticks. Enabling 64-bit ticks may require changes in the application
code to use the new typedef and to handle the larger tick values. The
:c:func:`counter_get_value_64` has been removed in favor of just using
:c:func:`counter_get_value` along with the :c:type:`counter_ticks_t` as it's parameter
defined as ``uint64_t`` with :kconfig:option:`CONFIG_COUNTER_64BITS` enabled. (:github:`94189`)

DMA
===

Expand Down
8 changes: 8 additions & 0 deletions drivers/counter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ config COUNTER_SHELL
help
Enable Shell Commands for Counter and Timer

config COUNTER_64BITS
bool
help
Select this option if the counter driver should use 64-bit
tick values for counter_ticks_t instead of 32-bit.
This is typically set by drivers that require extended
tick ranges beyond the 32-bit limit.

module = COUNTER
module-str = counter
source "subsys/logging/Kconfig.template.log_config"
Expand Down
2 changes: 2 additions & 0 deletions drivers/counter/Kconfig.ace
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
config ACE_V1X_ART_COUNTER
bool "DSP ART Wall Clock for ACE V1X"
depends on DT_HAS_INTEL_ACE_ART_COUNTER_ENABLED
select COUNTER_64BITS
default y
help
DSP ART Wall Clock used by ACE V1X.

config ACE_V1X_RTC_COUNTER
bool "DSP RTC Wall Clock for ACE V1X"
depends on DT_HAS_INTEL_ACE_RTC_COUNTER_ENABLED
select COUNTER_64BITS
default y
help
DSP RTC Wall Clock used by ACE V1X.
1 change: 1 addition & 0 deletions drivers/counter/Kconfig.cc23x0_rtc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ config COUNTER_CC23X0_RTC
default y
depends on DT_HAS_TI_CC23X0_RTC_ENABLED
depends on CC23X0_SYSTIM_TIMER
select COUNTER_64BITS
help
Enable counter driver based on RTC timer for cc23x0
1 change: 1 addition & 0 deletions drivers/counter/Kconfig.esp32_tmr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config COUNTER_TMR_ESP32
bool "ESP32 Counter Driver based on GP-Timers"
default y
depends on DT_HAS_ESPRESSIF_ESP32_COUNTER_ENABLED
select COUNTER_64BITS
help
Enables the Counter driver API based on Espressif's General
Purpose Timers for ESP32 series devices.
1 change: 1 addition & 0 deletions drivers/counter/Kconfig.stm32_rtc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config COUNTER_RTC_STM32_SAVE_VALUE_BETWEEN_RESETS
config COUNTER_RTC_STM32_SUBSECONDS
bool "Use the subseconds as a basic tick."
depends on !SOC_SERIES_STM32F1X
select COUNTER_64BITS
help
Use the subseconds as the basic time tick. It increases resolution
of the counter. The frequency of the time is RTC Source Clock divided
Expand Down
2 changes: 1 addition & 1 deletion drivers/counter/counter_ace_v1x_art.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int counter_ace_v1x_art_get_value(const struct device *dev, uint64_t *value)
}

static DEVICE_API(counter, ace_v1x_art_counter_apis) = {
.get_value_64 = counter_ace_v1x_art_get_value
.get_value = counter_ace_v1x_art_get_value
};

DEVICE_DT_DEFINE(DT_NODELABEL(ace_art_counter), NULL, NULL, NULL, NULL,
Expand Down
2 changes: 1 addition & 1 deletion drivers/counter/counter_ace_v1x_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int counter_ace_v1x_rtc_init(const struct device *dev)
}

static DEVICE_API(counter, ace_v1x_rtc_counter_apis) = {
.get_value_64 = counter_ace_v1x_rtc_get_value
.get_value = counter_ace_v1x_rtc_get_value
};

DEVICE_DT_DEFINE(DT_NODELABEL(ace_rtc_counter), counter_ace_v1x_rtc_init, NULL, NULL, NULL,
Expand Down
13 changes: 1 addition & 12 deletions drivers/counter/counter_cc23x0_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ struct counter_cc23x0_data {
struct counter_alarm_cfg alarm_cfg0;
};

static int counter_cc23x0_get_value(const struct device *dev, uint32_t *ticks)
{
/* Resolution is 8us and max timeout ~9.5h */
const struct counter_cc23x0_config *config = dev->config;

*ticks = HWREG(config->base + RTC_O_TIME8U);

return 0;
}

static int counter_cc23x0_get_value_64(const struct device *dev, uint64_t *ticks)
{
const struct counter_cc23x0_config *config = dev->config;
Expand Down Expand Up @@ -211,8 +201,7 @@ static int counter_cc23x0_init(const struct device *dev)
static DEVICE_API(counter, rtc_cc23x0_api) = {
.start = counter_cc23x0_start,
.stop = counter_cc23x0_stop,
.get_value = counter_cc23x0_get_value,
.get_value_64 = counter_cc23x0_get_value_64,
.get_value = counter_cc23x0_get_value_64,
.set_alarm = counter_cc23x0_set_alarm,
.cancel_alarm = counter_cc23x0_cancel_alarm,
.get_top_value = counter_cc23x0_get_top_value,
Expand Down
50 changes: 20 additions & 30 deletions drivers/counter/counter_esp32_tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ typedef bool (*timer_isr_t)(void *);

struct counter_esp32_top_data {
counter_top_callback_t callback;
uint32_t ticks;
counter_ticks_t ticks;
void *user_data;
bool auto_reload;
uint32_t guard_period;
counter_ticks_t guard_period;
};

struct counter_esp32_config {
Expand All @@ -47,7 +47,7 @@ struct counter_esp32_config {
struct counter_esp32_data {
struct counter_alarm_cfg alarm_cfg;
struct counter_esp32_top_data top_data;
uint32_t ticks;
counter_ticks_t ticks;
uint32_t clock_src_hz;
timer_hal_context_t hal_ctx;
};
Expand Down Expand Up @@ -120,17 +120,7 @@ static int counter_esp32_stop(const struct device *dev)
return 0;
}

static int counter_esp32_get_value(const struct device *dev, uint32_t *ticks)
{
struct counter_esp32_data *data = dev->data;

timer_ll_trigger_soft_capture(data->hal_ctx.dev, data->hal_ctx.timer_id);
*ticks = (uint32_t)timer_ll_get_counter_value(data->hal_ctx.dev, data->hal_ctx.timer_id);

return 0;
}

static int counter_esp32_get_value_64(const struct device *dev, uint64_t *ticks)
static int counter_esp32_get_value_64(const struct device *dev, counter_ticks_t *ticks)
{
struct counter_esp32_data *data = dev->data;

Expand All @@ -146,12 +136,12 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,
ARG_UNUSED(chan_id);
struct counter_esp32_data *data = dev->data;
bool absolute = alarm_cfg->flags & COUNTER_ALARM_CFG_ABSOLUTE;
uint32_t ticks = alarm_cfg->ticks;
uint32_t top = data->top_data.ticks;
uint32_t max_rel_val = data->top_data.ticks;
uint64_t now;
counter_ticks_t ticks = alarm_cfg->ticks;
counter_ticks_t top = data->top_data.ticks;
counter_ticks_t max_rel_val = data->top_data.ticks;
counter_ticks_t now;
uint64_t target;
uint32_t diff;
uint64_t diff;
int err = 0;
bool irq_on_late = 0;

Expand All @@ -177,7 +167,7 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,

timer_ll_set_alarm_value(data->hal_ctx.dev, data->hal_ctx.timer_id, target);

diff = (alarm_cfg->ticks - (uint32_t)now);
diff = (alarm_cfg->ticks - now);
if (diff > max_rel_val) {
if (absolute) {
err = -ETIME;
Expand Down Expand Up @@ -220,7 +210,7 @@ static int counter_esp32_set_top_value(const struct device *dev, const struct co
{
const struct counter_esp32_config *config = dev->config;
struct counter_esp32_data *data = dev->data;
uint32_t now;
counter_ticks_t now;

if (data->alarm_cfg.callback) {
return -EBUSY;
Expand All @@ -230,7 +220,7 @@ static int counter_esp32_set_top_value(const struct device *dev, const struct co
return -ENOTSUP;
}

counter_esp32_get_value(dev, &now);
counter_esp32_get_value_64(dev, &now);

if (!(cfg->flags & COUNTER_TOP_CFG_DONT_RESET)) {
timer_hal_set_counter_value(&data->hal_ctx, 0);
Expand Down Expand Up @@ -267,7 +257,7 @@ static uint32_t counter_esp32_get_pending_int(const struct device *dev)
return timer_ll_get_intr_status(data->hal_ctx.dev);
}

static uint32_t counter_esp32_get_top_value(const struct device *dev)
static counter_ticks_t counter_esp32_get_top_value(const struct device *dev)
{
struct counter_esp32_data *data = dev->data;

Expand All @@ -291,7 +281,7 @@ static int counter_esp32_reset(const struct device *dev)
return 0;
}

static uint32_t counter_esp32_get_guard_period(const struct device *dev, uint32_t flags)
static counter_ticks_t counter_esp32_get_guard_period(const struct device *dev, uint32_t flags)
{
struct counter_esp32_data *data = dev->data;

Expand All @@ -300,7 +290,8 @@ static uint32_t counter_esp32_get_guard_period(const struct device *dev, uint32_
return data->top_data.guard_period;
}

static int counter_esp32_set_guard_period(const struct device *dev, uint32_t ticks, uint32_t flags)
static int counter_esp32_set_guard_period(const struct device *dev, counter_ticks_t ticks,
uint32_t flags)
{
struct counter_esp32_data *data = dev->data;

Expand All @@ -317,9 +308,8 @@ static int counter_esp32_set_guard_period(const struct device *dev, uint32_t tic
static DEVICE_API(counter, counter_api) = {
.start = counter_esp32_start,
.stop = counter_esp32_stop,
.get_value = counter_esp32_get_value,
.reset = counter_esp32_reset,
.get_value_64 = counter_esp32_get_value_64,
.get_value = counter_esp32_get_value_64,
.set_alarm = counter_esp32_set_alarm,
.cancel_alarm = counter_esp32_cancel_alarm,
.set_top_value = counter_esp32_set_top_value,
Expand All @@ -336,9 +326,9 @@ static void counter_esp32_isr(void *arg)
struct counter_esp32_data *data = dev->data;
counter_alarm_callback_t cb = data->alarm_cfg.callback;
void *cb_data = data->alarm_cfg.user_data;
uint32_t now;
counter_ticks_t now;

counter_esp32_get_value(dev, &now);
counter_esp32_get_value_64(dev, &now);

if (cb) {
timer_ll_enable_intr(data->hal_ctx.dev,
Expand Down Expand Up @@ -374,7 +364,7 @@ static void counter_esp32_isr(void *arg)
static struct counter_esp32_data counter_data_##idx; \
\
static const struct counter_esp32_config counter_config_##idx = { \
.counter_info = {.max_top_value = UINT32_MAX, \
.counter_info = {.max_top_value = UINT64_MAX, \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = 1}, \
.config = \
Expand Down
25 changes: 8 additions & 17 deletions drivers/counter/counter_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static inline uint32_t z_vrfy_counter_get_frequency(const struct device *dev)
}
#include <zephyr/syscalls/counter_get_frequency_mrsh.c>

static inline uint32_t z_vrfy_counter_us_to_ticks(const struct device *dev,
static inline counter_ticks_t z_vrfy_counter_us_to_ticks(const struct device *dev,
uint64_t us)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
Expand All @@ -56,32 +56,23 @@ static inline uint32_t z_vrfy_counter_us_to_ticks(const struct device *dev,
#include <zephyr/syscalls/counter_us_to_ticks_mrsh.c>

static inline uint64_t z_vrfy_counter_ticks_to_us(const struct device *dev,
uint32_t ticks)
counter_ticks_t ticks)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_ticks_to_us((const struct device *)dev,
(uint32_t)ticks);
(counter_ticks_t)ticks);
}
#include <zephyr/syscalls/counter_ticks_to_us_mrsh.c>

static inline int z_vrfy_counter_get_value(const struct device *dev,
uint32_t *ticks)
counter_ticks_t *ticks)
{
K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_value));
K_OOPS(K_SYSCALL_MEMORY_WRITE(ticks, sizeof(*ticks)));
return z_impl_counter_get_value((const struct device *)dev, ticks);
}
#include <zephyr/syscalls/counter_get_value_mrsh.c>

static inline int z_vrfy_counter_get_value_64(const struct device *dev,
uint64_t *ticks)
{
K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_value_64));
K_OOPS(K_SYSCALL_MEMORY_WRITE(ticks, sizeof(*ticks)));
return z_impl_counter_get_value_64((const struct device *)dev, ticks);
}
#include <zephyr/syscalls/counter_get_value_64_mrsh.c>

static inline int z_vrfy_counter_set_channel_alarm(const struct device *dev,
uint8_t chan_id,
const struct counter_alarm_cfg *alarm_cfg)
Expand Down Expand Up @@ -124,21 +115,21 @@ static inline int z_vrfy_counter_set_top_value(const struct device *dev,
}
#include <zephyr/syscalls/counter_set_top_value_mrsh.c>

static inline uint32_t z_vrfy_counter_get_top_value(const struct device *dev)
static inline counter_ticks_t z_vrfy_counter_get_top_value(const struct device *dev)
{
K_OOPS(K_SYSCALL_DRIVER_COUNTER(dev, get_top_value));
return z_impl_counter_get_top_value((const struct device *)dev);
}
#include <zephyr/syscalls/counter_get_top_value_mrsh.c>

static inline uint32_t z_vrfy_counter_get_max_top_value(const struct device *dev)
static inline counter_ticks_t z_vrfy_counter_get_max_top_value(const struct device *dev)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_get_max_top_value((const struct device *)dev);
}
#include <zephyr/syscalls/counter_get_max_top_value_mrsh.c>

static inline uint32_t z_vrfy_counter_get_guard_period(const struct device *dev,
static inline counter_ticks_t z_vrfy_counter_get_guard_period(const struct device *dev,
uint32_t flags)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
Expand All @@ -148,7 +139,7 @@ static inline uint32_t z_vrfy_counter_get_guard_period(const struct device *dev,
#include <zephyr/syscalls/counter_get_guard_period_mrsh.c>

static inline int z_vrfy_counter_set_guard_period(const struct device *dev,
uint32_t ticks, uint32_t flags)
counter_ticks_t ticks, uint32_t flags)
{
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_COUNTER));
return z_impl_counter_set_guard_period((const struct device *)dev,
Expand Down
4 changes: 2 additions & 2 deletions drivers/counter/counter_ite_it8xxx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ static int counter_it8xxx2_init(const struct device *dev)
uint8_t et7_ctrl = counter_it8xxx2_read8(dev, ET7CTRL);
uint8_t et8_ctrl = counter_it8xxx2_read8(dev, ET8CTRL);

LOG_DBG("max top value = 0x%08x", config->info.max_top_value);
LOG_DBG("frequency = %d", config->info.freq);
LOG_DBG("max top value = 0x%08x", (uint32_t)config->info.max_top_value);
LOG_DBG("frequency = %llu", config->info.freq);
LOG_DBG("channels = %d", config->info.channels);

/* First time enable: enable and re-start timer -> disable timer */
Expand Down
Loading