diff options
author | Uros Majstorovic <majstor@majstor.org> | 2021-02-28 18:38:37 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2021-02-28 18:38:37 +0100 |
commit | 6a4c8a1f11f6a7bd57b0fd618f455bcdecbfe538 (patch) | |
tree | 6d16dbc38b3bac0e91d39f3e86bb6810761ddb84 /fw/fe310/eos/net.c | |
parent | 468e81e6da66f6dfec3a4857dc6e2f370ab180f1 (diff) |
net send will do selected spi dev pause/resume if more is set and netowk is not active
Diffstat (limited to 'fw/fe310/eos/net.c')
-rw-r--r-- | fw/fe310/eos/net.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c index 46700e8..eb5e6f2 100644 --- a/fw/fe310/eos/net.c +++ b/fw/fe310/eos/net.c @@ -486,17 +486,36 @@ void eos_net_free(unsigned char *buffer, unsigned char more) { int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more) { int rv = EOS_OK; - if (more) { - type |= EOS_NET_MTYPE_FLAG_ONEW; - } + if (more) type |= EOS_NET_MTYPE_FLAG_ONEW; + clear_csr(mstatus, MSTATUS_MIE); - if ((net_state_flags & NET_STATE_FLAG_RUN) && (net_state_flags & NET_STATE_FLAG_CTS)) { + if ((type & EOS_NET_MTYPE_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) { + uint8_t spi_dev; + + set_csr(mstatus, MSTATUS_MIE); + spi_dev = eos_spi_dev(); + rv = eos_spi_dev_deselect(); + if (rv) return rv; + + clear_csr(mstatus, MSTATUS_MIE); + while (!(net_state_flags & NET_STATE_FLAG_CTS)) { + asm volatile ("wfi"); + set_csr(mstatus, MSTATUS_MIE); + clear_csr(mstatus, MSTATUS_MIE); + } net_xchg_start(type, buffer, len); + set_csr(mstatus, MSTATUS_MIE); + + eos_spi_dev_select(spi_dev); } else { - rv = eos_msgq_push(&net_send_q, type, buffer, len); - if (rv) eos_bufq_push(&net_buf_q, buffer); + if ((net_state_flags & NET_STATE_FLAG_RUN) && (net_state_flags & NET_STATE_FLAG_CTS)) { + net_xchg_start(type, buffer, len); + } else { + rv = eos_msgq_push(&net_send_q, type, buffer, len); + if (rv) eos_bufq_push(&net_buf_q, buffer); + } + set_csr(mstatus, MSTATUS_MIE); } - set_csr(mstatus, MSTATUS_MIE); return rv; } |