Skip to content

Commit

Permalink
cpu/nrf5x_common: implement periph_timer_query_freq
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Dec 5, 2023
1 parent fe20117 commit 7a977cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpu/nrf5x_common/Kconfig
Original file line number Diff line number Diff line change
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_FREQ
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
Original file line number Diff line number Diff line change
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_freq
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ static inline NRF_TIMER_Type *dev(tim_t tim)
return timer_config[tim].dev;
}

uword_t timer_query_freq_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_freq(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

0 comments on commit 7a977cb

Please sign in to comment.