diff --git a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c index 9221a5a397..67e743d17a 100644 --- a/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c +++ b/arch/arm/src/sam34/sam4cm_oneshot_lowerhalf.c @@ -80,7 +80,7 @@ struct sam_oneshot_lowerhalf_s static void sam_oneshot_handler(void *arg); static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); static int sam_start(FAR struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts); @@ -159,8 +159,7 @@ static void sam_oneshot_handler(void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -169,13 +168,25 @@ static void sam_oneshot_handler(void *arg) ****************************************************************************/ static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec) + FAR struct timespec *ts) { FAR struct sam_oneshot_lowerhalf_s *priv = (FAR struct sam_oneshot_lowerhalf_s *)lower; + uint64_t usecs; + int ret; - DEBUGASSERT(priv != NULL && usec != NULL); - return sam_oneshot_max_delay(&priv->oneshot, usec); + DEBUGASSERT(priv != NULL && ts != NULL); + ret = sam_oneshot_max_delay(&priv->oneshot, &usecs); + if (ret >= 0) + { + uint64_t sec = usecs / 1000000; + usecs -= 1000000 * sec; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (long)(usecs * 1000); + } + + return ret; } /**************************************************************************** diff --git a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c index 48cecdcca6..e6aa2e40a7 100644 --- a/arch/arm/src/sama5/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/sama5/sam_oneshot_lowerhalf.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -81,7 +82,7 @@ struct sam_oneshot_lowerhalf_s static void sam_oneshot_handler(void *arg); static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); static int sam_start(FAR struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts); @@ -160,8 +161,7 @@ static void sam_oneshot_handler(void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -170,12 +170,13 @@ static void sam_oneshot_handler(void *arg) ****************************************************************************/ static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec) + FAR struct timespec *ts) { - DEBUGASSERT(priv != NULL && usec != NULL); + DEBUGASSERT(priv != NULL && ts != NULL); #warning Missing logic - *usec = UINT64_MAX; + ts->tv_sec = INT_MAX; + ts->tv_nsec = LONG_MAX; return -ENOSYS; } diff --git a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c index 0d5b4e75c5..b4ffbdd361 100644 --- a/arch/arm/src/samv7/sam_oneshot_lowerhalf.c +++ b/arch/arm/src/samv7/sam_oneshot_lowerhalf.c @@ -80,7 +80,7 @@ struct sam_oneshot_lowerhalf_s static void sam_oneshot_handler(void *arg); static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); static int sam_start(FAR struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts); @@ -159,8 +159,7 @@ static void sam_oneshot_handler(void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -169,13 +168,25 @@ static void sam_oneshot_handler(void *arg) ****************************************************************************/ static int sam_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec) + FAR struct timespec *ts) { FAR struct sam_oneshot_lowerhalf_s *priv = (FAR struct sam_oneshot_lowerhalf_s *)lower; + uint64_t usecs; + int ret; - DEBUGASSERT(priv != NULL && usec != NULL); - return sam_oneshot_max_delay(&priv->oneshot, usec); + DEBUGASSERT(priv != NULL && ts != NULL); + ret = sam_oneshot_max_delay(&priv->oneshot, &usecs); + if (ret >= 0) + { + uint64_t sec = usecs / 1000000; + usecs -= 1000000 * sec; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (long)(usecs * 1000); + } + + return ret; } /**************************************************************************** diff --git a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c index aee56316c5..24b36de555 100644 --- a/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32/stm32_oneshot_lowerhalf.c @@ -80,7 +80,7 @@ struct stm32_oneshot_lowerhalf_s static void stm32_oneshot_handler(void *arg); static int stm32_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); static int stm32_start(FAR struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts); @@ -159,8 +159,7 @@ static void stm32_oneshot_handler(void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -169,13 +168,25 @@ static void stm32_oneshot_handler(void *arg) ****************************************************************************/ static int stm32_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec) + FAR struct timespec *ts) { FAR struct stm32_oneshot_lowerhalf_s *priv = (FAR struct stm32_oneshot_lowerhalf_s *)lower; + uint64_t usecs; + int ret; - DEBUGASSERT(priv != NULL && usec != NULL); - return stm32_oneshot_max_delay(&priv->oneshot, usec); + DEBUGASSERT(priv != NULL && ts != NULL); + ret = stm32_oneshot_max_delay(&priv->oneshot, &usecs); + if (ret >= 0) + { + uint64_t sec = usecs / 1000000; + usecs -= 1000000 * sec; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (long)(usecs * 1000); + } + + return ret; } /**************************************************************************** diff --git a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c index 0db6af09d5..faf6afd5f5 100644 --- a/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c +++ b/arch/arm/src/stm32l4/stm32l4_oneshot_lowerhalf.c @@ -80,12 +80,12 @@ struct stm32l4_oneshot_lowerhalf_s static void stm32l4_oneshot_handler(void *arg); static int stm32l4_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); static int stm32l4_start(FAR struct oneshot_lowerhalf_s *lower, - oneshot_callback_t callback, FAR void *arg, - FAR const struct timespec *ts); + oneshot_callback_t callback, FAR void *arg, + FAR const struct timespec *ts); static int stm32l4_cancel(FAR struct oneshot_lowerhalf_s *lower, - FAR struct timespec *ts); + FAR struct timespec *ts); /**************************************************************************** * Private Data @@ -159,8 +159,7 @@ static void stm32l4_oneshot_handler(void *arg) * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -169,13 +168,25 @@ static void stm32l4_oneshot_handler(void *arg) ****************************************************************************/ static int stm32l4_max_delay(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec) + FAR struct timespec *ts) { FAR struct stm32l4_oneshot_lowerhalf_s *priv = (FAR struct stm32l4_oneshot_lowerhalf_s *)lower; + uint64_t usecs; + int ret; - DEBUGASSERT(priv != NULL && usec != NULL); - return stm32l4_oneshot_max_delay(&priv->oneshot, usec); + DEBUGASSERT(priv != NULL && ts != NULL); + ret = stm32l4_oneshot_max_delay(&priv->oneshot, &usecs); + if (ret >= 0) + { + uint64_t sec = usecs / 1000000; + usecs -= 1000000 * sec; + + ts->tv_sec = (time_t)sec; + ts->tv_nsec = (long)(usecs * 1000); + } + + return ret; } /**************************************************************************** diff --git a/drivers/timers/oneshot.c b/drivers/timers/oneshot.c index 5ff65edf62..975f83bba2 100644 --- a/drivers/timers/oneshot.c +++ b/drivers/timers/oneshot.c @@ -188,6 +188,7 @@ static ssize_t oneshot_read(FAR struct file *filep, FAR char *buffer, size_t buf /* Return zero -- usually meaning end-of-file */ tmrinfo("buflen=%ld\n", (unsigned long)buflen); + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); return 0; } @@ -205,6 +206,7 @@ static ssize_t oneshot_write(FAR struct file *filep, FAR const char *buffer, /* Return a failure */ tmrinfo("buflen=%ld\n", (unsigned long)buflen); + DEBUGASSERT(filep != NULL && filep->f_inode != NULL); return -EPERM; } @@ -250,21 +252,10 @@ static int oneshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case OSIOC_MAXDELAY: { - FAR struct timespec *ts; - uint64_t usecs; - - ts = (FAR struct timespec *)((uintptr_t)arg); + FAR struct timespec *ts = (FAR struct timespec *)((uintptr_t)arg); DEBUGASSERT(ts != NULL); - ret = ONESHOT_MAX_DELAY(priv->od_lower, &usecs); - if (ret >= 0) - { - uint64_t sec = usecs / 1000000; - usecs -= 1000000 * sec; - - ts->tv_sec = (time_t)sec; - ts->tv_nsec = (long)(usecs * 1000); - } + ret = ONESHOT_MAX_DELAY(priv->od_lower, ts); } break; diff --git a/include/nuttx/timers/oneshot.h b/include/nuttx/timers/oneshot.h index 31bd34d73f..2fd001758e 100644 --- a/include/nuttx/timers/oneshot.h +++ b/include/nuttx/timers/oneshot.h @@ -90,8 +90,7 @@ * lower An instance of the lower-half oneshot state structure. This * structure must have been previously initialized via a call to * oneshot_initialize(); - * usec The user-provided location in which to return the maxumum delay - * in microseconds. + * ts The location in which to return the maxumum delay. * * Returned Value: * Zero (OK) is returned on success; a negated errno value is returned @@ -99,7 +98,7 @@ * ****************************************************************************/ -#define ONESHOT_MAX_DELAY(l,u) ((l)->ops->max_delay(l,u)) +#define ONESHOT_MAX_DELAY(l,t) ((l)->ops->max_delay(l,t)) /**************************************************************************** * Name: ONESHOT_START @@ -170,7 +169,7 @@ struct timespec; struct oneshot_operations_s { CODE int (*max_delay)(FAR struct oneshot_lowerhalf_s *lower, - FAR uint64_t *usec); + FAR struct timespec *ts); CODE int (*start)(FAR struct oneshot_lowerhalf_s *lower, oneshot_callback_t callback, FAR void *arg, FAR const struct timespec *ts);