diff options
Diffstat (limited to 'fw/fe310/eos/dev/net.c')
-rw-r--r-- | fw/fe310/eos/dev/net.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/fw/fe310/eos/dev/net.c b/fw/fe310/eos/dev/net.c index d340e29..c8b90f3 100644 --- a/fw/fe310/eos/dev/net.c +++ b/fw/fe310/eos/dev/net.c @@ -3,13 +3,12 @@ #include "encoding.h" #include "platform.h" +#include "board.h" #include "eos.h" #include "msgq.h" #include "event.h" -#include "board.h" - #include "soc/interrupt.h" #include "soc/timer.h" #include "soc/pwr.h" @@ -331,7 +330,7 @@ static void net_stop(void) { eos_intr_set_handler(INT_SPI1_BASE, NULL); } -int eos_net_init(uint8_t wakeup_cause) { +int eos_net_init(void) { int i; eos_msgq_init(&net_send_q, net_sndq_array, EOS_NET_SIZE_BUFQ); @@ -364,12 +363,15 @@ int eos_net_init(uint8_t wakeup_cause) { return EOS_OK; } -int eos_net_run(uint8_t wakeup_cause) { +int eos_net_run(void) { + uint8_t wakeup_cause; + net_start(); + wakeup_cause = eos_pwr_wakeup_cause(); clear_csr(mstatus, MSTATUS_MIE); if (wakeup_cause != EOS_PWR_WAKE_RST) { - if (wakeup_cause != EOS_PWR_WAKE_BTN) { + if (wakeup_cause != EOS_PWR_WAKE_PIN) { net_xchg_wake(); } if (!(net_state_flags & NET_STATE_FLAG_CTS)) { @@ -413,9 +415,9 @@ int eos_net_sleep(uint32_t timeout) { if (rv) return rv; - start = eos_time_get_tick(); + start = eos_get_tick(); do { - if (eos_time_delta_ms(start) > timeout) return EOS_ERR_TIMEOUT; + if (eos_tdelta_ms(start) > timeout) return EOS_ERR_TIMEOUT; clear_csr(mstatus, MSTATUS_MIE); eos_evtq_flush_isr(); done = (eos_msgq_len(&net_send_q) == 0); @@ -428,7 +430,7 @@ int eos_net_sleep(uint32_t timeout) { } while (!done); while (!(GPIO_REG(GPIO_RISE_IP) & (1 << NET_PIN_CTS))) { - if (eos_time_delta_ms(start) > timeout) { + if (eos_tdelta_ms(start) > timeout) { rv = EOS_ERR_TIMEOUT; break; } @@ -516,29 +518,28 @@ void eos_net_free(unsigned char *buffer, unsigned char more) { static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, unsigned char flags) { int rv = EOS_OK; - int _sync = 0; + int sync = 0, dsel = 0; unsigned char _type = *type; uint16_t _len = *len; - uint8_t spi_dev = EOS_SPI_DEV_NET; if (flags & EOS_NET_FLAG_ONEW) _type |= EOS_NET_MTYPE_FLAG_ONEW; if (flags & EOS_NET_FLAG_REPL) _type |= EOS_NET_MTYPE_FLAG_REPL; - if (flags & EOS_NET_FLAG_SYNC) _sync = 1; + if (flags & EOS_NET_FLAG_SYNC) sync = 1; clear_csr(mstatus, MSTATUS_MIE); - if ((flags & EOS_NET_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) _sync = 1; - - if (_sync && !(net_state_flags & NET_STATE_FLAG_RUN)) { - int _rv; + if ((flags & EOS_NET_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) sync = 1; + if (sync && !(net_state_flags & NET_STATE_FLAG_RUN)) { set_csr(mstatus, MSTATUS_MIE); - spi_dev = eos_spi_dev(); - _rv = eos_spi_deselect(); - if (_rv) return _rv; + + rv = eos_spi_select(EOS_SPI_DEV_NET); + if (rv) return rv; + + dsel = 1; clear_csr(mstatus, MSTATUS_MIE); } - if (_sync) { + if (sync) { net_pause(); net_wait4cts(); if (flags & EOS_NET_FLAG_SYNC) { @@ -566,7 +567,7 @@ static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, u } set_csr(mstatus, MSTATUS_MIE); - if (spi_dev != EOS_SPI_DEV_NET) eos_spi_select(spi_dev); + if (dsel) eos_spi_deselect(); return rv; } |