summaryrefslogtreecommitdiff
path: root/code/ecp/fe310/time.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-10-19 19:37:03 +0200
committerUros Majstorovic <majstor@majstor.org>2019-10-19 19:37:03 +0200
commit84735c23109b77e0691da208d31c374aa943b257 (patch)
tree2ff1430be30807c326c3b8274b0d0c0db7e802a2 /code/ecp/fe310/time.c
parent3a5f92b720afcb4adac61174dbefefd420aa5319 (diff)
fixed transport interface; risc-v transport updated to support eos sock interface
Diffstat (limited to 'code/ecp/fe310/time.c')
-rw-r--r--code/ecp/fe310/time.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/code/ecp/fe310/time.c b/code/ecp/fe310/time.c
index 455c762..1346fea 100644
--- a/code/ecp/fe310/time.c
+++ b/code/ecp/fe310/time.c
@@ -1,21 +1,39 @@
#include <core.h>
#include <tr.h>
+#include <eos/eos.h>
+#include <eos/event.h>
#include <eos/timer.h>
#include "encoding.h"
#include "platform.h"
+extern ECPSocket *_ecp_tr_sock;
+
+static void timer_handler(unsigned char type) {
+ ecp_cts_t next = ecp_timer_exe(_ecp_tr_sock);
+ if (next) {
+ volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
+ uint64_t tick = *mtime + next * (uint64_t)RTC_FREQ / 1000;
+ eos_timer_set(tick, EOS_TIMER_ETYPE_ECP, 0);
+ }
+}
+
+int ecp_tm_init(ECPContext *ctx) {
+ eos_timer_set_handler(EOS_TIMER_ETYPE_ECP, timer_handler, EOS_EVT_FLAG_NET_BUF_ACQ);
+ return ECP_OK;
+}
+
ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
-
+
uint64_t now_ms = *mtime * 1000 / RTC_FREQ;
return now_ms + msec;
}
void ecp_tm_sleep_ms(ecp_cts_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);
}