This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9b156035247a96da83832f546b50127052e965fe Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 23 13:13:08 2026 +0200 include/nuttx/clock.h: Add CLOCK2USEC() and CLOCK2MSEC(). Applications such as dhcpc and ping convert a difference of clock() values to microseconds or milliseconds with TICK2USEC() and TICK2MSEC(). That takes clock() as a number of system ticks, which is true only while CLOCKS_PER_SEC is the tick rate. Add CLOCK2USEC() and CLOCK2MSEC(), which convert a value in CLOCKS_PER_SEC units. Each one multiplies or divides by a constant, as the value of CLOCKS_PER_SEC requires. While CLOCKS_PER_SEC is the tick rate, they give the same results as TICK2USEC() and TICK2MSEC(). Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/nuttx/clock.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index bcfd16eda0b..108cb7ea580 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -217,6 +217,19 @@ # define CLOCK2TICK(clk) ((clk) / (CLOCKS_PER_SEC / CLK_TCK)) #endif +/* CLOCK2USEC and CLOCK2MSEC convert a value of clock() (CLOCKS_PER_SEC + * units), for example the difference of two calls, to microseconds and + * milliseconds. + */ + +#define CLOCK2USEC(clk) ((clk) * (USEC_PER_SEC / CLOCKS_PER_SEC)) + +#if CLOCKS_PER_SEC >= MSEC_PER_SEC +# define CLOCK2MSEC(clk) div_const(clk, CLOCKS_PER_SEC / MSEC_PER_SEC) +#else +# define CLOCK2MSEC(clk) ((clk) * (MSEC_PER_SEC / CLOCKS_PER_SEC)) +#endif + /* MSEC2SEC */ #define MSEC2SEC(msec) div_const(msec, MSEC_PER_SEC)
