oneshot interface: max_delay method should return time in a standard struct timespec form.

This commit is contained in:
Gregory Nutt 2016-08-12 11:33:10 -06:00
parent 89135c55e4
commit 82b86cdcf3
7 changed files with 85 additions and 50 deletions

View File

@ -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;
}
/****************************************************************************

View File

@ -41,6 +41,7 @@
#include <stdint.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
@ -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;
}

View File

@ -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;
}
/****************************************************************************

View File

@ -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;
}
/****************************************************************************

View File

@ -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;
}
/****************************************************************************

View File

@ -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;

View File

@ -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);