apps/examples/oneshot: If the requested delay is > max_delay, then break the delay up into several pieces.

This commit is contained in:
Gregory Nutt 2016-08-15 11:44:52 -06:00
parent 85083236d7
commit 0a6dd4a24e

View File

@ -106,6 +106,8 @@ int oneshot_main(int argc, char *argv[])
unsigned long secs; unsigned long secs;
struct oneshot_start_s start; struct oneshot_start_s start;
struct siginfo info; struct siginfo info;
struct timespec ts;
uint64_t maxus;
sigset_t set; sigset_t set;
int ret; int ret;
int fd; int fd;
@ -158,12 +160,36 @@ int oneshot_main(int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Get the maximum delay */
ret = ioctl(fd, OSIOC_MAXDELAY, (unsigned long)((uintptr_t)&ts));
if (ret < 0)
{
fprintf(stderr, "ERROR: Failed to get the maximum delayl: %d\n",
errno);
close(fd);
return EXIT_FAILURE;
}
maxus = (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000;
printf("Maximum delay is %llu\n", maxus);
/* Loop waiting until the full delay expires */
while (usecs > 0)
{
/* Start the oneshot timer */ /* Start the oneshot timer */
sigemptyset(&set); sigemptyset(&set);
sigaddset(&set, CONFIG_EXAMPLE_ONESHOT_SIGNO); sigaddset(&set, CONFIG_EXAMPLE_ONESHOT_SIGNO);
printf("Starting oneshot timer with delay %lu microseconds\n", usecs); if (usecs < maxus)
{
/* Wait for the remaining time */
printf("Starting oneshot timer with delay %lu microseconds\n",
usecs);
start.pid = 0; start.pid = 0;
start.signo = CONFIG_EXAMPLE_ONESHOT_SIGNO; start.signo = CONFIG_EXAMPLE_ONESHOT_SIGNO;
@ -175,6 +201,23 @@ int oneshot_main(int argc, char *argv[])
start.ts.tv_sec = secs; start.ts.tv_sec = secs;
start.ts.tv_nsec = usecs * 1000; start.ts.tv_nsec = usecs * 1000;
/* Zero usecs to terminate the loop */
usecs = 0;
}
else
{
/* Wait for the maximum */
printf("Starting oneshot timer with delay %llu microseconds\n",
maxus);
start.ts.tv_sec = ts.tv_sec;
start.ts.tv_nsec = ts.tv_nsec;
usecs -= maxus;
}
ret = ioctl(fd, OSIOC_START, (unsigned long)((uintptr_t)&start)); ret = ioctl(fd, OSIOC_START, (unsigned long)((uintptr_t)&start));
if (ret < 0) if (ret < 0)
{ {
@ -195,6 +238,7 @@ int oneshot_main(int argc, char *argv[])
close(fd); close(fd);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}
/* Close the oneshot driver */ /* Close the oneshot driver */