diff options
Diffstat (limited to 'code/ecp/fe310')
-rw-r--r-- | code/ecp/fe310/Makefile | 4 | ||||
-rw-r--r-- | code/ecp/fe310/time.c | 9 | ||||
-rw-r--r-- | code/ecp/fe310/transport.c | 46 |
3 files changed, 47 insertions, 12 deletions
diff --git a/code/ecp/fe310/Makefile b/code/ecp/fe310/Makefile index 6dd42e2..1ccf322 100644 --- a/code/ecp/fe310/Makefile +++ b/code/ecp/fe310/Makefile @@ -1,5 +1,5 @@ -include ../../Makefile.platform -CFLAGS=$(CFLAGS_PL) $(PIC) -I.. +include ../Makefile.platform +CFLAGS=$(CFLAGS_PL) $(PIC) -I.. -I../../fe310 obj_tr = transport.o obj_tm = time.o diff --git a/code/ecp/fe310/time.c b/code/ecp/fe310/time.c index 2ff98cb..4b8b2a7 100644 --- a/code/ecp/fe310/time.c +++ b/code/ecp/fe310/time.c @@ -1,5 +1,7 @@ #include <core.h> +#include <eos/timer.h> + #include "encoding.h" #include "platform.h" @@ -10,9 +12,14 @@ static ecp_cts_t t_abstime_ms(ecp_cts_t msec) { return now_ms + msec; } +static void t_timer_set(ecp_cts_t next) { + uint32_t tick = next * (uint64_t)RTC_FREQ / 1000; + eos_timer_set(tick, 1); +} + int ecp_time_init(ECPTimeIface *t) { t->init = 1; t->abstime_ms = t_abstime_ms; - t->sleep_ms = NULL; + t->timer_set = t_timer_set; return 0; } diff --git a/code/ecp/fe310/transport.c b/code/ecp/fe310/transport.c index b833ee3..9ff04ca 100644 --- a/code/ecp/fe310/transport.c +++ b/code/ecp/fe310/transport.c @@ -1,10 +1,10 @@ #include <stddef.h> #include <string.h> -#include <core.h> +#include <eos/eos.h> +#include <eos/net.h> -#include "eos.h" -#include "net.h" +#include <core.h> static int t_addr_eq(ECPNetAddr *addr1, ECPNetAddr *addr2) { if (addr1->port != addr2->port) return 0; @@ -20,27 +20,55 @@ static int t_open(int *sock, void *addr_s) { 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; +static ssize_t t_send(int *sock, ECPBuffer *packet, size_t msg_size, ECPNetAddr *addr, unsigned char flags) { + unsigned char *buf = NULL; size_t addr_len = sizeof(addr->host) + sizeof(addr->port); uint16_t buf_size = msg_size + addr_len; + unsigned char cmd = EOS_NET_CMD_PKT; int rv; - buf -= addr_len; + if (flags & ECP_SEND_FLAG_MORE) { + cmd |= EOS_NET_CMD_FLAG_ONEW; + } + if (flags & ECP_SEND_FLAG_REPLY) { + if (packet && packet->buffer) buf = packet->buffer-addr_len; + } else { + buf = eos_net_alloc(); + } + if (buf == NULL) return ECP_ERR; memcpy(buf, addr->host, sizeof(addr->host)); memcpy(buf+sizeof(addr->host), &addr->port, sizeof(addr->port)); - rv = eos_net_send(EOS_NET_CMD_PKT, buf, buf_size); + rv = eos_net_send(cmd, buf, buf_size); if (rv) return ECP_ERR_SEND; return msg_size; } +static void t_buf_free(ECP2Buffer *b, unsigned char flags) { + size_t addr_len = ECP_IPv4_ADDR_SIZE + sizeof(uint16_t); + if (b && b->packet && b->packet->buffer) eos_net_free(b->packet->buffer-addr_len, flags & ECP_SEND_FLAG_MORE); +} + +static void t_buf_flag_set(ECP2Buffer *b, unsigned char flags) { + size_t addr_len = ECP_IPv4_ADDR_SIZE + sizeof(uint16_t); + if (flags & ECP_SEND_FLAG_MORE) { + if (b && b->packet && b->packet->buffer) eos_net_reserve(b->packet->buffer-addr_len); + } +} + +static void t_buf_flag_clear(ECP2Buffer *b, unsigned char flags) { + if (flags & ECP_SEND_FLAG_MORE) { + eos_net_release(1); + } +} + 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; + t->buf_free = t_buf_free; + t->buf_flag_set = t_buf_flag_set; + t->buf_flag_clear = t_buf_flag_clear; return ECP_OK; } |