This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 5e543421abbf64fafe9d5c2556b139aa941a1110 Author: ouyangxiangzhen <ouyangxiangz...@xiaomi.com> AuthorDate: Fri May 9 09:36:58 2025 +0800 clock: constants change to unsigned. This commit change the type of the constants to unsigned, avoiding signed integer division. Signed-off-by: ouyangxiangzhen <ouyangxiangz...@xiaomi.com> --- include/nuttx/clock.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 8230c8c2b4..cb1aa81483 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -101,25 +101,25 @@ /* Timing constants *********************************************************/ -#define NSEC_PER_SEC 1000000000L /* Seconds */ -#define USEC_PER_SEC 1000000L -#define MSEC_PER_SEC 1000L +#define NSEC_PER_SEC 1000000000UL /* Seconds */ +#define USEC_PER_SEC 1000000UL +#define MSEC_PER_SEC 1000UL #define DSEC_PER_SEC 10 #define HSEC_PER_SEC 2 -#define NSEC_PER_HSEC 500000000L /* Half seconds */ -#define USEC_PER_HSEC 500000L +#define NSEC_PER_HSEC 500000000UL /* Half seconds */ +#define USEC_PER_HSEC 500000UL #define MSEC_PER_HSEC 500 #define DSEC_PER_HSEC 5 -#define NSEC_PER_DSEC 100000000L /* Deciseconds */ -#define USEC_PER_DSEC 100000L +#define NSEC_PER_DSEC 100000000UL /* Deciseconds */ +#define USEC_PER_DSEC 100000UL #define MSEC_PER_DSEC 100 -#define NSEC_PER_MSEC 1000000L /* Milliseconds */ -#define USEC_PER_MSEC 1000L +#define NSEC_PER_MSEC 1000000UL /* Milliseconds */ +#define USEC_PER_MSEC 1000UL -#define NSEC_PER_USEC 1000L /* Microseconds */ +#define NSEC_PER_USEC 1000UL /* Microseconds */ #define SEC_PER_MIN 60 #define NSEC_PER_MIN (NSEC_PER_SEC * SEC_PER_MIN) @@ -351,7 +351,7 @@ EXTERN volatile clock_t g_system_ticks; while (0) #define clock_time2ticks(ts) \ - ((clock_t)(ts)->tv_sec * TICK_PER_SEC + NSEC2TICK((ts)->tv_nsec)) + ((clock_t)(ts)->tv_sec * TICK_PER_SEC + NSEC2TICK((uint32_t)(ts)->tv_nsec)) #define clock_usec2time(ts, usec) \ do \ @@ -364,7 +364,8 @@ EXTERN volatile clock_t g_system_ticks; while (0) #define clock_time2usec(ts) \ - ((uint64_t)(ts)->tv_sec * USEC_PER_SEC + div_const((ts)->tv_nsec, NSEC_PER_USEC)) + ((uint64_t)(ts)->tv_sec * USEC_PER_SEC + \ + div_const((uint32_t)(ts)->tv_nsec, NSEC_PER_USEC)) #define clock_nsec2time(ts, nsec) \ do \ @@ -377,7 +378,7 @@ EXTERN volatile clock_t g_system_ticks; while (0) #define clock_time2nsec(ts) \ - ((uint64_t)(ts)->tv_sec * NSEC_PER_SEC + (ts)->tv_nsec) + ((uint64_t)(ts)->tv_sec * NSEC_PER_SEC + (uint64_t)(ts)->tv_nsec) /**************************************************************************** * Name: clock_timespec_add