From 06438b0dcc59ba29328a7b199d697975ab8ea96d Mon Sep 17 00:00:00 2001 From: Dimitry Kloper Date: Mon, 4 Jan 2016 22:01:47 +0200 Subject: [PATCH] Fix 64-bit clock-related constant value evaluation for AVR compiler This may be specific for Atmel AVR8 toolchain compiler. The problem is that despite of being 8-bit architecture avr-gcc supports uint64_t, but the following code uint64_t value = 10000 * 1000; produces a wrong negative value in the final code (tested both with and without optimization). The work-around is simple: uint64_t value = 10000 * 1000L; The code is a reduced part from sched/signal/sig_timedwait.c where waitticks64 is calculated using NSEC_PER_TICK. This one is defined as USEC_PER_TICK * NSEC_PER_USEC which leads to the example above. --- include/nuttx/clock.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index c091300dbb..49659f04cb 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -98,16 +98,16 @@ /* Timing constants *********************************************************/ -#define NSEC_PER_SEC 1000000000 -#define USEC_PER_SEC 1000000 -#define MSEC_PER_SEC 1000 -#define DSEC_PER_SEC 10 -#define NSEC_PER_DSEC 100000000 -#define USEC_PER_DSEC 100000 -#define MSEC_PER_DSEC 100 -#define NSEC_PER_MSEC 1000000 -#define USEC_PER_MSEC 1000 -#define NSEC_PER_USEC 1000 +#define NSEC_PER_SEC 1000000000L +#define USEC_PER_SEC 1000000L +#define MSEC_PER_SEC 1000L +#define DSEC_PER_SEC 10L +#define NSEC_PER_DSEC 100000000L +#define USEC_PER_DSEC 100000L +#define MSEC_PER_DSEC 100L +#define NSEC_PER_MSEC 1000000L +#define USEC_PER_MSEC 1000L +#define NSEC_PER_USEC 1000L /* If CONFIG_SCHED_TICKLESS is not defined, then the interrupt interval of * the system timer is given by USEC_PER_TICK. This is the expected number