Skip to content
Permalink
Browse files

drivers: counter: Move nRF TIMER and RTC configuration to device tree

Reduced Kconfig for counter with nRF TIMER and RTC. Added overlays
for TIMER and RTC configuration in the counter test.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information...
nordic-krch authored and carlescufi committed May 14, 2019
1 parent a5f3642 commit 6d4a5200bc338cdfe66f6da491da6c7874b6e3a1
@@ -17,164 +17,58 @@ config COUNTER_TIMER0
select COUNTER_NRF_TIMER
select NRFX_TIMER0

if COUNTER_TIMER0

config COUNTER_TIMER0_PRESCALER
int "Timer prescaler"
default 0
range 0 9
help
Frequency = 16 Mhz / 2^prescaler.

endif #COUNTER_TIMER0

config COUNTER_TIMER1
bool "Enable Counter on TIMER1"
depends on HAS_HW_NRF_TIMER1
select COUNTER_NRF_TIMER
select NRFX_TIMER1

if COUNTER_TIMER1

config COUNTER_TIMER1_PRESCALER
int "Timer prescaler"
default 0
range 0 9
help
Frequency = 16 Mhz / 2^prescaler.

endif #COUNTER_TIMER1

config COUNTER_TIMER2
bool "Enable Counter on TIMER2"
depends on HAS_HW_NRF_TIMER2
select COUNTER_NRF_TIMER
select NRFX_TIMER2

if COUNTER_TIMER2

config COUNTER_TIMER2_PRESCALER
int "Timer prescaler"
default 0
range 0 9
help
Frequency = 16 Mhz / 2^prescaler.

endif #COUNTER_TIMER2

config COUNTER_TIMER3
bool "Enable Counter on TIMER3"
depends on HAS_HW_NRF_TIMER3
select COUNTER_NRF_TIMER
select NRFX_TIMER3

if COUNTER_TIMER3

config COUNTER_TIMER3_PRESCALER
int "Timer prescaler"
default 0
range 0 9
help
Frequency = 16 Mhz / 2^prescaler.

endif #COUNTER_TIMER3

config COUNTER_TIMER4
bool "Enable Counter on TIMER4"
depends on HAS_HW_NRF_TIMER4
select COUNTER_NRF_TIMER
select NRFX_TIMER4

if COUNTER_TIMER4

config COUNTER_TIMER4_PRESCALER
int "Timer prescaler"
default 0
range 0 9
help
Frequency = 16 Mhz / 2^prescaler.

endif #COUNTER_TIMER4

config COUNTER_RTC0
bool "Enable Counter on RTC0"
depends on HAS_HW_NRF_RTC0
depends on !BT_LL_SW
select COUNTER_NRF_RTC
select NRFX_RTC0

if COUNTER_RTC0

config COUNTER_RTC0_PRESCALER
int "RTC prescaler"
default 0
range 0 2047
help
Frequency = 32768 / (prescaler+1).

config COUNTER_RTC0_PPI_WRAP
bool "Enable PPI wrapping in RTC0"
select NRFX_PPI if HAS_HW_NRF_PPI
select NRFX_DPPI if HAS_HW_NRF_DPPIC
help
If enabled, overflow different than full range (24 bits) is handled
through PPI channel which ensures precise timing. If disabled then
counter is cleared in the interrupt which results in accumulative
error of counter period if top value is different than maximal.

endif #COUNTER_RTC0

config COUNTER_RTC1
bool "Enable Counter on RTC1"
depends on HAS_HW_NRF_RTC1
depends on !NRF_RTC_TIMER
select COUNTER_NRF_RTC
select NRFX_RTC1

if COUNTER_RTC1

config COUNTER_RTC1_PRESCALER
int "RTC prescaler"
default 0
range 0 2047
help
Frequency = 32768 / (prescaler+1).

config COUNTER_RTC1_PPI_WRAP
bool "Enable PPI wrapping in RTC1"
select NRFX_PPI if HAS_HW_NRF_PPI
select NRFX_DPPI if HAS_HW_NRF_DPPIC
help
If enabled, overflow different than full range (24 bits) is handled
through PPI channel which ensures precise timing. If disabled then
counter is cleared in the interrupt which results in accumulative
error of counter period if top value is different than maximal.

endif #COUNTER_RTC1

config COUNTER_RTC2
bool "Enable Counter on RTC2"
depends on HAS_HW_NRF_RTC2
select COUNTER_NRF_RTC
select NRFX_RTC2

if COUNTER_RTC2
# Internal flag which detects if PPI wrap feature is enabled for any instance
if $(dt_int_val,DT_NORDIC_NRF_RTC_0_PPI_WRAP) > 0 || \
$(dt_int_val,DT_NORDIC_NRF_RTC_1_PPI_WRAP) > 0 || \
$(dt_int_val,DT_NORDIC_NRF_RTC_2_PPI_WRAP) > 0

config COUNTER_RTC2_PRESCALER
int "RTC prescaler"
default 0
range 0 2047
help
Frequency = 32768 / (prescaler+1).

config COUNTER_RTC2_PPI_WRAP
bool "Enable PPI wrapping in RTC2"
config COUNTER_RTC_WITH_PPI_WRAP
bool
default y
select NRFX_PPI if HAS_HW_NRF_PPI
select NRFX_DPPI if HAS_HW_NRF_DPPIC
help
If enabled, overflow different than full range (24 bits) is handled
through PPI channel which ensures precise timing. If disabled then
counter is cleared in the interrupt which results in accumulative
error of counter period if top value is different than maximal.

endif # COUNTER_RTC2
endif
@@ -18,7 +18,6 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);

#define RTC_CLOCK 32768
#define COUNTER_MAX_TOP_VALUE RTC_COUNTER_COUNTER_Msk

#define CC_TO_ID(cc) ((cc) - 1)
@@ -27,16 +26,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#define TOP_CH 0
#define COUNTER_TOP_INT NRFX_RTC_INT_COMPARE0

#define IS_PPI_WRAP_ENABLED() \
(IS_ENABLED(CONFIG_COUNTER_RTC0_PPI_WRAP) || \
IS_ENABLED(CONFIG_COUNTER_RTC1_PPI_WRAP) || \
IS_ENABLED(CONFIG_COUNTER_RTC2_PPI_WRAP))

struct counter_nrfx_data {
counter_top_callback_t top_cb;
void *top_user_data;
u32_t top;
#if IS_PPI_WRAP_ENABLED()
#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
u8_t ppi_ch;
#endif
};
@@ -50,7 +44,7 @@ struct counter_nrfx_config {
struct counter_config_info info;
struct counter_nrfx_ch_data *ch_data;
nrfx_rtc_t rtc;
#if IS_PPI_WRAP_ENABLED()
#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
bool use_ppi;
#endif
LOG_INSTANCE_PTR_DECLARE(log);
@@ -200,7 +194,7 @@ static void event_handler(nrfx_rtc_int_type_t int_type, void *p_context)
if (int_type == COUNTER_TOP_INT) {
/* Manually reset counter if top value is different than max. */
if ((data->top != COUNTER_MAX_TOP_VALUE)
#if IS_PPI_WRAP_ENABLED()
#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
&& !get_nrfx_config(dev)->use_ppi
#endif
) {
@@ -221,7 +215,7 @@ static void event_handler(nrfx_rtc_int_type_t int_type, void *p_context)

static int ppi_setup(struct device *dev)
{
#if IS_PPI_WRAP_ENABLED()
#if CONFIG_COUNTER_RTC_WITH_PPI_WRAP
const struct counter_nrfx_config *nrfx_config = get_nrfx_config(dev);
struct counter_nrfx_data *data = get_dev_data(dev);
const nrfx_rtc_t *rtc = &nrfx_config->rtc;
@@ -259,7 +253,7 @@ static int ppi_setup(struct device *dev)
(void)nrfx_ppi_channel_assign(data->ppi_ch, evt, task);
(void)nrfx_ppi_channel_enable(data->ppi_ch);
#endif
#endif /* IS_PPI_WRAP_ENABLED() */
#endif /* CONFIG_COUNTER_RTC_WITH_PPI_WRAP */
return 0;
}

@@ -322,6 +316,9 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
};

#define COUNTER_NRFX_RTC_DEVICE(idx) \
BUILD_ASSERT_MSG((DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER - 1) <= \
RTC_PRESCALER_PRESCALER_Msk, \
"RTC prescaler out of range"); \
DEVICE_DECLARE(rtc_##idx); \
static void rtc_##idx##_handler(nrfx_rtc_int_type_t int_type) \
{ \
@@ -333,7 +330,8 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
DT_NORDIC_NRF_RTC_RTC_##idx##_IRQ_PRIORITY, \
nrfx_isr, nrfx_rtc_##idx##_irq_handler, 0); \
const nrfx_rtc_config_t config = { \
.prescaler = CONFIG_COUNTER_RTC##idx##_PRESCALER, \
.prescaler = \
DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER - 1, \
}; \
return init_rtc(dev, &config, rtc_##idx##_handler); \
} \
@@ -344,14 +342,14 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
static const struct counter_nrfx_config nrfx_counter_##idx##z_config = {\
.info = { \
.max_top_value = COUNTER_MAX_TOP_VALUE, \
.freq = RTC_CLOCK / \
(CONFIG_COUNTER_RTC##idx##_PRESCALER + 1), \
.freq = DT_NORDIC_NRF_RTC_RTC_##idx##_CLOCK_FREQUENCY /\
(DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER), \
.count_up = true, \
.channels = CC_TO_ID(RTC##idx##_CC_NUM) \
}, \
.ch_data = counter##idx##_ch_data, \
.rtc = NRFX_RTC_INSTANCE(idx), \
COND_CODE_1(CONFIG_COUNTER_RTC##idx##_PPI_WRAP, \
COND_CODE_1(DT_NORDIC_NRF_RTC_RTC_##idx##_PPI_WRAP, \
(.use_ppi = true,), ()) \
LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \
}; \
@@ -252,13 +252,17 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
};

#define COUNTER_NRFX_TIMER_DEVICE(idx) \
BUILD_ASSERT_MSG(DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER <= \
TIMER_PRESCALER_PRESCALER_Msk, \
"TIMER prescaler out of range"); \
static int counter_##idx##_init(struct device *dev) \
{ \
IRQ_CONNECT(DT_NORDIC_NRF_TIMER_TIMER_##idx##_IRQ, \
DT_NORDIC_NRF_TIMER_TIMER_##idx##_IRQ_PRIORITY, \
nrfx_isr, nrfx_timer_##idx##_irq_handler, 0); \
const nrfx_timer_config_t config = { \
.frequency = CONFIG_COUNTER_TIMER##idx##_PRESCALER, \
.frequency = \
DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER, \
.mode = NRF_TIMER_MODE_TIMER, \
.bit_width = (TIMER##idx##_MAX_SIZE == 32) ? \
NRF_TIMER_BIT_WIDTH_32 : \
@@ -276,7 +280,7 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
.max_top_value = (TIMER##idx##_MAX_SIZE == 32) ? \
0xffffffff : 0x0000ffff, \
.freq = TIMER_CLOCK / \
(1 << CONFIG_COUNTER_TIMER##idx##_PRESCALER), \
(1 << DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER), \
.count_up = true, \
.channels = CC_TO_ID(TIMER##idx##_CC_NUM), \
}, \
@@ -154,6 +154,8 @@
reg = <0x4000b000 0x1000>;
interrupts = <11 1>;
status = "ok";
clock-frequency = <32768>;
prescaler = <1>;
label = "RTC_0";
};

@@ -162,6 +164,8 @@
reg = <0x40011000 0x1000>;
interrupts = <17 1>;
status = "ok";
clock-frequency = <32768>;
prescaler = <1>;
label = "RTC_1";
};

@@ -170,6 +174,7 @@
status = "ok";
reg = <0x40008000 0x1000>;
interrupts = <8 1>;
prescaler = <0>;
label = "TIMER_0";
};

@@ -178,6 +183,7 @@
status = "ok";
reg = <0x40009000 0x1000>;
interrupts = <9 1>;
prescaler = <0>;
label = "TIMER_1";
};

@@ -186,6 +192,7 @@
status = "ok";
reg = <0x4000a000 0x1000>;
interrupts = <10 1>;
prescaler = <0>;
label = "TIMER_2";
};

@@ -140,6 +140,8 @@
reg = <0x4000b000 0x1000>;
interrupts = <11 1>;
status = "ok";
clock-frequency = <32768>;
prescaler = <1>;
label = "RTC_0";
};

@@ -148,6 +150,8 @@
reg = <0x40011000 0x1000>;
interrupts = <17 1>;
status = "ok";
clock-frequency = <32768>;
prescaler = <1>;
label = "RTC_1";
};

@@ -156,6 +160,7 @@
status = "ok";
reg = <0x40008000 0x1000>;
interrupts = <8 1>;
prescaler = <0>;
label = "TIMER_0";
};

@@ -164,6 +169,7 @@
status = "ok";
reg = <0x40009000 0x1000>;
interrupts = <9 1>;
prescaler = <0>;
label = "TIMER_1";
};

@@ -172,6 +178,7 @@
status = "ok";
reg = <0x4000a000 0x1000>;
interrupts = <10 1>;
prescaler = <0>;
label = "TIMER_2";
};

0 comments on commit 6d4a520

Please sign in to comment.
You can’t perform that action at this time.