summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2022-01-31 07:53:13 +0100
committerUros Majstorovic <majstor@majstor.org>2022-01-31 07:53:13 +0100
commit0eaf514b1f97cb1587815104477e43c50a3eebe6 (patch)
treee139a31e8e6360adbe93c9322bec7f6edabfdd19
parentdd19d6f5c7e0b335301a3f3e3d21bffb8c83e558 (diff)
fixed build sys
-rw-r--r--ecp/platform/fe310.mk7
-rw-r--r--ecp/platform/fe310/Makefile20
-rw-r--r--ecp/platform/fe310/time.c35
-rw-r--r--ecp/platform/fe310/transport.c116
-rw-r--r--ecp/platform/fe310/transport.h7
-rw-r--r--ecp/platform/fe310_obj.mk1
-rw-r--r--ecp/platform/posix.mk4
-rw-r--r--ecp/platform/posix/Makefile20
-rw-r--r--ecp/platform/posix/time.c24
-rw-r--r--ecp/platform/posix/transport.c113
-rw-r--r--ecp/platform/posix/transport.h7
-rw-r--r--ecp/platform/posix_obj.mk2
-rw-r--r--ecp/src/Makefile15
-rw-r--r--ecp/src/vconn/Makefile4
-rw-r--r--ecp/test/Makefile2
-rw-r--r--ecp/util/Makefile5
16 files changed, 369 insertions, 13 deletions
diff --git a/ecp/platform/fe310.mk b/ecp/platform/fe310.mk
new file mode 100644
index 0000000..fd3e6dd
--- /dev/null
+++ b/ecp/platform/fe310.mk
@@ -0,0 +1,7 @@
+FE310_HOME ?= $(PWD)/../../fw/fe310
+export FE310_HOME
+
+include $(FE310_HOME)/common.mk
+CFLAGS += -I$(FE310_HOME) -DECP_WITH_VCONN=1 -DECP_DEBUG=1 -D__FE310__
+
+platform = fe310
diff --git a/ecp/platform/fe310/Makefile b/ecp/platform/fe310/Makefile
new file mode 100644
index 0000000..340effa
--- /dev/null
+++ b/ecp/platform/fe310/Makefile
@@ -0,0 +1,20 @@
+include ../fe310.mk
+CFLAGS += -I../../src
+
+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/ecp/platform/fe310/time.c b/ecp/platform/fe310/time.c
new file mode 100644
index 0000000..3c74933
--- /dev/null
+++ b/ecp/platform/fe310/time.c
@@ -0,0 +1,35 @@
+#include <core.h>
+#include <tr.h>
+
+#include <eos/eos.h>
+#include <eos/net.h>
+#include <eos/event.h>
+#include <eos/timer.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) {
+ eos_timer_set(next, EOS_TIMER_ETYPE_ECP);
+ }
+}
+
+int ecp_tm_init(ECPContext *ctx) {
+ eos_timer_set_handler(EOS_TIMER_ETYPE_ECP, timer_handler);
+ eos_net_acquire_for_evt(EOS_EVT_TIMER | EOS_TIMER_ETYPE_ECP, 1);
+ return ECP_OK;
+}
+
+ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
+ return eos_time_get_tick() * 1000 / EOS_TIMER_RTC_FREQ + msec;
+}
+
+void ecp_tm_sleep_ms(ecp_cts_t msec) {
+ eos_time_sleep(msec);
+}
+
+void ecp_tm_timer_set(ecp_cts_t next) {
+ uint32_t _next = eos_timer_get(EOS_TIMER_ETYPE_ECP);
+ if ((_next == EOS_TIMER_NONE) || (next < _next)) eos_timer_set(next, EOS_TIMER_ETYPE_ECP);
+}
diff --git a/ecp/platform/fe310/transport.c b/ecp/platform/fe310/transport.c
new file mode 100644
index 0000000..777a956
--- /dev/null
+++ b/ecp/platform/fe310/transport.c
@@ -0,0 +1,116 @@
+#include <stdlib.h>
+
+#include <core.h>
+#include <tr.h>
+
+#include <eos/eos.h>
+#include <eos/net.h>
+
+static unsigned char _flags = 0;
+
+ECPSocket *_ecp_tr_sock = NULL;
+
+static void packet_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
+ ECPNetAddr addr;
+
+ ECP2Buffer bufs;
+ ECPBuffer packet;
+ ECPBuffer payload;
+ unsigned char pld_buf[ECP_MAX_PLD];
+
+ bufs.packet = &packet;
+ bufs.payload = &payload;
+
+ packet.buffer = buffer+EOS_SOCK_SIZE_UDP_HDR;
+ packet.size = ECP_MAX_PKT;
+ payload.buffer = pld_buf;
+ payload.size = ECP_MAX_PLD;
+
+ if ((buffer == NULL) || (len < EOS_SOCK_SIZE_UDP_HDR)) {
+ eos_net_free(buffer, 0);
+ return;
+ }
+
+ eos_sock_getfrom(buffer, &addr);
+ ssize_t rv = ecp_pkt_handle(_ecp_tr_sock, &addr, NULL, &bufs, len-EOS_SOCK_SIZE_UDP_HDR);
+#ifdef ECP_DEBUG
+ if (rv < 0) {
+ char b[16];
+ puts("ERR:");
+ puts(itoa(rv, b, 10));
+ puts("\n");
+ }
+#endif
+ if (bufs.packet->buffer) eos_net_free(buffer, 0);
+ eos_net_release();
+}
+
+int ecp_tr_init(ECPContext *ctx) {
+ return ECP_OK;
+}
+
+int ecp_tr_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;
+}
+
+int ecp_tr_addr_set(ECPNetAddr *addr, void *addr_s) {
+ return ECP_ERR;
+}
+
+int ecp_tr_open(ECPSocket *sock, void *addr_s) {
+ sock->sock = eos_sock_open_udp(packet_handler);
+ if (sock->sock < 0) {
+ sock->sock = 0;
+ return ECP_ERR_SEND;
+ }
+ _ecp_tr_sock = sock;
+ return ECP_OK;
+}
+
+void ecp_tr_close(ECPSocket *sock) {
+ eos_sock_close(sock->sock);
+ _ecp_tr_sock = NULL;
+}
+
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) {
+ unsigned char *buf = NULL;
+ int rv;
+
+ flags |= _flags;
+ if (packet && packet->buffer) {
+ if (flags & ECP_SEND_FLAG_REPLY) {
+ buf = packet->buffer-EOS_SOCK_SIZE_UDP_HDR;
+ packet->buffer = NULL;
+ } else {
+ buf = eos_net_alloc();
+ memcpy(buf+EOS_SOCK_SIZE_UDP_HDR, packet->buffer, msg_size);
+ }
+ }
+ if (buf == NULL) return ECP_ERR;
+ rv = eos_sock_sendto(sock->sock, buf, msg_size+EOS_SOCK_SIZE_UDP_HDR, flags & ECP_SEND_FLAG_MORE, addr);
+ if (rv) return ECP_ERR_SEND;
+ return msg_size;
+}
+
+ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int timeout) {
+ return ECP_ERR;
+}
+
+void ecp_tr_release(ECPBuffer *packet, unsigned char more) {
+ if (packet && packet->buffer) {
+ eos_net_free(packet->buffer-EOS_SOCK_SIZE_UDP_HDR, more);
+ packet->buffer = NULL;
+ } else if (!more) {
+ eos_net_release();
+ }
+}
+
+void ecp_tr_flag_set(unsigned char flags) {
+ _flags |= flags;
+}
+
+void ecp_tr_flag_clear(unsigned char flags) {
+ _flags &= ~flags;
+}
diff --git a/ecp/platform/fe310/transport.h b/ecp/platform/fe310/transport.h
new file mode 100644
index 0000000..47ad482
--- /dev/null
+++ b/ecp/platform/fe310/transport.h
@@ -0,0 +1,7 @@
+#include <eos/sock.h>
+
+#define ECP_IPv4_ADDR_SIZE 4
+
+typedef EOSNetAddr ECPNetAddr;
+typedef int ECPNetSock;
+
diff --git a/ecp/platform/fe310_obj.mk b/ecp/platform/fe310_obj.mk
new file mode 100644
index 0000000..52e4bb1
--- /dev/null
+++ b/ecp/platform/fe310_obj.mk
@@ -0,0 +1 @@
+subdirs += vconn
diff --git a/ecp/platform/posix.mk b/ecp/platform/posix.mk
new file mode 100644
index 0000000..7e7daeb
--- /dev/null
+++ b/ecp/platform/posix.mk
@@ -0,0 +1,4 @@
+CFLAGS += -O3 -DECP_WITH_PTHREAD=1 -DECP_WITH_HTABLE=1 -DECP_WITH_RBUF=1 -DECP_WITH_MSGQ=1 -DECP_WITH_VCONN=1 -DECP_WITH_DIRSRV -DECP_DEBUG=1
+LDFLAGS += -lm -pthread
+
+platform = posix
diff --git a/ecp/platform/posix/Makefile b/ecp/platform/posix/Makefile
new file mode 100644
index 0000000..aebb994
--- /dev/null
+++ b/ecp/platform/posix/Makefile
@@ -0,0 +1,20 @@
+include ../posix.mk
+CFLAGS += -I../../src
+
+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/ecp/platform/posix/time.c b/ecp/platform/posix/time.c
new file mode 100644
index 0000000..111e598
--- /dev/null
+++ b/ecp/platform/posix/time.c
@@ -0,0 +1,24 @@
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <core.h>
+#include <tm.h>
+
+int ecp_tm_init(ECPContext *ctx) {
+ return ECP_OK;
+}
+
+ecp_cts_t ecp_tm_abstime_ms(ecp_cts_t msec) {
+ struct timeval tv;
+ ecp_cts_t ms_now;
+
+ gettimeofday(&tv, NULL);
+ ms_now = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ return ms_now + msec;
+}
+
+void ecp_tm_sleep_ms(ecp_cts_t msec) {
+ usleep(msec*1000);
+}
+
+void ecp_tm_timer_set(ecp_cts_t next) {} \ No newline at end of file
diff --git a/ecp/platform/posix/transport.c b/ecp/platform/posix/transport.c
new file mode 100644
index 0000000..2032ce2
--- /dev/null
+++ b/ecp/platform/posix/transport.c
@@ -0,0 +1,113 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <poll.h>
+
+#include <core.h>
+#include <tr.h>
+
+#define ADDR_S_MAX 32
+
+int ecp_tr_init(ECPContext *ctx) {
+ return ECP_OK;
+}
+
+int ecp_tr_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;
+}
+
+int ecp_tr_addr_set(ECPNetAddr *addr, void *addr_s) {
+ int rv;
+ char addr_c[ADDR_S_MAX];
+ char *colon = NULL;
+ char *endptr = NULL;
+ uint16_t hport;
+
+ memset(addr_c, 0, sizeof(addr_c));
+ strncpy(addr_c, addr_s, ADDR_S_MAX-1);
+ colon = strchr(addr_c, ':');
+ if (colon == NULL) return -1;
+ *colon = '\0';
+ colon++;
+ if (*colon == '\0') return -1;
+ rv = inet_pton(AF_INET, addr_c, addr->host);
+ if (rv != 1) return -1;
+ hport = strtol(colon, &endptr, 10);
+ if (*endptr != '\0') return -1;
+ addr->port = htons(hport);
+
+ return 0;
+}
+
+int ecp_tr_open(ECPSocket *sock, void *addr_s) {
+ struct sockaddr_in _myaddr;
+
+ memset((char *)&_myaddr, 0, sizeof(_myaddr));
+ _myaddr.sin_family = AF_INET;
+ if (addr_s) {
+ ECPNetAddr addr;
+ int rv = ecp_tr_addr_set(&addr, addr_s);
+ if (rv) return rv;
+
+ memcpy((void *)&_myaddr.sin_addr, addr.host, sizeof(addr.host));
+ _myaddr.sin_port = addr.port;
+ } else {
+ _myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ _myaddr.sin_port = htons(0);
+ }
+
+ sock->sock = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sock->sock < 0) return sock->sock;
+
+ int rv = bind(sock->sock, (struct sockaddr *)&_myaddr, sizeof(_myaddr));
+ if (rv < 0) {
+ close(sock->sock);
+ return rv;
+ }
+ return ECP_OK;
+}
+
+void ecp_tr_close(ECPSocket *sock) {
+ close(sock->sock);
+}
+
+ssize_t ecp_tr_send(ECPSocket *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) {
+ struct sockaddr_in servaddr;
+
+ memset((void *)&servaddr, 0, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = addr->port;
+ memcpy((void *)&servaddr.sin_addr, addr->host, sizeof(addr->host));
+ return sendto(sock->sock, packet->buffer, msg_size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
+}
+
+ssize_t ecp_tr_recv(ECPSocket *sock, ECPBuffer *packet, ECPNetAddr *addr, int timeout) {
+ struct sockaddr_in servaddr;
+ socklen_t addrlen = sizeof(servaddr);
+ struct pollfd fds[] = {
+ {sock->sock, POLLIN, 0}
+ };
+
+ int rv = poll(fds, 1, timeout);
+ memset((void *)&servaddr, 0, sizeof(servaddr));
+ if (rv == 1) {
+ ssize_t recvlen = recvfrom(sock->sock, packet->buffer, packet->size, 0, (struct sockaddr *)&servaddr, &addrlen);
+ if (recvlen < 0) return recvlen;
+ if (recvlen < ECP_MIN_PKT) return ECP_ERR_RECV;
+
+ if (addr) {
+ addr->port = servaddr.sin_port;
+ memcpy(addr->host, (void *)&servaddr.sin_addr, sizeof(addr->host));
+ }
+ return recvlen;
+ }
+ return ECP_ERR_TIMEOUT;
+}
+
+void ecp_tr_release(ECPBuffer *packet, unsigned char more) {}
+void ecp_tr_flag_set(unsigned char flags) {}
+void ecp_tr_flag_clear(unsigned char flags) {}
+
diff --git a/ecp/platform/posix/transport.h b/ecp/platform/posix/transport.h
new file mode 100644
index 0000000..155bd9c
--- /dev/null
+++ b/ecp/platform/posix/transport.h
@@ -0,0 +1,7 @@
+#define ECP_IPv4_ADDR_SIZE 4
+
+typedef int ECPNetSock;
+typedef struct ECPNetAddr {
+ unsigned char host[ECP_IPv4_ADDR_SIZE];
+ uint16_t port;
+} ECPNetAddr;
diff --git a/ecp/platform/posix_obj.mk b/ecp/platform/posix_obj.mk
new file mode 100644
index 0000000..6ca3b8d
--- /dev/null
+++ b/ecp/platform/posix_obj.mk
@@ -0,0 +1,2 @@
+obj += rbuf.o rbuf_send.o rbuf_recv.o msgq.o
+subdirs += htable vconn
diff --git a/ecp/src/Makefile b/ecp/src/Makefile
index 502f582..120fcbc 100644
--- a/ecp/src/Makefile
+++ b/ecp/src/Makefile
@@ -1,9 +1,10 @@
-CFLAGS += $(PIC) -I.
+include platform.mk
+CFLAGS += -I.
obj = core.o timer.o dir.o dir_srv.o
-subdirs = crypto platform
+subdirs = crypto ../platform/$(platform)
-include Makefile.platform
+include ../platform/$(platform)_obj.mk
%.o: %.c
$(CC) $(CFLAGS) -c $<
@@ -12,17 +13,17 @@ include Makefile.platform
$(CC) $(CFLAGS) -c $<
all: $(obj)
- $(AR) rcs libecpcore.a $(obj)
+ $(AR) rcs libecp.a $(obj)
for i in $(subdirs); do \
(cd $$i && $(MAKE)) || exit; \
done
install: all
mkdir -p build-$(platform)/
- install libecpcore.a build-$(platform)/
+ install libecp.a build-$(platform)/
install crypto/libecpcr.a build-$(platform)/
- install platform/libecptm.a build-$(platform)/
- install platform/libecptr.a build-$(platform)/
+ install ../platform/$(platform)/libecptm.a build-$(platform)/
+ install ../platform/$(platform)/libecptr.a build-$(platform)/
if [ -f htable/libecpht.a ]; then \
install htable/libecpht.a build-$(platform)/; \
fi
diff --git a/ecp/src/vconn/Makefile b/ecp/src/vconn/Makefile
index 9d11406..459d16b 100644
--- a/ecp/src/vconn/Makefile
+++ b/ecp/src/vconn/Makefile
@@ -1,5 +1,5 @@
-include ../Makefile.platform
-CFLAGS += $(PIC) -I..
+include ../platform.mk
+CFLAGS += -I..
obj = vconn.o
diff --git a/ecp/test/Makefile b/ecp/test/Makefile
index 8bb17a3..29fc020 100644
--- a/ecp/test/Makefile
+++ b/ecp/test/Makefile
@@ -1,4 +1,4 @@
-include ../src/Makefile.posix
+include ../platform/posix.mk
CFLAGS += -I../src -I../util -Wno-int-to-void-pointer-cast
dep=../src/build-posix/*.a ../util/libecputil.a
diff --git a/ecp/util/Makefile b/ecp/util/Makefile
index b3cbc7c..58d5086 100644
--- a/ecp/util/Makefile
+++ b/ecp/util/Makefile
@@ -1,6 +1,5 @@
-include ../src/Makefile.posix
-CFLAGS=$(CFLAGS_PL) -I../src
-LDFLAGS=$(LDFLAGS_PL)
+include ../platform/posix.mk
+CFLAGS += -I../src
obj=util.o
dep=../src/build-posix/*.a ./libecputil.a