From ac42add946a62d79bbe6ded9c46bb9c37d6dbe7d Mon Sep 17 00:00:00 2001 From: Kerogit Date: Mon, 24 Mar 2025 10:41:59 +0100 Subject: [PATCH] nuttx/clock: make NSEC_PER_USEC and others long On AVR architecture, the compiler apparently sometimes truncates NSEC_PER_TICK to 16bit value, leading to clock_time2ticks returning incorrect results. This was encountered while attempting to add tickless OS support for AVR architecture but seemed to affect non-tickless mode of operation as well. This patch marks NSEC_PER_USEC (and to be safe, USEC_PER_MSEC and MSEC_PER_SEC too) as long. --- include/nuttx/clock.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index b750e5347d..e64f3fee6c 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -103,7 +103,7 @@ #define NSEC_PER_SEC 1000000000L /* Seconds */ #define USEC_PER_SEC 1000000L -#define MSEC_PER_SEC 1000 +#define MSEC_PER_SEC 1000L #define DSEC_PER_SEC 10 #define HSEC_PER_SEC 2 @@ -117,9 +117,9 @@ #define MSEC_PER_DSEC 100 #define NSEC_PER_MSEC 1000000L /* Milliseconds */ -#define USEC_PER_MSEC 1000 +#define USEC_PER_MSEC 1000L -#define NSEC_PER_USEC 1000 /* Microseconds */ +#define NSEC_PER_USEC 1000L /* Microseconds */ #define SEC_PER_MIN 60 #define NSEC_PER_MIN (NSEC_PER_SEC * SEC_PER_MIN)