mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-05-23 14:21:32 +01:00
lib: sbi_timer: Introduce sbi_timer_compute_delta() and friends
The users of timer event have to compute next_event (aka timer value in the future) based on desired units and unit frequency. Introduce sbi_timer_compute_delta() and friends to simplify computing next_event for timer event users. Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Link: https://lore.kernel.org/r/20260425104048.2335262-5-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
+10
-4
@@ -58,6 +58,15 @@ static void nop_delay_fn(void *opaque)
|
||||
cpu_relax();
|
||||
}
|
||||
|
||||
u64 sbi_timer_compute_delta(ulong units, u64 unit_freq)
|
||||
{
|
||||
u64 delta;
|
||||
|
||||
delta = ((u64)timer_dev->timer_freq * (u64)units);
|
||||
delta = delta / unit_freq;
|
||||
return delta;
|
||||
}
|
||||
|
||||
void sbi_timer_delay_loop(ulong units, u64 unit_freq,
|
||||
void (*delay_fn)(void *), void *opaque)
|
||||
{
|
||||
@@ -72,15 +81,12 @@ void sbi_timer_delay_loop(ulong units, u64 unit_freq,
|
||||
/* Save starting timer value */
|
||||
start_val = get_time_val();
|
||||
|
||||
/* Compute desired timer value delta */
|
||||
delta = ((u64)timer_dev->timer_freq * (u64)units);
|
||||
delta = delta / unit_freq;
|
||||
|
||||
/* Use NOP delay function if delay function not available */
|
||||
if (!delay_fn)
|
||||
delay_fn = nop_delay_fn;
|
||||
|
||||
/* Busy loop until desired timer value delta reached */
|
||||
delta = sbi_timer_compute_delta(units, unit_freq);
|
||||
while ((get_time_val() - start_val) < delta)
|
||||
delay_fn(opaque);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user