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 4dd8187afee4dcd92a7af00dc91f7e6515941b9a
Author: Jukka Laitinen <juk...@ssrc.tii.ae>
AuthorDate: Mon Jan 30 12:13:16 2023 +0400

    include/nuttx/clock.h: Change ?SEC2TICK macros to round up and fix nxstyle 
errors
    
    Signed-off-by: Jukka Laitinen <juk...@ssrc.tii.ae>
---
 include/nuttx/clock.h | 52 +++++++++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 22 deletions(-)

diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h
index 3a641c144f..0ca726e0ce 100644
--- a/include/nuttx/clock.h
+++ b/include/nuttx/clock.h
@@ -145,41 +145,49 @@
  * preferred for that reason (at the risk of overflow)
  */
 
-#define TICK_PER_HOUR         (USEC_PER_HOUR / USEC_PER_TICK)            /* 
Truncates! */
-#define TICK_PER_MIN          (USEC_PER_MIN  / USEC_PER_TICK)            /* 
Truncates! */
-#define TICK_PER_SEC          (USEC_PER_SEC  / USEC_PER_TICK)            /* 
Truncates! */
-#define TICK_PER_MSEC         (USEC_PER_MSEC / USEC_PER_TICK)            /* 
Truncates! */
-#define TICK_PER_DSEC         (USEC_PER_DSEC / USEC_PER_TICK)            /* 
Truncates! */
-#define TICK_PER_HSEC         (USEC_PER_HSEC / USEC_PER_TICK)            /* 
Truncates! */
+/* TICK_PER_* truncates! */
 
-#define MSEC_PER_TICK         (USEC_PER_TICK / USEC_PER_MSEC)            /* 
Truncates! */
-#define NSEC_PER_TICK         (USEC_PER_TICK * NSEC_PER_USEC)            /* 
Exact */
+#define TICK_PER_HOUR         (USEC_PER_HOUR / USEC_PER_TICK)
+#define TICK_PER_MIN          (USEC_PER_MIN  / USEC_PER_TICK)
+#define TICK_PER_SEC          (USEC_PER_SEC  / USEC_PER_TICK)
+#define TICK_PER_MSEC         (USEC_PER_MSEC / USEC_PER_TICK)
+#define TICK_PER_DSEC         (USEC_PER_DSEC / USEC_PER_TICK)
+#define TICK_PER_HSEC         (USEC_PER_HSEC / USEC_PER_TICK)
 
-#define NSEC2TICK(nsec)       (((nsec)+(NSEC_PER_TICK/2))/NSEC_PER_TICK) /* 
Rounds */
-#define USEC2TICK(usec)       (((usec)+(USEC_PER_TICK/2))/USEC_PER_TICK) /* 
Rounds */
+/* MSEC_PER_TICK truncates! */
+
+#define MSEC_PER_TICK         (USEC_PER_TICK / USEC_PER_MSEC)
+#define NSEC_PER_TICK         (USEC_PER_TICK * NSEC_PER_USEC)
+
+/* ?SEC2TIC rounds up */
+
+#define NSEC2TICK(nsec)       (((nsec) + (NSEC_PER_TICK - 1)) / NSEC_PER_TICK)
+#define USEC2TICK(usec)       (((usec) + (USEC_PER_TICK - 1)) / USEC_PER_TICK)
 
 #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK
-#  define MSEC2TICK(msec)     (((msec)+(MSEC_PER_TICK/2))/MSEC_PER_TICK) /* 
Rounds */
+#  define MSEC2TICK(msec)     (((msec) + (MSEC_PER_TICK - 1)) / MSEC_PER_TICK)
 #else
-#  define MSEC2TICK(msec)     USEC2TICK((msec) * USEC_PER_MSEC)          /* 
Rounds */
+#  define MSEC2TICK(msec)     USEC2TICK((msec) * USEC_PER_MSEC)
 #endif
 
-#define DSEC2TICK(dsec)       MSEC2TICK((dsec) * MSEC_PER_DSEC)          /* 
Rounds */
-#define HSEC2TICK(dsec)       MSEC2TICK((dsec) * MSEC_PER_HSEC)          /* 
Rounds */
-#define SEC2TICK(sec)         MSEC2TICK((sec)  * MSEC_PER_SEC)           /* 
Rounds */
+#define DSEC2TICK(dsec)       MSEC2TICK((dsec) * MSEC_PER_DSEC)
+#define HSEC2TICK(dsec)       MSEC2TICK((dsec) * MSEC_PER_HSEC)
+#define SEC2TICK(sec)         MSEC2TICK((sec)  * MSEC_PER_SEC)
 
-#define TICK2NSEC(tick)       ((tick) * NSEC_PER_TICK)                   /* 
Exact */
-#define TICK2USEC(tick)       ((tick) * USEC_PER_TICK)                   /* 
Exact */
+#define TICK2NSEC(tick)       ((tick) * NSEC_PER_TICK)
+#define TICK2USEC(tick)       ((tick) * USEC_PER_TICK)
 
 #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK
-#  define TICK2MSEC(tick)     ((tick)*MSEC_PER_TICK)                     /* 
Exact */
+#  define TICK2MSEC(tick)     ((tick) * MSEC_PER_TICK)
 #else
-#  define TICK2MSEC(tick)     (((tick)*USEC_PER_TICK)/USEC_PER_MSEC)     /* 
Rounds */
+#  define TICK2MSEC(tick)     (((tick) * USEC_PER_TICK) / USEC_PER_MSEC)
 #endif
 
-#define TICK2DSEC(tick)       (((tick)+(TICK_PER_DSEC/2))/TICK_PER_DSEC) /* 
Rounds */
-#define TICK2HSEC(tick)       (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* 
Rounds */
-#define TICK2SEC(tick)        (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC)   /* 
Rounds */
+/* TIC2?SEC rounds to nearest */
+
+#define TICK2DSEC(tick)       (((tick) + (TICK_PER_DSEC / 2)) / TICK_PER_DSEC)
+#define TICK2HSEC(tick)       (((tick) + (TICK_PER_HSEC / 2)) / TICK_PER_HSEC)
+#define TICK2SEC(tick)        (((tick) + (TICK_PER_SEC / 2)) / TICK_PER_SEC)
 
 #if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_SYSTEM_TIME64) && \
     !defined(CONFIG_SCHED_TICKLESS)

Reply via email to