From 9a23be0cd25e8a1ca75e3524ee5dc4262cf59707 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 13 Jan 2015 15:55:54 -0600 Subject: [PATCH] Tiva Timer: Timer test must attach a timer handler or the timer is stopped at the first interrupt --- examples/timer/timer_main.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/examples/timer/timer_main.c b/examples/timer/timer_main.c index ed1219447..4546e5b9d 100644 --- a/examples/timer/timer_main.c +++ b/examples/timer/timer_main.c @@ -71,6 +71,21 @@ * Private Data ****************************************************************************/ +/**************************************************************************** + * 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);