summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/timer.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-09-23 20:08:02 +0200
committerUros Majstorovic <majstor@majstor.org>2022-09-23 20:08:02 +0200
commit69ed847740e3efb5c5ff6319629c93d236150959 (patch)
treea479305afd898870f2ac0e55fe04be788e768fca /fw/fe310/eos/soc/timer.c
parent38e19a65fda7a37688320b4b732eb1113bbcbad7 (diff)
i2s driver fixed; added uart programming;
Diffstat (limited to 'fw/fe310/eos/soc/timer.c')
-rw-r--r--fw/fe310/eos/soc/timer.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/fw/fe310/eos/soc/timer.c b/fw/fe310/eos/soc/timer.c
index 91861a3..8d74c6d 100644
--- a/fw/fe310/eos/soc/timer.c
+++ b/fw/fe310/eos/soc/timer.c
@@ -26,12 +26,13 @@ static void timer_handle_evt(unsigned char type, unsigned char *buffer, uint16_t
}
void _eos_timer_handle(void) {
- 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 now = *mtime;
+ uint64_t now;
uint64_t next = 0;
+ int i;
+ now = *mtime;
for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
if (timer_next[i] && (timer_next[i] <= now)) {
timer_next[i] = 0;
@@ -48,8 +49,8 @@ void _eos_timer_handle(void) {
}
int eos_timer_init(uint8_t wakeup_cause) {
- int i;
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
+ int i;
clear_csr(mie, MIP_MTIP);
*mtimecmp = 0;
@@ -89,11 +90,11 @@ uint32_t eos_timer_get(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);
uint64_t tick = *mtime + msec * (uint64_t)EOS_TIMER_RTC_FREQ / 1000;
uint64_t next = 0;
+ int i;
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
timer_next[evt] = tick;
@@ -105,9 +106,9 @@ void eos_timer_set(unsigned char evt, uint32_t msec) {
}
void eos_timer_clear(unsigned char evt) {
- int i;
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
uint64_t next = 0;
+ int i;
if (*mtimecmp != 0) clear_csr(mie, MIP_MTIP);
if (timer_next[evt]) {
@@ -122,16 +123,22 @@ void eos_timer_clear(unsigned char evt) {
void eos_time_sleep(uint32_t msec) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
- uint64_t mtime0 = *mtime;
+ uint32_t mtime0 = *mtime;
while ((*mtime - mtime0) < (msec * EOS_TIMER_RTC_FREQ / 1000 + 1));
}
-uint64_t eos_time_get_tick(void) {
+uint32_t eos_time_get_tick(void) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
return *mtime;
}
+uint64_t eos_time_get_tick64(void) {
+ volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
+ return *mtime;
+}
+
+
uint32_t eos_time_delta_ms(uint32_t tick) {
- return ((uint32_t)eos_time_get_tick() - tick) * 1000 / EOS_TIMER_RTC_FREQ;
+ return (eos_time_get_tick() - tick) * 1000 / EOS_TIMER_RTC_FREQ;
}