timer_lowerhalf: minor improvements
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
b6bc460b2c
commit
b04447d066
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include "bl602_tim_lowerhalf.h"
|
||||
#include "bl602_tim.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user