From d897b4de76f5c45d5e85a1b04e347cef061710fb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Apr 2014 14:08:34 -0600 Subject: [PATCH] Enhanced timer interface from Bob Doiron --- drivers/timer.c | 12 ++++++++---- include/nuttx/timer.h | 26 ++++++++++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/timer.c b/drivers/timer.c index 01195d6c93..45581f3beb 100644 --- a/drivers/timer.c +++ b/drivers/timer.c @@ -372,12 +372,16 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; - /* cmd: TCIOC_CAPTURE - * Description: Called this handler on timeout + /* cmd: TCIOC_SETHANDLER + * Description: Call this handler on timeout * 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; @@ -406,7 +410,7 @@ static int timer_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } } break; - +#endif /* Any unrecognized IOCTL commands might be platform-specific ioctl commands */ diff --git a/include/nuttx/timer.h b/include/nuttx/timer.h index f5ad663f1b..a5e9dca8ea 100644 --- a/include/nuttx/timer.h +++ b/include/nuttx/timer.h @@ -55,7 +55,7 @@ /* The timer driver uses a standard character driver framework. However, * since the timer driver is a device control interface and not a data * 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. * @@ -67,18 +67,21 @@ * Argument: A writeable pointer to struct timer_status_s. * TCIOC_SETTIMEOUT - Reset the timer timeout to this value * 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. * * WARNING: May change TCIOC_SETTIMEOUT to pass pointer to 64bit nanoseconds * 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_STOP _TCIOC(0x002) #define TCIOC_GETSTATUS _TCIOC(0x003) #define TCIOC_SETTIMEOUT _TCIOC(0x004) -#define TCIOC_CAPTURE _TCIOC(0x005) +#define TCIOC_SETHANDLER _TCIOC(0x005) /* Bit Settings *************************************************************/ /* Bit settings for the struct timer_status_s flags field */ @@ -90,12 +93,19 @@ /**************************************************************************** * 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 { - CODE xcpt_t newhandler; /* The new timer capture handler */ - CODE xcpt_t oldhandler; /* The previous timer capture handler (if any) */ + CODE tccb_t newhandler; /* The new timer capture handler */ + 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 @@ -140,8 +150,8 @@ struct timer_ops_s * NOTE: Providing handler==NULL disable. */ - CODE xcpt_t (*capture)(FAR struct timer_lowerhalf_s *lower, - CODE xcpt_t handler); + CODE tccb_t (*capture)(FAR struct timer_lowerhalf_s *lower, + CODE tccb_t handler); /* Any ioctl commands that are not recognized by the "upper-half" driver * are forwarded to the lower half driver through this method.