Skip to content

Commit b40ab8f

Browse files
committed
cpu/nrf5x_common: implement periph_timer_query_freqs
1 parent 5dc3d9c commit b40ab8f

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

cpu/nrf53/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config CPU_FAM_NRF53
1616
select HAS_PERIPH_GPIO
1717
select HAS_PERIPH_GPIO_IRQ
1818
select HAS_PERIPH_TIMER_PERIODIC
19+
select HAS_PERIPH_TIMER_QUERY_FREQS
1920
select HAS_PERIPH_UART_MODECFG
2021
select HAS_PERIPH_WDT
2122
select HAS_PERIPH_WDT_CB

cpu/nrf5x_common/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ depends on !CPU_FAM_NRF53
2020
select HAS_PERIPH_HWRNG
2121
select HAS_PERIPH_TEMPERATURE
2222
select HAS_PERIPH_TIMER_PERIODIC
23+
select HAS_PERIPH_TIMER_QUERY_FREQS
2324
select HAS_PERIPH_RTT_OVERFLOW
2425
select HAS_PERIPH_UART_MODECFG
2526
select HAS_PERIPH_WDT

cpu/nrf5x_common/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ FEATURES_PROVIDED += periph_flashpage_in_address_space
55
FEATURES_PROVIDED += periph_flashpage_pagewise
66
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
77
FEATURES_PROVIDED += periph_timer_periodic
8+
FEATURES_PROVIDED += periph_timer_query_freqs
89
FEATURES_PROVIDED += periph_uart_modecfg
910
FEATURES_PROVIDED += periph_wdt periph_wdt_cb
1011

cpu/nrf5x_common/include/periph_cpu_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ typedef struct {
257257
*/
258258
#define PERIPH_TIMER_PROVIDES_SET 1
259259

260+
/**
261+
* @brief Maximum number of channels
262+
*
263+
* @note NRF_TIMER1 and NRF_TIMER2 only have 4 hardware channels (and 3 of
264+
* of them are available to the application, as one has to be used
265+
* to implement timer_read()). Use @ref timer_query_channel_numof to
266+
* check the actual number of supported channels for a given timer.
267+
*/
268+
#define TIMER_CHANNEL_NUMOF 5
269+
260270
#ifndef DOXYGEN
261271
/**
262272
* @brief Override SPI mode values

cpu/nrf5x_common/periph/timer.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ static inline NRF_TIMER_Type *dev(tim_t tim)
4545
return timer_config[tim].dev;
4646
}
4747

48+
uword_t timer_query_freqs_numof(tim_t dev)
49+
{
50+
assert(dev < TIMER_NUMOF);
51+
(void)dev;
52+
return 10;
53+
}
54+
55+
uword_t timer_query_channel_numof(tim_t dev)
56+
{
57+
assert(dev < TIMER_NUMOF);
58+
return timer_config[dev].channels;
59+
}
60+
61+
uint32_t timer_query_freqs(tim_t dev, uword_t index)
62+
{
63+
assert(dev < TIMER_NUMOF);
64+
(void)dev;
65+
if (index >= 10) {
66+
return 0;
67+
}
68+
69+
return F_TIMER >> index;
70+
}
71+
4872
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
4973
{
5074
/* make sure the given timer is valid */
@@ -75,7 +99,7 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
7599
dev(tim)->PRESCALER = i;
76100
break;
77101
}
78-
cando /= 2;
102+
cando >>= 1;
79103
}
80104
if (i == 10) {
81105
return -1;

cpu/nrf9160/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ config CPU_FAM_NRF9160
1717
select HAS_PERIPH_GPIO_LL_IRQ
1818
select HAS_PERIPH_GPIO_LL_IRQ_UNMASK
1919
select HAS_PERIPH_TIMER_PERIODIC
20+
select HAS_PERIPH_TIMER_QUERY_FREQS
2021
select HAS_PERIPH_UART_MODECFG
2122
select HAS_PERIPH_SPI_GPIO_MODE
2223
select HAS_PERIPH_WDT

0 commit comments

Comments
 (0)