diff --git a/.clang-format b/.clang-format index c6c8a8afeb6..aa43aae1f3d 100644 --- a/.clang-format +++ b/.clang-format @@ -23,7 +23,7 @@ AlignConsecutiveBitFields: AlignCompound: true PadOperators: true AlignConsecutiveDeclarations: - Enabled: false + Enabled: true AcrossEmptyLines: false AcrossComments: false AlignCompound: false diff --git a/components/drivers/ktime/inc/ktime.h b/components/drivers/ktime/inc/ktime.h index a1e7d65ef0d..979fcb6da18 100644 --- a/components/drivers/ktime/inc/ktime.h +++ b/components/drivers/ktime/inc/ktime.h @@ -24,7 +24,7 @@ struct rt_ktime_hrtimer { struct rt_object parent; /**< inherit from rt_object */ rt_list_t row; - void *parameter; + void *parameter; unsigned long init_cnt; unsigned long timeout_cnt; rt_err_t error; @@ -62,21 +62,21 @@ rt_err_t rt_ktime_boottime_get_ns(struct timespec *ts); * * @return (resolution * RT_KTIME_RESMUL) */ -unsigned long rt_ktime_cputimer_getres(void); +rt_uint64_t rt_ktime_cputimer_getres(void); /** * @brief Get cputimer frequency * * @return frequency */ -unsigned long rt_ktime_cputimer_getfrq(void); +rt_uint64_t rt_ktime_cputimer_getfrq(void); /** * @brief Get cputimer the value of the cnt counter * * @return cnt */ -unsigned long rt_ktime_cputimer_getcnt(void); +rt_uint64_t rt_ktime_cputimer_getcnt(void); /** * @brief Get cputimer the cnt value corresponding to 1 os tick @@ -96,21 +96,21 @@ void rt_ktime_cputimer_init(void); * * @return (resolution * RT_KTIME_RESMUL) */ -unsigned long rt_ktime_hrtimer_getres(void); +rt_uint64_t rt_ktime_hrtimer_getres(void); /** * @brief Get hrtimer frequency * * @return frequency */ -unsigned long rt_ktime_hrtimer_getfrq(void); +rt_uint64_t rt_ktime_hrtimer_getfrq(void); /** * @brief Get hrtimer the value of the cnt counter * * @return cnt */ -unsigned long rt_ktime_hrtimer_getcnt(void); +rt_uint64_t rt_ktime_hrtimer_getcnt(void); /** * @brief set hrtimer timeout, when timeout, the timer callback will call timeout diff --git a/components/drivers/ktime/src/aarch64/cputimer.c b/components/drivers/ktime/src/aarch64/cputimer.c index cc1c5255e98..09163b22918 100644 --- a/components/drivers/ktime/src/aarch64/cputimer.c +++ b/components/drivers/ktime/src/aarch64/cputimer.c @@ -11,19 +11,19 @@ #include "gtimer.h" #include "ktime.h" -static volatile unsigned long _init_cnt = 0; +static volatile rt_uint64_t _init_cnt = 0; -unsigned long rt_ktime_cputimer_getres(void) +rt_uint64_t rt_ktime_cputimer_getres(void) { - return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq(); + return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq(); } -unsigned long rt_ktime_cputimer_getfrq(void) +rt_uint64_t rt_ktime_cputimer_getfrq(void) { return rt_hw_get_gtimer_frq(); } -unsigned long rt_ktime_cputimer_getcnt(void) +rt_uint64_t rt_ktime_cputimer_getcnt(void) { return rt_hw_get_cntpct_val() - _init_cnt; } diff --git a/components/drivers/ktime/src/boottime.c b/components/drivers/ktime/src/boottime.c index d380cd7e930..8e69141b68d 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; } diff --git a/components/drivers/ktime/src/cputimer.c b/components/drivers/ktime/src/cputimer.c index f182be894ce..c3ec9f106a7 100644 --- a/components/drivers/ktime/src/cputimer.c +++ b/components/drivers/ktime/src/cputimer.c @@ -10,17 +10,17 @@ #include "ktime.h" -rt_weak unsigned long rt_ktime_cputimer_getres(void) +rt_weak rt_uint64_t rt_ktime_cputimer_getres(void) { - return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND; + return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / RT_TICK_PER_SECOND; } -rt_weak unsigned long rt_ktime_cputimer_getfrq(void) +rt_weak rt_uint64_t rt_ktime_cputimer_getfrq(void) { return RT_TICK_PER_SECOND; } -rt_weak unsigned long rt_ktime_cputimer_getcnt(void) +rt_weak rt_uint64_t rt_ktime_cputimer_getcnt(void) { return rt_tick_get(); } diff --git a/components/drivers/ktime/src/risc-v/virt64/cputimer.c b/components/drivers/ktime/src/risc-v/virt64/cputimer.c index bbc7576c5ec..301ee6d81d9 100644 --- a/components/drivers/ktime/src/risc-v/virt64/cputimer.c +++ b/components/drivers/ktime/src/risc-v/virt64/cputimer.c @@ -10,19 +10,19 @@ #include "ktime.h" -static volatile unsigned long _init_cnt = 0; +static volatile rt_uint64_t _init_cnt = 0; -unsigned long rt_ktime_cputimer_getres(void) +rt_uint64_t rt_ktime_cputimer_getres(void) { - return ((1000UL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ; + return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / CPUTIME_TIMER_FREQ; } -unsigned long rt_ktime_cputimer_getfrq(void) +rt_uint64_t rt_ktime_cputimer_getfrq(void) { return CPUTIME_TIMER_FREQ; } -unsigned long rt_ktime_cputimer_getcnt(void) +rt_uint64_t rt_ktime_cputimer_getcnt(void) { unsigned long time_elapsed; __asm__ __volatile__("rdtime %0" : "=r"(time_elapsed));