examples/oneshot: fixed wrong constant and refactored

This commit is contained in:
Sara Souza 2021-03-23 10:20:04 -03:00 committed by David Sidrane
parent d656982f7a
commit bf71741452

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* examples/oneshot/oneshot_main.c * apps/examples/oneshot/oneshot_main.c
* *
* Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -178,9 +178,10 @@ int main(int argc, FAR char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
maxus = (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000; maxus = (uint64_t)ts.tv_sec * USEC_PER_SEC +
(uint64_t)ts.tv_nsec / NSEC_PER_USEC;
printf("Maximum delay is %llu\n", maxus); printf("Maximum delay is %" PRIu64 "\n", maxus);
/* Ignore the default signal action */ /* Ignore the default signal action */
@ -202,13 +203,12 @@ int main(int argc, FAR char *argv[])
printf("Starting oneshot timer with delay %lu microseconds\n", printf("Starting oneshot timer with delay %lu microseconds\n",
usecs); usecs);
start.pid = 0; start.pid = 0;
secs = usecs / USEC_PER_SEC;
secs = usecs / 1000000; usecs -= USEC_PER_SEC * secs;
usecs -= 1000000 * secs;
start.ts.tv_sec = secs; start.ts.tv_sec = secs;
start.ts.tv_nsec = usecs * 1000; start.ts.tv_nsec = usecs * NSEC_PER_USEC;
start.event.sigev_notify = SIGEV_SIGNAL; start.event.sigev_notify = SIGEV_SIGNAL;
start.event.sigev_signo = CONFIG_EXAMPLES_ONESHOT_SIGNO; start.event.sigev_signo = CONFIG_EXAMPLES_ONESHOT_SIGNO;
@ -228,16 +228,16 @@ int main(int argc, FAR char *argv[])
start.ts.tv_sec = ts.tv_sec; start.ts.tv_sec = ts.tv_sec;
start.ts.tv_nsec = ts.tv_nsec; start.ts.tv_nsec = ts.tv_nsec;
usecs -= maxus; usecs -= maxus;
#if FUDGE_FACTOR > 0 #if FUDGE_FACTOR > 0
if (usecs > FUDGE_FACTOR) if (usecs > FUDGE_FACTOR)
{ {
usecs -= FUDGE_FACTOR; usecs -= FUDGE_FACTOR;
} }
else else
{ {
usecs = 0; usecs = 0;
} }
#endif #endif
} }