diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-13 15:55:54 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-13 15:55:54 -0600 |
commit | ff41392ee5f6d7c3606ce23fa03d1a80a0edd653 (patch) | |
tree | 1d9f0466163c80176d92dbaf5f9c0f418d33ed84 /apps/examples/timer/timer_main.c | |
parent | 88c0a658b7fd624af3dacf652c5ed16c02199650 (diff) | |
download | nuttx-ff41392ee5f6d7c3606ce23fa03d1a80a0edd653.tar.gz nuttx-ff41392ee5f6d7c3606ce23fa03d1a80a0edd653.tar.bz2 nuttx-ff41392ee5f6d7c3606ce23fa03d1a80a0edd653.zip |
Tiva Timer: Timer test must attach a timer handler or the timer is stopped at the first interrupt
Diffstat (limited to 'apps/examples/timer/timer_main.c')
-rw-r--r-- | apps/examples/timer/timer_main.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/apps/examples/timer/timer_main.c b/apps/examples/timer/timer_main.c index ed1219447..4546e5b9d 100644 --- a/apps/examples/timer/timer_main.c +++ b/apps/examples/timer/timer_main.c @@ -72,6 +72,21 @@ ****************************************************************************/ /**************************************************************************** + * timer_handler + ****************************************************************************/ + +static bool timer_handler(FAR uint32_t *next_interval_us) +{ + /* This handler may: + * + * (1) Modify the timeout value to change the frequency dynamically, or + * (2) Return false to stop the timer. + */ + + return true; +} + +/**************************************************************************** * timer_status ****************************************************************************/ @@ -111,6 +126,7 @@ int main(int argc, FAR char *argv[]) int timer_main(int argc, char *argv[]) #endif { + struct timer_sethandler_s handler; int ret; int fd; int i; @@ -144,6 +160,28 @@ int timer_main(int argc, char *argv[]) return EXIT_FAILURE; } + /* Show the timer status before attaching the timer handler */ + + timer_status(fd); + + /* Attach the timer handler + * + * NOTE: If no handler is attached, the timer stop at the first interrupt. + */ + + printf("Attach timer handler\n"); + + handler.newhandler = timer_handler; + handler.oldhandler = NULL; + + ret = ioctl(fd, TCIOC_SETHANDLER, (unsigned long)((uintptr_t)&handler)); + if (ret < 0) + { + fprintf(stderr, "ERROR: Failed to set the timer handler: %d\n", errno); + close(fd); + return EXIT_FAILURE; + } + /* Show the timer status before starting */ timer_status(fd); |