summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/timer.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-05-13 12:26:19 +0200
committerUros Majstorovic <majstor@majstor.org>2022-05-13 12:26:19 +0200
commit9ccb4db8d59ec9dab33ee8617d462f21a8bb4fa8 (patch)
treea4f8ba9375a4ee82bae6ddc0cb3a35227f6f9469 /fw/fe310/eos/timer.c
parent45f0d9b890b086493f9bb06428c46cd802324223 (diff)
touch controller/eve fixes
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;
+}