Tiva Timer: Timer test must attach a timer handler or the timer is stopped at the first interrupt

This commit is contained in:
Gregory Nutt 2015-01-13 15:55:54 -06:00
parent a9eedb0054
commit 9a23be0cd2

View File

@ -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);