summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/fe310/eos/eos.c4
-rw-r--r--code/fe310/eos/eos.h4
-rw-r--r--code/fe310/eos/event.c4
-rw-r--r--code/fe310/eos/event.h1
-rw-r--r--code/fe310/eos/evt_def.h3
-rw-r--r--code/fe310/eos/i2s.c29
-rw-r--r--code/fe310/eos/i2s.h4
-rw-r--r--code/fe310/eos/irq_def.h4
-rw-r--r--code/fe310/eos/msgq.c2
-rw-r--r--code/fe310/eos/net.c128
-rw-r--r--code/fe310/eos/net.h3
-rw-r--r--code/fe310/eos/sock.c45
-rw-r--r--code/fe310/eos/sock.h6
-rw-r--r--code/fe310/eos/spi.c35
-rw-r--r--code/fe310/eos/spi.h3
-rw-r--r--code/fe310/eos/timer.c44
-rw-r--r--code/fe310/eos/timer.h3
-rw-r--r--code/fe310/eos/trap_entry.S2
-rw-r--r--code/fe310/eos/wifi.c43
-rw-r--r--code/fe310/eos/wifi.h6
20 files changed, 191 insertions, 182 deletions
diff --git a/code/fe310/eos/eos.c b/code/fe310/eos/eos.c
index a0bf4c9..bb231d1 100644
--- a/code/fe310/eos/eos.c
+++ b/code/fe310/eos/eos.c
@@ -2,9 +2,11 @@
#include "interrupt.h"
#include "timer.h"
#include "i2s.h"
+#include "uart.h"
#include "spi.h"
#include "net.h"
#include "wifi.h"
+#include "cell.h"
#include "sock.h"
#include "eve.h"
@@ -15,9 +17,11 @@ void eos_init(void) {
eos_intr_init();
eos_timer_init();
eos_i2s_init();
+ eos_uart_init();
eos_spi_init();
eos_net_init();
eos_wifi_init();
+ eos_cell_init();
eos_sock_init();
eos_spi_dev_start(EOS_SPI_DEV_DISP);
eos_eve_init();
diff --git a/code/fe310/eos/eos.h b/code/fe310/eos/eos.h
index f1d7907..08bd10b 100644
--- a/code/fe310/eos/eos.h
+++ b/code/fe310/eos/eos.h
@@ -1,7 +1,7 @@
#define EOS_OK 0
#define EOS_ERR -1
-#define EOS_ERR_Q_FULL -10
-#define EOS_ERR_Q_EMPTY -11
+#define EOS_ERR_FULL -10
+#define EOS_ERR_EMPTY -11
#define EOS_ERR_NET -20
void eos_init(void);
diff --git a/code/fe310/eos/event.c b/code/fe310/eos/event.c
index 9371ca7..ed313fb 100644
--- a/code/fe310/eos/event.c
+++ b/code/fe310/eos/event.c
@@ -32,6 +32,10 @@ int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len) {
return ret;
}
+int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len) {
+ return eos_msgq_push(&_eos_event_q, type, buffer, len);
+}
+
void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len) {
clear_csr(mstatus, MSTATUS_MIE);
eos_msgq_pop(&_eos_event_q, type, buffer, len);
diff --git a/code/fe310/eos/event.h b/code/fe310/eos/event.h
index 8a16dfd..6beb263 100644
--- a/code/fe310/eos/event.h
+++ b/code/fe310/eos/event.h
@@ -6,6 +6,7 @@ typedef void (*eos_evt_fptr_t) (unsigned char, unsigned char *, uint16_t);
void eos_evtq_init(void);
int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len);
+int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len);
void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len);
void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len);
void eos_evtq_set_handler(unsigned char type, eos_evt_fptr_t handler);
diff --git a/code/fe310/eos/evt_def.h b/code/fe310/eos/evt_def.h
index 529ee72..0cd63bb 100644
--- a/code/fe310/eos/evt_def.h
+++ b/code/fe310/eos/evt_def.h
@@ -2,7 +2,8 @@
#define EOS_EVT_AUDIO 0x20
#define EOS_EVT_NET 0x30
#define EOS_EVT_SPI 0x40
-#define EOS_EVT_USER 0x50
+#define EOS_EVT_UART 0x50
+#define EOS_EVT_USER 0x60
#define EOS_EVT_MAX_EVT 8
#define EOS_EVT_MASK 0xF0
diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c
index d71a31d..4702bc3 100644
--- a/code/fe310/eos/i2s.c
+++ b/code/fe310/eos/i2s.c
@@ -33,8 +33,8 @@ uint32_t _eos_i2s_spk_wm = 0;
uint32_t _eos_i2s_mic_evt_enable = 0;
uint32_t _eos_i2s_spk_evt_enable = 0;
-static eos_i2s_fptr_t spk_evt_handler = NULL;
-static eos_i2s_fptr_t mic_evt_handler = NULL;
+static eos_i2s_fptr_t i2s_spk_handler = NULL;
+static eos_i2s_fptr_t i2s_mic_handler = NULL;
static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) {
buf->idx_r = 0;
@@ -44,7 +44,7 @@ static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) {
}
static int _abuf_push8(EOSABuf *buf, uint8_t sample) {
- if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_Q_FULL;
+ if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_FULL;
buf->array[EOS_ABUF_IDX_MASK(buf->idx_w, buf->size)] = sample;
buf->idx_w++;
@@ -52,7 +52,7 @@ static int _abuf_push8(EOSABuf *buf, uint8_t sample) {
}
static int _abuf_push16(EOSABuf *buf, uint16_t sample) {
- if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_Q_FULL;
+ if ((uint16_t)(buf->idx_w - buf->idx_r) == buf->size) return EOS_ERR_FULL;
buf->array[EOS_ABUF_IDX_MASK(buf->idx_w, buf->size)] = sample >> 8;
buf->array[EOS_ABUF_IDX_MASK(buf->idx_w + 1, buf->size)] = sample & 0xFF;
@@ -62,7 +62,7 @@ static int _abuf_push16(EOSABuf *buf, uint16_t sample) {
static int _abuf_pop8(EOSABuf *buf, uint8_t *sample) {
if (buf->idx_r == buf->idx_w) {
- return EOS_ERR_Q_EMPTY;
+ return EOS_ERR_EMPTY;
} else {
*sample = buf->array[EOS_ABUF_IDX_MASK(buf->idx_r, buf->size)];
buf->idx_r++;
@@ -72,7 +72,7 @@ static int _abuf_pop8(EOSABuf *buf, uint8_t *sample) {
static int _abuf_pop16(EOSABuf *buf, uint16_t *sample) {
if (buf->idx_r == buf->idx_w) {
- return EOS_ERR_Q_EMPTY;
+ return EOS_ERR_EMPTY;
} else {
*sample = buf->array[EOS_ABUF_IDX_MASK(buf->idx_r, buf->size)] << 8;
*sample |= buf->array[EOS_ABUF_IDX_MASK(buf->idx_r + 1, buf->size)];
@@ -94,13 +94,13 @@ static uint16_t _abuf_len(EOSABuf *buf) {
static void i2s_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
switch(type & ~EOS_EVT_MASK) {
case I2S_ETYPE_MIC:
- if (mic_evt_handler) mic_evt_handler(type);
+ if (i2s_mic_handler) i2s_mic_handler(type);
clear_csr(mstatus, MSTATUS_MIE);
_eos_i2s_mic_evt_enable = 1;
set_csr(mstatus, MSTATUS_MIE);
break;
case I2S_ETYPE_SPK:
- if (spk_evt_handler) spk_evt_handler(type);
+ if (i2s_spk_handler) i2s_spk_handler(type);
clear_csr(mstatus, MSTATUS_MIE);
_eos_i2s_spk_evt_enable = 1;
set_csr(mstatus, MSTATUS_MIE);
@@ -115,7 +115,6 @@ extern void _eos_i2s_start_pwm(void);
void eos_i2s_init(void) {
eos_evtq_set_handler(EOS_EVT_AUDIO, i2s_handler_evt);
- eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, EOS_NET_FLAG_BACQ);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK);
@@ -249,10 +248,12 @@ void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size) {
set_csr(mstatus, MSTATUS_MIE);
}
-void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler) {
+void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) {
clear_csr(mstatus, MSTATUS_MIE);
- mic_evt_handler = wm_handler;
+ i2s_mic_handler = wm_handler;
set_csr(mstatus, MSTATUS_MIE);
+
+ if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_MIC, flags);
}
void eos_i2s_mic_set_wm(uint16_t wm) {
@@ -308,10 +309,12 @@ void eos_i2s_spk_init(uint8_t *spk_arr, uint16_t spk_arr_size) {
set_csr(mstatus, MSTATUS_MIE);
}
-void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler) {
+void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags) {
clear_csr(mstatus, MSTATUS_MIE);
- spk_evt_handler = wm_handler;
+ i2s_spk_handler = wm_handler;
set_csr(mstatus, MSTATUS_MIE);
+
+ if (flags) eos_evtq_set_flags(EOS_EVT_AUDIO | I2S_ETYPE_SPK, flags);
}
void eos_i2s_spk_set_wm(uint16_t wm) {
diff --git a/code/fe310/eos/i2s.h b/code/fe310/eos/i2s.h
index 8ae7d98..af91dd3 100644
--- a/code/fe310/eos/i2s.h
+++ b/code/fe310/eos/i2s.h
@@ -16,14 +16,14 @@ void eos_i2s_init(void);
void eos_i2s_start(uint32_t sample_rate, unsigned char fmt);
void eos_i2s_stop(void);
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size);
-void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler);
+void eos_i2s_mic_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags);
void eos_i2s_mic_set_wm(uint16_t wm);
uint16_t eos_i2s_mic_len(void);
uint16_t eos_i2s_mic_read(uint8_t *sample, uint16_t ssize);
int eos_i2s_mic_pop8(uint8_t *sample);
int eos_i2s_mic_pop16(uint16_t *sample);
void eos_i2s_spk_init(uint8_t *mic_arr, uint16_t mic_arr_size);
-void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler);
+void eos_i2s_spk_set_handler(eos_i2s_fptr_t wm_handler, uint8_t flags);
void eos_i2s_spk_set_wm(uint16_t wm);
uint16_t eos_i2s_spk_len(void);
uint16_t eos_i2s_spk_write(uint8_t *sample, uint16_t ssize);
diff --git a/code/fe310/eos/irq_def.h b/code/fe310/eos/irq_def.h
index 4584b01..b6a9dbb 100644
--- a/code/fe310/eos/irq_def.h
+++ b/code/fe310/eos/irq_def.h
@@ -4,4 +4,6 @@
#define IRQ_PRIORITY_SPI_XCHG 5
#define IRQ_PRIORITY_NET_CTS 4
-#define IRQ_PRIORITY_NET_RTS 4 \ No newline at end of file
+#define IRQ_PRIORITY_NET_RTS 4
+
+#define IRQ_PRIORITY_UART 1 \ No newline at end of file
diff --git a/code/fe310/eos/msgq.c b/code/fe310/eos/msgq.c
index d0fe405..35e0d15 100644
--- a/code/fe310/eos/msgq.c
+++ b/code/fe310/eos/msgq.c
@@ -20,7 +20,7 @@ void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size) {
}
int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len) {
- if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_Q_FULL;
+ if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_FULL;
uint8_t idx = EOS_MSGQ_IDX_MASK(msgq->idx_w, msgq->size);
msgq->array[idx].type = type;
diff --git a/code/fe310/eos/net.c b/code/fe310/eos/net.c
index 319a3f5..f3a82b8 100644
--- a/code/fe310/eos/net.c
+++ b/code/fe310/eos/net.c
@@ -44,7 +44,6 @@ 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;
@@ -106,7 +105,39 @@ static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t l
SPI1_REG(SPI_REG_IE) = SPI_IP_RXWM;
}
-static void net_xchg_handler(void) {
+static int net_xchg_next(unsigned char *_buffer) {
+ unsigned char type;
+ unsigned char *buffer = NULL;
+ uint16_t len;
+
+ eos_msgq_pop(&net_send_q, &type, &buffer, &len);
+ if (type) {
+ net_xchg_start(type, buffer, len);
+ } else if (net_state_flags & NET_STATE_FLAG_RTS) {
+ if (_buffer == NULL) _buffer = net_bufq_pop();
+ if (_buffer) {
+ net_xchg_start(0, _buffer, 0);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void eos_net_xchg_done(void) {
+ SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO;
+ if (net_state_type) {
+ int r = eos_evtq_push_isr(EOS_EVT_NET | net_state_type, _eos_spi_state_buf, net_state_len_rx);
+ if (r) net_bufq_push(_eos_spi_state_buf);
+ } else if (((net_state_flags & NET_STATE_FLAG_ONEW) || net_state_next_cnt) && (net_state_next_buf == NULL)) {
+ net_state_next_buf = _eos_spi_state_buf;
+ net_state_flags &= ~NET_STATE_FLAG_ONEW;
+ } else {
+ net_bufq_push(_eos_spi_state_buf);
+ }
+ net_state_flags &= ~NET_STATE_FLAG_XCHG;
+}
+
+static void net_handler_xchg(void) {
volatile uint32_t r1, r2;
if (net_state_flags & NET_STATE_FLAG_RST) {
@@ -155,38 +186,6 @@ static void net_xchg_handler(void) {
eos_spi_xchg_handler();
}
-static int net_xchg_next(unsigned char *_buffer) {
- unsigned char type;
- unsigned char *buffer = NULL;
- uint16_t len;
-
- eos_msgq_pop(&net_send_q, &type, &buffer, &len);
- if (type) {
- net_xchg_start(type, buffer, len);
- } else if (net_state_flags & NET_STATE_FLAG_RTS) {
- if (_buffer == NULL) _buffer = net_bufq_pop();
- if (_buffer) {
- net_xchg_start(0, _buffer, 0);
- return 0;
- }
- }
- return 1;
-}
-
-void eos_net_xchg_done(void) {
- SPI1_REG(SPI_REG_CSMODE) = SPI_CSMODE_AUTO;
- if (net_state_type) {
- int r = eos_msgq_push(&_eos_event_q, EOS_EVT_NET | net_state_type, _eos_spi_state_buf, net_state_len_rx);
- if (r) net_bufq_push(_eos_spi_state_buf);
- } else if (((net_state_flags & NET_STATE_FLAG_ONEW) || net_state_next_cnt) && (net_state_next_buf == NULL)) {
- net_state_next_buf = _eos_spi_state_buf;
- net_state_flags &= ~NET_STATE_FLAG_ONEW;
- } else {
- net_bufq_push(_eos_spi_state_buf);
- }
- net_state_flags &= ~NET_STATE_FLAG_XCHG;
-}
-
static void net_handler_cts(void) {
GPIO_REG(GPIO_RISE_IP) = (1 << NET_PIN_CTS);
net_state_flags |= NET_STATE_FLAG_CTS;
@@ -210,37 +209,13 @@ static void net_handler_rts(void) {
static void net_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
- uint16_t buf_free = ((uint16_t)1 << idx) & evt_handler_flags_buf_free;
- uint16_t buf_acq = ((uint16_t)1 << idx) & evt_handler_flags_buf_acq;
if (idx >= EOS_NET_MAX_MTYPE) {
eos_evtq_bad_handler(type, buffer, len);
eos_net_free(buffer, 0);
return;
}
- if (buf_free) {
- eos_net_free(buffer, buf_acq);
- buffer = NULL;
- len = 0;
- }
-
- evt_handler[idx](type, buffer, len);
-
- if (buf_free && buf_acq) eos_net_release();
-}
-
-void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t flags) {
- if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) {
- mtype--;
- } else {
- return;
- }
- if (flags) {
- uint16_t flag = (uint16_t)1 << mtype;
- if (flags & EOS_NET_FLAG_BFREE) evt_handler_flags_buf_free |= flag;
- if (flags & EOS_NET_FLAG_BACQ) evt_handler_flags_buf_acq |= flag;
- }
- evt_handler[mtype] = handler;
+ _eos_net_handle(type, buffer, len, idx, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
}
void eos_net_init(void) {
@@ -272,7 +247,7 @@ void eos_net_init(void) {
}
void eos_net_start(void) {
- eos_intr_set_handler(INT_SPI1_BASE, net_xchg_handler);
+ eos_intr_set_handler(INT_SPI1_BASE, net_handler_xchg);
SPI1_REG(SPI_REG_SCKDIV) = SPI_DIV_NET;
SPI1_REG(SPI_REG_CSID) = SPI_CS_IDX_NET;
@@ -298,6 +273,39 @@ void eos_net_stop(void) {
}
}
+void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, eos_evt_fptr_t handlers[], uint16_t *flags_buf_free, uint16_t *flags_buf_acq) {
+ uint16_t buf_free = ((uint16_t)1 << idx) & *flags_buf_free;
+ uint16_t buf_acq = ((uint16_t)1 << idx) & *flags_buf_acq;
+
+ if (buf_free) {
+ eos_net_free(buffer, buf_acq);
+ buffer = NULL;
+ len = 0;
+ }
+
+ handlers[idx](type, buffer, len);
+
+ if (buf_free && buf_acq) eos_net_release();
+}
+
+void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq) {
+ if (flags) {
+ uint16_t flag = (uint16_t)1 << idx;
+ if (flags & EOS_NET_FLAG_BFREE) *flags_buf_free |= flag;
+ if (flags & EOS_NET_FLAG_BACQ) *flags_buf_acq |= flag;
+ }
+ handlers[idx] = handler;
+}
+
+void eos_net_set_handler(unsigned char mtype, eos_evt_fptr_t handler, uint8_t flags) {
+ if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) {
+ mtype--;
+ } else {
+ return;
+ }
+ _eos_net_set_handler(mtype, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
+}
+
int _eos_net_acquire(unsigned char reserved) {
int ret = 0;
diff --git a/code/fe310/eos/net.h b/code/fe310/eos/net.h
index 127942c..e0fdbf9 100644
--- a/code/fe310/eos/net.h
+++ b/code/fe310/eos/net.h
@@ -19,7 +19,10 @@ void eos_net_xchg_done(void);
void eos_net_init(void);
void eos_net_start(void);
void eos_net_stop(void);
+void _eos_net_handle(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char idx, eos_evt_fptr_t handlers[], uint16_t *flags_buf_free, uint16_t *flags_buf_acq);
+void _eos_net_set_handler(unsigned char idx, eos_evt_fptr_t handler, eos_evt_fptr_t handlers[], uint16_t flags, uint16_t *flags_buf_free, uint16_t *flags_buf_acq);
void eos_net_set_handler(unsigned char type, eos_evt_fptr_t handler, uint8_t flags);
+
int _eos_net_acquire(unsigned char reserved);
void eos_net_acquire(void);
void eos_net_release(void);
diff --git a/code/fe310/eos/sock.c b/code/fe310/eos/sock.c
index 2c6ba5d..077c93d 100644
--- a/code/fe310/eos/sock.c
+++ b/code/fe310/eos/sock.c
@@ -8,9 +8,9 @@
#include "sock.h"
-static eos_sock_fptr_t sock_handler[EOS_SOCK_MAX_SOCK];
-static uint16_t sock_handler_flags_buf_free = 0;
-static uint16_t sock_handler_flags_buf_acq = 0;
+static eos_evt_fptr_t evt_handler[EOS_SOCK_MAX_SOCK];
+static uint16_t evt_handler_flags_buf_free = 0;
+static uint16_t evt_handler_flags_buf_acq = 0;
static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
if ((buffer == NULL) || (len < 2)) {
@@ -28,24 +28,28 @@ static void sock_handler_evt(unsigned char type, unsigned char *buffer, uint16_t
eos_net_free(buffer, 0);
return;
}
- uint16_t buf_free = ((uint16_t)1 << sock) & sock_handler_flags_buf_free;
- uint16_t buf_acq = ((uint16_t)1 << sock) & sock_handler_flags_buf_acq;
- if (buf_free) {
- eos_net_free(buffer, buf_acq);
- buffer = NULL;
- len = 0;
- }
-
- sock_handler[sock](buffer, len);
-
- if (buf_free && buf_acq) eos_net_release();
+ _eos_net_handle(type, buffer, len, sock, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
}
}
void eos_sock_init(void) {
+ int i;
+
+ for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
+ evt_handler[i] = eos_evtq_bad_handler;
+ }
eos_net_set_handler(EOS_NET_MTYPE_SOCK, sock_handler_evt, 0);
}
+void eos_sock_set_handler(int sock, eos_evt_fptr_t handler, uint8_t flags) {
+ if (sock && (sock <= EOS_SOCK_MAX_SOCK)) {
+ sock--;
+ } else {
+ return;
+ }
+ _eos_net_set_handler(sock, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
+}
+
int eos_sock_open_udp(void) {
unsigned char type = EOS_SOCK_MTYPE_OPEN_DGRAM;
unsigned char *buffer = eos_net_alloc();
@@ -92,16 +96,3 @@ void eos_sock_getfrom(unsigned char *buffer, EOSNetAddr *addr) {
}
-void eos_sock_set_handler(int sock, eos_sock_fptr_t handler, uint8_t flags) {
- if (sock && (sock <= EOS_SOCK_MAX_SOCK)) {
- sock--;
- } else {
- return;
- }
- if (flags) {
- uint16_t flag = (uint16_t)1 << sock;
- if (flags & EOS_NET_FLAG_BFREE) sock_handler_flags_buf_free |= flag;
- if (flags & EOS_NET_FLAG_BACQ) sock_handler_flags_buf_acq |= flag;
- }
- sock_handler[sock] = handler;
-}
diff --git a/code/fe310/eos/sock.h b/code/fe310/eos/sock.h
index 3e0527b..db1db21 100644
--- a/code/fe310/eos/sock.h
+++ b/code/fe310/eos/sock.h
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include "event.h"
#define EOS_SOCK_MTYPE_PKT 0
#define EOS_SOCK_MTYPE_OPEN_DGRAM 1
@@ -15,11 +16,10 @@ typedef struct EOSNetAddr {
uint16_t port;
} EOSNetAddr;
-typedef void (*eos_sock_fptr_t) (unsigned char *, uint16_t);
-
void eos_sock_init(void);
+void eos_sock_set_handler(int sock, eos_evt_fptr_t handler, uint8_t flags);
+
int eos_sock_open_udp(void);
void eos_sock_close(int sock);
int eos_sock_sendto(int sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr);
void eos_sock_getfrom(unsigned char *buffer, EOSNetAddr *addr);
-void eos_sock_set_handler(int sock, eos_sock_fptr_t handler, uint8_t flags);
diff --git a/code/fe310/eos/spi.c b/code/fe310/eos/spi.c
index 56ef318..d752bfb 100644
--- a/code/fe310/eos/spi.c
+++ b/code/fe310/eos/spi.c
@@ -18,8 +18,6 @@
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define SPI_IOF_MASK (((uint32_t)1 << IOF_SPI1_SCK) | ((uint32_t)1 << IOF_SPI1_MOSI) | ((uint32_t)1 << IOF_SPI1_MISO)) | ((uint32_t)1 << IOF_SPI1_SS0) | ((uint32_t)1 << IOF_SPI1_SS2) | ((uint32_t)1 << IOF_SPI1_SS3)
-extern EOSMsgQ _eos_event_q;
-
static uint8_t spi_dev;
static uint8_t spi_dev_cs_pin;
static uint8_t spi_state_flags;
@@ -60,6 +58,14 @@ static void spi_xchg_wait(void) {
}
void eos_spi_init(void) {
+ int i;
+
+ for (i=0; i<EOS_SPI_MAX_DEV; i++) {
+ evt_handler[i] = eos_evtq_bad_handler;
+ }
+ eos_evtq_set_handler(EOS_EVT_SPI, spi_handler_evt);
+ eos_intr_set(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG, NULL);
+
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << SPI_CS_PIN_CAM);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << SPI_CS_PIN_CAM);
GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << SPI_CS_PIN_CAM);
@@ -77,9 +83,6 @@ void eos_spi_init(void) {
// There is no way here to change the CS polarity.
// SPI1_REG(SPI_REG_CSDEF) = 0xFFFF;
-
- eos_intr_set(INT_SPI1_BASE, IRQ_PRIORITY_SPI_XCHG, NULL);
- eos_evtq_set_handler(EOS_EVT_SPI, spi_handler_evt);
}
void eos_spi_dev_start(unsigned char dev) {
@@ -116,6 +119,17 @@ void eos_spi_dev_stop(void) {
eos_net_start();
}
+void eos_spi_set_handler(unsigned char dev, eos_evt_fptr_t handler, uint8_t flags) {
+ if (dev && (dev <= EOS_SPI_MAX_DEV)) {
+ dev--;
+ } else {
+ return;
+ }
+ evt_handler[dev] = handler;
+
+ if (flags) eos_evtq_set_flags(EOS_EVT_SPI | dev + 1, flags);
+}
+
void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags) {
if (spi_in_xchg) spi_xchg_wait();
if (!(flags & EOS_SPI_FLAG_TX) && (spi_state_flags & EOS_SPI_FLAG_TX)) spi_flush();
@@ -140,7 +154,7 @@ static void spi_xchg_done(void) {
} else {
spi_state_flags &= ~SPI_FLAG_XCHG;
if (!(spi_state_flags & (EOS_SPI_FLAG_MORE | SPI_FLAG_CS))) eos_spi_cs_clear();
- eos_msgq_push(&_eos_event_q, EOS_EVT_SPI | spi_dev, _eos_spi_state_buf, _eos_spi_state_len);
+ eos_evtq_push_isr(EOS_EVT_SPI | spi_dev, _eos_spi_state_buf, _eos_spi_state_len);
}
}
@@ -367,12 +381,3 @@ uint32_t eos_spi_xchg32(uint32_t data, uint8_t flags) {
return r;
}
-
-void eos_spi_set_handler(unsigned char dev, eos_evt_fptr_t handler) {
- if (dev && (dev <= EOS_SPI_MAX_DEV)) {
- dev--;
- } else {
- return;
- }
- evt_handler[dev] = handler;
-}
diff --git a/code/fe310/eos/spi.h b/code/fe310/eos/spi.h
index 394c400..1619b18 100644
--- a/code/fe310/eos/spi.h
+++ b/code/fe310/eos/spi.h
@@ -16,6 +16,7 @@
void eos_spi_init(void);
void eos_spi_dev_start(unsigned char dev);
void eos_spi_dev_stop(void);
+void eos_spi_set_handler(unsigned char dev, eos_evt_fptr_t handler, uint8_t flags);
void eos_spi_xchg(unsigned char *buffer, uint16_t len, uint8_t flags);
void eos_spi_xchg_handler(void);
@@ -26,5 +27,3 @@ uint8_t eos_spi_xchg8(uint8_t data, uint8_t flags);
uint16_t eos_spi_xchg16(uint16_t data, uint8_t flags);
uint32_t eos_spi_xchg24(uint32_t data, uint8_t flags);
uint32_t eos_spi_xchg32(uint32_t data, uint8_t flags);
-
-void eos_spi_set_handler(unsigned char dev, eos_evt_fptr_t handler); \ No newline at end of file
diff --git a/code/fe310/eos/timer.c b/code/fe310/eos/timer.c
index f443a8d..9fd8d23 100644
--- a/code/fe310/eos/timer.c
+++ b/code/fe310/eos/timer.c
@@ -14,8 +14,6 @@
static eos_timer_fptr_t timer_handler[EOS_TIMER_MAX_ETYPE + 1];
static uint64_t timer_next[EOS_TIMER_MAX_ETYPE + 1];
-extern EOSMsgQ _eos_event_q;
-
static void timer_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
unsigned char idx = (type & ~EOS_EVT_MASK) - 1;
@@ -26,7 +24,7 @@ static void timer_handler_evt(unsigned char type, unsigned char *buffer, uint16_
}
}
-void eos_timer_handle(void) {
+void _eos_timer_handle(void) {
int i;
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
@@ -39,7 +37,7 @@ void eos_timer_handle(void) {
if (i == EOS_TIMER_MAX_ETYPE) {
timer_handler[EOS_TIMER_MAX_ETYPE](0);
} else {
- eos_msgq_push(&_eos_event_q, EOS_EVT_TIMER | i + 1, NULL, 0);
+ eos_evtq_push_isr(EOS_EVT_TIMER | i + 1, NULL, 0);
}
}
next = next && timer_next[i] ? MIN(next, timer_next[i]) : (next ? next : timer_next[i]);
@@ -54,13 +52,31 @@ void eos_timer_init(void) {
clear_csr(mie, MIP_MTIP);
*mtimecmp = 0;
- for (i = 0; i <= EOS_TIMER_MAX_ETYPE; i++) {
+ for (i=0; i<=EOS_TIMER_MAX_ETYPE; i++) {
timer_next[i] = 0;
timer_handler[i] = NULL;
}
eos_evtq_set_handler(EOS_EVT_TIMER, timer_handler_evt);
}
+void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags) {
+ uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
+
+ if (evt && (evt <= EOS_TIMER_MAX_ETYPE)) {
+ evt--;
+ } else if (evt == 0) {
+ evt = EOS_TIMER_MAX_ETYPE;
+ } else {
+ return;
+ }
+
+ clear_csr(mie, MIP_MTIP);
+ timer_handler[evt] = handler;
+ if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
+
+ if ((evt != EOS_TIMER_MAX_ETYPE) && flags) eos_evtq_set_flags(EOS_EVT_TIMER | evt + 1, flags);
+}
+
uint64_t eos_timer_get(unsigned char evt) {
uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
uint64_t ret = 0;
@@ -130,24 +146,6 @@ void eos_timer_clear(unsigned char evt) {
if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
}
-void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags) {
- uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
-
- if (evt && (evt <= EOS_TIMER_MAX_ETYPE)) {
- evt--;
- } else if (evt == 0) {
- evt = EOS_TIMER_MAX_ETYPE;
- } else {
- return;
- }
-
- clear_csr(mie, MIP_MTIP);
- timer_handler[evt] = handler;
- if (*mtimecmp != 0) set_csr(mie, MIP_MTIP);
-
- if ((evt != EOS_TIMER_MAX_ETYPE) && flags) eos_evtq_set_flags(EOS_EVT_TIMER | evt + 1, flags);
-}
-
void eos_timer_sleep(uint32_t msec) {
volatile uint64_t *mtime = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIME);
diff --git a/code/fe310/eos/timer.h b/code/fe310/eos/timer.h
index dff9b2b..e8416ab 100644
--- a/code/fe310/eos/timer.h
+++ b/code/fe310/eos/timer.h
@@ -8,8 +8,9 @@
typedef void (*eos_timer_fptr_t) (unsigned char);
void eos_timer_init(void);
+void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags);
+
uint64_t eos_timer_get(unsigned char evt);
void eos_timer_set(uint32_t msec, unsigned char evt, unsigned char b);
void eos_timer_clear(unsigned char evt);
-void eos_timer_set_handler(unsigned char evt, eos_timer_fptr_t handler, uint8_t flags);
void eos_timer_sleep(uint32_t msec);
diff --git a/code/fe310/eos/trap_entry.S b/code/fe310/eos/trap_entry.S
index 3939a3e..5948b13 100644
--- a/code/fe310/eos/trap_entry.S
+++ b/code/fe310/eos/trap_entry.S
@@ -477,7 +477,7 @@ trap_entry_text:
call _exit
handle_timer:
- call eos_timer_handle
+ call _eos_timer_handle
j trap_exit_text
handle_ext:
diff --git a/code/fe310/eos/wifi.c b/code/fe310/eos/wifi.c
index 67682aa..688e675 100644
--- a/code/fe310/eos/wifi.c
+++ b/code/fe310/eos/wifi.c
@@ -8,9 +8,9 @@
#include "wifi.h"
-static eos_wifi_fptr_t wifi_handler[EOS_WIFI_MAX_MTYPE];
-static uint16_t wifi_handler_flags_buf_free = 0;
-static uint16_t wifi_handler_flags_buf_acq = 0;
+static eos_evt_fptr_t evt_handler[EOS_WIFI_MAX_MTYPE];
+static uint16_t evt_handler_flags_buf_free = 0;
+static uint16_t evt_handler_flags_buf_acq = 0;
static void wifi_handler_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
if ((buffer == NULL) || (len < 1)) {
@@ -26,23 +26,25 @@ static void wifi_handler_evt(unsigned char type, unsigned char *buffer, uint16_t
return;
}
- uint16_t buf_free = ((uint16_t)1 << mtype) & wifi_handler_flags_buf_free;
- uint16_t buf_acq = ((uint16_t)1 << mtype) & wifi_handler_flags_buf_acq;
- if (buf_free) {
- eos_net_free(buffer, buf_acq);
- buffer = NULL;
- len = 0;
- }
-
- wifi_handler[mtype](buffer, len);
-
- if (buf_free && buf_acq) eos_net_release();
+ _eos_net_handle(type, buffer, len, mtype, evt_handler, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
}
void eos_wifi_init(void) {
+ int i;
+
+ for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
+ evt_handler[i] = eos_evtq_bad_handler;
+ }
eos_net_set_handler(EOS_NET_MTYPE_WIFI, wifi_handler_evt, 0);
}
+void eos_wifi_set_handler(int mtype, eos_evt_fptr_t handler, uint8_t flags) {
+ if (mtype >= EOS_WIFI_MAX_MTYPE) {
+ return;
+ }
+ _eos_net_set_handler(mtype, handler, evt_handler, flags, &evt_handler_flags_buf_free, &evt_handler_flags_buf_acq);
+}
+
void eos_wifi_connect(const char *ssid, const char *pass) {
int ssid_len = strlen(ssid);
int pass_len = strlen(pass);
@@ -61,16 +63,3 @@ void eos_wifi_disconnect(void) {
buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
}
-
-void eos_wifi_set_handler(int mtype, eos_wifi_fptr_t handler, uint8_t flags) {
- if (mtype >= EOS_WIFI_MAX_MTYPE) {
- return;
- }
-
- if (flags) {
- uint16_t flag = (uint16_t)1 << mtype;
- if (flags & EOS_NET_FLAG_BFREE) wifi_handler_flags_buf_free |= flag;
- if (flags & EOS_NET_FLAG_BACQ) wifi_handler_flags_buf_acq |= flag;
- }
- wifi_handler[mtype] = handler;
-}
diff --git a/code/fe310/eos/wifi.h b/code/fe310/eos/wifi.h
index d46d25b..3587d1d 100644
--- a/code/fe310/eos/wifi.h
+++ b/code/fe310/eos/wifi.h
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include "event.h"
#define EOS_WIFI_MTYPE_SCAN 0
#define EOS_WIFI_MTYPE_CONNECT 1
@@ -6,9 +7,8 @@
#define EOS_WIFI_MAX_MTYPE 3
-typedef void (*eos_wifi_fptr_t) (unsigned char *, uint16_t);
-
void eos_wifi_init(void);
+void eos_wifi_set_handler(int mtype, eos_evt_fptr_t handler, uint8_t flags);
+
void eos_wifi_connect(const char *ssid, const char *pass);
void eos_wifi_disconnect(void);
-void eos_wifi_set_handler(int mtype, eos_wifi_fptr_t handler, uint8_t flags); \ No newline at end of file