summaryrefslogtreecommitdiff
path: root/include/sbi/sbi_timer.h
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2021-09-15 07:41:24 +0300
committerAnup Patel <anup@brainfault.org>2021-09-26 17:22:15 +0300
commit9d0ab35ab4e2b9edf022237e2592d999dfe54704 (patch)
tree1a13f3b9bf115657923f82ae9fb991d4b2f6f995 /include/sbi/sbi_timer.h
parent6355155f51d4b636a228b75d82ebbdc706174ae7 (diff)
downloadopensbi-9d0ab35ab4e2b9edf022237e2592d999dfe54704.tar.xz
lib: sbi: Add generic timer delay loop function
We now have frequency of the timer device provided by the platform support so we can emulate desired delay using a loop where the number loop iterations are based on timer frequency. This patch provides sbi_timer_delay_loop() for above purpose. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
Diffstat (limited to 'include/sbi/sbi_timer.h')
-rw-r--r--include/sbi/sbi_timer.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h
index 211e83d..63ef1af 100644
--- a/include/sbi/sbi_timer.h
+++ b/include/sbi/sbi_timer.h
@@ -32,6 +32,22 @@ struct sbi_timer_device {
struct sbi_scratch;
+/** Generic delay loop of desired granularity */
+void sbi_timer_delay_loop(ulong units, u64 unit_freq,
+ void (*delay_fn)(void *), void *opaque);
+
+/** Provide delay in terms of milliseconds */
+static inline void sbi_timer_mdelay(ulong msecs)
+{
+ sbi_timer_delay_loop(msecs, 1000, NULL, NULL);
+}
+
+/** Provide delay in terms of microseconds */
+static inline void sbi_timer_udelay(ulong usecs)
+{
+ sbi_timer_delay_loop(usecs, 1000000, NULL, NULL);
+}
+
/** Get timer value for current HART */
u64 sbi_timer_value(void);