From 85500fe0d01b691a9bdd8c2330d26d66bc2bc177 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 18 Oct 2019 18:38:00 +0200 Subject: added spi driver --- code/fe310/eos/net.c | 226 +++++++++++++++++++++------------------------------ 1 file changed, 92 insertions(+), 134 deletions(-) (limited to 'code/fe310/eos/net.c') diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c index b8a5056..7d1803d 100644 --- a/code/fe310/eos/net.c +++ b/code/fe310/eos/net.c @@ -1,8 +1,5 @@ -#include #include -#include #include -#include #include "encoding.h" #include "platform.h" @@ -10,8 +7,11 @@ #include "eos.h" #include "msgq.h" #include "interrupt.h" +#include "event.h" #include "spi.h" +#include "spi_def.h" + #include "net.h" #include "net_def.h" @@ -31,17 +31,11 @@ static EOSMsgItem net_sndq_array[NET_SIZE_BUFQ]; static EOSNetBufQ net_buf_q; static unsigned char net_bufq_array[NET_SIZE_BUFQ][NET_SIZE_BUF]; -extern EOSMsgQ _eos_event_q; - -uint32_t _eos_spi_state_len = 0; -uint32_t _eos_spi_state_len_tx = 0; -uint32_t _eos_spi_state_len_rx = 0; -uint32_t _eos_spi_state_idx_tx = 0; -uint32_t _eos_spi_state_idx_rx = 0; -unsigned char *_eos_spi_state_buf = NULL; - static uint8_t net_state_flags = 0; static unsigned char net_state_type = 0; +static uint32_t net_state_len_tx = 0; +static uint32_t net_state_len_rx = 0; + static uint8_t net_state_next_cnt = 0; static unsigned char *net_state_next_buf = NULL; @@ -49,6 +43,22 @@ static eos_evt_fptr_t evt_handler[EOS_NET_MAX_MTYPE]; static uint16_t evt_handler_flags_buf_free = 0; static uint16_t evt_handler_flags_buf_acq = 0; +extern EOSMsgQ _eos_event_q; +extern uint32_t _eos_spi_state_len; +extern uint32_t _eos_spi_state_idx_tx; +extern uint32_t _eos_spi_state_idx_rx; +extern unsigned char *_eos_spi_state_buf; + +static void net_bufq_init(void) { + int i; + + net_buf_q.idx_r = 0; + net_buf_q.idx_w = NET_SIZE_BUFQ; + for (i=0; i> 3); - _eos_spi_state_len_rx = ((r1 & 0x07) << 8); - _eos_spi_state_len_rx |= (r2 & 0xFF); - _eos_spi_state_len = MAX(_eos_spi_state_len_tx, _eos_spi_state_len_rx); + net_state_len_rx = ((r1 & 0x07) << 8); + net_state_len_rx |= (r2 & 0xFF); + _eos_spi_state_len = MAX(net_state_len_tx, net_state_len_rx); + _eos_spi_state_idx_tx = 0; + _eos_spi_state_idx_rx = 0; // Work around esp32 bug if (_eos_spi_state_len < 6) { @@ -159,57 +151,54 @@ static void net_handler_xchg(void) { return; } - uint16_t sz_chunk = MIN(_eos_spi_state_len - _eos_spi_state_idx_tx, SPI_SIZE_CHUNK); - for (i=0; i