diff options
author | Christian Cunningham <cc@localhost> | 2022-02-21 21:56:01 -0700 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-02-21 21:56:01 -0700 |
commit | 3b883c24da327036a049a0430bd00ebfdffd5c8f (patch) | |
tree | a266169da94b95f8c1b156285c2f3504c89cd5f3 | |
parent | 6c7bdd85bbe8d2b791e0fe52f93f5e75e8beea2d (diff) |
Added wait
-rw-r--r-- | include/util/time.h | 1 | ||||
-rw-r--r-- | later/sd.c | 8 | ||||
-rw-r--r-- | src/util/time.c | 7 |
3 files changed, 10 insertions, 6 deletions
diff --git a/include/util/time.h b/include/util/time.h index dc51e00..e5e18b1 100644 --- a/include/util/time.h +++ b/include/util/time.h @@ -10,6 +10,7 @@ unsigned long read_cntv_tval(void); void write_cntv_tval(unsigned long val); unsigned long read_cntfrq(void); unsigned long long get_time(void); +void wait_msec(unsigned int n); static inline void enablecntv(void) { @@ -1,7 +1,9 @@ +// Adapted from bztsrc #include <drivers/uart.h> #include <drivers/sd.h> #include <symbols.h> #include <sys/core.h> +#include <util/time.h> #define EMMC_ARG2 ((volatile unsigned int*)(MMIO_BASE+0x00300000)) #define EMMC_BLKSIZECNT ((volatile unsigned int*)(MMIO_BASE+0x00300004)) @@ -91,12 +93,6 @@ unsigned long sd_scr[2], sd_ocr, sd_rca, sd_err, sd_hv; -void wait_msec(unsigned int n) -{ - for(unsigned long i = 0; i < n*100; i++) - asm volatile("nop"); -} - /** * Wait for data or command ready */ diff --git a/src/util/time.c b/src/util/time.c index 0ae3ccf..abb9c8d 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -67,3 +67,10 @@ unsigned long long get_time(void) t.tvalb.high = *(unsigned long*)SYS_TIMER_CHI; return t.tval; } + +void wait_msec(unsigned int n) +{ + unsigned long start = *(volatile unsigned long*)SYS_TIMER_CHI; + while (*(volatile unsigned long*)SYS_TIMER_CHI - start < n) + asm volatile("nop"); +} |