From b04447d0661eadebb8bcbd09cde5404d48f0575c Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Mon, 14 Mar 2022 22:06:52 +0100 Subject: [PATCH] timer_lowerhalf: minor improvements Signed-off-by: Petro Karashchenko --- arch/arm/src/lpc43xx/lpc43_timer.c | 10 ++--- arch/arm/src/samv7/sam_afec.c | 2 +- arch/arm/src/samv7/sam_tc.h | 17 -------- arch/arm/src/stm32f7/stm32_tim.h | 7 ++-- arch/arm/src/stm32f7/stm32_tim_lowerhalf.c | 11 +++-- arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c | 2 +- arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c | 2 +- arch/arm/src/stm32u5/stm32_tim_lowerhalf.c | 2 +- .../src/pic32mz/pic32mz_timer_lowerhalf.c | 10 ++--- arch/risc-v/src/bl602/bl602_tim_lowerhalf.c | 41 ++++++++----------- arch/risc-v/src/bl602/bl602_tim_lowerhalf.h | 1 - arch/sparc/src/bm3803/bm3803_tim_lowerhalf.c | 2 +- arch/xtensa/src/esp32/esp32_tim_lowerhalf.c | 4 +- .../src/esp32s2/esp32s2_tim_lowerhalf.c | 4 +- .../src/esp32s3/esp32s3_tim_lowerhalf.c | 2 +- .../stm32l4/b-l475e-iot01a/src/stm32_timer.c | 24 +++++------ 16 files changed, 56 insertions(+), 85 deletions(-) diff --git a/arch/arm/src/lpc43xx/lpc43_timer.c b/arch/arm/src/lpc43xx/lpc43_timer.c index 50e7a96cb4..e1471942c9 100644 --- a/arch/arm/src/lpc43xx/lpc43_timer.c +++ b/arch/arm/src/lpc43xx/lpc43_timer.c @@ -125,12 +125,12 @@ static int lpc43_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd, static const struct timer_ops_s g_tmrops = { - .start = lpc43_start, - .stop = lpc43_stop, - .getstatus = lpc43_getstatus, - .settimeout = lpc43_settimeout, + .start = lpc43_start, + .stop = lpc43_stop, + .getstatus = lpc43_getstatus, + .settimeout = lpc43_settimeout, .setcallback = lpc43_setcallback, - .ioctl = lpc43_ioctl, + .ioctl = lpc43_ioctl, }; /* "Lower half" driver state */ diff --git a/arch/arm/src/samv7/sam_afec.c b/arch/arm/src/samv7/sam_afec.c index 9dad543121..d568a6dc7a 100644 --- a/arch/arm/src/samv7/sam_afec.c +++ b/arch/arm/src/samv7/sam_afec.c @@ -503,7 +503,7 @@ static void sam_afec_dmastart(struct adc_dev_s *dev) #ifdef CONFIG_SAMV7_AFEC_TIOATRIG static int sam_afec_settimer(struct samv7_dev_s *priv, uint32_t frequency, - int channel) + int channel) { uint32_t div; uint32_t tcclks; diff --git a/arch/arm/src/samv7/sam_tc.h b/arch/arm/src/samv7/sam_tc.h index 1b13d74059..9ffb69fbb2 100644 --- a/arch/arm/src/samv7/sam_tc.h +++ b/arch/arm/src/samv7/sam_tc.h @@ -287,23 +287,6 @@ uint16_t sam_tc_getcounter(TC_HANDLE handle); void sam_tc_setblockmode(TC_HANDLE handle, uint32_t regval); -/**************************************************************************** - * Name: sam_tc_infreq - * - * Description: - * Return the timer input frequency, that is, the MCK frequency divided - * down so that the timer/counter is driven within its maximum frequency. - * - * Input Parameters: - * None - * - * Returned Value: - * The timer input frequency. - * - ****************************************************************************/ - -uint32_t sam_tc_infreq(void); - /**************************************************************************** * Name: sam_tc_divfreq * diff --git a/arch/arm/src/stm32f7/stm32_tim.h b/arch/arm/src/stm32f7/stm32_tim.h index 7ac33061ee..45c4b8ee25 100644 --- a/arch/arm/src/stm32f7/stm32_tim.h +++ b/arch/arm/src/stm32f7/stm32_tim.h @@ -137,7 +137,7 @@ typedef enum STM32_TIM_CH_INCAPTURE = 0x10, STM32_TIM_CH_INPWM = 0x20 - STM32_TIM_CH_DRIVE_OC -- open collector mode + STM32_TIM_CH_DRIVE_OC /* -- open collector mode */ #endif } stm32_tim_channel_t; @@ -196,15 +196,14 @@ int stm32_tim_deinit(FAR struct stm32_tim_dev_s *dev); * form /dev/timer0 * timer - the timer number. * - * Returned Value: + * Returned Values: * Zero (OK) is returned on success; A negated errno value is returned * to indicate the nature of any failure. * ****************************************************************************/ #ifdef CONFIG_TIMER -FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, - int timer); +int stm32_timer_initialize(FAR const char *devpath, int timer); #endif #undef EXTERN diff --git a/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c b/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c index 0d1971802a..a0573b277d 100644 --- a/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c +++ b/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c @@ -475,8 +475,7 @@ static void stm32_setcallback(FAR struct timer_lowerhalf_s *lower, * ****************************************************************************/ -FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, - int timer) +int stm32_timer_initialize(FAR const char *devpath, int timer) { FAR struct stm32_lowerhalf_s *lower; @@ -553,7 +552,7 @@ FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, break; #endif default: - return 0; + return -ENODEV; } /* Initialize the elements of lower half state structure */ @@ -564,7 +563,7 @@ FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, if (lower->tim == NULL) { - return 0; + return -EINVAL; } /* Register the timer driver as /dev/timerX. The returned value from @@ -582,10 +581,10 @@ FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, * indicate the failure (implying the non-unique devpath). */ - return 0; + return -EEXIST; } - return (FAR struct timer_lowerhalf_s *)lower; + return OK; } #endif /* CONFIG_TIMER */ diff --git a/arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c b/arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c index e31ee5d085..8f55c14a6b 100644 --- a/arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c +++ b/arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c @@ -397,7 +397,7 @@ static int stm32l4_getstatus(FAR struct timer_lowerhalf_s *lower, /* Get the time remaining until the timer expires (in microseconds) */ - clock_factor = (clock == 1000000)? 1: (clock / 1000000); + clock_factor = (clock == 1000000) ? 1 : (clock / 1000000); status->timeleft = (timeout - STM32L4_TIM_GETCOUNTER(priv->tim)) * clock_factor; return OK; diff --git a/arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c b/arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c index 2d4a1550a2..eae5f171f1 100644 --- a/arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c +++ b/arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c @@ -377,7 +377,7 @@ static int stm32l5_getstatus(FAR struct timer_lowerhalf_s *lower, /* Get the time remaining until the timer expires (in microseconds) */ - clock_factor = (clock == 1000000)? 1: (clock / 1000000); + clock_factor = (clock == 1000000) ? 1 : (clock / 1000000); status->timeleft = (timeout - STM32L5_TIM_GETCOUNTER(priv->tim)) * clock_factor; return OK; diff --git a/arch/arm/src/stm32u5/stm32_tim_lowerhalf.c b/arch/arm/src/stm32u5/stm32_tim_lowerhalf.c index d3abed4b83..cbfd674bc0 100644 --- a/arch/arm/src/stm32u5/stm32_tim_lowerhalf.c +++ b/arch/arm/src/stm32u5/stm32_tim_lowerhalf.c @@ -377,7 +377,7 @@ static int stm32_getstatus(FAR struct timer_lowerhalf_s *lower, /* Get the time remaining until the timer expires (in microseconds) */ - clock_factor = (clock == 1000000)? 1: (clock / 1000000); + clock_factor = (clock == 1000000) ? 1 : (clock / 1000000); status->timeleft = (timeout - STM32U5_TIM_GETCOUNTER(priv->tim)) * clock_factor; return OK; diff --git a/arch/mips/src/pic32mz/pic32mz_timer_lowerhalf.c b/arch/mips/src/pic32mz/pic32mz_timer_lowerhalf.c index 29405a7d51..ce9913bc1d 100644 --- a/arch/mips/src/pic32mz/pic32mz_timer_lowerhalf.c +++ b/arch/mips/src/pic32mz/pic32mz_timer_lowerhalf.c @@ -251,7 +251,7 @@ static uint32_t pic32mz_ticks2usec(FAR struct pic32mz_lowerhalf_s *priv, static int pic32mz_timer_handler(int irq, FAR void *context, FAR void *arg) { FAR struct pic32mz_lowerhalf_s *lower = - (struct pic32mz_lowerhalf_s *) arg; + (FAR struct pic32mz_lowerhalf_s *)arg; uint32_t next_interval_us = 0; PIC32MZ_TIMER_ACKINT(lower->timer); @@ -530,8 +530,8 @@ static void pic32mz_setcallback(FAR struct timer_lowerhalf_s *lower, * ****************************************************************************/ -static int pic32mz_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd, - unsigned long arg) +static int pic32mz_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd, + unsigned long arg) { int ret = -ENOTTY; @@ -557,8 +557,8 @@ static int pic32mz_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd, * ****************************************************************************/ -static int pic32mz_maxtimeout(FAR struct timer_lowerhalf_s *lower, - FAR uint32_t *maxtimeout) +static int pic32mz_maxtimeout(FAR struct timer_lowerhalf_s *lower, + FAR uint32_t *maxtimeout) { FAR struct pic32mz_lowerhalf_s *priv = (FAR struct pic32mz_lowerhalf_s *)lower; diff --git a/arch/risc-v/src/bl602/bl602_tim_lowerhalf.c b/arch/risc-v/src/bl602/bl602_tim_lowerhalf.c index 89a0a18a04..af2d5ac2ff 100644 --- a/arch/risc-v/src/bl602/bl602_tim_lowerhalf.c +++ b/arch/risc-v/src/bl602/bl602_tim_lowerhalf.c @@ -74,12 +74,11 @@ static int bl602_timer_handler(int irq, void *context, void *arg); static int bl602_tim_start(struct timer_lowerhalf_s *lower); static int bl602_tim_stop(struct timer_lowerhalf_s *lower); static int bl602_tim_getstatus(struct timer_lowerhalf_s *lower, - struct timer_status_s * status); + struct timer_status_s *status); static int bl602_tim_settimeout(struct timer_lowerhalf_s *lower, - uint32_t timeout); + uint32_t timeout); static void bl602_tim_setcallback(struct timer_lowerhalf_s *lower, - tccb_t callback, - void * arg); + tccb_t callback, void *arg); /**************************************************************************** * Private Data @@ -133,8 +132,7 @@ static struct bl602_tim_lowerhalf_s g_tim2_lowerhalf = static int bl602_timer_handler(int irq, void *context, void *arg) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)arg; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)arg; uint32_t next_interval_us = 0; /* Clear Interrupt Bits */ @@ -159,8 +157,8 @@ static int bl602_timer_handler(int irq, void *context, void *arg) /* Set a value to the alarm */ bl602_timer_disable(priv->tim); - bl602_timer_setcompvalue( - priv->tim, TIMER_COMP_ID_0, next_interval_us); + bl602_timer_setcompvalue(priv->tim, TIMER_COMP_ID_0, + next_interval_us); bl602_timer_setpreloadvalue(priv->tim, 0); bl602_timer_enable(priv->tim); } @@ -206,8 +204,7 @@ static int bl602_timer_handler(int irq, void *context, void *arg) static int bl602_tim_start(struct timer_lowerhalf_s *lower) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)lower; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower; if (!priv->started) { @@ -247,8 +244,7 @@ static int bl602_tim_start(struct timer_lowerhalf_s *lower) static int bl602_tim_stop(struct timer_lowerhalf_s *lower) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)lower; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower; /* timer disable */ @@ -283,10 +279,9 @@ static int bl602_tim_stop(struct timer_lowerhalf_s *lower) ****************************************************************************/ static int bl602_tim_getstatus(struct timer_lowerhalf_s *lower, - struct timer_status_s * status) + struct timer_status_s *status) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)lower; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower; uint32_t current_count; status->timeout = bl602_timer_getcompvalue(priv->tim, TIMER_COMP_ID_0); @@ -320,10 +315,9 @@ static int bl602_tim_getstatus(struct timer_lowerhalf_s *lower, ****************************************************************************/ static int bl602_tim_settimeout(struct timer_lowerhalf_s *lower, - uint32_t timeout) + uint32_t timeout) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)lower; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower; bl602_timer_setcompvalue(priv->tim, TIMER_COMP_ID_0, timeout); @@ -351,11 +345,9 @@ static int bl602_tim_settimeout(struct timer_lowerhalf_s *lower, ****************************************************************************/ static void bl602_tim_setcallback(struct timer_lowerhalf_s *lower, - tccb_t callback, - void * arg) + tccb_t callback, void *arg) { - struct bl602_tim_lowerhalf_s *priv = - (struct bl602_tim_lowerhalf_s *)lower; + struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower; irqstate_t flags = enter_critical_section(); /* Save the new callback */ @@ -391,7 +383,7 @@ static void bl602_tim_setcallback(struct timer_lowerhalf_s *lower, int bl602_timer_initialize(const char *devpath, int timer) { struct bl602_tim_lowerhalf_s *lower; - struct timer_cfg_s timstr; + struct timer_cfg_s timstr; switch (timer) { @@ -442,8 +434,7 @@ int bl602_timer_initialize(const char *devpath, int timer) * REVISIT: The returned handle is discard here. */ - void *drvr = - timer_register(devpath, (struct timer_lowerhalf_s *)lower); + void *drvr = timer_register(devpath, (struct timer_lowerhalf_s *)lower); if (drvr == NULL) { /* The actual cause of the failure may have been a failure to allocate diff --git a/arch/risc-v/src/bl602/bl602_tim_lowerhalf.h b/arch/risc-v/src/bl602/bl602_tim_lowerhalf.h index 6a6c476d76..932d744bc5 100644 --- a/arch/risc-v/src/bl602/bl602_tim_lowerhalf.h +++ b/arch/risc-v/src/bl602/bl602_tim_lowerhalf.h @@ -27,7 +27,6 @@ #include -#include "bl602_tim_lowerhalf.h" #include "bl602_tim.h" /**************************************************************************** diff --git a/arch/sparc/src/bm3803/bm3803_tim_lowerhalf.c b/arch/sparc/src/bm3803/bm3803_tim_lowerhalf.c index 9a256c6d1a..2047f7be5d 100644 --- a/arch/sparc/src/bm3803/bm3803_tim_lowerhalf.c +++ b/arch/sparc/src/bm3803/bm3803_tim_lowerhalf.c @@ -291,7 +291,7 @@ static int bm3803_getstatus(FAR struct timer_lowerhalf_s *lower, /* Get the time remaining until the timer expires (in microseconds) */ - clock_factor = (clock == 1000000)? 1: (clock / 1000000); + clock_factor = (clock == 1000000) ? 1 : (clock / 1000000); status->timeleft = (timeout - BM3803_TIM_GETCOUNTER(priv->tim)) * clock_factor; return OK; diff --git a/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c b/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c index 0506b33bc0..75d1bc3f49 100644 --- a/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_tim_lowerhalf.c @@ -97,8 +97,8 @@ static const struct timer_ops_s g_esp32_timer_ops = .getstatus = esp32_timer_getstatus, .settimeout = esp32_timer_settimeout, .setcallback = esp32_timer_setcallback, - .maxtimeout = esp32_timer_maxtimeout, .ioctl = NULL, + .maxtimeout = esp32_timer_maxtimeout }; #ifdef CONFIG_ESP32_TIMER0 @@ -477,7 +477,7 @@ static void esp32_timer_setcallback(struct timer_lowerhalf_s *lower, /* There is a user callback and the timer has already been started */ - if (callback != NULL && priv->started == true) + if (callback != NULL && priv->started) { ret = ESP32_TIM_SETISR(priv->tim, esp32_timer_handler, priv); ESP32_TIM_ENABLEINT(priv->tim); diff --git a/arch/xtensa/src/esp32s2/esp32s2_tim_lowerhalf.c b/arch/xtensa/src/esp32s2/esp32s2_tim_lowerhalf.c index 2c83d90bea..b481c783aa 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_tim_lowerhalf.c +++ b/arch/xtensa/src/esp32s2/esp32s2_tim_lowerhalf.c @@ -91,8 +91,8 @@ static const struct timer_ops_s g_esp32s2_timer_ops = .getstatus = esp32s2_timer_getstatus, .settimeout = esp32s2_timer_settimeout, .setcallback = esp32s2_timer_setcallback, - .maxtimeout = esp32s2_timer_maxtimeout, .ioctl = NULL, + .maxtimeout = esp32s2_timer_maxtimeout }; #ifdef CONFIG_ESP32S2_TIMER0 @@ -471,7 +471,7 @@ static void esp32s2_timer_setcallback(struct timer_lowerhalf_s *lower, /* There is a user callback and the timer has already been started */ - if (callback != NULL && priv->started == true) + if (callback != NULL && priv->started) { ret = ESP32S2_TIM_SETISR(priv->tim, esp32s2_timer_handler, priv); ESP32S2_TIM_ENABLEINT(priv->tim); diff --git a/arch/xtensa/src/esp32s3/esp32s3_tim_lowerhalf.c b/arch/xtensa/src/esp32s3/esp32s3_tim_lowerhalf.c index 1c2e6521cb..06470efb65 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_tim_lowerhalf.c +++ b/arch/xtensa/src/esp32s3/esp32s3_tim_lowerhalf.c @@ -98,8 +98,8 @@ static const struct timer_ops_s g_esp32s3_timer_ops = .getstatus = timer_lh_getstatus, .settimeout = timer_lh_settimeout, .setcallback = timer_lh_setcallback, - .maxtimeout = timer_lh_maxtimeout, .ioctl = NULL, + .maxtimeout = timer_lh_maxtimeout }; #if defined(CONFIG_ESP32S3_TIMER0) diff --git a/boards/arm/stm32l4/b-l475e-iot01a/src/stm32_timer.c b/boards/arm/stm32l4/b-l475e-iot01a/src/stm32_timer.c index bea6bd1a32..1786c30ebd 100644 --- a/boards/arm/stm32l4/b-l475e-iot01a/src/stm32_timer.c +++ b/boards/arm/stm32l4/b-l475e-iot01a/src/stm32_timer.c @@ -49,7 +49,7 @@ * ****************************************************************************/ - #ifdef CONFIG_TIMER +#ifdef CONFIG_TIMER int stm32l4_timer_driver_setup(void) { int ret = OK; @@ -59,7 +59,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM1 at /dev/timer0: %d\n", - ret); + ret); } #endif @@ -68,7 +68,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer1: %d\n", - ret); + ret); } #endif @@ -77,7 +77,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM3 at /dev/timer2: %d\n", - ret); + ret); } #endif @@ -86,7 +86,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer3: %d\n", - ret); + ret); } #endif @@ -95,7 +95,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM5 at /dev/timer4: %d\n", - ret); + ret); } #endif @@ -104,7 +104,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM6 at /dev/timer5: %d\n", - ret); + ret); } #endif @@ -113,7 +113,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM7 at /dev/timer6: %d\n", - ret); + ret); } #endif @@ -122,7 +122,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM8 at /dev/timer7: %d\n", - ret); + ret); } #endif @@ -131,7 +131,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM15 at /dev/time8: %d\n", - ret); + ret); } #endif @@ -140,7 +140,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM16 at /dev/time9: %d\n", - ret); + ret); } #endif @@ -149,7 +149,7 @@ int stm32l4_timer_driver_setup(void) if (ret < 0) { syslog(LOG_ERR, "ERROR: Failed to setup TIM17 at /dev/time10: %d\n", - ret); + ret); } #endif