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)
This commit is contained in:
parent
a6c68d233d
commit
fc194cf2ec
@ -46,7 +46,6 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
@ -306,6 +305,21 @@ static int oneshot_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
{
|
{
|
||||||
tmrerr("ERROR: Unrecognized cmd: %d arg: %ld\n", cmd, arg);
|
tmrerr("ERROR: Unrecognized cmd: %d arg: %ld\n", cmd, arg);
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@ -68,6 +69,9 @@
|
|||||||
* OSIOC_CANCEL - Stop the timer
|
* OSIOC_CANCEL - Stop the timer
|
||||||
* Argument: A reference to a struct timespec in which
|
* Argument: A reference to a struct timespec in which
|
||||||
* the time remaining will be returned.
|
* 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
|
* NOTE: _TCIOC(0x0020) througn _TCIOC(0x003f) are reserved for use by the
|
||||||
* oneshot driver to assure that the values are unique. Other timer drivers
|
* oneshot driver to assure that the values are unique. Other timer drivers
|
||||||
@ -77,6 +81,7 @@
|
|||||||
#define OSIOC_MAXDELAY _TCIOC(0x0020)
|
#define OSIOC_MAXDELAY _TCIOC(0x0020)
|
||||||
#define OSIOC_START _TCIOC(0x0021)
|
#define OSIOC_START _TCIOC(0x0021)
|
||||||
#define OSIOC_CANCEL _TCIOC(0x0022)
|
#define OSIOC_CANCEL _TCIOC(0x0022)
|
||||||
|
#define OSIOC_CURRENT _TCIOC(0x0023)
|
||||||
|
|
||||||
/* Method access helper macros **********************************************/
|
/* Method access helper macros **********************************************/
|
||||||
|
|
||||||
@ -148,6 +153,27 @@
|
|||||||
|
|
||||||
#define ONESHOT_CANCEL(l,t) ((l)->ops->cancel(l,t))
|
#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
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -175,6 +201,8 @@ struct oneshot_operations_s
|
|||||||
FAR const struct timespec *ts);
|
FAR const struct timespec *ts);
|
||||||
CODE int (*cancel)(struct oneshot_lowerhalf_s *lower,
|
CODE int (*cancel)(struct oneshot_lowerhalf_s *lower,
|
||||||
FAR struct timespec *ts);
|
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 */
|
/* This structure describes the state of the oneshot timer lower-half driver */
|
||||||
|
Loading…
Reference in New Issue
Block a user