1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/periph/timer: Use uint32_t for frequency

For all currently supported platforms `unsigned long` is 32 bit in width. But
better use `uint32_t` to be safe.
This commit is contained in:
Marian Buschsieweke 2020-10-30 12:14:35 +01:00
parent 4021b10c2b
commit 125c892c03
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
19 changed files with 32 additions and 26 deletions

View File

@ -95,7 +95,7 @@ static inline bool is_oneshot(tim_t tim, int chan)
/**
* @brief Setup the given timer
*/
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/*
* A debug pin can be used to probe timer interrupts with an oscilloscope or

View File

@ -183,7 +183,7 @@ static inline cc2538_gptimer_t *dev(tim_t tim)
* @brief Setup the given timer
*
*/
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("%s(%u, %lu, %p, %p)\n", __FUNCTION__, tim, freq, cb, arg);

View File

@ -98,7 +98,7 @@ static inline gpt_reg_t *dev(tim_t tim)
return ((gpt_reg_t *)(GPT0_BASE | (((uint32_t)tim) << 12)));
}
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("timer_init(%u, %lu)\n", tim, freq);
/* make sure given timer is valid */

View File

@ -73,7 +73,7 @@ static inline bool _is_letimer(timer_t dev)
#endif
}
static void _letimer_init(tim_t dev, unsigned long freq)
static void _letimer_init(tim_t dev, uint32_t freq)
{
(void) freq;
#if LETIMER_COUNT
@ -98,7 +98,7 @@ static void _letimer_init(tim_t dev, unsigned long freq)
#endif
}
static void _timer_init(tim_t dev, unsigned long freq)
static void _timer_init(tim_t dev, uint32_t freq)
{
TIMER_TypeDef *pre, *tim;
@ -143,7 +143,7 @@ static void _timer_init(tim_t dev, unsigned long freq)
TIMER_IntEnable(tim, TIMER_IEN_CC0 | TIMER_IEN_CC1 | TIMER_IEN_CC2);
}
int timer_init(tim_t dev, unsigned long freq, timer_cb_t callback, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t callback, void *arg)
{
/* test if given timer device is valid */
if (dev >= TIMER_NUMOF) {

View File

@ -18,6 +18,8 @@
* @}
*/
#include <inttypes.h>
/*
* WARNING! enable debugging will have timing side effects and can lead
* to timer underflows, system crashes or system dead locks in worst case.
@ -191,9 +193,10 @@ void IRAM hw_timer_handler(void* arg)
irq_isr_exit();
}
int timer_init (tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init (tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("%s dev=%u freq=%lu cb=%p arg=%p\n", __func__, dev, freq, cb, arg);
DEBUG("%s dev=%u freq=%" PRIu32 " cb=%p arg=%p\n",
__func__, dev, freq, cb, arg);
CHECK_PARAM_RET (dev < HW_TIMER_NUMOF, -1);
CHECK_PARAM_RET (freq == XTIMER_HZ_BASE, -1);
@ -434,7 +437,7 @@ void IRAM hw_timer_handler(void* arg)
irq_isr_exit();
}
int timer_init (tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init (tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("%s dev=%u freq=%lu cb=%p arg=%p\n", __func__, dev, freq, cb, arg);

View File

@ -18,6 +18,8 @@
* @}
*/
#include <inttypes.h>
/* WARNING! enable debugging will have timing side effects and can lead
* to timer underflows, system crashes or system dead locks in worst case. */
#define ENABLE_DEBUG 0
@ -113,9 +115,10 @@ void IRAM hw_timer_handler(void* arg)
irq_isr_exit();
}
int timer_init (tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init (tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("%s dev=%u freq=%lu cb=%p arg=%p\n", __func__, dev, freq, cb, arg);
DEBUG("%s dev=%u freq=%" PRIu32 " cb=%p arg=%p\n",
__func__, dev, freq, cb, arg);
CHECK_PARAM_RET (dev < HW_TIMER_NUMOF, -1);
CHECK_PARAM_RET (freq == XTIMER_HZ_BASE, -1);
@ -378,7 +381,7 @@ void IRAM os_timer_handler (void* arg)
irq_isr_exit ();
}
int timer_init (tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init (tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
DEBUG("%s dev=%u freq=%lu cb=%p arg=%p\n", __func__, dev, freq, cb, arg);

View File

@ -37,7 +37,7 @@ static timer_cb_t isr_cb;
*/
static void *isr_arg;
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
/* Using RISC-V built in timer (64bit value) */
if (dev != 0) {

View File

@ -607,7 +607,7 @@ static inline void lptmr_irq_handler(tim_t tim)
#endif
/* ****** Common timer API functions ****** */
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
if ((unsigned int)dev >= TIMER_NUMOF) {
/* invalid timer */

View File

@ -63,7 +63,7 @@ static inline uint32_t _llvalue_to_scaled_value(uint64_t corrected,
return scaledv;
}
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
if (tim >= TIMER_NUMOF){
return -1;

View File

@ -39,7 +39,7 @@
*/
static timer_isr_ctx_t config[TIMER_NUMOF];
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
if (dev == 0) {
/* save callback */

View File

@ -127,7 +127,7 @@ static inline void pwr_clk_and_isr(tim_t tim, uint32_t scale)
}
}
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/* get the timers base register */
lpc23xx_timer_t *dev = get_dev(tim);

View File

@ -120,7 +120,7 @@ int gettimeofday(struct timeval *__restrict __p, void *__restrict __tz)
return 0;
}
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
assert(dev == 0);

View File

@ -41,7 +41,7 @@ static timer_cb_t isr_cb;
static void *isr_arg;
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
/* using fixed TIMER_BASE for now */
if (dev != 0) {

View File

@ -81,7 +81,7 @@ void native_isr_timer(void)
_callback(_cb_arg, 0);
}
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg)
{
(void)freq;
DEBUG("%s\n", __func__);

View File

@ -43,7 +43,7 @@ static inline NRF_TIMER_Type *dev(tim_t tim)
return timer_config[tim].dev;
}
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/* make sure the given timer is valid */
if (tim >= TIMER_NUMOF) {

View File

@ -89,7 +89,7 @@ static inline void _irq_enable(tim_t tim)
NVIC_EnableIRQ(timer_config[tim].irq);
}
static uint8_t _get_prescaler(unsigned long freq_out, unsigned long freq_in)
static uint8_t _get_prescaler(uint32_t freq_out, uint32_t freq_in)
{
uint8_t scale = 0;
while (freq_in > freq_out) {
@ -136,7 +136,7 @@ static inline void _set_nfrq(tim_t tim)
/**
* @brief Setup the given timer
*/
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
const tc32_conf_t *cfg = &timer_config[tim];
uint8_t scale = _get_prescaler(freq, sam0_gclk_freq(cfg->gclk_src));

View File

@ -75,7 +75,7 @@ static inline Tc *dev(tim_t tim)
* For each timer, channel 1 is used to implement a prescaler. Channel 1 is
* driven by the MCK / 2 (42MHz) (TIMER_CLOCK1).
*/
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/* check if device is valid */
if (tim >= TIMER_NUMOF) {

View File

@ -87,7 +87,7 @@ static inline bool is_oneshot(tim_t tim, int chan)
#endif /* MODULE_PERIPH_TIMER_PERIODIC */
int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg)
int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
{
/* check if device is valid */
if (tim >= TIMER_NUMOF) {

View File

@ -127,7 +127,7 @@ typedef struct {
* @return 0 on success
* @return -1 if speed not applicable or unknown device given
*/
int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg);
int timer_init(tim_t dev, uint32_t freq, timer_cb_t cb, void *arg);
/**
* @brief Set a given timer channel for the given timer device