mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
timer_lowerhalf: minor improvements
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
committed by
Xiang Xiao
parent
b6bc460b2c
commit
b04447d066
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -78,8 +78,7 @@ static int bl602_tim_getstatus(struct timer_lowerhalf_s *lower,
|
||||
static int bl602_tim_settimeout(struct timer_lowerhalf_s *lower,
|
||||
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 */
|
||||
|
||||
@@ -285,8 +281,7 @@ 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 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);
|
||||
@@ -322,8 +317,7 @@ static int bl602_tim_getstatus(struct timer_lowerhalf_s *lower,
|
||||
static int bl602_tim_settimeout(struct timer_lowerhalf_s *lower,
|
||||
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 */
|
||||
@@ -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"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user