Skip to content

Commit 35e140b

Browse files
committed
cpu/qn908x: implement periph_timer_query_freqs
1 parent 5dc3d9c commit 35e140b

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

cpu/qn908x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config CPU_FAM_QN908X
1616
select HAS_PERIPH_I2C_RECONFIGURE
1717
select HAS_PERIPH_RTC
1818
select HAS_PERIPH_SPI_RECONFIGURE
19+
select HAS_PERIPH_TIMER_QUERY_FREQS
1920
select HAS_PERIPH_WDT
2021
select HAS_PERIPH_WDT_CB
2122

cpu/qn908x/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq
77
FEATURES_PROVIDED += periph_i2c_reconfigure
88
FEATURES_PROVIDED += periph_rtc
99
FEATURES_PROVIDED += periph_spi_reconfigure
10+
FEATURES_PROVIDED += periph_timer_query_freqs
1011
FEATURES_PROVIDED += periph_wdt periph_wdt_cb
1112

1213
include $(RIOTCPU)/cortexm_common/Makefile.features

cpu/qn908x/include/periph_cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ typedef uint16_t adc_conf_t;
333333
* @brief CPU specific timer Counter/Timers (CTIMER) configuration
334334
* @{
335335
*/
336-
#define TIMER_CHANNELS (4)
336+
#define TIMER_CHANNEL_NUMOF (4)
337337
#define TIMER_MAX_VALUE (0xffffffff)
338338
/**
339339
* @brief The nRF5x periph_timer implements timer_set()

cpu/qn908x/periph/timer.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ static const clock_ip_name_t ctimers_clocks[FSL_FEATURE_SOC_CTIMER_COUNT] =
6767
#error "ERROR in board timer configuration: too many timers defined"
6868
#endif
6969

70+
uword_t timer_query_freqs_numof(tim_t dev)
71+
{
72+
assert(dev < TIMER_NUMOF);
73+
(void)dev;
74+
return 256;
75+
}
76+
77+
uint32_t timer_query_freqs(tim_t dev, uword_t index)
78+
{
79+
assert(dev < TIMER_NUMOF);
80+
(void)dev;
81+
82+
if (index >= UINT8_MAX) {
83+
return 0;
84+
}
85+
86+
return CLOCK_GetFreq(kCLOCK_ApbClk) / (index + 1);
87+
}
88+
7089
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
7190
{
7291
DEBUG("timer_init(%u, %" PRIu32 ")\n", tim, freq);
@@ -103,7 +122,7 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
103122
int timer_set_absolute(tim_t tim, int channel, unsigned int value)
104123
{
105124
DEBUG("timer_set_absolute(%u, %u, %u)\n", tim, channel, value);
106-
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
125+
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
107126
return -1;
108127
}
109128
CTIMER_Type* const dev = ctimers[tim];
@@ -115,7 +134,7 @@ int timer_set_absolute(tim_t tim, int channel, unsigned int value)
115134
int timer_set(tim_t tim, int channel, unsigned int value)
116135
{
117136
DEBUG("timer_set(%u, %u, %u)\n", tim, channel, value);
118-
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
137+
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
119138
return -1;
120139
}
121140
CTIMER_Type* const dev = ctimers[tim];
@@ -140,7 +159,7 @@ int timer_set(tim_t tim, int channel, unsigned int value)
140159
int timer_clear(tim_t tim, int channel)
141160
{
142161
DEBUG("timer_clear(%u, %d)\n", tim, channel);
143-
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
162+
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
144163
return -1;
145164
}
146165
CTIMER_Type* const dev = ctimers[tim];
@@ -170,7 +189,7 @@ static inline void isr_ctimer_n(CTIMER_Type *dev, uint32_t ctimer_num)
170189
{
171190
DEBUG("isr_ctimer_%" PRIu32 " flags=0x%" PRIx32 "\n",
172191
ctimer_num, dev->IR);
173-
unsigned state = dev->IR & ((1 << TIMER_CHANNELS) - 1);
192+
unsigned state = dev->IR & ((1 << TIMER_CHANNEL_NUMOF) - 1);
174193
while (state) {
175194
uint8_t channel;
176195
state = bitarithm_test_and_clear(state, &channel);

0 commit comments

Comments
 (0)