]>
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 #if CONFIG_SYS_HZ != 1000
14 #warning "CONFIG_SYS_HZ must be 1000 and should not be defined by platforms"
17 #ifndef CONFIG_WD_PERIOD
18 # define CONFIG_WD_PERIOD (10 * 1000 * 1000) /* 10 seconds default */
21 DECLARE_GLOBAL_DATA_PTR
;
23 #ifdef CONFIG_SYS_TIMER_RATE
24 /* Returns tick rate in ticks per second */
25 ulong notrace
get_tbclk(void)
27 return CONFIG_SYS_TIMER_RATE
;
31 #ifdef CONFIG_SYS_TIMER_COUNTER
32 unsigned long notrace
timer_read_counter(void)
34 #ifdef CONFIG_SYS_TIMER_COUNTS_DOWN
35 return ~readl(CONFIG_SYS_TIMER_COUNTER
);
37 return readl(CONFIG_SYS_TIMER_COUNTER
);
41 extern unsigned long __weak
timer_read_counter(void);
44 unsigned long long __weak notrace
get_ticks(void)
46 unsigned long now
= timer_read_counter();
48 /* increment tbu if tbl has rolled over */
49 if (now
< gd
->timebase_l
)
52 return ((unsigned long long)gd
->timebase_h
<< 32) | gd
->timebase_l
;
55 /* Returns time in milliseconds */
56 static unsigned long long notrace
tick_to_time(unsigned long long tick
)
58 ulong div
= get_tbclk();
60 tick
*= CONFIG_SYS_HZ
;
65 int __weak
timer_init(void)
70 /* Returns time in milliseconds */
71 ulong __weak
get_timer(ulong base
)
73 return tick_to_time(get_ticks()) - base
;
76 unsigned long __weak notrace
timer_get_us(void)
78 return tick_to_time(get_ticks() * 1000);
81 static unsigned long long usec_to_tick(unsigned long usec
)
83 unsigned long long tick
= usec
;
85 do_div(tick
, 1000000);
89 void __weak
__udelay(unsigned long usec
)
91 unsigned long long tmp
;
93 tmp
= get_ticks() + usec_to_tick(usec
); /* get current timestamp */
95 while (get_ticks() < tmp
+1) /* loop till event */
99 /* ------------------------------------------------------------------------- */
101 void udelay(unsigned long usec
)
107 kv
= usec
> CONFIG_WD_PERIOD
? CONFIG_WD_PERIOD
: usec
;
113 void mdelay(unsigned long msec
)