Skip to content

Commit

Permalink
drivers/counter/counter_native_sim: Rename from counter_native_posix
Browse files Browse the repository at this point in the history
Including renaming the DTS binding and kconfig options
deprecating the old one.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar authored and kartben committed Mar 10, 2025
1 parent 7ffd698 commit ab7a6de
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion boards/native/native_sim/native_sim.dts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@

counter0: counter {
status = "okay";
compatible = "zephyr,native-posix-counter";
compatible = "zephyr,native-sim-counter";
};

gpio0: gpio_emul {
Expand Down
2 changes: 1 addition & 1 deletion drivers/counter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ zephyr_library_sources_ifdef(CONFIG_COUNTER_MCUX_TPM counter_mcux_tpm
zephyr_library_sources_ifdef(CONFIG_COUNTER_XEC counter_mchp_xec.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_MCUX_LPTMR counter_mcux_lptmr.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_MAXIM_DS3231 maxim_ds3231.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_NATIVE_POSIX counter_native_posix.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_NATIVE_SIM counter_native_sim.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE counter_handlers.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_NXP_PIT counter_nxp_pit.c)
zephyr_library_sources_ifdef(CONFIG_COUNTER_XLNX_AXI_TIMER counter_xlnx_axi_timer.c)
Expand Down
2 changes: 1 addition & 1 deletion drivers/counter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ source "drivers/counter/Kconfig.mcux_lptmr"

source "drivers/counter/Kconfig.maxim_ds3231"

source "drivers/counter/Kconfig.native_posix"
source "drivers/counter/Kconfig.native_sim"

source "drivers/counter/Kconfig.nxp_pit"

Expand Down
17 changes: 0 additions & 17 deletions drivers/counter/Kconfig.native_posix

This file was deleted.

29 changes: 29 additions & 0 deletions drivers/counter/Kconfig.native_sim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2020, Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config COUNTER_NATIVE_SIM
bool "Counter on COUNTER_0"
default y
depends on (DT_HAS_ZEPHYR_NATIVE_SIM_COUNTER_ENABLED || DT_HAS_ZEPHYR_NATIVE_POSIX_COUNTER_ENABLED)

config COUNTER_NATIVE_SIM_FREQUENCY
int "native_sim counter frequency in Hz"
default COUNTER_NATIVE_POSIX_FREQUENCY
depends on COUNTER_NATIVE_SIM

config COUNTER_NATIVE_SIM_NBR_CHANNELS
int "native_sim counter: number of channels"
default COUNTER_NATIVE_POSIX_NBR_CHANNELS
depends on COUNTER_NATIVE_SIM

config COUNTER_NATIVE_POSIX
bool "Counter on COUNTER_0 (deprecated)"
select DEPRECATED

config COUNTER_NATIVE_POSIX_FREQUENCY
int "native_posix counter frequency in Hz (deprecated)"
default 1000

config COUNTER_NATIVE_POSIX_NBR_CHANNELS
int "native counter, number of channels (deprecated)"
default 4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/devicetree.h>
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_native_posix_counter)
#define DT_DRV_COMPAT zephyr_native_posix_counter
#warning "zephyr,native-posix-counter is deprecated in favor of zephyr,native-sim-counter"
#else
#define DT_DRV_COMPAT zephyr_native_sim_counter
#endif

#include <string.h>
#include <zephyr/device.h>
Expand All @@ -15,11 +21,11 @@
#include <limits.h>

#define DRIVER_CONFIG_INFO_FLAGS (COUNTER_CONFIG_INFO_COUNT_UP)
#define DRIVER_CONFIG_INFO_CHANNELS CONFIG_COUNTER_NATIVE_POSIX_NBR_CHANNELS
#define COUNTER_NATIVE_POSIX_IRQ_FLAGS (0)
#define COUNTER_NATIVE_POSIX_IRQ_PRIORITY (2)
#define DRIVER_CONFIG_INFO_CHANNELS CONFIG_COUNTER_NATIVE_SIM_NBR_CHANNELS
#define COUNTER_NATIVE_SIM_IRQ_FLAGS (0)
#define COUNTER_NATIVE_SIM_IRQ_PRIORITY (2)

#define COUNTER_PERIOD (USEC_PER_SEC / CONFIG_COUNTER_NATIVE_POSIX_FREQUENCY)
#define COUNTER_PERIOD (USEC_PER_SEC / CONFIG_COUNTER_NATIVE_SIM_FREQUENCY)
#define TOP_VALUE (UINT_MAX)

static struct counter_alarm_cfg pending_alarm[DRIVER_CONFIG_INFO_CHANNELS];
Expand Down Expand Up @@ -83,8 +89,8 @@ static int ctr_init(const struct device *dev)
is_top_set = false;
top.ticks = TOP_VALUE;

IRQ_CONNECT(COUNTER_EVENT_IRQ, COUNTER_NATIVE_POSIX_IRQ_PRIORITY,
counter_isr, NULL, COUNTER_NATIVE_POSIX_IRQ_FLAGS);
IRQ_CONNECT(COUNTER_EVENT_IRQ, COUNTER_NATIVE_SIM_IRQ_PRIORITY,
counter_isr, NULL, COUNTER_NATIVE_SIM_IRQ_FLAGS);
irq_enable(COUNTER_EVENT_IRQ);
hw_counter_set_period(COUNTER_PERIOD);
hw_counter_set_wrap_value((uint64_t)top.ticks + 1);
Expand Down Expand Up @@ -240,7 +246,7 @@ static DEVICE_API(counter, ctr_api) = {

static const struct counter_config_info ctr_config = {
.max_top_value = UINT_MAX,
.freq = CONFIG_COUNTER_NATIVE_POSIX_FREQUENCY,
.freq = CONFIG_COUNTER_NATIVE_SIM_FREQUENCY,
.channels = DRIVER_CONFIG_INFO_CHANNELS,
.flags = DRIVER_CONFIG_INFO_FLAGS
};
Expand Down
8 changes: 8 additions & 0 deletions dts/bindings/counter/zephyr,native-sim-counter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2022, Kumar Gala <[email protected]>
# SPDX-License-Identifier: Apache-2.0

description: Native_sim Counter

compatible: "zephyr,native-sim-counter"

include: base.yaml
2 changes: 1 addition & 1 deletion samples/drivers/counter/alarm/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct counter_alarm_cfg alarm_cfg;
#define TIMER DT_INST(0, st_stm32_rtc)
#elif defined(CONFIG_COUNTER_SMARTBOND_TIMER)
#define TIMER DT_NODELABEL(timer3)
#elif defined(CONFIG_COUNTER_NATIVE_POSIX)
#elif defined(CONFIG_COUNTER_NATIVE_SIM)
#define TIMER DT_NODELABEL(counter0)
#elif defined(CONFIG_COUNTER_XLNX_AXI_TIMER)
#define TIMER DT_INST(0, xlnx_xps_timer_1_00_a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@

counter0: counter {
status = "okay";
compatible = "zephyr,native-posix-counter";
compatible = "zephyr,native-sim-counter";
};

gpio0: gpio@800 {
Expand Down
4 changes: 2 additions & 2 deletions tests/drivers/counter/counter_basic_api/src/test_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static const struct device *const devices[] = {
#undef DT_DRV_COMPAT
#undef STM32_COUNTER_DEV
#endif
#ifdef CONFIG_COUNTER_NATIVE_POSIX
#ifdef CONFIG_COUNTER_NATIVE_SIM
DEVICE_DT_GET(DT_NODELABEL(counter0)),
#endif
#ifdef CONFIG_COUNTER_INFINEON_CAT1
Expand Down Expand Up @@ -1086,7 +1086,7 @@ static bool reliable_cancel_capable(const struct device *dev)
return true;
}
#endif
#ifdef CONFIG_COUNTER_NATIVE_POSIX
#ifdef CONFIG_COUNTER_NATIVE_SIM
if (dev == DEVICE_DT_GET(DT_NODELABEL(counter0))) {
return true;
}
Expand Down

0 comments on commit ab7a6de

Please sign in to comment.