]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib/time.c
2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
13 #ifndef CONFIG_WD_PERIOD
14 # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */
17 DECLARE_GLOBAL_DATA_PTR
;
19 #ifdef CONFIG_SYS_TIMER_RATE
20 /* Returns tick rate in ticks per second */
21 ulong notrace
get_tbclk(void)
23 return CONFIG_SYS_TIMER_RATE
;
27 #ifdef CONFIG_SYS_TIMER_COUNTER
28 unsigned long notrace
timer_read_counter(void)
30 #ifdef CONFIG_SYS_TIMER_COUNTS_DOWN
31 return ~readl(CONFIG_SYS_TIMER_COUNTER
);
33 return readl(CONFIG_SYS_TIMER_COUNTER
);
37 extern unsigned long __weak
timer_read_counter(void);
40 uint64_t __weak notrace
get_ticks(void)
42 unsigned long now
= timer_read_counter();
44 /* increment tbu if tbl has rolled over */
45 if (now
< gd
->timebase_l
)
48 return ((uint64_t)gd
->timebase_h
<< 32) | gd
->timebase_l
;
51 /* Returns time in milliseconds */
52 static uint64_t notrace
tick_to_time(uint64_t tick
)
54 ulong div
= get_tbclk();
56 tick
*= CONFIG_SYS_HZ
;
61 int __weak
timer_init(void)
66 /* Returns time in milliseconds */
67 ulong __weak
get_timer(ulong base
)
69 return tick_to_time(get_ticks()) - base
;
72 unsigned long __weak notrace
timer_get_us(void)
74 return tick_to_time(get_ticks() * 1000);
77 static uint64_t usec_to_tick(unsigned long usec
)
81 do_div(tick
, 1000000);
85 void __weak
__udelay(unsigned long usec
)
89 tmp
= get_ticks() + usec_to_tick(usec
); /* get current timestamp */
91 while (get_ticks() < tmp
+1) /* loop till event */
95 /* ------------------------------------------------------------------------- */
97 void udelay(unsigned long usec
)
103 kv
= usec
> CONFIG_WD_PERIOD
? CONFIG_WD_PERIOD
: usec
;
109 void mdelay(unsigned long msec
)