summaryrefslogtreecommitdiff
path: root/code/fe310/eos
diff options
context:
space:
mode:
Diffstat (limited to 'code/fe310/eos')
-rw-r--r--code/fe310/eos/net.c29
-rw-r--r--code/fe310/eos/net_def.h1
-rw-r--r--code/fe310/eos/spi.c21
-rw-r--r--code/fe310/eos/spi.h1
4 files changed, 29 insertions, 23 deletions
diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c
index b6f5722..1b9e34a 100644
--- a/code/fe310/eos/net.c
+++ b/code/fe310/eos/net.c
@@ -72,7 +72,7 @@ static unsigned char *net_bufq_pop(void) {
static void net_xchg_reset(void) {
net_state_flags &= ~NET_STATE_FLAG_CTS;
- net_state_flags |= NET_STATE_FLAG_RST;
+ net_state_flags |= (NET_STATE_FLAG_RST | NET_STATE_FLAG_XCHG);
// before starting a transaction, set SPI peripheral to desired mode
SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_HOLD;
@@ -85,7 +85,7 @@ static void net_xchg_reset(void) {
static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t len) {
net_state_flags &= ~NET_STATE_FLAG_CTS;
- net_state_flags |= NET_STATE_FLAG_INIT;
+ net_state_flags |= (NET_STATE_FLAG_INIT | NET_STATE_FLAG_XCHG);
if (net_state_next_cnt && (net_state_next_buf == NULL)) type |= NET_MTYPE_FLAG_ONEW;
if (type & NET_MTYPE_FLAG_ONEW) net_state_flags |= NET_STATE_FLAG_ONEW;
@@ -183,6 +183,7 @@ void eos_net_xchg_done(void) {
} else {
net_bufq_push(_eos_spi_state_buf);
}
+ net_state_flags &= ~NET_STATE_FLAG_XCHG;
}
static void net_handler_cts(void) {
@@ -244,6 +245,13 @@ void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t fl
void eos_net_init(void) {
int i;
+ net_bufq_init();
+ eos_msgq_init(&net_send_q, net_sndq_array, NET_SIZE_BUFQ);
+ for (i=0; i<EOS_NET_MAX_MTYPE; i++) {
+ evt_handler[i] = eos_evtq_bad_handler;
+ }
+ eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt);
+
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_CTS);
GPIO_REG(GPIO_PULLUP_EN) |= (1 << NET_PIN_CTS);
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_CTS);
@@ -256,13 +264,6 @@ void eos_net_init(void) {
GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_RTS);
GPIO_REG(GPIO_FALL_IE) |= (1 << NET_PIN_RTS);
eos_intr_set(INT_GPIO_BASE + NET_PIN_RTS, IRQ_PRIORITY_NET_RTS, net_handler_rts);
-
- net_bufq_init();
- eos_msgq_init(&net_send_q, net_sndq_array, NET_SIZE_BUFQ);
- for (i=0; i<EOS_NET_MAX_MTYPE; i++) {
- evt_handler[i] = eos_evtq_bad_handler;
- }
- eos_evtq_set_handler(EOS_EVT_NET, net_handler_evt);
}
void eos_net_start(void) {
@@ -271,16 +272,20 @@ void eos_net_start(void) {
SPI1_REG(SPI_REG_CSID) = SPI_CS_IDX_NET;
net_state_flags |= NET_STATE_FLAG_RUN;
- if (net_state_flags & NET_STATE_FLAG_CTS) net_xchg_next(NULL);
+ if (net_state_flags & NET_STATE_FLAG_CTS) {
+ clear_csr(mstatus, MSTATUS_MIE);
+ net_xchg_next(NULL);
+ set_csr(mstatus, MSTATUS_MIE);
+ }
}
void eos_net_stop(void) {
- volatile uint8_t done = 0;
+ uint8_t done = 0;
while (!done) {
clear_csr(mstatus, MSTATUS_MIE);
net_state_flags &= ~NET_STATE_FLAG_RUN;
- done = net_state_flags & NET_STATE_FLAG_CTS;
+ done = !(net_state_flags & NET_STATE_FLAG_XCHG);
if (!done) asm volatile ("wfi");
set_csr(mstatus, MSTATUS_MIE);
}
diff --git a/code/fe310/eos/net_def.h b/code/fe310/eos/net_def.h
index 473714c..e38216d 100644
--- a/code/fe310/eos/net_def.h
+++ b/code/fe310/eos/net_def.h
@@ -10,6 +10,7 @@
#define NET_STATE_FLAG_CTS 0x08
#define NET_STATE_FLAG_INIT 0x10
#define NET_STATE_FLAG_ONEW 0x20
+#define NET_STATE_FLAG_XCHG 0x40
#define NET_MTYPE_FLAG_ONEW 0x10
diff --git a/code/fe310/eos/spi.c b/code/fe310/eos/spi.c
index 034ae99..2928e82 100644
--- a/code/fe310/eos/spi.c
+++ b/code/fe310/eos/spi.c
@@ -136,6 +136,11 @@ static void spi_xchg_done(void) {
spi_state_flags &= ~SPI_FLAG_XCHG;
if (!(spi_state_flags & (EOS_SPI_FLAG_MORE | SPI_FLAG_CS))) eos_spi_cs_clear();
SPI1_REG(SPI_REG_IE) = 0x0;
+ if (spi_dev == EOS_SPI_DEV_NET) {
+ eos_net_xchg_done();
+ } else {
+ eos_msgq_push(&_eos_event_q, EOS_EVT_SPI | spi_dev, _eos_spi_state_buf, _eos_spi_state_len);
+ }
}
void eos_spi_xchg_handler(void) {
@@ -156,19 +161,13 @@ void eos_spi_xchg_handler(void) {
}
_eos_spi_state_idx_rx += i;
- if ((spi_state_flags & EOS_SPI_FLAG_TX) && _eos_spi_state_idx_tx == _eos_spi_state_len) {
- spi_state_flags &= ~EOS_SPI_FLAG_TX;
- spi_xchg_done();
- } else if (_eos_spi_state_idx_rx == _eos_spi_state_len) {
- spi_xchg_done();
- if (spi_dev == EOS_SPI_DEV_NET) {
- eos_net_xchg_done();
+ if (_eos_spi_state_idx_tx == _eos_spi_state_len) {
+ if ((_eos_spi_state_idx_rx == _eos_spi_state_len) || (spi_state_flags & EOS_SPI_FLAG_TX)) {
+ spi_xchg_done();
} else {
- eos_msgq_push(&_eos_event_q, EOS_EVT_SPI | spi_dev, _eos_spi_state_buf, _eos_spi_state_len);
+ SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(MIN(_eos_spi_state_len - _eos_spi_state_idx_rx - 1, SPI_SIZE_WM - 1));
+ SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM;
}
- } else if (_eos_spi_state_idx_tx == _eos_spi_state_len) {
- SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(MIN(_eos_spi_state_len - _eos_spi_state_idx_rx - 1, SPI_SIZE_WM - 1));
- SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM;
}
}
diff --git a/code/fe310/eos/spi.h b/code/fe310/eos/spi.h
index 2327413..24d7996 100644
--- a/code/fe310/eos/spi.h
+++ b/code/fe310/eos/spi.h
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include "event.h"
#define EOS_SPI_DEV_NET 0
#define EOS_SPI_DEV_DISP 1