timer_lowerhalf: minor improvements

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko
2022-03-14 22:06:52 +01:00
committed by Xiang Xiao
parent b6bc460b2c
commit b04447d066
16 changed files with 56 additions and 85 deletions
+5 -5
View File
@@ -125,12 +125,12 @@ static int lpc43_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd,
static const struct timer_ops_s g_tmrops = static const struct timer_ops_s g_tmrops =
{ {
.start = lpc43_start, .start = lpc43_start,
.stop = lpc43_stop, .stop = lpc43_stop,
.getstatus = lpc43_getstatus, .getstatus = lpc43_getstatus,
.settimeout = lpc43_settimeout, .settimeout = lpc43_settimeout,
.setcallback = lpc43_setcallback, .setcallback = lpc43_setcallback,
.ioctl = lpc43_ioctl, .ioctl = lpc43_ioctl,
}; };
/* "Lower half" driver state */ /* "Lower half" driver state */
+1 -1
View File
@@ -503,7 +503,7 @@ static void sam_afec_dmastart(struct adc_dev_s *dev)
#ifdef CONFIG_SAMV7_AFEC_TIOATRIG #ifdef CONFIG_SAMV7_AFEC_TIOATRIG
static int sam_afec_settimer(struct samv7_dev_s *priv, uint32_t frequency, static int sam_afec_settimer(struct samv7_dev_s *priv, uint32_t frequency,
int channel) int channel)
{ {
uint32_t div; uint32_t div;
uint32_t tcclks; uint32_t tcclks;
-17
View File
@@ -287,23 +287,6 @@ uint16_t sam_tc_getcounter(TC_HANDLE handle);
void sam_tc_setblockmode(TC_HANDLE handle, uint32_t regval); 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 * Name: sam_tc_divfreq
* *
+3 -4
View File
@@ -137,7 +137,7 @@ typedef enum
STM32_TIM_CH_INCAPTURE = 0x10, STM32_TIM_CH_INCAPTURE = 0x10,
STM32_TIM_CH_INPWM = 0x20 STM32_TIM_CH_INPWM = 0x20
STM32_TIM_CH_DRIVE_OC -- open collector mode STM32_TIM_CH_DRIVE_OC /* -- open collector mode */
#endif #endif
} stm32_tim_channel_t; } stm32_tim_channel_t;
@@ -196,15 +196,14 @@ int stm32_tim_deinit(FAR struct stm32_tim_dev_s *dev);
* form /dev/timer0 * form /dev/timer0
* timer - the timer number. * timer - the timer number.
* *
* Returned Value: * Returned Values:
* Zero (OK) is returned on success; A negated errno value is returned * Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure. * to indicate the nature of any failure.
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_TIMER #ifdef CONFIG_TIMER
FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath, int stm32_timer_initialize(FAR const char *devpath, int timer);
int timer);
#endif #endif
#undef EXTERN #undef EXTERN
+5 -6
View File
@@ -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 stm32_timer_initialize(FAR const char *devpath, int timer)
int timer)
{ {
FAR struct stm32_lowerhalf_s *lower; FAR struct stm32_lowerhalf_s *lower;
@@ -553,7 +552,7 @@ FAR struct timer_lowerhalf_s *stm32_timer_initialize(FAR const char *devpath,
break; break;
#endif #endif
default: default:
return 0; return -ENODEV;
} }
/* Initialize the elements of lower half state structure */ /* 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) if (lower->tim == NULL)
{ {
return 0; return -EINVAL;
} }
/* Register the timer driver as /dev/timerX. The returned value from /* 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). * indicate the failure (implying the non-unique devpath).
*/ */
return 0; return -EEXIST;
} }
return (FAR struct timer_lowerhalf_s *)lower; return OK;
} }
#endif /* CONFIG_TIMER */ #endif /* CONFIG_TIMER */
+1 -1
View File
@@ -397,7 +397,7 @@ static int stm32l4_getstatus(FAR struct timer_lowerhalf_s *lower,
/* Get the time remaining until the timer expires (in microseconds) */ /* 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)) * status->timeleft = (timeout - STM32L4_TIM_GETCOUNTER(priv->tim)) *
clock_factor; clock_factor;
return OK; return OK;
+1 -1
View File
@@ -377,7 +377,7 @@ static int stm32l5_getstatus(FAR struct timer_lowerhalf_s *lower,
/* Get the time remaining until the timer expires (in microseconds) */ /* 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)) * status->timeleft = (timeout - STM32L5_TIM_GETCOUNTER(priv->tim)) *
clock_factor; clock_factor;
return OK; return OK;
+1 -1
View File
@@ -377,7 +377,7 @@ static int stm32_getstatus(FAR struct timer_lowerhalf_s *lower,
/* Get the time remaining until the timer expires (in microseconds) */ /* 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)) * status->timeleft = (timeout - STM32U5_TIM_GETCOUNTER(priv->tim)) *
clock_factor; clock_factor;
return OK; return OK;
@@ -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) static int pic32mz_timer_handler(int irq, FAR void *context, FAR void *arg)
{ {
FAR struct pic32mz_lowerhalf_s *lower = FAR struct pic32mz_lowerhalf_s *lower =
(struct pic32mz_lowerhalf_s *) arg; (FAR struct pic32mz_lowerhalf_s *)arg;
uint32_t next_interval_us = 0; uint32_t next_interval_us = 0;
PIC32MZ_TIMER_ACKINT(lower->timer); 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, static int pic32mz_ioctl(FAR struct timer_lowerhalf_s *lower, int cmd,
unsigned long arg) unsigned long arg)
{ {
int ret = -ENOTTY; 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, static int pic32mz_maxtimeout(FAR struct timer_lowerhalf_s *lower,
FAR uint32_t *maxtimeout) FAR uint32_t *maxtimeout)
{ {
FAR struct pic32mz_lowerhalf_s *priv = FAR struct pic32mz_lowerhalf_s *priv =
(FAR struct pic32mz_lowerhalf_s *)lower; (FAR struct pic32mz_lowerhalf_s *)lower;
+16 -25
View File
@@ -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_start(struct timer_lowerhalf_s *lower);
static int bl602_tim_stop(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, 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, 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, static void bl602_tim_setcallback(struct timer_lowerhalf_s *lower,
tccb_t callback, tccb_t callback, void *arg);
void * arg);
/**************************************************************************** /****************************************************************************
* Private Data * 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) static int bl602_timer_handler(int irq, void *context, void *arg)
{ {
struct bl602_tim_lowerhalf_s *priv = struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)arg;
(struct bl602_tim_lowerhalf_s *)arg;
uint32_t next_interval_us = 0; uint32_t next_interval_us = 0;
/* Clear Interrupt Bits */ /* Clear Interrupt Bits */
@@ -159,8 +157,8 @@ static int bl602_timer_handler(int irq, void *context, void *arg)
/* Set a value to the alarm */ /* Set a value to the alarm */
bl602_timer_disable(priv->tim); bl602_timer_disable(priv->tim);
bl602_timer_setcompvalue( bl602_timer_setcompvalue(priv->tim, TIMER_COMP_ID_0,
priv->tim, TIMER_COMP_ID_0, next_interval_us); next_interval_us);
bl602_timer_setpreloadvalue(priv->tim, 0); bl602_timer_setpreloadvalue(priv->tim, 0);
bl602_timer_enable(priv->tim); 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) static int bl602_tim_start(struct timer_lowerhalf_s *lower)
{ {
struct bl602_tim_lowerhalf_s *priv = struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower;
(struct bl602_tim_lowerhalf_s *)lower;
if (!priv->started) 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) static int bl602_tim_stop(struct timer_lowerhalf_s *lower)
{ {
struct bl602_tim_lowerhalf_s *priv = struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower;
(struct bl602_tim_lowerhalf_s *)lower;
/* timer disable */ /* 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, 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 *priv = (struct bl602_tim_lowerhalf_s *)lower;
(struct bl602_tim_lowerhalf_s *)lower;
uint32_t current_count; uint32_t current_count;
status->timeout = bl602_timer_getcompvalue(priv->tim, TIMER_COMP_ID_0); 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, 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 *priv = (struct bl602_tim_lowerhalf_s *)lower;
(struct bl602_tim_lowerhalf_s *)lower;
bl602_timer_setcompvalue(priv->tim, TIMER_COMP_ID_0, timeout); 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, static void bl602_tim_setcallback(struct timer_lowerhalf_s *lower,
tccb_t callback, tccb_t callback, void *arg)
void * arg)
{ {
struct bl602_tim_lowerhalf_s *priv = struct bl602_tim_lowerhalf_s *priv = (struct bl602_tim_lowerhalf_s *)lower;
(struct bl602_tim_lowerhalf_s *)lower;
irqstate_t flags = enter_critical_section(); irqstate_t flags = enter_critical_section();
/* Save the new callback */ /* 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) int bl602_timer_initialize(const char *devpath, int timer)
{ {
struct bl602_tim_lowerhalf_s *lower; struct bl602_tim_lowerhalf_s *lower;
struct timer_cfg_s timstr; struct timer_cfg_s timstr;
switch (timer) switch (timer)
{ {
@@ -442,8 +434,7 @@ int bl602_timer_initialize(const char *devpath, int timer)
* REVISIT: The returned handle is discard here. * REVISIT: The returned handle is discard here.
*/ */
void *drvr = void *drvr = timer_register(devpath, (struct timer_lowerhalf_s *)lower);
timer_register(devpath, (struct timer_lowerhalf_s *)lower);
if (drvr == NULL) if (drvr == NULL)
{ {
/* The actual cause of the failure may have been a failure to allocate /* The actual cause of the failure may have been a failure to allocate
@@ -27,7 +27,6 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include "bl602_tim_lowerhalf.h"
#include "bl602_tim.h" #include "bl602_tim.h"
/**************************************************************************** /****************************************************************************
+1 -1
View File
@@ -291,7 +291,7 @@ static int bm3803_getstatus(FAR struct timer_lowerhalf_s *lower,
/* Get the time remaining until the timer expires (in microseconds) */ /* 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)) * status->timeleft = (timeout - BM3803_TIM_GETCOUNTER(priv->tim)) *
clock_factor; clock_factor;
return OK; return OK;
+2 -2
View File
@@ -97,8 +97,8 @@ static const struct timer_ops_s g_esp32_timer_ops =
.getstatus = esp32_timer_getstatus, .getstatus = esp32_timer_getstatus,
.settimeout = esp32_timer_settimeout, .settimeout = esp32_timer_settimeout,
.setcallback = esp32_timer_setcallback, .setcallback = esp32_timer_setcallback,
.maxtimeout = esp32_timer_maxtimeout,
.ioctl = NULL, .ioctl = NULL,
.maxtimeout = esp32_timer_maxtimeout
}; };
#ifdef CONFIG_ESP32_TIMER0 #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 */ /* 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); ret = ESP32_TIM_SETISR(priv->tim, esp32_timer_handler, priv);
ESP32_TIM_ENABLEINT(priv->tim); ESP32_TIM_ENABLEINT(priv->tim);
@@ -91,8 +91,8 @@ static const struct timer_ops_s g_esp32s2_timer_ops =
.getstatus = esp32s2_timer_getstatus, .getstatus = esp32s2_timer_getstatus,
.settimeout = esp32s2_timer_settimeout, .settimeout = esp32s2_timer_settimeout,
.setcallback = esp32s2_timer_setcallback, .setcallback = esp32s2_timer_setcallback,
.maxtimeout = esp32s2_timer_maxtimeout,
.ioctl = NULL, .ioctl = NULL,
.maxtimeout = esp32s2_timer_maxtimeout
}; };
#ifdef CONFIG_ESP32S2_TIMER0 #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 */ /* 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); ret = ESP32S2_TIM_SETISR(priv->tim, esp32s2_timer_handler, priv);
ESP32S2_TIM_ENABLEINT(priv->tim); ESP32S2_TIM_ENABLEINT(priv->tim);
@@ -98,8 +98,8 @@ static const struct timer_ops_s g_esp32s3_timer_ops =
.getstatus = timer_lh_getstatus, .getstatus = timer_lh_getstatus,
.settimeout = timer_lh_settimeout, .settimeout = timer_lh_settimeout,
.setcallback = timer_lh_setcallback, .setcallback = timer_lh_setcallback,
.maxtimeout = timer_lh_maxtimeout,
.ioctl = NULL, .ioctl = NULL,
.maxtimeout = timer_lh_maxtimeout
}; };
#if defined(CONFIG_ESP32S3_TIMER0) #if defined(CONFIG_ESP32S3_TIMER0)
@@ -49,7 +49,7 @@
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_TIMER #ifdef CONFIG_TIMER
int stm32l4_timer_driver_setup(void) int stm32l4_timer_driver_setup(void)
{ {
int ret = OK; int ret = OK;
@@ -59,7 +59,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM1 at /dev/timer0: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM1 at /dev/timer0: %d\n",
ret); ret);
} }
#endif #endif
@@ -68,7 +68,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer1: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer1: %d\n",
ret); ret);
} }
#endif #endif
@@ -77,7 +77,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM3 at /dev/timer2: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM3 at /dev/timer2: %d\n",
ret); ret);
} }
#endif #endif
@@ -86,7 +86,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer3: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM2 at /dev/timer3: %d\n",
ret); ret);
} }
#endif #endif
@@ -95,7 +95,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM5 at /dev/timer4: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM5 at /dev/timer4: %d\n",
ret); ret);
} }
#endif #endif
@@ -104,7 +104,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM6 at /dev/timer5: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM6 at /dev/timer5: %d\n",
ret); ret);
} }
#endif #endif
@@ -113,7 +113,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM7 at /dev/timer6: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM7 at /dev/timer6: %d\n",
ret); ret);
} }
#endif #endif
@@ -122,7 +122,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM8 at /dev/timer7: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM8 at /dev/timer7: %d\n",
ret); ret);
} }
#endif #endif
@@ -131,7 +131,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM15 at /dev/time8: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM15 at /dev/time8: %d\n",
ret); ret);
} }
#endif #endif
@@ -140,7 +140,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM16 at /dev/time9: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM16 at /dev/time9: %d\n",
ret); ret);
} }
#endif #endif
@@ -149,7 +149,7 @@ int stm32l4_timer_driver_setup(void)
if (ret < 0) if (ret < 0)
{ {
syslog(LOG_ERR, "ERROR: Failed to setup TIM17 at /dev/time10: %d\n", syslog(LOG_ERR, "ERROR: Failed to setup TIM17 at /dev/time10: %d\n",
ret); ret);
} }
#endif #endif