From 69ed847740e3efb5c5ff6319629c93d236150959 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 23 Sep 2022 20:08:02 +0200 Subject: i2s driver fixed; added uart programming; --- fw/fe310/eos/soc/i2s.c | 5 ----- fw/fe310/eos/soc/pwr.c | 3 +++ fw/fe310/eos/soc/spi.c | 54 ++++++++++++++++++++++++++++-------------------- fw/fe310/eos/soc/timer.c | 23 ++++++++++++++------- fw/fe310/eos/soc/timer.h | 3 ++- 5 files changed, 52 insertions(+), 36 deletions(-) (limited to 'fw/fe310/eos/soc') diff --git a/fw/fe310/eos/soc/i2s.c b/fw/fe310/eos/soc/i2s.c index c5b52bf..8416ec1 100644 --- a/fw/fe310/eos/soc/i2s.c +++ b/fw/fe310/eos/soc/i2s.c @@ -108,7 +108,6 @@ static uint16_t _abuf_len(EOSABuf *buf) { return buf->idx_w - buf->idx_r; } -__attribute__ ((section (".itim"))) static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) { switch(type & ~EOS_EVT_MASK) { case EOS_I2S_ETYPE_MIC: @@ -298,7 +297,6 @@ void eos_i2s_mic_set_wm(uint16_t wm) { set_csr(mstatus, MSTATUS_MIE); } -__attribute__ ((section (".itim"))) uint16_t eos_i2s_mic_len(void) { uint16_t ret; @@ -309,7 +307,6 @@ uint16_t eos_i2s_mic_len(void) { return ret; } -__attribute__ ((section (".itim"))) uint16_t eos_i2s_mic_read(uint8_t *sample, uint16_t ssize) { uint16_t i; uint16_t _ssize = 0; @@ -381,7 +378,6 @@ void eos_i2s_spk_set_wm(uint16_t wm) { set_csr(mstatus, MSTATUS_MIE); } -__attribute__ ((section (".itim"))) uint16_t eos_i2s_spk_len(void) { uint16_t ret; @@ -392,7 +388,6 @@ uint16_t eos_i2s_spk_len(void) { return ret; } -__attribute__ ((section (".itim"))) uint16_t eos_i2s_spk_write(uint8_t *sample, uint16_t ssize) { uint16_t i; uint16_t _ssize = 0; diff --git a/fw/fe310/eos/soc/pwr.c b/fw/fe310/eos/soc/pwr.c index a2adfd4..970db8b 100644 --- a/fw/fe310/eos/soc/pwr.c +++ b/fw/fe310/eos/soc/pwr.c @@ -6,6 +6,7 @@ #include "eos.h" #include "timer.h" +#include "dev/flash.h" #include "dev/net.h" #include "pwr.h" @@ -39,6 +40,8 @@ int eos_pwr_sleep(void) { rv = eos_net_sleep(1000); if (rv) return rv; + eos_flash_norm(); + AON_REG(AON_PMUKEY) = 0x51F15E; AON_REG(AON_PMUSLEEP) = 1; diff --git a/fw/fe310/eos/soc/spi.c b/fw/fe310/eos/soc/spi.c index b722c7e..351c9c8 100644 --- a/fw/fe310/eos/soc/spi.c +++ b/fw/fe310/eos/soc/spi.c @@ -57,10 +57,11 @@ int eos_spi_init(uint8_t wakeup_cause) { eos_intr_set_priority(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG); SPI1_REG(SPI_REG_SCKMODE) = SPI_MODE0; - SPI1_REG(SPI_REG_FMT) = SPI_FMT_PROTO(SPI_PROTO_S) | - SPI_FMT_ENDIAN(SPI_ENDIAN_MSB) | - SPI_FMT_DIR(SPI_DIR_RX) | - SPI_FMT_LEN(8); + SPI1_REG(SPI_REG_FMT) = \ + SPI_FMT_PROTO(SPI_PROTO_S) | + SPI_FMT_ENDIAN(SPI_ENDIAN_MSB) | + SPI_FMT_DIR(SPI_DIR_RX) | + SPI_FMT_LEN(8); /* for spi 9bit protocol */ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_SCK); @@ -69,8 +70,6 @@ int eos_spi_init(uint8_t wakeup_cause) { eos_spi_enable(); - // There is no way here to change the CS polarity. - // SPI1_REG(SPI_REG_CSDEF) = 0xFFFF; return EOS_OK; } @@ -117,7 +116,6 @@ void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler) { if (evt && (evt <= EOS_SPI_MAX_EVT)) evt_handler[evt - 1] = handler; } -__attribute__ ((section (".itim"))) void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags) { spi_state_flags &= 0xF0; spi_state_flags |= (SPI_FLAG_XCHG | flags); @@ -127,7 +125,7 @@ void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags) { spi_state_idx_rx = 0; } -static void spi_xchg_finish(void) { +static void spi_wait4xchg(void) { uint8_t done = 0; while (!done) { @@ -140,7 +138,7 @@ static void spi_xchg_finish(void) { } void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) { - if (spi_in_xchg) spi_xchg_finish(); + if (spi_in_xchg) spi_wait4xchg(); spi_in_xchg = 1; _eos_spi_xchg_init(buffer, len, flags); @@ -150,7 +148,6 @@ void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) { SPI1_REG(SPI_REG_IE) = SPI_IP_TXWM; } -__attribute__ ((section (".itim"))) void eos_spi_handle_xchg(void) { int i; uint16_t sz_chunk = MIN(spi_state_len - spi_state_idx_tx, SPI_SIZE_CHUNK); @@ -162,15 +159,21 @@ void eos_spi_handle_xchg(void) { } spi_state_idx_tx += i; - for (i=0; i