Skip to content

Commit b69ff79

Browse files
committed
fix(zephyr): Use zephyr macros instead of hardcoded values
1 parent d9b5d66 commit b69ff79

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

core/shared/platform/zephyr/zephyr_sleep.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ os_nanosleep(const os_timespec *req, os_timespec *rem)
4343
return __WASI_EINVAL;
4444
}
4545

46-
if (req->tv_sec < 0 || req->tv_nsec < 0 || req->tv_nsec >= 1000000000) {
46+
if (req->tv_sec < 0 || req->tv_nsec < 0 || req->tv_nsec >= NSEC_PER_SEC) {
4747
return __WASI_EINVAL;
4848
}
4949

@@ -67,9 +67,9 @@ os_nanosleep(const os_timespec *req, os_timespec *rem)
6767
if (rc > 0) {
6868

6969
#ifdef CONFIG_TIMEOUT_64BIT
70-
rem_ticks = (k_ticks_t)((uint64_t)rc * CONFIG_SYS_CLOCK_TICKS_PER_SEC / 1000);
70+
rem_ticks = (k_ticks_t)((uint64_t)rc * CONFIG_SYS_CLOCK_TICKS_PER_SEC / MSEC_PER_SEC);
7171
#else /* CONFIG_TIMEOUT_32BIT */
72-
uint64_t temp_ticks = (uint64_t)rc * CONFIG_SYS_CLOCK_TICKS_PER_SEC / 1000;
72+
uint64_t temp_ticks = (uint64_t)rc * CONFIG_SYS_CLOCK_TICKS_PER_SEC / MSEC_PER_SEC;
7373
rem_ticks = (k_ticks_t)(temp_ticks > UINT32_MAX ? UINT32_MAX : temp_ticks);
7474
#endif
7575
ticks_to_timespec(rem_ticks, rem);
@@ -88,8 +88,8 @@ static k_ticks_t timespec_to_ticks(const os_timespec *ts)
8888
const uint64_t ticks_per_sec = CONFIG_SYS_CLOCK_TICKS_PER_SEC;
8989
uint64_t total_ns, ticks;
9090

91-
total_ns = (uint64_t)ts->tv_sec * 1000000000ULL + (uint64_t)ts->tv_nsec;
92-
ticks = total_ns * ticks_per_sec / 1000000000ULL;
91+
total_ns = (uint64_t)ts->tv_sec * NSEC_PER_SEC + (uint64_t)ts->tv_nsec;
92+
ticks = total_ns * ticks_per_sec / NSEC_PER_SEC;
9393

9494
#ifdef CONFIG_TIMEOUT_64BIT
9595
if (ticks > INT64_MAX) {
@@ -113,8 +113,8 @@ static void ticks_to_timespec(k_ticks_t ticks, os_timespec *ts)
113113
return;
114114
}
115115

116-
total_ns = ((uint64_t)ticks * 1000000000ULL) / ticks_per_sec;
116+
total_ns = ((uint64_t)ticks * NSEC_PER_SEC) / ticks_per_sec;
117117

118-
ts->tv_sec = (long)(total_ns / 1000000000ULL);
119-
ts->tv_nsec = (long)(total_ns % 1000000000ULL);
118+
ts->tv_sec = (long)(total_ns / NSEC_PER_SEC);
119+
ts->tv_nsec = (long)(total_ns % NSEC_PER_SEC);
120120
}

0 commit comments

Comments
 (0)