From 0b7db1a4555da3f9a153d72f44bc2a5d070df51f Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Thu, 11 Jan 2018 18:03:58 +0100 Subject: fe310 platform introdiced --- code/core/fe310/Makefile | 20 ++++++++++++++++++++ code/core/fe310/time.c | 18 ++++++++++++++++++ code/core/fe310/transport.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ code/core/fe310/transport.h | 10 ++++++++++ 4 files changed, 92 insertions(+) create mode 100644 code/core/fe310/Makefile create mode 100644 code/core/fe310/time.c create mode 100644 code/core/fe310/transport.c create mode 100644 code/core/fe310/transport.h diff --git a/code/core/fe310/Makefile b/code/core/fe310/Makefile new file mode 100644 index 0000000..6dd42e2 --- /dev/null +++ b/code/core/fe310/Makefile @@ -0,0 +1,20 @@ +include ../../Makefile.platform +CFLAGS=$(CFLAGS_PL) $(PIC) -I.. + +obj_tr = transport.o +obj_tm = time.o + + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +all: libecptr.a libecptm.a + +libecptr.a: $(obj_tr) + $(AR) rcs libecptr.a $(obj_tr) + +libecptm.a: $(obj_tm) + $(AR) rcs libecptm.a $(obj_tm) + +clean: + rm -f *.o *.a diff --git a/code/core/fe310/time.c b/code/core/fe310/time.c new file mode 100644 index 0000000..2ff98cb --- /dev/null +++ b/code/core/fe310/time.c @@ -0,0 +1,18 @@ +#include + +#include "encoding.h" +#include "platform.h" + +static ecp_cts_t t_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; +} + +int ecp_time_init(ECPTimeIface *t) { + t->init = 1; + t->abstime_ms = t_abstime_ms; + t->sleep_ms = NULL; + return 0; +} diff --git a/code/core/fe310/transport.c b/code/core/fe310/transport.c new file mode 100644 index 0000000..7afdbf7 --- /dev/null +++ b/code/core/fe310/transport.c @@ -0,0 +1,44 @@ +#include +#include + +#include + +#include "eos.h" +#include "net.h" + +static int t_addr_eq(ECPNetAddr *addr1, ECPNetAddr *addr2) { + if (addr1->port != addr2->port) return 0; + if (memcmp(addr1->host, addr2->host, sizeof(addr1->host)) != 0) return 0; + return 1; +} + +static int t_open(int *sock, void *addr_s) { + *sock = 0; + return ECP_OK; +} + +static void t_close(int *sock) { +} + +static ssize_t t_send(int *sock, void *msg, size_t msg_size, ECPNetAddr *addr) { + unsigned char *buf = msg; + size_t addr_len = sizeof(addr->host) + sizeof(addr->port); + uint16_t buf_size = msg_size + addr_len; + int rv; + + buf -= addr_len; + rv = eos_net_send(EOS_NET_CMD_PKT, buf, buf_size); + if (rv) return ECP_ERR_SEND; + return msg_size; +} + +int ecp_transport_init(ECPTransportIface *t) { + t->init = 1; + t->open = t_open; + t->close = t_close; + t->send = t_send; + t->recv = NULL; + t->addr_eq = t_addr_eq; + t->addr_set = NULL; + return ECP_OK; +} diff --git a/code/core/fe310/transport.h b/code/core/fe310/transport.h new file mode 100644 index 0000000..c35e13e --- /dev/null +++ b/code/core/fe310/transport.h @@ -0,0 +1,10 @@ +#include + +#define ECP_IPv4_ADDR_SIZE 4 + +typedef int ECPNetSock; +typedef struct ECPNetAddr { + unsigned char host[ECP_IPv4_ADDR_SIZE]; + uint16_t port; +} ECPNetAddr; + -- cgit v1.2.3