Timer driver updates from Bob Doiron

This commit is contained in:
Gregory Nutt
2014-05-05 14:40:19 -06:00
parent 84d28641b7
commit f06e9dbcaa
3 changed files with 26 additions and 44 deletions
+2
View File
@@ -7290,3 +7290,5 @@
counter (2014-5-5). counter (2014-5-5).
* configs/sam4s-xplained-pro: Clean-up of LED usage and also some * configs/sam4s-xplained-pro: Clean-up of LED usage and also some
integration of new timer features. From Bob Doiron (2014-5-5). integration of new timer features. From Bob Doiron (2014-5-5).
* drivers/timer.c and include/nuttx/timer.h: Timer driver updates from
Bob Doiron (2014-5-5).
+7 -7
View File
@@ -374,7 +374,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* cmd: TCIOC_SETHANDLER /* cmd: TCIOC_SETHANDLER
* Description: Call this handler on timeout * Description: Call this handler on timeout
* Argument: A pointer to struct timer_capture_s. * Argument: A pointer to struct timer_sethandler_s.
* *
* NOTE: This ioctl cannot be support in the kernel build mode. In that * NOTE: This ioctl cannot be support in the kernel build mode. In that
* case direct callbacks from kernel space into user space is forbidden. * case direct callbacks from kernel space into user space is forbidden.
@@ -383,20 +383,20 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
#ifndef CONFIG_NUTTX_KERNEL #ifndef CONFIG_NUTTX_KERNEL
case TCIOC_SETHANDLER: case TCIOC_SETHANDLER:
{ {
FAR struct timer_capture_s *capture; FAR struct timer_sethandler_s *sethandler;
/* Don't reset on timer timeout; instead, call this user /* Don't reset on timer timeout; instead, call this user
* provider timeout handler. NOTE: Providing handler==NULL will * provider timeout handler. NOTE: Providing handler==NULL will
* restore the reset behavior. * restore the reset behavior.
*/ */
if (lower->ops->capture) /* Optional */ if (lower->ops->sethandler) /* Optional */
{ {
capture = (FAR struct timer_capture_s *)((uintptr_t)arg); sethandler = (FAR struct timer_sethandler_s *)((uintptr_t)arg);
if (capture) if (sethandler)
{ {
capture->oldhandler = sethandler->oldhandler =
lower->ops->capture(lower, capture->newhandler); lower->ops->sethandler(lower, sethandler->newhandler);
ret = OK; ret = OK;
} }
else else
+12 -32
View File
@@ -68,13 +68,14 @@
* TCIOC_SETTIMEOUT - Reset the timer timeout to this value * TCIOC_SETTIMEOUT - Reset the timer timeout to this value
* Argument: A 32-bit timeout value in microseconds. * Argument: A 32-bit timeout value in microseconds.
* TCIOC_SETHANDLER - Call this handler on timer expiration * TCIOC_SETHANDLER - Call this handler on timer expiration
* Argument: A pointer to struct timer_capture_s. * Argument: A pointer to struct timer_sethandler_s.
* *
* WARNING: May change TCIOC_SETTIMEOUT to pass pointer to 64bit nanoseconds * WARNING: May change TCIOC_SETTIMEOUT to pass pointer to 64bit nanoseconds
* or timespec structure. * or timespec structure.
* *
* NOTE: This ioctl cannot be support in the kernel build mode. In that * NOTE: The TCIOC_SETHANDLER ioctl cannot be supported in the kernel build
* case direct callbacks from kernel space into user space is forbidden. * mode. In that case direct callbacks from kernel space into user space is
* forbidden.
*/ */
#define TCIOC_START _TCIOC(0x001) #define TCIOC_START _TCIOC(0x001)
@@ -87,7 +88,7 @@
/* Bit settings for the struct timer_status_s flags field */ /* Bit settings for the struct timer_status_s flags field */
#define TCFLAGS_ACTIVE (1 << 0) /* 1=The timer is running */ #define TCFLAGS_ACTIVE (1 << 0) /* 1=The timer is running */
#define TCFLAGS_CAPTURE (1 << 1) /* 1=Call the user function when the #define TCFLAGS_HANDLER (1 << 1) /* 1=Call the user function when the
* timer expires */ * timer expires */
/**************************************************************************** /****************************************************************************
@@ -102,10 +103,10 @@ typedef bool (*tccb_t)(FAR uint32_t *next_interval_us);
/* This is the type of the argument passed to the TCIOC_SETHANDLER ioctl */ /* This is the type of the argument passed to the TCIOC_SETHANDLER ioctl */
struct timer_capture_s struct timer_sethandler_s
{ {
CODE tccb_t newhandler; /* The new timer capture handler */ CODE tccb_t newhandler; /* The new timer interrupt handler */
CODE tccb_t oldhandler; /* The previous timer capture handler (if any) */ CODE tccb_t oldhandler; /* The previous timer interrupt handler (if any) */
}; };
/* This is the type of the argument passed to the TCIOC_GETSTATUS ioctl and /* This is the type of the argument passed to the TCIOC_GETSTATUS ioctl and
@@ -115,9 +116,9 @@ struct timer_capture_s
struct timer_status_s struct timer_status_s
{ {
uint32_t flags; /* See TCFLAGS_* definitions above */ uint32_t flags; /* See TCFLAGS_* definitions above */
uint32_t timeout; /* The current timeout setting (in milliseconds) */ uint32_t timeout; /* The current timeout setting (in microseconds) */
uint32_t timeleft; /* Time left until the timer expiration uint32_t timeleft; /* Time left until the timer expiration
* (in milliseconds) */ * (in microseconds) */
}; };
/* This structure provides the "lower-half" driver operations available to /* This structure provides the "lower-half" driver operations available to
@@ -150,7 +151,7 @@ struct timer_ops_s
* NOTE: Providing handler==NULL disable. * NOTE: Providing handler==NULL disable.
*/ */
CODE tccb_t (*capture)(FAR struct timer_lowerhalf_s *lower, CODE tccb_t (*sethandler)(FAR struct timer_lowerhalf_s *lower,
CODE tccb_t handler); CODE tccb_t handler);
/* Any ioctl commands that are not recognized by the "upper-half" driver /* Any ioctl commands that are not recognized by the "upper-half" driver
@@ -210,7 +211,7 @@ extern "C"
* *
* NOTE: Normally, this function would not be called by application code. * NOTE: Normally, this function would not be called by application code.
* Rather it is called indirectly through the architecture-specific * Rather it is called indirectly through the architecture-specific
* interface up_timerinitialize() described below. * initialization.
* *
* Input parameters: * Input parameters:
* dev path - The full path to the driver to be registers in the NuttX * dev path - The full path to the driver to be registers in the NuttX
@@ -255,27 +256,6 @@ void timer_unregister(FAR void *handle);
* Architecture-specific Application Interfaces * Architecture-specific Application Interfaces
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: up_timerinitialize()
*
* Description:
* Perform architecture-specific initialization of the timer hardware.
* This interface should be provided by all configurations using
* to avoid exposed platform-dependent logic.
*
* At a minimum, this function should call timer_register() which is
* described above.
*
* Input parameters:
* None
*
* Returned Value:
* Zero on success; a negated errno value on failure.
*
****************************************************************************/
int up_timerinitialize(void);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus
} }