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/cc26xx_cc13xx: implement periph_timer_query_freqs #20143

Merged
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
cpu/cc26xx_cc13xx: implement periph_timer_query_freqs
  • Loading branch information
Marian Buschsieweke authored and maribu committed Dec 7, 2023
commit c18c47d621f64d27aad7549bbb642cef0fc62385
1 change: 1 addition & 0 deletions cpu/cc26xx_cc13xx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
config CPU_COMMON_CC26XX_CC13XX
bool
select HAS_PERIPH_CPUID
select HAS_PERIPH_TIMER_QUERY_FREQS
select HAS_PERIPH_UART
select HAS_PERIPH_UART_MODECFG

Expand Down
1 change: 1 addition & 0 deletions cpu/cc26xx_cc13xx/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_uart_modecfg
FEATURES_PROVIDED += periph_timer_query_freqs

-include $(RIOTCPU)/cortexm_common/Makefile.features
12 changes: 12 additions & 0 deletions cpu/cc26xx_cc13xx/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ typedef struct {
uint8_t chn; /**< number of channels [1,2] */
} timer_conf_t;

/**
* @brief Maximum number of channels
*
* @note 32 bit timers only support one channel instead of two. But knowing
* the worst case is useful e.g. for static allocation. Users are
* expected to either do proper error handling with `timer_set()` and
* `timer_set_absolute()`, or at least verify with
* @ref timer_query_channel_numof what the actual number of channels
* of a timer is.
*/
#define TIMER_CHANNEL_NUMOF 2

#define PERIPH_I2C_NEED_READ_REG
#define PERIPH_I2C_NEED_READ_REGS
#define PERIPH_I2C_NEED_WRITE_REG
Expand Down
42 changes: 40 additions & 2 deletions cpu/cc26xx_cc13xx/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
* @}
*/

#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

#include "assert.h"
#include "board.h"
Expand Down Expand Up @@ -77,7 +78,7 @@
NVIC_SetPriority(irqn, TIMER_IRQ_PRIO);
NVIC_EnableIRQ(irqn);
/* and channel B, if enabled */
if(timer_config[tim].chn == 2) {

Check warning on line 81 in cpu/cc26xx_cc13xx/periph/timer.c

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'if' not followed by a single space
irqn++;
NVIC_SetPriority(irqn, TIMER_IRQ_PRIO);
NVIC_EnableIRQ(irqn);
Expand All @@ -98,9 +99,44 @@
return ((gpt_reg_t *)(GPT0_BASE | (((uint32_t)tim) << 12)));
}

uword_t timer_query_freqs_numof(tim_t dev)
{
assert(dev < TIMER_NUMOF);
/* 32 bit timers only work at CPU clock */
if (timer_config[dev].cfg == GPT_CFG_32T) {
return 1;
}

return 256;
}

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

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

/* 32 bit timers only work at CPU clock */
if (timer_config[dev].cfg == GPT_CFG_32T) {
if (index) {
return 0;
}
return RCOSC48M_FREQ;
}

if (index > UINT8_MAX) {
return 0;
}
return RCOSC48M_FREQ / (index + 1);
}

int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("timer_init(%u, %lu)\n", tim, freq);
DEBUG("timer_init(%u, %" PRIu32 ")\n", tim, freq);
/* make sure given timer is valid */
if (tim >= TIMER_NUMOF) {
return -1;
Expand Down Expand Up @@ -182,6 +218,8 @@
dev(tim)->TBMATCHR = (timer_config[tim].cfg == GPT_CFG_32T) ?
value : (LOAD_VALUE - value);
}

/* unmask IRQ */
dev(tim)->IMR |= chn_isr_cfg[channel].flag;

return 0;
Expand Down
Loading