diff --git a/changelog.yaml b/changelog.yaml index 5224441cc..3591f029c 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -900,6 +900,9 @@ subsections: - title: Console scope: console + - title: Delay Timer + scope: delay-timer + - title: Generic Clock scope: clk diff --git a/drivers/delay_timer/delay_timer.c b/drivers/delay_timer/delay_timer.c index a3fd7bfeb..bdbbbf6ae 100644 --- a/drivers/delay_timer/delay_timer.c +++ b/drivers/delay_timer/delay_timer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -80,3 +80,25 @@ void timer_init(const timer_ops_t *ops_ptr) timer_ops = ops_ptr; } + +/*********************************************************** + * Initialize the timer in us + ***********************************************************/ +uint64_t timeout_init_us(uint32_t usec) +{ + assert(timer_ops != NULL); + assert(timer_ops->timeout_init_us != NULL); + + return timer_ops->timeout_init_us(usec); +} + +/*********************************************************** + * check the given timeout elapsed or not. + ***********************************************************/ +bool timeout_elapsed(uint64_t cnt) +{ + assert(timer_ops != NULL); + assert(timer_ops->timeout_elapsed != NULL); + + return timer_ops->timeout_elapsed(cnt); +} diff --git a/drivers/delay_timer/generic_delay_timer.c b/drivers/delay_timer/generic_delay_timer.c index ca522e05a..0407e3859 100644 --- a/drivers/delay_timer/generic_delay_timer.c +++ b/drivers/delay_timer/generic_delay_timer.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -18,7 +18,26 @@ static timer_ops_t ops; -static uint32_t get_timer_value(void) +static uint64_t timeout_cnt_us2cnt(uint32_t us) +{ + return ((uint64_t)us * (uint64_t)read_cntfrq_el0()) / 1000000ULL; +} + +static uint64_t generic_delay_timeout_init_us(uint32_t us) +{ + uint64_t cnt = timeout_cnt_us2cnt(us); + + cnt += read_cntpct_el0(); + + return cnt; +} + +static bool generic_delay_timeout_elapsed(uint64_t expire_cnt) +{ + return read_cntpct_el0() > expire_cnt; +} + +static uint32_t generic_delay_get_timer_value(void) { /* * Generic delay timer implementation expects the timer to be a down @@ -31,9 +50,11 @@ static uint32_t get_timer_value(void) void generic_delay_timer_init_args(uint32_t mult, uint32_t div) { - ops.get_timer_value = get_timer_value; + ops.get_timer_value = generic_delay_get_timer_value; ops.clk_mult = mult; ops.clk_div = div; + ops.timeout_init_us = generic_delay_timeout_init_us; + ops.timeout_elapsed = generic_delay_timeout_elapsed; timer_init(&ops); @@ -59,4 +80,3 @@ void generic_delay_timer_init(void) generic_delay_timer_init_args(mult, div); } - diff --git a/include/drivers/delay_timer.h b/include/drivers/delay_timer.h index 20a554357..e9fdfb785 100644 --- a/include/drivers/delay_timer.h +++ b/include/drivers/delay_timer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. * Copyright (c) 2019, Linaro Limited * * SPDX-License-Identifier: BSD-3-Clause @@ -25,27 +25,12 @@ typedef struct timer_ops { uint32_t (*get_timer_value)(void); uint32_t clk_mult; uint32_t clk_div; + uint64_t (*timeout_init_us)(uint32_t usec); + bool (*timeout_elapsed)(uint64_t cnt); } timer_ops_t; -static inline uint64_t timeout_cnt_us2cnt(uint32_t us) -{ - return ((uint64_t)us * (uint64_t)read_cntfrq_el0()) / 1000000ULL; -} - -static inline uint64_t timeout_init_us(uint32_t us) -{ - uint64_t cnt = timeout_cnt_us2cnt(us); - - cnt += read_cntpct_el0(); - - return cnt; -} - -static inline bool timeout_elapsed(uint64_t expire_cnt) -{ - return read_cntpct_el0() > expire_cnt; -} - +uint64_t timeout_init_us(uint32_t usec); +bool timeout_elapsed(uint64_t cnt); void mdelay(uint32_t msec); void udelay(uint32_t usec); void timer_init(const timer_ops_t *ops_ptr);