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/qn908x: implement periph_timer_query_freqs #20146

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpu/qn908x/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ config CPU_FAM_QN908X
select HAS_PERIPH_I2C_RECONFIGURE
select HAS_PERIPH_RTC
select HAS_PERIPH_SPI_RECONFIGURE
select HAS_PERIPH_TIMER_QUERY_FREQS
select HAS_PERIPH_WDT
select HAS_PERIPH_WDT_CB

Expand Down
1 change: 1 addition & 0 deletions cpu/qn908x/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_i2c_reconfigure
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_spi_reconfigure
FEATURES_PROVIDED += periph_timer_query_freqs
FEATURES_PROVIDED += periph_wdt periph_wdt_cb

include $(RIOTCPU)/cortexm_common/Makefile.features
2 changes: 1 addition & 1 deletion cpu/qn908x/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ typedef uint16_t adc_conf_t;
* @brief CPU specific timer Counter/Timers (CTIMER) configuration
* @{
*/
#define TIMER_CHANNELS (4)
#define TIMER_CHANNEL_NUMOF (4)
#define TIMER_MAX_VALUE (0xffffffff)
/**
* @brief The nRF5x periph_timer implements timer_set()
Expand Down
27 changes: 23 additions & 4 deletions cpu/qn908x/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ static const clock_ip_name_t ctimers_clocks[FSL_FEATURE_SOC_CTIMER_COUNT] =
#error "ERROR in board timer configuration: too many timers defined"
#endif

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

uint32_t timer_query_freqs(tim_t dev, uword_t index)
{
assert(dev < TIMER_NUMOF);
(void)dev;

if (index >= UINT8_MAX) {
return 0;
}

return CLOCK_GetFreq(kCLOCK_ApbClk) / (index + 1);
}

int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("timer_init(%u, %" PRIu32 ")\n", tim, freq);
Expand Down Expand Up @@ -103,7 +122,7 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
int timer_set_absolute(tim_t tim, int channel, unsigned int value)
{
DEBUG("timer_set_absolute(%u, %u, %u)\n", tim, channel, value);
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
return -1;
}
CTIMER_Type* const dev = ctimers[tim];
Expand All @@ -115,7 +134,7 @@ int timer_set_absolute(tim_t tim, int channel, unsigned int value)
int timer_set(tim_t tim, int channel, unsigned int value)
{
DEBUG("timer_set(%u, %u, %u)\n", tim, channel, value);
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
return -1;
}
CTIMER_Type* const dev = ctimers[tim];
Expand All @@ -140,7 +159,7 @@ int timer_set(tim_t tim, int channel, unsigned int value)
int timer_clear(tim_t tim, int channel)
{
DEBUG("timer_clear(%u, %d)\n", tim, channel);
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNELS)) {
if ((tim >= TIMER_NUMOF) || (channel >= TIMER_CHANNEL_NUMOF)) {
return -1;
}
CTIMER_Type* const dev = ctimers[tim];
Expand Down Expand Up @@ -170,7 +189,7 @@ static inline void isr_ctimer_n(CTIMER_Type *dev, uint32_t ctimer_num)
{
DEBUG("isr_ctimer_%" PRIu32 " flags=0x%" PRIx32 "\n",
ctimer_num, dev->IR);
unsigned state = dev->IR & ((1 << TIMER_CHANNELS) - 1);
unsigned state = dev->IR & ((1 << TIMER_CHANNEL_NUMOF) - 1);
while (state) {
uint8_t channel;
state = bitarithm_test_and_clear(state, &channel);
Expand Down