summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2026-01-07 22:58:33 +0100
committerUros Majstorovic <majstor@majstor.org>2026-01-07 22:58:33 +0100
commit46b08fc235f3f068034355970697acc0956e5c99 (patch)
tree96e2bde5d95c295a57afae353684a25544fb09fa /fw/fe310/eos/soc
parent285ddd410a559449b7e2cbab9b2b10e850efbd08 (diff)
introduced EOSMessage struct for SPI and Event queue messages; added APP <-> FE310 bridge SPI messages; LCD/touch panel driver for app module; save relevant state to AON module before sleep;
Diffstat (limited to 'fw/fe310/eos/soc')
-rw-r--r--fw/fe310/eos/soc/i2s.c16
-rw-r--r--fw/fe310/eos/soc/i2s.h7
-rw-r--r--fw/fe310/eos/soc/spi.c32
-rw-r--r--fw/fe310/eos/soc/spi.h10
-rw-r--r--fw/fe310/eos/soc/timer.c13
-rw-r--r--fw/fe310/eos/soc/timer.h6
-rw-r--r--fw/fe310/eos/soc/uart.c14
-rw-r--r--fw/fe310/eos/soc/uart.h6
8 files changed, 53 insertions, 51 deletions
diff --git a/fw/fe310/eos/soc/i2s.c b/fw/fe310/eos/soc/i2s.c
index 8bd5600..52c7a8b 100644
--- a/fw/fe310/eos/soc/i2s.c
+++ b/fw/fe310/eos/soc/i2s.c
@@ -31,8 +31,8 @@
#define EOS_ABUF_IDX_MASK(IDX, SIZE) ((IDX) & ((SIZE) - 1))
-static eos_i2s_handler_t i2s_mic_handler = NULL;
-static eos_i2s_handler_t i2s_spk_handler = NULL;
+static eos_evt_simple_handler_t i2s_mic_handler = NULL;
+static eos_evt_simple_handler_t i2s_spk_handler = NULL;
static uint32_t i2s_clk_period;
static uint8_t i2s_mic_volume = 0; /* 0 - 8 */
static uint8_t i2s_spk_volume = 16; /* 0 - 16 */
@@ -93,11 +93,11 @@ static int _sbuf_push(uint16_t sample) {
return EOS_OK;
}
-static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
+static void i2s_handle_evt(unsigned char type, EOSMessage *msg, uint16_t len) {
switch(type & ~EOS_EVT_MASK) {
case EOS_I2S_ETYPE_MIC:
if (i2s_mic_handler) {
- i2s_mic_handler(type);
+ i2s_mic_handler(type & ~EOS_EVT_MASK);
clear_csr(mstatus, MSTATUS_MIE);
_eos_i2s_drvr[I2S_MIC_EVT] = 1;
set_csr(mstatus, MSTATUS_MIE);
@@ -106,7 +106,7 @@ static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l
case EOS_I2S_ETYPE_SPK:
if (i2s_spk_handler) {
- i2s_spk_handler(type);
+ i2s_spk_handler(type & ~EOS_EVT_MASK);
clear_csr(mstatus, MSTATUS_MIE);
_eos_i2s_drvr[I2S_SPK_EVT] = 1;
set_csr(mstatus, MSTATUS_MIE);
@@ -114,7 +114,7 @@ static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l
break;
default:
- eos_evtq_bad_handler(type, buffer, len);
+ eos_evtq_bad_handler(type, msg, len);
break;
}
}
@@ -281,7 +281,7 @@ int eos_i2s_set_lsgain(int gain) {
return eos_egpio_set_val(EGPIO_PIN_LSGAIN_SEL, gain);
}
-void eos_i2s_mic_set_handler(eos_i2s_handler_t handler, uint16_t wm) {
+void eos_i2s_mic_set_handler(eos_evt_simple_handler_t handler, uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
if ((i2s_mic_handler == NULL) && handler) _eos_i2s_drvr[I2S_MIC_EVT] = 1;
if (i2s_mic_handler && (handler == NULL)) _eos_i2s_drvr[I2S_MIC_EVT] = 0;
@@ -355,7 +355,7 @@ void eos_i2s_mic_set_vol(int vol) {
set_csr(mstatus, MSTATUS_MIE);
}
-void eos_i2s_spk_set_handler(eos_i2s_handler_t handler, uint16_t wm) {
+void eos_i2s_spk_set_handler(eos_evt_simple_handler_t handler, uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
if ((i2s_spk_handler == NULL) && handler) _eos_i2s_drvr[I2S_SPK_EVT] = 1;
if (i2s_spk_handler && (handler == NULL)) _eos_i2s_drvr[I2S_SPK_EVT] = 0;
diff --git a/fw/fe310/eos/soc/i2s.h b/fw/fe310/eos/soc/i2s.h
index e2155a4..ef2b966 100644
--- a/fw/fe310/eos/soc/i2s.h
+++ b/fw/fe310/eos/soc/i2s.h
@@ -1,6 +1,7 @@
#include <stdint.h>
#include "i2s_def.h"
+#include "../event.h"
#define EOS_I2S_MODE_STEREO 0
#define EOS_I2S_MODE_MONO_L 1
@@ -13,15 +14,13 @@ typedef struct EOSABuf {
uint16_t *array;
} EOSABuf;
-typedef void (*eos_i2s_handler_t) (unsigned char);
-
int eos_i2s_init(void);
int eos_i2s_start(uint32_t sample_rate, int mode);
void eos_i2s_stop(void);
int eos_i2s_running(void);
int eos_i2s_set_lsgain(int gain);
-void eos_i2s_mic_set_handler(eos_i2s_handler_t handler, uint16_t wm);
+void eos_i2s_mic_set_handler(eos_evt_simple_handler_t handler, uint16_t wm);
void eos_i2s_mic_set_buf(uint16_t *mic_arr, uint16_t mic_arr_size);
uint16_t *eos_i2s_mic_get_buf(void);
uint16_t eos_i2s_mic_len(void);
@@ -30,7 +29,7 @@ int eos_i2s_mic_pop(uint16_t *sample);
int eos_i2s_mic_get_vol(void);
void eos_i2s_mic_set_vol(int vol);
-void eos_i2s_spk_set_handler(eos_i2s_handler_t handler, uint16_t wm);
+void eos_i2s_spk_set_handler(eos_evt_simple_handler_t handler, uint16_t wm);
void eos_i2s_spk_set_buf(uint16_t *spk_arr, uint16_t spk_arr_size);
uint16_t *eos_i2s_spk_get_buf(void);
uint16_t eos_i2s_spk_len(void);
diff --git a/fw/fe310/eos/soc/spi.c b/fw/fe310/eos/soc/spi.c
index 64a057b..a337924 100644
--- a/fw/fe310/eos/soc/spi.c
+++ b/fw/fe310/eos/soc/spi.c
@@ -7,7 +7,6 @@
#include "eos.h"
#include "log.h"
-#include "msgq.h"
#include "interrupt.h"
#include "event.h"
@@ -35,24 +34,25 @@ static uint32_t spi_state_len = 0;
static uint32_t spi_state_idx_tx = 0;
static uint32_t spi_state_idx_rx = 0;
static unsigned char *spi_state_buf = NULL;
+static uint16_t spi_state_buf_sz = 0;
-static eos_evt_handler_t evt_handler[EOS_SPI_MAX_EVT];
+static eos_evt_handler_t spi_handler[EOS_SPI_MAX_ETYPE];
-static void spi_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
+static void spi_handle_evt(unsigned char type, EOSMessage *msg, uint16_t len) {
+ unsigned char idx = type & ~EOS_EVT_MASK;
- if (idx < EOS_SPI_MAX_EVT) {
- evt_handler[idx](type, buffer, len);
+ if (idx && (idx <= EOS_SPI_MAX_ETYPE) && spi_handler[idx - 1]) {
+ spi_handler[idx - 1](type & ~EOS_EVT_MASK, msg, len);
} else {
- eos_evtq_bad_handler(type, buffer, len);
+ eos_evtq_bad_handler(type, msg, len);
}
}
int eos_spi_init(void) {
int i;
- for (i=0; i<EOS_SPI_MAX_EVT; i++) {
- evt_handler[i] = eos_evtq_bad_handler;
+ for (i=0; i<EOS_SPI_MAX_ETYPE; i++) {
+ spi_handler[i] = eos_evtq_bad_handler;
}
eos_evtq_set_handler(EOS_EVT_SPI, spi_handle_evt);
eos_intr_set_priority(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG);
@@ -114,13 +114,14 @@ void eos_spi_disable(void) {
void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler) {
if (handler == NULL) handler = eos_evtq_bad_handler;
- if (evt && (evt <= EOS_SPI_MAX_EVT)) evt_handler[evt - 1] = handler;
+ if (evt && (evt <= EOS_SPI_MAX_ETYPE)) spi_handler[evt - 1] = handler;
}
-void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags) {
+void _eos_spi_xchg_init(unsigned char *buffer, uint16_t size, uint16_t len, uint8_t flags) {
spi_state_flags &= 0xF0;
spi_state_flags |= (SPI_FLAG_XCHG | flags);
spi_state_buf = buffer;
+ spi_state_buf_sz = size;
spi_state_len = len;
spi_state_idx_tx = 0;
spi_state_idx_rx = 0;
@@ -137,12 +138,12 @@ static void spi_wait4xchg(void) {
}
}
-int eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) {
+int eos_spi_xchg(EOSMessage *msg, uint16_t len, uint8_t flags) {
if (!spi_evt) return EOS_ERR;
spi_wait4xchg();
- _eos_spi_xchg_init(buffer, len, flags);
+ _eos_spi_xchg_init(msg->buffer, msg->size, len, flags);
eos_spi_set_cs();
SPI1_REG(SPI_REG_TXCTRL) = SPI_TXWM(SPI_SIZE_WM);
@@ -184,9 +185,12 @@ void eos_spi_handle_xchg(void) {
spi_state_flags &= (~SPI_FLAG_XCHG & 0xF0);
if (spi_evt) {
+ EOSMessage msg;
int rv;
- rv = eos_evtq_push_isr(EOS_EVT_SPI | spi_evt, spi_state_buf, spi_state_len);
+ msg.buffer = spi_state_buf;
+ msg.size = spi_state_buf_sz;
+ rv = eos_evtq_push_isr(EOS_EVT_SPI | spi_evt, &msg, spi_state_len);
if (rv) EOS_LOG(EOS_LOG_ERR, "SPI XCHG EVTQ PUSH ERR:%d\n", rv);
}
} else {
diff --git a/fw/fe310/eos/soc/spi.h b/fw/fe310/eos/soc/spi.h
index 20999b5..6ded15f 100644
--- a/fw/fe310/eos/soc/spi.h
+++ b/fw/fe310/eos/soc/spi.h
@@ -6,10 +6,10 @@
#define EOS_SPI_FLAG_MORE 0x02
#define EOS_SPI_FLAG_BSWAP 0x04
-#define EOS_SPI_EVT_SDC 1
-#define EOS_SPI_EVT_CAM 2
+#define EOS_SPI_ETYPE_SDC 1
+#define EOS_SPI_ETYPE_CAM 2
-#define EOS_SPI_MAX_EVT 2
+#define EOS_SPI_MAX_ETYPE 2
int eos_spi_init(void);
void eos_spi_configure(uint16_t div, uint8_t csid, uint8_t cspin, unsigned char evt);
@@ -20,8 +20,8 @@ void eos_spi_disable(void);
void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler);
-void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags);
-int eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags);
+void _eos_spi_xchg_init(unsigned char *buffer, uint16_t size, uint16_t len, uint8_t flags);
+int eos_spi_xchg(EOSMessage *msg, uint16_t len, uint8_t flags);
void eos_spi_handle_xchg(void);
int eos_spi_get_cs(void);
diff --git a/fw/fe310/eos/soc/timer.c b/fw/fe310/eos/soc/timer.c
index 0573e84..f26f601 100644
--- a/fw/fe310/eos/soc/timer.c
+++ b/fw/fe310/eos/soc/timer.c
@@ -5,23 +5,22 @@
#include "platform.h"
#include "eos.h"
-#include "msgq.h"
#include "event.h"
#include "timer.h"
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
-static eos_timer_handler_t timer_handler[EOS_TIMER_MAX_ETYPE + 1];
+static eos_evt_simple_handler_t timer_handler[EOS_TIMER_MAX_ETYPE + 1];
static uint64_t timer_next[EOS_TIMER_MAX_ETYPE + 1];
-static void timer_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char idx = (type & ~EOS_EVT_MASK);
+static void timer_handle_evt(unsigned char type, EOSMessage *msg, uint16_t len) {
+ unsigned char idx = type & ~EOS_EVT_MASK;
if (idx && (idx <= EOS_TIMER_MAX_ETYPE) && timer_handler[idx]) {
- timer_handler[idx](type);
+ timer_handler[idx](type & ~EOS_EVT_MASK);
} else {
- eos_evtq_bad_handler(type, buffer, len);
+ eos_evtq_bad_handler(type, msg, len);
}
}
@@ -63,7 +62,7 @@ int eos_timer_init(void) {
return EOS_OK;
}
-void eos_timer_set_handler(unsigned char evt, eos_timer_handler_t handler) {
+void eos_timer_set_handler(unsigned char evt, eos_evt_simple_handler_t handler) {
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
if (!evt && (*mtimecmp != 0)) clear_csr(mie, MIP_MTIP);
diff --git a/fw/fe310/eos/soc/timer.h b/fw/fe310/eos/soc/timer.h
index f5c7b4e..ef4005c 100644
--- a/fw/fe310/eos/soc/timer.h
+++ b/fw/fe310/eos/soc/timer.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#include "../event.h"
+
#define EOS_TIMER_ETYPE_UI 1
#define EOS_TIMER_ETYPE_EVE 2
#define EOS_TIMER_ETYPE_ECP 3
@@ -10,10 +12,8 @@
#define EOS_TIMER_NONE -1
#define EOS_TIMER_RTC_FREQ 32768
-typedef void (*eos_timer_handler_t) (unsigned char);
-
int eos_timer_init(void);
-void eos_timer_set_handler(unsigned char evt, eos_timer_handler_t handler);
+void eos_timer_set_handler(unsigned char evt, eos_evt_simple_handler_t handler);
uint32_t eos_timer_get(unsigned char evt);
void eos_timer_set(unsigned char evt, uint32_t msec);
diff --git a/fw/fe310/eos/soc/uart.c b/fw/fe310/eos/soc/uart.c
index 44c9a52..a5ba35f 100644
--- a/fw/fe310/eos/soc/uart.c
+++ b/fw/fe310/eos/soc/uart.c
@@ -13,15 +13,15 @@
#include "uart.h"
-static eos_uart_handler_t uart_handler[EOS_UART_MAX_ETYPE];
+static eos_evt_simple_handler_t uart_handler[EOS_UART_MAX_ETYPE];
-static void uart_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
+static void uart_handle_evt(unsigned char type, EOSMessage *msg, uint16_t len) {
+ unsigned char idx = type & ~EOS_EVT_MASK;
- if ((idx < EOS_UART_MAX_ETYPE) && uart_handler[idx]) {
- uart_handler[idx](type);
+ if (idx && (idx <= EOS_UART_MAX_ETYPE) && uart_handler[idx - 1]) {
+ uart_handler[idx - 1](type & ~EOS_EVT_MASK);
} else {
- eos_evtq_bad_handler(type, buffer, len);
+ eos_evtq_bad_handler(type, msg, len);
}
}
@@ -76,7 +76,7 @@ void eos_uart_speed(uint32_t baud_rate) {
UART0_REG(UART_REG_DIV) = PRCI_get_cpu_freq() / baud_rate - 1;
}
-void eos_uart_set_handler(unsigned char type, eos_uart_handler_t handler) {
+void eos_uart_set_handler(unsigned char type, eos_evt_simple_handler_t handler) {
if (type && (type <= EOS_UART_MAX_ETYPE)) uart_handler[type - 1] = handler;
}
diff --git a/fw/fe310/eos/soc/uart.h b/fw/fe310/eos/soc/uart.h
index 474942d..93866af 100644
--- a/fw/fe310/eos/soc/uart.h
+++ b/fw/fe310/eos/soc/uart.h
@@ -1,5 +1,7 @@
#include <stdint.h>
+#include "../event.h"
+
#define EOS_UART_ETYPE_TX 1
#define EOS_UART_ETYPE_RX 2
@@ -7,8 +9,6 @@
#define EOS_UART_SPEED 115200
-typedef void (*eos_uart_handler_t) (unsigned char);
-
void eos_uart_preinit(void);
int eos_uart_init(void);
void eos_uart_enable(void);
@@ -16,7 +16,7 @@ void eos_uart_disable(void);
int eos_uart_enabled(void);
void eos_uart_speed(uint32_t baud_rate);
-void eos_uart_set_handler(unsigned char type, eos_uart_handler_t handler);
+void eos_uart_set_handler(unsigned char type, eos_evt_simple_handler_t handler);
void eos_uart_txwm_set(uint8_t wm);
void eos_uart_txwm_clear(void);