diff options
author | Uros Majstorovic <majstor@majstor.org> | 2019-11-25 17:02:50 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2019-11-25 17:02:50 +0100 |
commit | 898780a7c2b410793ca0dc60887b8e985b777b14 (patch) | |
tree | a31a68f4957bb1f039500ab407caaafc52a8cf79 /code/fe310/eos | |
parent | 45e12774e2a1d334b13684399e156b1a83d55777 (diff) |
timer added sleep, timer_set gets msec
Diffstat (limited to 'code/fe310/eos')
-rw-r--r-- | code/fe310/eos/timer.c | 11 | ||||
-rw-r--r-- | code/fe310/eos/timer.h | 3 |
2 files changed, 12 insertions, 2 deletions
diff --git a/code/fe310/eos/timer.c b/code/fe310/eos/timer.c index ed6aac4..f443a8d 100644 --- a/code/fe310/eos/timer.c +++ b/code/fe310/eos/timer.c @@ -80,9 +80,11 @@ uint64_t eos_timer_get(unsigned char evt) { return ret; } -void eos_timer_set(uint64_t tick, unsigned char evt, unsigned char b) { +void eos_timer_set(uint32_t msec, unsigned char evt, unsigned char b) { int i; + volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); + uint64_t tick = *mtime + msec * (uint64_t)RTC_FREQ / 1000; uint64_t next = 0; if (evt && (evt <= EOS_TIMER_MAX_ETYPE)) { @@ -145,3 +147,10 @@ void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t if ((evt != EOS_TIMER_MAX_ETYPE) && flags) eos_evtq_set_flags(EOS_EVT_TIMER | evt + 1, flags); } + +void eos_timer_sleep(uint32_t msec) { + volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME); + + uint64_t now_ms = *mtime * 1000 / RTC_FREQ; + while (*mtime * 1000 / RTC_FREQ < now_ms + msec); +} diff --git a/code/fe310/eos/timer.h b/code/fe310/eos/timer.h index 0807d96..dff9b2b 100644 --- a/code/fe310/eos/timer.h +++ b/code/fe310/eos/timer.h @@ -9,6 +9,7 @@ typedef void (*eos_timer_fptr_t) (unsigned char); void eos_timer_init(void); uint64_t eos_timer_get(unsigned char evt); -void eos_timer_set(uint64_t tick, unsigned char evt, unsigned char b); +void eos_timer_set(uint32_t msec, unsigned char evt, unsigned char b); void eos_timer_clear(unsigned char evt); void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags); +void eos_timer_sleep(uint32_t msec); |