diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-04-30 14:08:34 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-04-30 14:08:34 -0600 |
commit | dc9c2633f86894a4be35596994464c1e616fedf8 (patch) | |
tree | 84d9c46b32ecbe73db5a96d23c5c5c5f34c4d3ab | |
parent | bc484165db04a5c4c8bcfbce28e48eb3d6a11cbb (diff) | |
download | nuttx-dc9c2633f86894a4be35596994464c1e616fedf8.tar.gz nuttx-dc9c2633f86894a4be35596994464c1e616fedf8.tar.bz2 nuttx-dc9c2633f86894a4be35596994464c1e616fedf8.zip |
Enhanced timer interface from Bob Doiron
-rw-r--r-- | nuttx/drivers/timer.c | 12 | ||||
-rw-r--r-- | nuttx/include/nuttx/timer.h | 26 |
2 files changed, 26 insertions, 12 deletions
diff --git a/nuttx/drivers/timer.c b/nuttx/drivers/timer.c index 01195d6c9..45581f3be 100644 --- a/nuttx/drivers/timer.c +++ b/nuttx/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/nuttx/include/nuttx/timer.h b/nuttx/include/nuttx/timer.h index f5ad663f1..a5e9dca8e 100644 --- a/nuttx/include/nuttx/timer.h +++ b/nuttx/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. |