summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/eos/timer.c')
-rw-r--r--fw/fe310/eos/timer.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/fw/fe310/eos/timer.c b/fw/fe310/eos/timer.c
index 5ae58da..91861a3 100644
--- a/fw/fe310/eos/timer.c
+++ b/fw/fe310/eos/timer.c
@@ -32,7 +32,7 @@ void _eos_timer_handle(void) {
uint64_t now = *mtime;
uint64_t next = 0;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
if (timer_next[i] && (timer_next[i] <= now)) {
timer_next[i] = 0;
if (i == 0) {
@@ -88,7 +88,7 @@ uint32_t eos_timer_get(unsigned char evt) {
return ret;
}
-void eos_timer_set(uint32_t msec, unsigned char evt) {
+void eos_timer_set(unsigned char evt, uint32_t msec) {
int i;
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
@@ -97,7 +97,7 @@ void eos_timer_set(uint32_t msec, unsigned char evt) {
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
timer_next[evt] = tick;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]);
}
*mtimecmp = next;
@@ -112,7 +112,7 @@ void eos_timer_clear(unsigned char evt) {
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
if (timer_next[evt]) {
timer_next[evt] = 0;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]);
}
*mtimecmp = next;
@@ -120,12 +120,11 @@ void eos_timer_clear(unsigned char evt) {
if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
}
-
void eos_time_sleep(uint32_t msec) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
- uint64_t now_ms = *mtime * 1000 / EOS_TIMER_RTC_FREQ;
+ uint64_t mtime0 = *mtime;
- while (*mtime * 1000 / EOS_TIMER_RTC_FREQ < now_ms + msec);
+ while ((*mtime - mtime0) < (msec * EOS_TIMER_RTC_FREQ / 1000 + 1));
}
uint64_t eos_time_get_tick(void) {
@@ -133,6 +132,6 @@ uint64_t eos_time_get_tick(void) {
return *mtime;
}
-uint32_t eos_time_since(uint32_t start) {
- return (eos_time_get_tick() - start) * 1000 / EOS_TIMER_RTC_FREQ;
- }
+uint32_t eos_time_delta_ms(uint32_t tick) {
+ return ((uint32_t)eos_time_get_tick() - tick) * 1000 / EOS_TIMER_RTC_FREQ;
+}