From 1aaad9e44871ee421548a14dee25f710b77eba20 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Thu, 22 Mar 2018 05:26:21 +0100 Subject: spi exchange handler simplified; net test pass with asm spi handlers --- code/fe310/eos/net.c | 50 ++++++++++++-------------- code/fe310/eos/spi_def.h | 3 +- code/fe310/eos/trap_entry.S | 87 ++++++++++++++++++++++----------------------- 3 files changed, 66 insertions(+), 74 deletions(-) (limited to 'code') diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c index c0b5252..8213262 100644 --- a/code/fe310/eos/net.c +++ b/code/fe310/eos/net.c @@ -56,7 +56,6 @@ static void spi_xchg_reset(void) { // before starting a transaction, set SPI peripheral to desired mode SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_HOLD; - while (SPI1_REG(SPI_REG_TXFIFO) & SPI_TXFIFO_FULL); SPI1_REG(SPI_REG_TXFIFO) = 0; SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(0); @@ -80,10 +79,7 @@ static void spi_xchg_start(unsigned char cmd, unsigned char *buffer, uint16_t le // before starting a transaction, set SPI peripheral to desired mode SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_HOLD; - while (SPI1_REG(SPI_REG_TXFIFO) & SPI_TXFIFO_FULL); SPI1_REG(SPI_REG_TXFIFO) = ((cmd << 3) | (len >> 8)) & 0xFF; - - while (SPI1_REG(SPI_REG_TXFIFO) & SPI_TXFIFO_FULL); SPI1_REG(SPI_REG_TXFIFO) = len & 0xFF; SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(1); @@ -108,20 +104,23 @@ static int spi_xchg_next(unsigned char *_buffer) { return 1; } -static void spi_xchg_handler(void) { +static void spi_handler_xchg(void) { volatile uint32_t r1, r2; int i; if (_eos_spi_state_flags & SPI_FLAG_RST) { - while ((r1 = SPI1_REG(SPI_REG_RXFIFO)) & SPI_RXFIFO_EMPTY); + _eos_spi_state_flags &= ~SPI_FLAG_RST; + + r1 = SPI1_REG(SPI_REG_RXFIFO); SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO; SPI1_REG(SPI_REG_IE) = 0x0; - _eos_spi_state_flags &= ~SPI_FLAG_RST; return; } else if (_eos_spi_state_flags & SPI_FLAG_INIT) { - while ((r1 = SPI1_REG(SPI_REG_RXFIFO)) & SPI_RXFIFO_EMPTY); - while ((r2 = SPI1_REG(SPI_REG_RXFIFO)) & SPI_RXFIFO_EMPTY); + _eos_spi_state_flags &= ~SPI_FLAG_INIT; + + r1 = SPI1_REG(SPI_REG_RXFIFO); + r2 = SPI1_REG(SPI_REG_RXFIFO); if (_eos_spi_state_cmd & EOS_NET_CMD_FLAG_ONEW) { r1 = 0; @@ -140,22 +139,19 @@ static void spi_xchg_handler(void) { _eos_spi_state_len = ((_eos_spi_state_len + 2)/4 + 1) * 4 - 2; } - SPI1_REG(SPI_REG_TXCTRL) = SPI_TXWM(SPI_SIZE_TXWM); - SPI1_REG(SPI_REG_RXCTRL) = SPI_RXWM(SPI_SIZE_RXWM); - SPI1_REG(SPI_REG_IE) = SPI_IP_TXWM | SPI_IP_RXWM; - _eos_spi_state_flags &= ~SPI_FLAG_INIT; + SPI1_REG(SPI_REG_TXCTRL) = SPI_TXWM(SPI_SIZE_WM); + SPI1_REG(SPI_REG_IE) = SPI_IP_TXWM; + return; } - if (SPI1_REG(SPI_REG_IP) & SPI_IP_TXWM) { - uint16_t sz_chunk = MIN(_eos_spi_state_len - _eos_spi_state_idx_tx, SPI_SIZE_CHUNK); - for (i=0; i