| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <comdef.h> |
| 23 |
#include <sys.h> |
| 24 |
#include <timer.h> |
| 25 |
#include <clkgen_ctrl_macro.h> |
| 26 |
#include <uart.h> |
| 27 |
#include <div64.h> |
| 28 |
|
| 29 |
#define TIMER_RATE_HZ (TIMER_CLK_HZ /1000) |
| 30 |
|
| 31 |
#include "platform.h" |
| 32 |
|
| 33 |
unsigned long long get_ticks(void) |
| 34 |
{ |
| 35 |
return readq(CLINT_CTRL_MTIME); |
| 36 |
} |
| 37 |
|
| 38 |
u32 get_timer(unsigned int base) |
| 39 |
{ |
| 40 |
return lldiv(get_ticks(), TIMER_RATE_HZ) - base; |
| 41 |
} |
| 42 |
#if 0 |
| 43 |
u32 usec_to_tick(u32 usec) |
| 44 |
{ |
| 45 |
u32 value = usec*(timer_clk/1000000); |
| 46 |
|
| 47 |
|
| 48 |
return usec*(timer_clk/1000000); |
| 49 |
} |
| 50 |
|
| 51 |
int udelay(u32 usec) |
| 52 |
{ |
| 53 |
UINT64 tmp; |
| 54 |
UINT64 tmo; |
| 55 |
|
| 56 |
tmo = usec_to_tick(usec); |
| 57 |
tmp = get_ticks(0) + tmo; |
| 58 |
|
| 59 |
while (get_ticks(0) < tmp) |
| 60 |
|
| 61 |
{ |
| 62 |
} |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
#endif |
| 68 |
|
| 69 |
u64 usec_to_tick(u64 usec) |
| 70 |
{ |
| 71 |
u64 value; |
| 72 |
value = usec*(TIMER_CLK_HZ/1000)/1000; |
| 73 |
return value; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
int udelay(unsigned int usec) |
| 78 |
{ |
| 79 |
unsigned long tmp; |
| 80 |
|
| 81 |
tmp = readq((volatile void *)CLINT_CTRL_MTIME) + usec_to_tick(usec); |
| 82 |
|
| 83 |
while (readq((volatile void *)CLINT_CTRL_MTIME) < tmp); |
| 84 |
} |
| 85 |
|
| 86 |
void mdelay(unsigned int ms) |
| 87 |
{ |
| 88 |
udelay(1000*ms); |
| 89 |
} |
| 90 |
|
| 91 |
void sdelay(unsigned int s) |
| 92 |
{ |
| 93 |
mdelay(1000*s); |
| 94 |
} |
| 95 |
|