From fc194cf2ecbcae5a522b0d61f2d1b40083f9b47c Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 24 Aug 2018 10:21:29 -0600 Subject: [PATCH] drivers/timers: Add a new method to the struct oneshot_operations_s interface to get the current time from a oneshot timer driver (if it is available from the lower half) --- drivers/timers/oneshot.c | 16 +++++++++++++++- include/nuttx/timers/oneshot.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/timers/oneshot.c b/drivers/timers/oneshot.c index 8de9a3ef32..ea80d26382 100644 --- a/drivers/timers/oneshot.c +++ b/drivers/timers/oneshot.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -306,6 +305,21 @@ static int oneshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + /* OSIOC_CURRENT - Get the current time + * Argument: A reference to a struct timespec in + * which the current time will be returned. + */ + + case OSIOC_CURRENT: + { + FAR struct timespec *ts = (FAR struct timespec *)((uintptr_t)arg); + + /* Get the current time */ + + ret = ONESHOT_CURRENT(priv->od_lower, ts); + } + break; + default: { tmrerr("ERROR: Unrecognized cmd: %d arg: %ld\n", cmd, arg); diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index 2fd001758e..2245286a2c 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -42,6 +42,7 @@ #include +#include #include #include @@ -68,6 +69,9 @@ * OSIOC_CANCEL - Stop the timer * Argument: A reference to a struct timespec in which * the time remaining will be returned. + * OSIOC_CURRENT - Get the current time + * Argument: A reference to a struct timespec in which + * the current time will be returned. * * NOTE: _TCIOC(0x0020) througn _TCIOC(0x003f) are reserved for use by the * oneshot driver to assure that the values are unique. Other timer drivers @@ -77,6 +81,7 @@ #define OSIOC_MAXDELAY _TCIOC(0x0020) #define OSIOC_START _TCIOC(0x0021) #define OSIOC_CANCEL _TCIOC(0x0022) +#define OSIOC_CURRENT _TCIOC(0x0023) /* Method access helper macros **********************************************/ @@ -148,6 +153,27 @@ #define ONESHOT_CANCEL(l,t) ((l)->ops->cancel(l,t)) +/**************************************************************************** + * Name: ONESHOT_CURRENT + * + * Description: + * Get the current time. + * + * Input Parameters: + * lower Caller allocated instance of the oneshot state structure. This + * structure must have been previously initialized via a call to + * oneshot_initialize(); + * ts The location in which to return the current time. A time of zero + * is returned for the initialization moment. + * + * Returned Value: + * Zero (OK) is returned on success, a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +#define ONESHOT_CURRENT(l,t) ((l)->ops->current ? (l)->ops->current(l,t) : -ENOSYS) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -175,6 +201,8 @@ struct oneshot_operations_s FAR const struct timespec *ts); CODE int (*cancel)(struct oneshot_lowerhalf_s *lower, FAR struct timespec *ts); + CODE int (*current)(struct oneshot_lowerhalf_s *lower, + FAR struct timespec *ts); }; /* This structure describes the state of the oneshot timer lower-half driver */