summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/Makefile2
-rw-r--r--fw/fe310/bsp/drivers/prci_driver.c16
-rw-r--r--fw/fe310/common.mk1
-rw-r--r--fw/fe310/eos/Makefile2
-rw-r--r--fw/fe310/eos/app/app_status.c17
-rw-r--r--fw/fe310/eos/board.h4
-rw-r--r--fw/fe310/eos/eos.h7
-rw-r--r--fw/fe310/eos/eve/eve_eos.c2
-rw-r--r--fw/fe310/eos/event.c2
-rw-r--r--fw/fe310/eos/i2s.c177
-rw-r--r--fw/fe310/eos/i2s.h4
-rw-r--r--fw/fe310/eos/i2s_def.h3
-rw-r--r--fw/fe310/eos/interrupt.c2
-rw-r--r--fw/fe310/eos/net.c62
-rw-r--r--fw/fe310/eos/net.h13
-rw-r--r--fw/fe310/eos/sock.c101
-rw-r--r--fw/fe310/eos/sock.h10
-rw-r--r--fw/fe310/eos/trap_entry.S192
-rw-r--r--fw/fe310/eos/wifi.c61
-rw-r--r--fw/fe310/eos/wifi.h7
-rw-r--r--fw/fe310/test/Makefile14
-rw-r--r--fw/fe310/test/app/Makefile (renamed from fw/fe310/eos/app/Makefile)0
-rw-r--r--fw/fe310/test/app/app_root.c (renamed from fw/fe310/eos/app/app_root.c)16
-rw-r--r--fw/fe310/test/app/app_root.h (renamed from fw/fe310/eos/app/app_root.h)0
-rw-r--r--fw/fe310/test/app/app_status.c (renamed from fw/fe310/test/status.c)27
-rw-r--r--fw/fe310/test/app/app_status.h (renamed from fw/fe310/eos/app/app_status.h)1
-rw-r--r--fw/fe310/test/cam.c5
-rw-r--r--fw/fe310/test/cell_dev.c9
-rw-r--r--fw/fe310/test/cell_pdp.c11
-rw-r--r--fw/fe310/test/fs.c2
-rw-r--r--fw/fe310/test/main.c27
-rw-r--r--fw/fe310/test/modem.c10
-rw-r--r--fw/fe310/test/phone.c21
-rw-r--r--fw/fe310/test/status.h2
-rw-r--r--fw/fe310/test/test.c7
-rw-r--r--fw/fe310/test/wifi.c42
36 files changed, 527 insertions, 352 deletions
diff --git a/fw/fe310/Makefile b/fw/fe310/Makefile
index a4f5d1e..f9da883 100644
--- a/fw/fe310/Makefile
+++ b/fw/fe310/Makefile
@@ -5,7 +5,7 @@ MAKEFLAGS += -I$(fe310_dir)
include $(crypto_dir)/crypto_obj.mk
obj_crypto = $(addprefix $(crypto_dir)/,$(obj_dep))
-subdirs = bsp/drivers bsp/gloss bsp/metal eos eos/i2c eos/eve eos/eve/screen eos/eve/widget eos/app $(ext_dir)/fsfat
+subdirs = bsp/drivers bsp/gloss bsp/metal eos eos/i2c eos/eve eos/eve/screen eos/eve/widget $(ext_dir)/fsfat
all: libeos.a
diff --git a/fw/fe310/bsp/drivers/prci_driver.c b/fw/fe310/bsp/drivers/prci_driver.c
index c2df2c9..29118a2 100644
--- a/fw/fe310/bsp/drivers/prci_driver.c
+++ b/fw/fe310/bsp/drivers/prci_driver.c
@@ -51,16 +51,16 @@ uint32_t PRCI_measure_mcycle_freq(uint32_t mtime_ticks, uint32_t mtime_freq)
unsigned long PRCI_get_cpu_freq()
{
- static uint32_t cpu_freq;
+ static uint32_t cpu_freq;
- if (!cpu_freq) {
- // warm up I$
- PRCI_measure_mcycle_freq(3000, RTC_FREQ);
- // measure for real
- cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ);
- }
+ if (!cpu_freq) {
+ // warm up I$
+ PRCI_measure_mcycle_freq(3000, RTC_FREQ);
+ // measure for real
+ cpu_freq = PRCI_measure_mcycle_freq(3000, RTC_FREQ);
+ }
- return cpu_freq;
+ return cpu_freq;
}
void PRCI_use_hfrosc(int div, int trim)
diff --git a/fw/fe310/common.mk b/fw/fe310/common.mk
index 80a34a9..dbfda51 100644
--- a/fw/fe310/common.mk
+++ b/fw/fe310/common.mk
@@ -2,6 +2,7 @@ fe310_dir := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
bsp_dir := $(abspath $(fe310_dir)/bsp)
eos_dir := $(abspath $(fe310_dir)/eos)
ext_dir := $(abspath $(fe310_dir)/../../ext)
+ecp_dir := $(abspath $(fe310_dir)/../../ecp)
include $(fe310_dir)/platform.mk
CFLAGS += -I$(eos_dir)
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index 01318de..a52b5db 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -1,7 +1,7 @@
include ../common.mk
CFLAGS += -I. -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto
-obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o spi_dev.o lcd.o sdcard.o sdc_crypto.o cam.o net.o wifi.o cell.o sock.o unicode.o
+obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o pwr.o i2s.o i2c.o uart.o spi.o spi_dev.o lcd.o sdcard.o sdc_crypto.o cam.o net.o rng.o wifi.o cell.o sock.o unicode.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/app/app_status.c b/fw/fe310/eos/app/app_status.c
deleted file mode 100644
index 4ab0a97..0000000
--- a/fw/fe310/eos/app/app_status.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <stdlib.h>
-
-#include "eve/eve.h"
-#include "eve/eve_kbd.h"
-#include "eve/eve_font.h"
-
-#include "eve/screen/window.h"
-
-#include "app_status.h"
-
-uint8_t app_status_draw(EVEView *view, uint8_t tag0) {
- return eve_view_clear(view, tag0, 0);
-}
-
-int app_status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
- return 0;
-}
diff --git a/fw/fe310/eos/board.h b/fw/fe310/eos/board.h
index a18b58f..99832a7 100644
--- a/fw/fe310/eos/board.h
+++ b/fw/fe310/eos/board.h
@@ -30,8 +30,8 @@
#define I2S_PIN_SD_IN 13
#define I2S_PIN_SD_OUT 12
-#define I2S_IRQ_WS_ID (INT_PWM1_BASE + 0)
-#define I2S_IRQ_SD_ID (INT_PWM1_BASE + 3)
+#define I2S_IRQ_WS_ID (INT_PWM2_BASE + 0)
+#define I2S_IRQ_SD_ID (INT_PWM2_BASE + 3)
#define I2S_CTRL_ADDR_CK PWM0_CTRL_ADDR
#define I2S_CTRL_ADDR_WS_MIC PWM1_CTRL_ADDR
diff --git a/fw/fe310/eos/eos.h b/fw/fe310/eos/eos.h
index 6c061d5..87a7e27 100644
--- a/fw/fe310/eos/eos.h
+++ b/fw/fe310/eos/eos.h
@@ -5,9 +5,10 @@
#define EOS_ERR_TIMEOUT -2
#define EOS_ERR_BUSY -3
-#define EOS_ERR_FULL -10
-#define EOS_ERR_EMPTY -11
-#define EOS_ERR_NOTFOUND -12
+#define EOS_ERR_SIZE -10
+#define EOS_ERR_FULL -11
+#define EOS_ERR_EMPTY -12
+#define EOS_ERR_NOTFOUND -13
#define EOS_ERR_NET -20
diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c
index 283aa6a..2e13cd2 100644
--- a/fw/fe310/eos/eve/eve_eos.c
+++ b/fw/fe310/eos/eve/eve_eos.c
@@ -101,4 +101,4 @@ void eos_eve_stop(void) {
eve_spi_start();
_stop();
eve_spi_stop();
-} \ No newline at end of file
+}
diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c
index 4a6493f..753cdb4 100644
--- a/fw/fe310/eos/event.c
+++ b/fw/fe310/eos/event.c
@@ -140,7 +140,7 @@ void eos_evtq_loop(void) {
}
void eos_evtq_bad_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
- printf("evt bad handler:0x%x\n", type);
+ printf("EVT BAD HANDLER:0x%x\n", type);
}
void eos_evtq_set_handler(unsigned char type, eos_evt_handler_t handler) {
diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c
index 9cc32e0..9cc9d9c 100644
--- a/fw/fe310/eos/i2s.c
+++ b/fw/fe310/eos/i2s.c
@@ -25,22 +25,41 @@
#define EOS_ABUF_IDX_MASK(IDX, SIZE) ((IDX) & ((SIZE) - 1))
-EOSABuf _eos_i2s_mic_buf;
-EOSABuf _eos_i2s_spk_buf;
-uint32_t _eos_i2s_fmt = 0;
-uint32_t _eos_i2s_mode = 0;
-uint32_t _eos_i2s_sample = 0;
-uint32_t _eos_i2s_mic_wm = 0;
-uint32_t _eos_i2s_spk_wm = 0;
-uint32_t _eos_i2s_mic_evt_enable = 0;
-uint32_t _eos_i2s_spk_evt_enable = 0;
+EOSABuf i2s_mic_buf;
+EOSABuf i2s_spk_buf;
-static eos_i2s_handler_t i2s_spk_handler = NULL;
static eos_i2s_handler_t i2s_mic_handler = NULL;
+static eos_i2s_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 */
+uint32_t _eos_i2s_drvr[] = {
+ 0, /* I2S_MIC_BUF */
+ 0, /* I2S_SPK_BUF */
+ EOS_I2S_FMT_PCM16, /* I2S_FMT */
+ EOS_I2S_MODE_STEREO, /* I2S_MODE */
+ 0, /* I2S_MIC_WM */
+ 0, /* I2S_SPK_WM */
+ 0, /* I2S_MIC_EVT */
+ 0, /* I2S_SPK_EVT */
+ 0, /* I2S_MIC_CMP2 */
+ 0, /* I2S_MIC_CMP3 */
+ 0, /* I2S_SAMPLE */
+};
+
+#define I2S_MIC_BUF 0
+#define I2S_SPK_BUF 1
+#define I2S_FMT 2
+#define I2S_MODE 3
+#define I2S_MIC_WM 4
+#define I2S_SPK_WM 5
+#define I2S_MIC_EVT 6
+#define I2S_SPK_EVT 7
+#define I2S_MIC_CMP2 8
+#define I2S_MIC_CMP3 9
+#define I2S_SAMPLE 10
+
static void _abuf_init(EOSABuf *buf, uint8_t *array, uint16_t size) {
buf->idx_r = 0;
buf->idx_w = 0;
@@ -86,7 +105,6 @@ static int _abuf_pop16(EOSABuf *buf, uint16_t *sample) {
}
}
-
static void _abuf_flush(EOSABuf *buf) {
buf->idx_r = 0;
buf->idx_w = 0;
@@ -99,17 +117,21 @@ static uint16_t _abuf_len(EOSABuf *buf) {
static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
switch(type & ~EOS_EVT_MASK) {
case EOS_I2S_ETYPE_MIC:
- if (i2s_mic_handler) i2s_mic_handler(type);
- clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_mic_evt_enable = 1;
- set_csr(mstatus, MSTATUS_MIE);
+ if (i2s_mic_handler) {
+ i2s_mic_handler(type);
+ clear_csr(mstatus, MSTATUS_MIE);
+ _eos_i2s_drvr[I2S_MIC_EVT] = 1;
+ set_csr(mstatus, MSTATUS_MIE);
+ }
break;
case EOS_I2S_ETYPE_SPK:
- if (i2s_spk_handler) i2s_spk_handler(type);
- clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_spk_evt_enable = 1;
- set_csr(mstatus, MSTATUS_MIE);
+ if (i2s_spk_handler) {
+ i2s_spk_handler(type);
+ clear_csr(mstatus, MSTATUS_MIE);
+ _eos_i2s_drvr[I2S_SPK_EVT] = 1;
+ set_csr(mstatus, MSTATUS_MIE);
+ }
break;
default:
@@ -118,23 +140,40 @@ static void i2s_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l
}
}
-static void _mic_vol_set(uint8_t vol) {
- I2S_REG_WS_MIC(PWM_CMP2) = i2s_clk_period * (vol + 1);
- I2S_REG_WS_MIC(PWM_CMP3) = I2S_REG_WS_MIC(PWM_CMP2) + i2s_clk_period * 16;
-}
+#define PLIC_PRIORITY 0x0C000000
+
+static void i2s_cmp_set(void) {
+ int c = 7; /* interrupt will trigger c i2s clocks before spk ws */
+ int spk_ws_offset = i2s_spk_volume - 16 + i2s_mic_volume;
+ volatile uint32_t *p = (uint32_t *)PLIC_PRIORITY+I2S_IRQ_SD_ID;
+
+ /* interrupt trigger - will start with left channel */
+ if (spk_ws_offset - c < 0) {
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (64 + spk_ws_offset - c);
+ } else {
+ I2S_REG_WS_SPK(PWM_CMP3) = i2s_clk_period * (spk_ws_offset - c);
+ }
-static void _spk_vol_set(uint8_t vol) {
- int spk_cmp = vol + i2s_mic_volume - 16;
+ /* disable interrupt for this cycle */
+ *p = 0;
- if (spk_cmp <= 0) {
- I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * (32 + spk_cmp);
- I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (64 + spk_cmp);
+ /* empty buffers */
+ // i2s_mic_buf.idx_r = i2s_mic_buf.idx_w;
+ // i2s_spk_buf.idx_w = i2s_spk_buf.idx_r;
+
+ /* adjust spk ws relative to mic ws */
+ if (spk_ws_offset <= 0) {
+ spk_ws_offset += 32;
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
} else {
- I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_cmp;
- I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_cmp);
- GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << I2S_PIN_WS_SPK);
+ GPIO_REG(GPIO_OUTPUT_XOR) |= (1 << I2S_PIN_WS_SPK);
}
+ I2S_REG_WS_SPK(PWM_CMP1) = i2s_clk_period * spk_ws_offset;
+ I2S_REG_WS_SPK(PWM_CMP2) = i2s_clk_period * (32 + spk_ws_offset);
+
+ /* mic cmp2 relative to interrupt trigger */
+ _eos_i2s_drvr[I2S_MIC_CMP2] = (17 + c - i2s_spk_volume) * i2s_clk_period; /* (17 + c - i2s_spk_volume) == (1 + i2s_mic_volume) - (spk_ws_offset - c) */
+ _eos_i2s_drvr[I2S_MIC_CMP3] = 16 * i2s_clk_period;
}
extern void _eos_i2s_start_pwm(void);
@@ -179,7 +218,7 @@ void eos_i2s_init_mux(void) {
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
}
-void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
+void eos_i2s_start(uint32_t sample_rate) {
i2s_clk_period = ((PRCI_get_cpu_freq() / (sample_rate * 64)) & ~I2S_PWM_SCALE_CK_MASK) + 1;
GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN);
@@ -195,18 +234,28 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
I2S_REG_WS_MIC(PWM_CMP0) = i2s_clk_period * 64 - 1;
I2S_REG_WS_MIC(PWM_CMP1) = i2s_clk_period * 32;
- _mic_vol_set(i2s_mic_volume);
I2S_REG_WS_SPK(PWM_CMP0) = i2s_clk_period * 64 - 1;
- _spk_vol_set(i2s_spk_volume);
+ i2s_cmp_set();
I2S_REG_CK(PWM_COUNT) = 0;
I2S_REG_WS_MIC(PWM_COUNT) = 0;
I2S_REG_WS_SPK(PWM_COUNT) = i2s_clk_period / 2;
- _eos_i2s_fmt = fmt;
- _eos_i2s_mic_evt_enable = 1;
- _eos_i2s_spk_evt_enable = 1;
+ if (i2s_mic_buf.array && i2s_mic_buf.size) {
+ _eos_i2s_drvr[I2S_MIC_BUF] = (uint32_t)&i2s_mic_buf;
+ if (_eos_i2s_drvr[I2S_MIC_WM] == 0) {
+ _eos_i2s_drvr[I2S_MIC_WM] = i2s_mic_buf.size / 2;
+ }
+ }
+ if (i2s_spk_buf.array && i2s_spk_buf.size) {
+ _eos_i2s_drvr[I2S_SPK_BUF] = (uint32_t)&i2s_spk_buf;
+ if (_eos_i2s_drvr[I2S_SPK_WM] == 0) {
+ _eos_i2s_drvr[I2S_SPK_WM] = i2s_spk_buf.size / 2;
+ }
+ }
+ if (i2s_mic_handler) _eos_i2s_drvr[I2S_MIC_EVT] = 1;
+ if (i2s_spk_handler) _eos_i2s_drvr[I2S_SPK_EVT] = 1;
eos_intr_set_priority(I2S_IRQ_SD_ID, IRQ_PRIORITY_I2S_SD);
eos_intr_set_priority(I2S_IRQ_WS_ID, IRQ_PRIORITY_I2S_WS);
@@ -237,8 +286,13 @@ void eos_i2s_stop(void) {
I2S_REG_WS_MIC(PWM_COUNT) = 0;
I2S_REG_WS_SPK(PWM_COUNT) = 0;
- _eos_i2s_mic_evt_enable = 0;
- _eos_i2s_spk_evt_enable = 0;
+ _eos_i2s_drvr[I2S_MIC_BUF] = 0;
+ _eos_i2s_drvr[I2S_MIC_EVT] = 0;
+ _eos_i2s_drvr[I2S_MIC_WM] = 0;
+
+ _eos_i2s_drvr[I2S_SPK_BUF] = 0;
+ _eos_i2s_drvr[I2S_SPK_EVT] = 0;
+ _eos_i2s_drvr[I2S_SPK_WM] = 0;
eos_intr_disable(I2S_IRQ_WS_ID);
eos_intr_disable(I2S_IRQ_SD_ID);
@@ -257,9 +311,17 @@ int eos_i2s_running(void) {
return !!(GPIO_REG(GPIO_IOF_EN) & (1 << I2S_PIN_CK));
}
+void eos_i2s_set_fmt(unsigned char fmt) {
+ _eos_i2s_drvr[I2S_FMT] = fmt;
+}
+
+void eos_i2s_set_mode(unsigned char mode) {
+ _eos_i2s_drvr[I2S_MODE] = mode;
+}
+
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size) {
clear_csr(mstatus, MSTATUS_MIE);
- _abuf_init(&_eos_i2s_mic_buf, mic_arr, mic_arr_size);
+ _abuf_init(&i2s_mic_buf, mic_arr, mic_arr_size);
set_csr(mstatus, MSTATUS_MIE);
}
@@ -271,14 +333,14 @@ void eos_i2s_mic_set_handler(eos_i2s_handler_t wm_handler) {
void eos_i2s_mic_set_wm(uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_mic_wm = wm;
+ _eos_i2s_drvr[I2S_MIC_WM] = wm;
set_csr(mstatus, MSTATUS_MIE);
}
uint16_t eos_i2s_mic_len(void) {
clear_csr(mstatus, MSTATUS_MIE);
- uint16_t ret = _abuf_len(&_eos_i2s_mic_buf);
+ uint16_t ret = _abuf_len(&i2s_mic_buf);
set_csr(mstatus, MSTATUS_MIE);
return ret;
}
@@ -288,15 +350,15 @@ uint16_t eos_i2s_mic_read(uint8_t *sample, uint16_t ssize) {
uint16_t _ssize = 0;
clear_csr(mstatus, MSTATUS_MIE);
- _ssize = MIN(ssize, _abuf_len(&_eos_i2s_mic_buf));
+ _ssize = MIN(ssize, _abuf_len(&i2s_mic_buf));
set_csr(mstatus, MSTATUS_MIE);
for (i=0; i<_ssize; i++) {
- sample[i] = _eos_i2s_mic_buf.array[EOS_ABUF_IDX_MASK(_eos_i2s_mic_buf.idx_r + i, _eos_i2s_mic_buf.size)];
+ sample[i] = i2s_mic_buf.array[EOS_ABUF_IDX_MASK(i2s_mic_buf.idx_r + i, i2s_mic_buf.size)];
}
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_mic_buf.idx_r += _ssize;
+ i2s_mic_buf.idx_r += _ssize;
set_csr(mstatus, MSTATUS_MIE);
return _ssize;
@@ -306,7 +368,7 @@ int eos_i2s_mic_pop8(uint8_t *sample) {
int ret;
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_pop8(&_eos_i2s_mic_buf, sample);
+ ret = _abuf_pop8(&i2s_mic_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
return ret;
@@ -316,7 +378,7 @@ int eos_i2s_mic_pop16(uint16_t *sample) {
int ret;
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_pop16(&_eos_i2s_mic_buf, sample);
+ ret = _abuf_pop16(&i2s_mic_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
return ret;
@@ -332,14 +394,13 @@ void eos_i2s_mic_vol_set(int vol) {
i2s_mic_volume = vol;
clear_csr(mstatus, MSTATUS_MIE);
- _mic_vol_set(vol);
- _spk_vol_set(i2s_spk_volume);
+ i2s_cmp_set();
set_csr(mstatus, MSTATUS_MIE);
}
void eos_i2s_spk_init(uint8_t *spk_arr, uint16_t spk_arr_size) {
clear_csr(mstatus, MSTATUS_MIE);
- _abuf_init(&_eos_i2s_spk_buf, spk_arr, spk_arr_size);
+ _abuf_init(&i2s_spk_buf, spk_arr, spk_arr_size);
set_csr(mstatus, MSTATUS_MIE);
}
@@ -351,13 +412,13 @@ void eos_i2s_spk_set_handler(eos_i2s_handler_t wm_handler) {
void eos_i2s_spk_set_wm(uint16_t wm) {
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_spk_wm = wm;
+ _eos_i2s_drvr[I2S_SPK_WM] = wm;
set_csr(mstatus, MSTATUS_MIE);
}
uint16_t eos_i2s_spk_len(void) {
clear_csr(mstatus, MSTATUS_MIE);
- uint16_t ret = _abuf_len(&_eos_i2s_spk_buf);
+ uint16_t ret = _abuf_len(&i2s_spk_buf);
set_csr(mstatus, MSTATUS_MIE);
return ret;
}
@@ -367,15 +428,15 @@ uint16_t eos_i2s_spk_write(uint8_t *sample, uint16_t ssize) {
uint16_t _ssize = 0;
clear_csr(mstatus, MSTATUS_MIE);
- _ssize = MIN(ssize, _eos_i2s_spk_buf.size - _abuf_len(&_eos_i2s_spk_buf));
+ _ssize = MIN(ssize, i2s_spk_buf.size - _abuf_len(&i2s_spk_buf));
set_csr(mstatus, MSTATUS_MIE);
for (i=0; i<_ssize; i++) {
- _eos_i2s_spk_buf.array[EOS_ABUF_IDX_MASK(_eos_i2s_spk_buf.idx_w + i, _eos_i2s_spk_buf.size)] = sample[i];
+ i2s_spk_buf.array[EOS_ABUF_IDX_MASK(i2s_spk_buf.idx_w + i, i2s_spk_buf.size)] = sample[i];
}
clear_csr(mstatus, MSTATUS_MIE);
- _eos_i2s_spk_buf.idx_w += _ssize;
+ i2s_spk_buf.idx_w += _ssize;
set_csr(mstatus, MSTATUS_MIE);
return _ssize;
@@ -385,7 +446,7 @@ int eos_i2s_spk_push8(uint8_t sample) {
int ret;
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_push8(&_eos_i2s_spk_buf, sample);
+ ret = _abuf_push8(&i2s_spk_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
return ret;
@@ -395,7 +456,7 @@ int eos_i2s_spk_push16(uint16_t sample) {
int ret;
clear_csr(mstatus, MSTATUS_MIE);
- ret = _abuf_push16(&_eos_i2s_spk_buf, sample);
+ ret = _abuf_push16(&i2s_spk_buf, sample);
set_csr(mstatus, MSTATUS_MIE);
return ret;
@@ -411,6 +472,6 @@ void eos_i2s_spk_vol_set(int vol) {
i2s_spk_volume = vol;
clear_csr(mstatus, MSTATUS_MIE);
- _spk_vol_set(vol);
+ i2s_cmp_set();
set_csr(mstatus, MSTATUS_MIE);
}
diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h
index f53e183..81b4ade 100644
--- a/fw/fe310/eos/i2s.h
+++ b/fw/fe310/eos/i2s.h
@@ -13,9 +13,11 @@ typedef void (*eos_i2s_handler_t) (unsigned char);
int eos_i2s_init(uint8_t wakeup_cause);
void eos_i2s_init_mux(void);
-void eos_i2s_start(uint32_t sample_rate, unsigned char fmt);
+void eos_i2s_start(uint32_t sample_rate);
void eos_i2s_stop(void);
int eos_i2s_running(void);
+void eos_i2s_set_fmt(unsigned char fmt);
+void eos_i2s_set_mode(unsigned char mode);
void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size);
void eos_i2s_mic_set_handler(eos_i2s_handler_t wm_handler);
void eos_i2s_mic_set_wm(uint16_t wm);
diff --git a/fw/fe310/eos/i2s_def.h b/fw/fe310/eos/i2s_def.h
index a338828..3529be1 100644
--- a/fw/fe310/eos/i2s_def.h
+++ b/fw/fe310/eos/i2s_def.h
@@ -1,5 +1,8 @@
#define EOS_I2S_FMT_PCM16 0
#define EOS_I2S_FMT_ALAW 1
+#define EOS_I2S_MODE_STEREO 0
+#define EOS_I2S_MODE_MONO 1
+
#define EOS_I2S_ETYPE_MIC 1
#define EOS_I2S_ETYPE_SPK 2
diff --git a/fw/fe310/eos/interrupt.c b/fw/fe310/eos/interrupt.c
index 8af492b..dab6fab 100644
--- a/fw/fe310/eos/interrupt.c
+++ b/fw/fe310/eos/interrupt.c
@@ -20,7 +20,7 @@ uintptr_t eos_intr_handle(uintptr_t int_num) {
if ((int_num >=1) && (int_num <= PLIC_NUM_INTERRUPTS) && (ext_interrupt_handler[int_num-1])) {
ext_interrupt_handler[int_num-1]();
} else {
- printf("error:%d\n", int_num);
+ printf("INTR ERROR:%d\n", int_num);
exit(int_num);
}
return int_num;
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c
index e65bcd2..e10414c 100644
--- a/fw/fe310/eos/net.c
+++ b/fw/fe310/eos/net.c
@@ -24,7 +24,7 @@
#define NET_STATE_FLAG_INIT 0x02
#define NET_STATE_FLAG_XCHG 0x04
#define NET_STATE_FLAG_ONEW 0x10
-#define NET_STATE_FLAG_REPW 0x20
+#define NET_STATE_FLAG_SYNC 0x20
#define NET_STATE_FLAG_RTS 0x40
#define NET_STATE_FLAG_CTS 0x80
@@ -108,7 +108,6 @@ static void net_xchg_start(unsigned char type, unsigned char *buffer, uint16_t l
if (net_state_next_cnt && (net_state_next_buf == NULL)) type |= EOS_NET_MTYPE_FLAG_ONEW;
if (type & EOS_NET_MTYPE_FLAG_ONEW) net_state_flags |= NET_STATE_FLAG_ONEW;
- if (type & EOS_NET_MTYPE_FLAG_REPW) net_state_flags |= NET_STATE_FLAG_REPW;
net_state_type = type;
net_state_len_tx = len;
@@ -156,7 +155,7 @@ static void net_handle_xchg(void) {
r2 = SPI1_REG(SPI_REG_RXFIFO);
r3 = SPI1_REG(SPI_REG_RXFIFO);
- if (net_state_flags & (NET_STATE_FLAG_ONEW | NET_STATE_FLAG_REPW)) {
+ if (net_state_flags & NET_STATE_FLAG_ONEW) {
r1 = 0;
r2 = 0;
r3 = 0;
@@ -189,20 +188,17 @@ static void net_handle_xchg(void) {
eos_spi_handle_xchg();
if (SPI1_REG(SPI_REG_CSMODE) == SPI_CSMODE_AUTO) { // exchange done
- if (net_state_flags & NET_STATE_FLAG_REPW) {
- net_state_flags &= ~NET_STATE_FLAG_REPW;
- } else {
+ if (!(net_state_flags & NET_STATE_FLAG_SYNC)) {
if (net_state_type) {
int r = eos_evtq_push_isr(EOS_EVT_NET | net_state_type, net_state_buf, net_state_len_rx);
if (r) eos_bufq_push(&net_buf_q, net_state_buf);
} else if (((net_state_flags & NET_STATE_FLAG_ONEW) || net_state_next_cnt) && (net_state_next_buf == NULL)) {
net_state_next_buf = net_state_buf;
- net_state_flags &= ~NET_STATE_FLAG_ONEW;
} else {
eos_bufq_push(&net_buf_q, net_state_buf);
}
}
- net_state_flags &= ~NET_STATE_FLAG_XCHG;
+ net_state_flags &= ~(NET_STATE_FLAG_ONEW | NET_STATE_FLAG_XCHG);
}
}
@@ -515,17 +511,21 @@ void eos_net_free(unsigned char *buffer, unsigned char more) {
set_csr(mstatus, MSTATUS_MIE);
}
-static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len) {
+static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len, unsigned char flags) {
int rv = EOS_OK;
int _sync = 0;
unsigned char _type = *type;
uint16_t _len = *len;
uint8_t spi_dev = EOS_SPI_DEV_NET;
+ if (flags & EOS_NET_FLAG_ONEW) _type |= EOS_NET_MTYPE_FLAG_ONEW;
+ if (flags & EOS_NET_FLAG_REPL) _type |= EOS_NET_MTYPE_FLAG_REPL;
+ if (flags & EOS_NET_FLAG_SYNC) _sync = 1;
+
clear_csr(mstatus, MSTATUS_MIE);
- if ((_type & EOS_NET_MTYPE_FLAG_REPW) || ((_type & EOS_NET_MTYPE_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN))) _sync = 1;
+ if ((flags & EOS_NET_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) _sync = 1;
- if (!(net_state_flags & NET_STATE_FLAG_RUN) && _sync) {
+ if (_sync && !(net_state_flags & NET_STATE_FLAG_RUN)) {
int _rv;
set_csr(mstatus, MSTATUS_MIE);
@@ -542,19 +542,25 @@ static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len) {
set_csr(mstatus, MSTATUS_MIE);
clear_csr(mstatus, MSTATUS_MIE);
}
+ if (flags & EOS_NET_FLAG_SYNC) {
+ net_state_flags |= NET_STATE_FLAG_SYNC;
+ }
net_xchg_start(_type, buffer, _len);
- if (_type & EOS_NET_MTYPE_FLAG_REPW) {
- while (!(net_state_flags & NET_STATE_FLAG_CTS)) {
- asm volatile ("wfi");
- set_csr(mstatus, MSTATUS_MIE);
- clear_csr(mstatus, MSTATUS_MIE);
+ if (flags & EOS_NET_FLAG_SYNC) {
+ if (flags & EOS_NET_FLAG_REPL) {
+ while (!(net_state_flags & NET_STATE_FLAG_CTS)) {
+ asm volatile ("wfi");
+ set_csr(mstatus, MSTATUS_MIE);
+ clear_csr(mstatus, MSTATUS_MIE);
+ }
+ net_xchg_start(0, buffer, 0);
}
- net_xchg_start(0, buffer, 0);
while (net_state_flags & NET_STATE_FLAG_XCHG) {
asm volatile ("wfi");
set_csr(mstatus, MSTATUS_MIE);
clear_csr(mstatus, MSTATUS_MIE);
}
+ net_state_flags &= ~NET_STATE_FLAG_SYNC;
*type = net_state_type;
*len = net_state_len_rx;
}
@@ -574,12 +580,22 @@ static int net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len) {
return rv;
}
-int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more) {
- if (more) type |= EOS_NET_MTYPE_FLAG_ONEW;
- return net_xchg(&type, buffer, &len);
+int eos_net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len) {
+ return net_xchg(type, buffer, len, (EOS_NET_FLAG_ONEW | EOS_NET_FLAG_SYNC | EOS_NET_FLAG_REPL));
+}
+
+int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len) {
+ return net_xchg(&type, buffer, &len, (EOS_NET_FLAG_ONEW | EOS_NET_FLAG_SYNC));
}
-int eos_net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len) {
- *type |= EOS_NET_MTYPE_FLAG_REPW;
- return net_xchg(type, buffer, len);
+int eos_net_send_async(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more) {
+ return net_xchg(&type, buffer, &len, more ? EOS_NET_FLAG_ONEW : 0);
+}
+
+int _eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char async, unsigned char more) {
+ if (async) {
+ eos_net_send_async(type, buffer, len, more);
+ } else {
+ eos_net_send(type, buffer, len);
+ }
}
diff --git a/fw/fe310/eos/net.h b/fw/fe310/eos/net.h
index 86496bb..79caf4b 100644
--- a/fw/fe310/eos/net.h
+++ b/fw/fe310/eos/net.h
@@ -3,9 +3,10 @@
/* common */
#define EOS_NET_MTU 1500
-#define EOS_NET_SIZE_BUF (EOS_NET_MTU + 4)
+#define EOS_NET_SIZE_BUF EOS_NET_MTU
#define EOS_NET_MTYPE_SOCK 1
+#define EOS_NET_MTYPE_RNG 3
#define EOS_NET_MTYPE_POWER 4
#define EOS_NET_MTYPE_WIFI 5
@@ -16,12 +17,16 @@
#define EOS_NET_MAX_MTYPE 8
#define EOS_NET_MTYPE_FLAG_ONEW 0x40
-#define EOS_NET_MTYPE_FLAG_REPW 0x80
+#define EOS_NET_MTYPE_FLAG_REPL 0x80
#define EOS_NET_MTYPE_FLAG_MASK 0xc0
/* fe310 specific */
#define EOS_NET_SIZE_BUFQ 2
+#define EOS_NET_FLAG_ONEW 0x1
+#define EOS_NET_FLAG_SYNC 0x2
+#define EOS_NET_FLAG_REPL 0x4
+
int eos_net_init(uint8_t wakeup_cause);
int eos_net_run(uint8_t wakeup_cause);
void eos_net_start(void);
@@ -36,5 +41,7 @@ void eos_net_acquire(void);
void eos_net_release(void);
unsigned char *eos_net_alloc(void);
void eos_net_free(unsigned char *buffer, unsigned char more);
-int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more);
int eos_net_xchg(unsigned char *type, unsigned char *buffer, uint16_t *len);
+int eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len);
+int eos_net_send_async(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char more);
+int _eos_net_send(unsigned char type, unsigned char *buffer, uint16_t len, unsigned char async, unsigned char more);
diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/sock.c
index ef043d1..7365c97 100644
--- a/fw/fe310/eos/sock.c
+++ b/fw/fe310/eos/sock.c
@@ -52,52 +52,103 @@ eos_evt_handler_t eos_sock_get_handler(unsigned char sock) {
return NULL;
}
-int eos_sock_open_udp(eos_evt_handler_t handler) {
- unsigned char type = EOS_SOCK_MTYPE_OPEN_DGRAM;
- unsigned char *buffer = eos_net_alloc();
- uint16_t buf_size;
+int eos_sock_open_udp(eos_evt_handler_t handler, unsigned char *buffer) {
+ unsigned char type;
+ uint16_t len;
+ int do_release;
int rv, sock;
- buffer[0] = type;
- rv = eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 1, 0);
+ do_release = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ do_release = 1;
+ }
+
+ type = EOS_NET_MTYPE_SOCK;
+ len = 1;
+ buffer[0] = EOS_SOCK_MTYPE_OPEN_DGRAM;
+
+ rv = eos_net_xchg(&type, buffer, &len);
if (rv) return rv;
- eos_evtq_wait(EOS_NET_MTYPE_SOCK, &type, 1, &buffer, &buf_size);
- if (buf_size < 2) {
- eos_net_free(buffer, 0);
- return EOS_ERR_NET;
- }
+ if (type != EOS_NET_MTYPE_SOCK) return EOS_ERR_NET;
+ if (len < 2) return EOS_ERR_SIZE;
sock = buffer[1];
- eos_net_free(buffer, 1);
-
if (sock == 0) return EOS_ERR_NET;
+ if (do_release) {
+ eos_net_free(buffer, 1);
+ }
eos_sock_set_handler(sock, handler);
+
return sock;
}
-void eos_sock_close(unsigned char sock) {
- unsigned char *buffer = eos_net_alloc();
+void eos_sock_close(unsigned char sock, unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
buffer[0] = EOS_SOCK_MTYPE_CLOSE;
buffer[1] = sock;
- eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 2, 1);
+ _eos_net_send(EOS_NET_MTYPE_SOCK, buffer, 2, async, 1);
eos_sock_set_handler(sock, NULL);
}
-int eos_sock_sendto(unsigned char sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr) {
- unsigned char type = EOS_NET_MTYPE_SOCK;
-
+static int sock_send(unsigned char sock, unsigned char *msg, uint16_t msg_len, EOSNetAddr *addr, unsigned char *buffer) {
buffer[0] = EOS_SOCK_MTYPE_PKT;
buffer[1] = sock;
- memcpy(buffer+2, addr->host, sizeof(addr->host));
- memcpy(buffer+2+sizeof(addr->host), &addr->port, sizeof(addr->port));
- return eos_net_send(type, buffer, size, more);
+ buffer += 2;
+ memcpy(buffer, addr->host, sizeof(addr->host));
+ buffer += sizeof(addr->host);
+ buffer[0] = addr->port >> 8;
+ buffer[1] = addr->port;
+ buffer += sizeof(addr->port);
+ if (msg) {
+ if (msg_len + EOS_SOCK_SIZE_UDP_HDR > EOS_NET_MTU) return EOS_ERR_SIZE;
+ memcpy(buffer, msg, msg_len);
+ }
+
+ return EOS_OK;
}
-void eos_sock_getfrom(unsigned char *buffer, EOSNetAddr *addr) {
- memcpy(addr->host, buffer+2, sizeof(addr->host));
- memcpy(&addr->port, buffer+2+sizeof(addr->host), sizeof(addr->port));
+int eos_sock_sendto(unsigned char sock, unsigned char *msg, size_t msg_len, EOSNetAddr *addr, unsigned char *buffer) {
+ int rv;
+
+ rv = sock_send(sock, msg, msg_len, addr, buffer);
+ if (rv) return rv;
+
+ return eos_net_send(EOS_NET_MTYPE_SOCK, buffer, msg_len + EOS_SOCK_SIZE_UDP_HDR);
+}
+
+int eos_sock_sendto_async(unsigned char sock, unsigned char *msg, size_t msg_len, EOSNetAddr *addr, unsigned char *buffer, unsigned char more) {
+ int rv;
+
+ rv = sock_send(sock, msg, msg_len, addr, buffer);
+ if (rv) return rv;
+
+ return eos_net_send_async(EOS_NET_MTYPE_SOCK, buffer, msg_len + EOS_SOCK_SIZE_UDP_HDR, more);
}
+int eos_sock_recvfrom(unsigned char *buffer, uint16_t len, unsigned char *msg, size_t msg_size, EOSNetAddr *addr) {
+ if (len < EOS_SOCK_SIZE_UDP_HDR) return EOS_ERR_SIZE;
+
+ if (buffer[0] != EOS_SOCK_MTYPE_PKT) return EOS_ERR_NET;
+ buffer += 2;
+ memcpy(addr->host, buffer, sizeof(addr->host));
+ buffer += sizeof(addr->host);
+ addr->port = (uint16_t)buffer[0] << 8;
+ addr->port |= (uint16_t)buffer[1];
+ buffer += sizeof(addr->port);
+ if (msg) {
+ if (msg_size < len - EOS_SOCK_SIZE_UDP_HDR) return EOS_ERR_SIZE;
+ memcpy(msg, buffer, len - EOS_SOCK_SIZE_UDP_HDR);
+ }
+
+ return EOS_OK;
+}
diff --git a/fw/fe310/eos/sock.h b/fw/fe310/eos/sock.h
index 66fa2e1..5ef42e3 100644
--- a/fw/fe310/eos/sock.h
+++ b/fw/fe310/eos/sock.h
@@ -20,7 +20,9 @@ void eos_sock_netinit(void);
void eos_sock_set_handler(unsigned char sock, eos_evt_handler_t handler);
eos_evt_handler_t eos_sock_get_handler(unsigned char sock);
-int eos_sock_open_udp(eos_evt_handler_t handler);
-void eos_sock_close(unsigned char sock);
-int eos_sock_sendto(unsigned char sock, unsigned char *buffer, uint16_t size, unsigned char more, EOSNetAddr *addr);
-void eos_sock_getfrom(unsigned char *buffer, EOSNetAddr *addr);
+int eos_sock_open_udp(eos_evt_handler_t handler, unsigned char *buffer);
+void eos_sock_close(unsigned char sock, unsigned char *buffer);
+
+int eos_sock_sendto(unsigned char sock, unsigned char *msg, size_t msg_len, EOSNetAddr *addr, unsigned char *buffer);
+int eos_sock_sendto_async(unsigned char sock, unsigned char *msg, size_t msg_len, EOSNetAddr *addr, unsigned char *buffer, unsigned char more);
+int eos_sock_recvfrom(unsigned char *buffer, uint16_t len, unsigned char *msg, size_t msg_size, EOSNetAddr *addr);
diff --git a/fw/fe310/eos/trap_entry.S b/fw/fe310/eos/trap_entry.S
index 506683b..fb2b121 100644
--- a/fw/fe310/eos/trap_entry.S
+++ b/fw/fe310/eos/trap_entry.S
@@ -25,6 +25,18 @@
#define INT_PWM1_BASE 44
#define INT_PWM2_BASE 48
+#define I2S_MIC_BUF (0*4)
+#define I2S_SPK_BUF (1*4)
+#define I2S_FMT (2*4)
+#define I2S_MODE (3*4)
+#define I2S_MIC_WM (4*4)
+#define I2S_SPK_WM (5*4)
+#define I2S_MIC_EVT (6*4)
+#define I2S_SPK_EVT (7*4)
+#define I2S_MIC_CMP2 (8*4)
+#define I2S_MIC_CMP3 (9*4)
+#define I2S_SAMPLE (10*4)
+
#include "board.h"
#include "irq_def.h"
#include "evt_def.h"
@@ -37,7 +49,7 @@
.global eos_trap_entry
eos_trap_entry:
- addi sp, sp, -10*REGBYTES
+ addi sp, sp, -12*REGBYTES
STORE x8, 0*REGBYTES(sp)
STORE x9, 1*REGBYTES(sp)
STORE x18, 2*REGBYTES(sp)
@@ -46,8 +58,10 @@ eos_trap_entry:
STORE x21, 5*REGBYTES(sp)
STORE x22, 6*REGBYTES(sp)
STORE x23, 7*REGBYTES(sp)
- STORE x24, 8*REGBYTES(sp)
- STORE x25, 9*REGBYTES(sp)
+ STORE x24, 8*REGBYTES(sp) # format: 0 - PCM16; 1 - ALAW
+ STORE x25, 9*REGBYTES(sp) # mode: 0 - stereo; 1 - mono
+ STORE x26, 10*REGBYTES(sp) # channel: 0 - left; 1 - right
+ STORE x27, 11*REGBYTES(sp) # _eos_event_q addr
csrr x8, mcause
li x18, MCAUSE_EXT
@@ -86,51 +100,57 @@ evtq_push:
jalr x0, x21
i2s_handle_sd:
- li x9, I2S_CTRL_ADDR_WS_MIC
- lw x18, PWM_COUNT(x9)
- lw x19, PWM_CMP1(x9)
- lw x20, PWM_CMP2(x9)
- lw x21, PWM_CMP3(x9)
+ li x8, I2S_CTRL_ADDR_WS_SPK
+ lw x18, PWM_COUNT(x8)
+ lw x19, PWM_CMP3(x8)
# exit if too early
- bltu x18, x21, i2s_sd_exit
-
- # move CMPs for next channel and store parity to x25
- li x25, 0
- bltu x20, x19, 0f
- li x25, 1
- neg x19, x19
- li x22, PLIC_PRIORITY
- sw x0, 4*I2S_IRQ_SD_ID(x22)
+ bltu x18, x19, i2s_sd_exit
+
+ la x27, _eos_i2s_drvr
+
+ # move CMPs for next channel and store channel bit to x26
+ lw x20, I2S_MIC_CMP2(x27)
+ lw x21, I2S_MIC_CMP3(x27) # 16-bit period
+
+ add x23, x19, x20
+ add x24, x23, x21
+ slli x20, x21, 1 # 32-bit period
+ slli x21, x20, 1 # 64-bit period
+ bltu x24, x21, 0f
+ neg x21, x21
+ add x23, x23, x21
+ add x24, x24, x21
0:
- add x20, x20, x19
- add x21, x21, x19
- sw x20, PWM_CMP2(x9)
- sw x21, PWM_CMP3(x9)
+ li x26, 0
+ bltu x23, x20, 0f
+ li x26, 1
+0:
+ bltu x19, x20, 0f
+ neg x20, x20
+ li x18, PLIC_PRIORITY
+ sw x0, 4*I2S_IRQ_SD_ID(x18)
+0:
+ add x19, x19, x20
+
+ li x9, I2S_CTRL_ADDR_WS_MIC
+ sw x19, PWM_CMP3(x8)
+ sw x23, PWM_CMP2(x9)
+ sw x24, PWM_CMP3(x9)
- la x9, _eos_i2s_fmt
- lw x24, 0(x9)
+ lw x24, I2S_FMT(x27)
+ lw x25, I2S_MODE(x27)
i2s_abuf_pop:
- la x9, _eos_i2s_mode
- lw x22, 0(x9)
- and x22, x22, x25
- beqz x22, 0f
+ and x8, x25, x26
+ beqz x8, 0f
- la x9, _eos_i2s_sample
- lw x8, 0(x9)
+ lw x8, I2S_SAMPLE(x27)
j i2s_sd_xchg
-
0:
- mv x8, x0
-
- # check for pop from spk buf
- la x9, _eos_i2s_spk_wm
- lw x22, 0(x9)
- beqz x22, i2s_sd_xchg
-
# pop from spk buf -> x8
- la x9, _eos_i2s_spk_buf
+ lw x9, I2S_SPK_BUF(x27)
+ beqz x9, i2s_sd_xchg
lhu x18, I2S_ABUF_OFF_IDXR(x9)
lhu x19, I2S_ABUF_OFF_IDXW(x9)
lhu x20, I2S_ABUF_OFF_SIZE(x9)
@@ -160,12 +180,12 @@ i2s_abuf_pop:
and x18, x18, x21
# check for push to event queue
- bgtu x18, x22, i2s_decode
+ lw x9, I2S_SPK_WM(x27)
+ bgtu x18, x9, i2s_decode
- la x9, _eos_i2s_spk_evt_enable
- lw x18, 0(x9)
- beqz x18, i2s_decode
- sw x0, 0(x9)
+ lw x9, I2S_SPK_EVT(x27)
+ beqz x9, i2s_decode
+ sw x0, I2S_SPK_EVT(x27)
# push to event queue
jal x22, evtq_push
@@ -212,8 +232,8 @@ i2s_decode:
beqz x9, 3f
mul x8, x8, x9
3:
- la x9, _eos_i2s_sample
- sw x8, 0(x9)
+ beqz x25, i2s_sd_xchg
+ sw x8, I2S_SAMPLE(x27)
i2s_sd_xchg:
# read/write shift reg: x8 -> sr -> x8
@@ -318,16 +338,12 @@ i2s_encode:
andi x8, x8, 0xff
i2s_abuf_push:
- # check parity
- # bnez x25, i2s_sd_exit
-
- # check for push to mic buf
- la x9, _eos_i2s_mic_wm
- lw x22, 0(x9)
- beqz x22, i2s_sd_exit
+ # check channel
+ # bnez x26, i2s_sd_exit
# push to mic buf
- la x9, _eos_i2s_mic_buf
+ lw x9, I2S_MIC_BUF(x27)
+ beqz x9, i2s_sd_exit
lhu x18, I2S_ABUF_OFF_IDXR(x9)
lhu x19, I2S_ABUF_OFF_IDXW(x9)
lhu x20, I2S_ABUF_OFF_SIZE(x9)
@@ -357,12 +373,12 @@ i2s_abuf_push:
2:
# check for push to event queue
- bltu x18, x22, i2s_sd_exit
+ lw x9, I2S_MIC_WM(x27)
+ bltu x18, x9, i2s_sd_exit
- la x9, _eos_i2s_mic_evt_enable
- lw x18, 0(x9)
- beqz x18, i2s_sd_exit
- sw x0, 0(x9)
+ lw x9, I2S_MIC_EVT(x27)
+ beqz x9, i2s_sd_exit
+ sw x0, I2S_MIC_EVT(x27)
# push to event queue
jal x22, evtq_push
@@ -427,16 +443,6 @@ _eos_i2s_start_pwm:
ret
-.global _eos_flash_set
-_eos_flash_set:
- li a3, SPI0_CTRL_ADDR
- sw x0, SPI_REG_FCTRL(a3)
- sw a0, SPI_REG_SCKDIV(a3)
- sw a1, SPI_REG_FFMT(a3)
- li a0, 1
- sw a0, SPI_REG_FCTRL(a3)
- ret
-
trap_exit_data:
# Remain in M-mode after mret
li x18, MSTATUS_MPP
@@ -452,7 +458,9 @@ trap_exit_data:
LOAD x23, 7*REGBYTES(sp)
LOAD x24, 8*REGBYTES(sp)
LOAD x25, 9*REGBYTES(sp)
- addi sp, sp, 10*REGBYTES
+ LOAD x26, 10*REGBYTES(sp)
+ LOAD x27, 11*REGBYTES(sp)
+ addi sp, sp, 12*REGBYTES
mret
@@ -465,7 +473,7 @@ handle_intr:
.align 4
trap_entry_text:
- addi sp, sp, -22*REGBYTES
+ addi sp, sp, -20*REGBYTES
STORE x1, 0*REGBYTES(sp)
STORE x2, 1*REGBYTES(sp)
@@ -482,12 +490,10 @@ trap_entry_text:
STORE x15, 12*REGBYTES(sp)
STORE x16, 13*REGBYTES(sp)
STORE x17, 14*REGBYTES(sp)
- STORE x26, 15*REGBYTES(sp)
- STORE x27, 16*REGBYTES(sp)
- STORE x28, 17*REGBYTES(sp)
- STORE x29, 18*REGBYTES(sp)
- STORE x30, 19*REGBYTES(sp)
- STORE x31, 20*REGBYTES(sp)
+ STORE x28, 15*REGBYTES(sp)
+ STORE x29, 16*REGBYTES(sp)
+ STORE x30, 17*REGBYTES(sp)
+ STORE x31, 18*REGBYTES(sp)
li x18, MCAUSE_TIMER
beq x8, x18, handle_timer
@@ -526,23 +532,23 @@ trap_exit_text:
LOAD x15, 12*REGBYTES(sp)
LOAD x16, 13*REGBYTES(sp)
LOAD x17, 14*REGBYTES(sp)
- LOAD x26, 15*REGBYTES(sp)
- LOAD x27, 16*REGBYTES(sp)
- LOAD x28, 17*REGBYTES(sp)
- LOAD x29, 18*REGBYTES(sp)
- LOAD x30, 19*REGBYTES(sp)
- LOAD x31, 20*REGBYTES(sp)
-
- LOAD x8, 22*REGBYTES(sp)
- LOAD x9, 23*REGBYTES(sp)
- LOAD x18, 24*REGBYTES(sp)
- LOAD x19, 25*REGBYTES(sp)
- LOAD x20, 26*REGBYTES(sp)
- LOAD x21, 27*REGBYTES(sp)
- LOAD x22, 28*REGBYTES(sp)
- LOAD x23, 29*REGBYTES(sp)
- LOAD x24, 30*REGBYTES(sp)
- LOAD x25, 31*REGBYTES(sp)
+ LOAD x28, 15*REGBYTES(sp)
+ LOAD x29, 16*REGBYTES(sp)
+ LOAD x30, 17*REGBYTES(sp)
+ LOAD x31, 18*REGBYTES(sp)
+
+ LOAD x8, 20*REGBYTES(sp)
+ LOAD x9, 21*REGBYTES(sp)
+ LOAD x18, 22*REGBYTES(sp)
+ LOAD x19, 23*REGBYTES(sp)
+ LOAD x20, 24*REGBYTES(sp)
+ LOAD x21, 25*REGBYTES(sp)
+ LOAD x22, 26*REGBYTES(sp)
+ LOAD x23, 27*REGBYTES(sp)
+ LOAD x24, 28*REGBYTES(sp)
+ LOAD x25, 29*REGBYTES(sp)
+ LOAD x26, 30*REGBYTES(sp)
+ LOAD x27, 31*REGBYTES(sp)
addi sp, sp, 32*REGBYTES
mret
diff --git a/fw/fe310/eos/wifi.c b/fw/fe310/eos/wifi.c
index d7c1824..0663582 100644
--- a/fw/fe310/eos/wifi.c
+++ b/fw/fe310/eos/wifi.c
@@ -43,3 +43,64 @@ eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype) {
if (mtype < EOS_WIFI_MAX_MTYPE) return evt_handler[mtype];
return NULL;
}
+
+int eos_wifi_scan(unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_SCAN;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
+
+int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer) {
+ unsigned char *buf;
+ size_t ssid_len, pass_len;
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ ssid_len = strlen(ssid) + 1;
+ pass_len = strlen(pass) + 1;
+ if ((1 + ssid_len + pass_len) > EOS_NET_MTU) return EOS_ERR_SIZE;
+
+ buf = buffer;
+ buf[0] = EOS_WIFI_MTYPE_AUTH;
+ buf++;
+ strcpy(buf, ssid);
+ buf += ssid_len;
+ strcpy(buf, pass);
+ buf += pass_len;
+
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1 + ssid_len + pass_len, async, 1);
+}
+
+int eos_wifi_connect(unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_CONNECT;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
+
+int eos_wifi_disconnect(unsigned char *buffer) {
+ int async;
+
+ async = 0;
+ if (buffer == NULL) {
+ buffer = eos_net_alloc();
+ async = 1;
+ }
+ buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
+ return _eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, async, 1);
+}
diff --git a/fw/fe310/eos/wifi.h b/fw/fe310/eos/wifi.h
index 87f418f..4a49518 100644
--- a/fw/fe310/eos/wifi.h
+++ b/fw/fe310/eos/wifi.h
@@ -2,7 +2,7 @@
#include "event.h"
#define EOS_WIFI_MTYPE_SCAN 1
-#define EOS_WIFI_MTYPE_CONFIG 2
+#define EOS_WIFI_MTYPE_AUTH 2
#define EOS_WIFI_MTYPE_CONNECT 3
#define EOS_WIFI_MTYPE_DISCONNECT 4
@@ -11,3 +11,8 @@
void eos_wifi_netinit(void);
void eos_wifi_set_handler(unsigned char mtype, eos_evt_handler_t handler);
eos_evt_handler_t eos_wifi_get_handler(unsigned char mtype);
+
+int eos_wifi_scan(unsigned char *buffer);
+int eos_wifi_auth(const char *ssid, const char *pass, unsigned char *buffer);
+int eos_wifi_connect(unsigned char *buffer);
+int eos_wifi_disconnect(unsigned char *buffer);
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
index 3b32c73..5e708ed 100644
--- a/fw/fe310/test/Makefile
+++ b/fw/fe310/test/Makefile
@@ -1,20 +1,24 @@
include ../common.mk
-CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto
-LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -Wl,--end-group -T../bsp/default.lds
+CFLAGS += -I$(bsp_dir)/include -I$(bsp_dir)/drivers -I$(ext_dir)/crypto -I$(ext_dir)/fsfat -I$(ecp_dir)/src -I$(ecp_dir)/src/platform/fe310 -I..
+LDFLAGS = app/*.o $(CFLAGS) -L.. -L$(ecp_dir)/build-fe310 -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -lecp -lecpcr -lecptr -lecptm -lecpdir -lecpvconn -Wl,--end-group -T../bsp/default.lds
-DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o audio.o test.o
-# DEPS = main.o status.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o fs.o test.o
+DEPS = main.o mem.o cell_dev.o cell_pdp.o phone.o modem.o wifi.o cam.o fs.o ecp.o ecp_init.o audio.o test.o
TARGET = phone
+
all: $(TARGET)
+app_:
+ (cd app && $(MAKE)) || exit;
+
%.o: %.c
$(CC) $(CFLAGS) -c $<
-$(TARGET): $(DEPS)
+$(TARGET): app_ $(DEPS)
$(CC) $(DEPS) $(LDFLAGS) -o $@
clean:
+ (cd app && $(MAKE) clean) || exit;
rm -f *.o *.a $(TARGET)
upload: $(TARGET)
diff --git a/fw/fe310/eos/app/Makefile b/fw/fe310/test/app/Makefile
index fe0ba21..fe0ba21 100644
--- a/fw/fe310/eos/app/Makefile
+++ b/fw/fe310/test/app/Makefile
diff --git a/fw/fe310/eos/app/app_root.c b/fw/fe310/test/app/app_root.c
index fac9548..7dda3c7 100644
--- a/fw/fe310/eos/app/app_root.c
+++ b/fw/fe310/test/app/app_root.c
@@ -1,16 +1,16 @@
#include <stdlib.h>
-#include "net.h"
+#include <net.h>
-#include "eve/eve.h"
-#include "eve/eve_kbd.h"
-#include "eve/eve_font.h"
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
-#include "eve/screen/window.h"
-#include "eve/screen/page.h"
-#include "eve/screen/form.h"
+#include <eve/screen/window.h>
+#include <eve/screen/page.h>
+#include <eve/screen/form.h>
-#include "eve/widget/widgets.h"
+#include <eve/widget/widgets.h>
#include "app_status.h"
#include "app_root.h"
diff --git a/fw/fe310/eos/app/app_root.h b/fw/fe310/test/app/app_root.h
index b085344..b085344 100644
--- a/fw/fe310/eos/app/app_root.h
+++ b/fw/fe310/test/app/app_root.h
diff --git a/fw/fe310/test/status.c b/fw/fe310/test/app/app_status.c
index 42d193a..cc25599 100644
--- a/fw/fe310/test/status.c
+++ b/fw/fe310/test/app/app_status.c
@@ -17,17 +17,19 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
+#include "app_root.h"
+#include "app_status.h"
-#include "phone.h"
-#include "status.h"
+#include "../phone.h"
static char status_msg[128];
-static int status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
- unsigned char state = app_phone_state_get();
- int8_t touch_idx = eve_touch_get_idx(touch);
+int app_status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0) {
+ unsigned char state = 0;
+ int8_t touch_idx;
+ // state = app_phone_state_get();
+ touch_idx = eve_touch_get_idx(touch);
if (touch_idx != 0) return 0;
evt = eve_touch_evt(touch, evt, tag0, view->tag, 2);
@@ -36,14 +38,14 @@ static int status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t ta
unsigned char *buf = eos_net_alloc();
buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_ANSWER;
- eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, 1, 0);
status_msg[0] = '\0';
}
if ((state != VOICE_STATE_IDLE) && (touch->eevt & EVE_TOUCH_EETYPE_TRACK_RIGHT)) {
unsigned char *buf = eos_net_alloc();
buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_HANGUP;
- eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, 1, 0);
status_msg[0] = '\0';
}
return 1;
@@ -51,7 +53,7 @@ static int status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t ta
return 0;
}
-static uint8_t status_draw(EVEView *view, uint8_t tag0) {
+uint8_t app_status_draw(EVEView *view, uint8_t tag0) {
uint8_t tag_opt = EVE_TOUCH_OPT_TRACK | EVE_TOUCH_OPT_TRACK_XY;
tag0 = eve_view_clear(view, tag0, tag_opt);
@@ -72,10 +74,3 @@ void app_status_msg_set(char *msg, int refresh) {
if (refresh) app_root_refresh();
}
-
-void app_status_init(void) {
- EVEWindowRoot *root = app_root();
- EVEWindow *status = eve_window_search(&root->w, "status");
- status->view->touch = status_touch;
- status->view->draw = status_draw;
-}
diff --git a/fw/fe310/eos/app/app_status.h b/fw/fe310/test/app/app_status.h
index 9b2ac66..262d29c 100644
--- a/fw/fe310/eos/app/app_status.h
+++ b/fw/fe310/test/app/app_status.h
@@ -2,3 +2,4 @@
int app_status_touch(EVEView *view, EVETouch *touch, uint16_t evt, uint8_t tag0);
uint8_t app_status_draw(EVEView *view, uint8_t tag0);
+void app_status_msg_set(char *msg, int refresh);
diff --git a/fw/fe310/test/cam.c b/fw/fe310/test/cam.c
index 9338ae9..766884b 100644
--- a/fw/fe310/test/cam.c
+++ b/fw/fe310/test/cam.c
@@ -5,6 +5,7 @@
#include <eos.h>
#include <cam.h>
+#include <board.h>
#include <i2c.h>
#include <i2c/ov2640.h>
@@ -19,9 +20,7 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
-
-#include <board.h>
+#include "app/app_root.h"
#include "cam.h"
diff --git a/fw/fe310/test/cell_dev.c b/fw/fe310/test/cell_dev.c
index 40f2736..492ba22 100644
--- a/fw/fe310/test/cell_dev.c
+++ b/fw/fe310/test/cell_dev.c
@@ -7,7 +7,14 @@
#include <net.h>
#include <cell.h>
-#include "status.h"
+#include <eve/eve.h>
+#include <eve/eve_kbd.h>
+#include <eve/eve_font.h>
+#include <eve/screen/window.h>
+
+#include "app/app_root.h"
+#include "app/app_status.h"
+
#include "cell_dev.h"
static void cell_dev_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
diff --git a/fw/fe310/test/cell_pdp.c b/fw/fe310/test/cell_pdp.c
index 9fc4a21..724cca7 100644
--- a/fw/fe310/test/cell_pdp.c
+++ b/fw/fe310/test/cell_pdp.c
@@ -17,9 +17,9 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
+#include "app/app_root.h"
+#include "app/app_status.h"
-#include "status.h"
#include "cell_pdp.h"
static void cell_pdp_connect(char *apn, char *user, char *pass) {
@@ -34,17 +34,16 @@ static void cell_pdp_connect(char *apn, char *user, char *pass) {
p += strlen(user) + 1;
strcpy(p, pass);
p += strlen(pass) + 1;
- eos_net_send(EOS_NET_MTYPE_CELL, buffer, p - buffer, 1);
+ eos_net_send(EOS_NET_MTYPE_CELL, buffer, p - buffer);
- buffer = eos_net_alloc();
buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_CONNECT;
- eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buffer, 1, 0);
}
static void cell_pdp_disconnect(void) {
unsigned char *buffer = eos_net_alloc();
buffer[0] = EOS_CELL_MTYPE_PDP | EOS_CELL_MTYPE_PDP_DISCONNECT;
- eos_net_send(EOS_NET_MTYPE_CELL, buffer, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buffer, 1, 0);
}
static void cell_pdp_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
diff --git a/fw/fe310/test/fs.c b/fw/fe310/test/fs.c
index e8b3587..222833b 100644
--- a/fw/fe310/test/fs.c
+++ b/fw/fe310/test/fs.c
@@ -16,7 +16,7 @@
#include <eve/widget/widgets.h>
#include <aes/aes.h>
-#include <fsfat/ff.h>
+#include <ff.h>
#include "fs.h"
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
index 13c113e..d1409f7 100644
--- a/fw/fe310/test/main.c
+++ b/fw/fe310/test/main.c
@@ -17,23 +17,24 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
-
#include <prci_driver.h>
-#include "status.h"
+#include "app/app_root.h"
+
#include "cell_dev.h"
#include "cell_pdp.h"
#include "phone.h"
#include "modem.h"
#include "wifi.h"
#include "cam.h"
-// #include "fs.h"
+#include "fs.h"
#include "audio.h"
+#include "ecp.h"
#include "test.h"
void app_home_page(EVEWindow *window, EVEViewStack *stack) {
EVEWidgetSpec spec[] = {
+ /*
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
@@ -64,7 +65,6 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) {
.widget.spec.page.title = "Camera",
.widget.spec.page.constructor = app_cam
},
- /*
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
@@ -80,21 +80,24 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) {
},
};
- EVEForm *form = eve_form_create(window, stack, spec, 6, NULL, NULL, NULL);
+ EVEForm *form = eve_form_create(window, stack, spec, 1, NULL, NULL, NULL);
}
+void print_mem(void);
+
int main() {
eos_init();
printf("FREQ:%lu\n", PRCI_get_cpu_freq());
printf("\nREADY.\n");
app_root_init(app_home_page, 0x20);
- app_status_init();
- app_phone_init();
- app_wifi_init();
- app_cell_dev_init();
- app_cell_pdp_init();
+ // app_phone_init();
+ // app_wifi_init();
+ // app_cell_dev_init();
+ // app_cell_pdp_init();
// app_fs_init();
- audio_start();
+ // audio_start();
+ app_ecp_init();
+
eos_evtq_loop();
}
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
index b9fd1b1..89ff32a 100644
--- a/fw/fe310/test/modem.c
+++ b/fw/fe310/test/modem.c
@@ -19,7 +19,7 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
+#include "app/app_root.h"
#include "modem.h"
@@ -50,7 +50,7 @@ static void key_down(void *p, int c) {
buf[1] = c;
}
- eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, i, 0);
eve_text_scroll0(text);
}
@@ -71,7 +71,7 @@ static void handle_uart(unsigned char type) {
i++;
if (i == EOS_NET_MTU) break;
}
- eos_net_send(EOS_NET_MTYPE_CELL, buf, i, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, i, 0);
eos_uart_rxwm_set(0);
}
@@ -139,7 +139,7 @@ void app_modem(EVEWindow *window, EVEViewStack *stack) {
buf = eos_net_alloc();
buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_UART_TAKE;
- eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, 1, 0);
eos_uart_rxwm_set(0);
}
@@ -152,7 +152,7 @@ void app_modem_close(EVEView *view) {
EVEViewStack *stack = param->stack;
buf[0] = EOS_CELL_MTYPE_DEV | EOS_CELL_MTYPE_RESET;
- eos_net_send(EOS_NET_MTYPE_CELL, buf, 1, 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, 1, 0);
eos_uart_rxwm_clear();
eos_uart_set_handler(EOS_UART_ETYPE_RX, NULL);
eos_cell_set_handler(EOS_CELL_MTYPE_DEV, param->cell_dev_handler);
diff --git a/fw/fe310/test/phone.c b/fw/fe310/test/phone.c
index 78531b5..0027d77 100644
--- a/fw/fe310/test/phone.c
+++ b/fw/fe310/test/phone.c
@@ -18,9 +18,9 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
+#include "app/app_root.h"
+#include "app/app_status.h"
-#include "status.h"
#include "phone.h"
#define ABUF_SIZE 128
@@ -41,8 +41,8 @@ static void handle_mic(unsigned char type) {
unsigned char *buf = eos_net_alloc();
buf[0] = EOS_CELL_MTYPE_VOICE_PCM;
- size = eos_i2s_mic_read(buf+1, MIC_WM);
- eos_net_send(EOS_NET_MTYPE_CELL, buf, size+1, 0);
+ size = eos_i2s_mic_read(buf + 1, MIC_WM);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, size + 1, 0);
}
static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16_t len) {
@@ -62,7 +62,11 @@ static void cell_voice_handler(unsigned char type, unsigned char *buffer, uint16
case EOS_CELL_MTYPE_VOICE_BEGIN:
printf("VOICE BEGIN\n");
voice_state = VOICE_STATE_CIP;
- eos_i2s_start(8000, EOS_I2S_FMT_PCM16);
+ eos_i2s_mic_init(mic_arr, ABUF_SIZE);
+ eos_i2s_mic_set_wm(MIC_WM);
+ eos_i2s_mic_set_handler(handle_mic);
+ eos_i2s_spk_init(spk_arr, ABUF_SIZE);
+ eos_i2s_start(8000);
break;
case EOS_CELL_MTYPE_VOICE_END:
@@ -100,7 +104,7 @@ void app_phone_action(EVEForm *form) {
buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_DIAL;
strcpy(buf + 1, w->str);
- eos_net_send(EOS_NET_MTYPE_CELL, buf, 1 + strlen(w->str), 0);
+ eos_net_send_async(EOS_NET_MTYPE_CELL, buf, 1 + strlen(w->str), 0);
voice_state = VOICE_STATE_DIAL;
sprintf(msg, "DIAL:%s", w->str);
@@ -109,11 +113,6 @@ void app_phone_action(EVEForm *form) {
void app_phone_init(void) {
eos_cell_set_handler(EOS_CELL_MTYPE_VOICE, cell_voice_handler);
-
- eos_i2s_mic_init(mic_arr, ABUF_SIZE);
- eos_i2s_mic_set_wm(MIC_WM);
- eos_i2s_mic_set_handler(handle_mic);
- eos_i2s_spk_init(spk_arr, ABUF_SIZE);
eos_net_acquire_for_evt(EOS_EVT_I2S | EOS_I2S_ETYPE_MIC, 1);
}
diff --git a/fw/fe310/test/status.h b/fw/fe310/test/status.h
deleted file mode 100644
index c891b7d..0000000
--- a/fw/fe310/test/status.h
+++ /dev/null
@@ -1,2 +0,0 @@
-void app_status_msg_set(char *msg, int refresh);
-void app_status_init(void);
diff --git a/fw/fe310/test/test.c b/fw/fe310/test/test.c
index 9cf7605..fddbbc1 100644
--- a/fw/fe310/test/test.c
+++ b/fw/fe310/test/test.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <eos.h>
+
#include <i2c.h>
#include <i2c/bq25895.h>
#include <eve/eve.h>
@@ -16,14 +17,10 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
-
-#include <board.h>
+#include "app/app_root.h"
#include "test.h"
-#include <stdio.h>
-
static int reg_read(uint8_t reg, uint8_t *data) {
return eos_i2c_read8(BQ25895_ADDR, reg, data, 1);
}
diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c
index 814d808..e7522e3 100644
--- a/fw/fe310/test/wifi.c
+++ b/fw/fe310/test/wifi.c
@@ -17,41 +17,12 @@
#include <eve/widget/widgets.h>
-#include <app/app_root.h>
+#include "app/app_root.h"
+#include "app/app_status.h"
-#include "status.h"
#include "wifi.h"
-static void wifi_scan(void) {
- unsigned char *buffer = eos_net_alloc();
- buffer[0] = EOS_WIFI_MTYPE_SCAN;
- eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
-}
-
-static void wifi_connect(const char *ssid, const char *pass) {
- unsigned char *buffer, *p;
-
- buffer = eos_net_alloc();
- buffer[0] = EOS_WIFI_MTYPE_CONFIG;
- p = buffer + 1;
- strcpy(p, ssid);
- p += strlen(ssid) + 1;
- strcpy(p, pass);
- p += strlen(pass) + 1;
- eos_net_send(EOS_NET_MTYPE_WIFI, buffer, p - buffer, 1);
-
- buffer = eos_net_alloc();
- buffer[0] = EOS_WIFI_MTYPE_CONNECT;
- eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
-}
-
-static void wifi_disconnect(void) {
- unsigned char *buffer = eos_net_alloc();
- buffer[0] = EOS_WIFI_MTYPE_DISCONNECT;
- eos_net_send(EOS_NET_MTYPE_WIFI, buffer, 1, 0);
-}
-
-void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
+static void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size) {
EVEWindowRoot *root = app_root();
EVEWindow *window = eve_window_search(&root->w, "main");
EVEForm *form = (EVEForm *)window->view;
@@ -97,7 +68,7 @@ void app_wifi(EVEWindow *window, EVEViewStack *stack) {
};
EVEForm *form = eve_form_create(window, stack, spec, 3, NULL, app_wifi_action, app_wifi_close);
- wifi_scan();
+ eos_wifi_scan(NULL);
}
void app_wifi_action(EVEForm *form) {
@@ -105,7 +76,10 @@ void app_wifi_action(EVEForm *form) {
EVEStrWidget *str = (EVEStrWidget *)eve_page_widget(&form->p, 2);
char *ssid = eve_selectw_option_get_select(sel);
- if (ssid) wifi_connect(ssid, str->str);
+ if (ssid) {
+ eos_wifi_auth(ssid, str->str, NULL);
+ eos_wifi_connect(NULL);
+ }
}
void app_wifi_close(EVEForm *form) {