Enhanced timer interface from Bob Doiron

This commit is contained in:
Gregory Nutt 2014-04-30 14:08:34 -06:00
parent ae4584f0db
commit d897b4de76
2 changed files with 26 additions and 12 deletions

View File

@ -372,12 +372,16 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
break; break;
/* cmd: TCIOC_CAPTURE /* cmd: TCIOC_SETHANDLER
* Description: Called this handler on timeout * Description: Call this handler on timeout
* Argument: A pointer to struct timer_capture_s. * Argument: A pointer to struct timer_capture_s.
*
* 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 TCIOC_CAPTURE: #ifndef CONFIG_NUTTX_KERNEL
case TCIOC_SETHANDLER:
{ {
FAR struct timer_capture_s *capture; FAR struct timer_capture_s *capture;
@ -406,7 +410,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
} }
break; break;
#endif
/* Any unrecognized IOCTL commands might be platform-specific ioctl commands */ /* Any unrecognized IOCTL commands might be platform-specific ioctl commands */

View File

@ -55,7 +55,7 @@
/* The timer driver uses a standard character driver framework. However, /* The timer driver uses a standard character driver framework. However,
* since the timer driver is a device control interface and not a data * since the timer driver is a device control interface and not a data
* transfer interface, the majority of the functionality is implemented in * transfer interface, the majority of the functionality is implemented in
* driver ioctl calls. The timer ioctl commands are lised below: * driver ioctl calls. The timer ioctl commands are listed below:
* *
* These are detected and handled by the "upper half" timer driver. * These are detected and handled by the "upper half" timer driver.
* *
@ -67,18 +67,21 @@
* Argument: A writeable pointer to struct timer_status_s. * Argument: A writeable pointer to struct timer_status_s.
* 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_CAPTURE - Do not reset. Instead, called this handler. * TCIOC_SETHANDLER - Call this handler on timer expiration
* Argument: A pointer to struct timer_capture_s. * Argument: A pointer to struct timer_capture_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
* case direct callbacks from kernel space into user space is forbidden.
*/ */
#define TCIOC_START _TCIOC(0x001) #define TCIOC_START _TCIOC(0x001)
#define TCIOC_STOP _TCIOC(0x002) #define TCIOC_STOP _TCIOC(0x002)
#define TCIOC_GETSTATUS _TCIOC(0x003) #define TCIOC_GETSTATUS _TCIOC(0x003)
#define TCIOC_SETTIMEOUT _TCIOC(0x004) #define TCIOC_SETTIMEOUT _TCIOC(0x004)
#define TCIOC_CAPTURE _TCIOC(0x005) #define TCIOC_SETHANDLER _TCIOC(0x005)
/* Bit Settings *************************************************************/ /* Bit Settings *************************************************************/
/* Bit settings for the struct timer_status_s flags field */ /* Bit settings for the struct timer_status_s flags field */
@ -90,12 +93,19 @@
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* This is the type of the argument passed to the TCIOC_CAPTURE ioctl */
/* User function prototype. Returns true to reload the timer, and the
* function can modify the next interval if desired.
*/
typedef bool (*tccb_t)(FAR uint32_t *next_interval_us);
/* This is the type of the argument passed to the TCIOC_SETHANDLER ioctl */
struct timer_capture_s struct timer_capture_s
{ {
CODE xcpt_t newhandler; /* The new timer capture handler */ CODE tccb_t newhandler; /* The new timer capture handler */
CODE xcpt_t oldhandler; /* The previous timer capture handler (if any) */ CODE tccb_t oldhandler; /* The previous timer capture 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
@ -140,8 +150,8 @@ struct timer_ops_s
* NOTE: Providing handler==NULL disable. * NOTE: Providing handler==NULL disable.
*/ */
CODE xcpt_t (*capture)(FAR struct timer_lowerhalf_s *lower, CODE tccb_t (*capture)(FAR struct timer_lowerhalf_s *lower,
CODE xcpt_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
* are forwarded to the lower half driver through this method. * are forwarded to the lower half driver through this method.