diff options
| author | LaterComer <[email protected]> | 2024-05-30 12:04:33 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-30 12:04:33 +0800 |
| commit | 2cbe8bdae01cdd2d8fc0c55f363a94f13fb11a47 (patch) | |
| tree | ace26cd740059239a7abcc31345e88a7b7baa7fe /components/drivers/ktime/src/boottime.c | |
| parent | 2fcf151a8e93806907081652a0389fb89aedd355 (diff) | |
解决ktime部分函数计算时unsigned long溢出 (#9008)
* 解决ktime部分函数计算时unsigned long溢出
* 恢复部分不需要ktime中部分rt_uint64_t类型的为unsigned long
Diffstat (limited to 'components/drivers/ktime/src/boottime.c')
| -rw-r--r-- | components/drivers/ktime/src/boottime.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/components/drivers/ktime/src/boottime.c b/components/drivers/ktime/src/boottime.c index d380cd7e93..8e69141b68 100644 --- a/components/drivers/ktime/src/boottime.c +++ b/components/drivers/ktime/src/boottime.c @@ -10,16 +10,16 @@ #include "ktime.h" -#define __KTIME_MUL ((1000UL * 1000 * 1000) / RT_TICK_PER_SECOND) +#define __KTIME_MUL ((1000ULL * 1000 * 1000) / RT_TICK_PER_SECOND) rt_weak rt_err_t rt_ktime_boottime_get_us(struct timeval *tv) { RT_ASSERT(tv != RT_NULL); - unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; + rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; - tv->tv_sec = ns / (1000UL * 1000 * 1000); - tv->tv_usec = (ns % (1000UL * 1000 * 1000)) / 1000; + tv->tv_sec = ns / (1000ULL * 1000 * 1000); + tv->tv_usec = (ns % (1000ULL * 1000 * 1000)) / 1000; return RT_EOK; } @@ -28,9 +28,9 @@ rt_weak rt_err_t rt_ktime_boottime_get_s(time_t *t) { RT_ASSERT(t != RT_NULL); - unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; + rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; - *t = ns / (1000UL * 1000 * 1000); + *t = ns / (1000ULL * 1000 * 1000); return RT_EOK; } @@ -39,10 +39,10 @@ rt_weak rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts) { RT_ASSERT(ts != RT_NULL); - unsigned long ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; + rt_uint64_t ns = (rt_ktime_cputimer_getcnt() * rt_ktime_cputimer_getres()) / RT_KTIME_RESMUL; - ts->tv_sec = ns / (1000UL * 1000 * 1000); - ts->tv_nsec = ns % (1000UL * 1000 * 1000); + ts->tv_sec = ns / (1000ULL * 1000 * 1000); + ts->tv_nsec = ns % (1000ULL * 1000 * 1000); return RT_EOK; } |
