Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/nrf5x_common: implement periph_timer_query_freqs #20145

Merged
merged 1 commit into from Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cpu/nrf53/Kconfig
Expand Up @@ -16,6 +16,7 @@ config CPU_FAM_NRF53
select HAS_PERIPH_GPIO
select HAS_PERIPH_GPIO_IRQ
select HAS_PERIPH_TIMER_PERIODIC
select HAS_PERIPH_TIMER_QUERY_FREQS
select HAS_PERIPH_UART_MODECFG
select HAS_PERIPH_WDT
select HAS_PERIPH_WDT_CB
Expand Down
1 change: 1 addition & 0 deletions cpu/nrf5x_common/Kconfig
Expand Up @@ -20,6 +20,7 @@ depends on !CPU_FAM_NRF53
select HAS_PERIPH_HWRNG
select HAS_PERIPH_TEMPERATURE
select HAS_PERIPH_TIMER_PERIODIC
select HAS_PERIPH_TIMER_QUERY_FREQS
select HAS_PERIPH_RTT_OVERFLOW
select HAS_PERIPH_UART_MODECFG
select HAS_PERIPH_WDT
Expand Down
1 change: 1 addition & 0 deletions cpu/nrf5x_common/Makefile.features
Expand Up @@ -5,6 +5,7 @@ FEATURES_PROVIDED += periph_flashpage_in_address_space
FEATURES_PROVIDED += periph_flashpage_pagewise
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_timer_periodic
FEATURES_PROVIDED += periph_timer_query_freqs
FEATURES_PROVIDED += periph_uart_modecfg
FEATURES_PROVIDED += periph_wdt periph_wdt_cb

Expand Down
10 changes: 10 additions & 0 deletions cpu/nrf5x_common/include/periph_cpu_common.h
Expand Up @@ -257,6 +257,16 @@ typedef struct {
*/
#define PERIPH_TIMER_PROVIDES_SET 1

/**
* @brief Maximum number of channels
*
* @note NRF_TIMER1 and NRF_TIMER2 only have 4 hardware channels (and 3 of
* of them are available to the application, as one has to be used
* to implement timer_read()). Use @ref timer_query_channel_numof to
* check the actual number of supported channels for a given timer.
*/
#define TIMER_CHANNEL_NUMOF 5

#ifndef DOXYGEN
/**
* @brief Override SPI mode values
Expand Down
26 changes: 25 additions & 1 deletion cpu/nrf5x_common/periph/timer.c
Expand Up @@ -45,6 +45,30 @@ static inline NRF_TIMER_Type *dev(tim_t tim)
return timer_config[tim].dev;
}

uword_t timer_query_freqs_numof(tim_t dev)
{
assert(dev < TIMER_NUMOF);
(void)dev;
return 10;
}

uword_t timer_query_channel_numof(tim_t dev)
{
assert(dev < TIMER_NUMOF);
return timer_config[dev].channels;
}

uint32_t timer_query_freqs(tim_t dev, uword_t index)
{
assert(dev < TIMER_NUMOF);
(void)dev;
if (index >= 10) {
return 0;
}

return F_TIMER >> index;
}

int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/* make sure the given timer is valid */
Expand Down Expand Up @@ -75,7 +99,7 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
dev(tim)->PRESCALER = i;
break;
}
cando /= 2;
cando >>= 1;
}
if (i == 10) {
return -1;
Expand Down
1 change: 1 addition & 0 deletions cpu/nrf9160/Kconfig
Expand Up @@ -17,6 +17,7 @@ config CPU_FAM_NRF9160
select HAS_PERIPH_GPIO_LL_IRQ
select HAS_PERIPH_GPIO_LL_IRQ_UNMASK
select HAS_PERIPH_TIMER_PERIODIC
select HAS_PERIPH_TIMER_QUERY_FREQS
select HAS_PERIPH_UART_MODECFG
select HAS_PERIPH_SPI_GPIO_MODE
select HAS_PERIPH_WDT
Expand Down