summaryrefslogtreecommitdiff
path: root/fw
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-12-09 23:50:58 +0100
committerUros Majstorovic <majstor@majstor.org>2021-12-09 23:50:58 +0100
commit7d03a941be6e9226e71cb5f5b4f7949e06bbfb02 (patch)
treecde9218dbe97837f972c426552c463f5f2a6a256 /fw
parent9c8f5a5e8f11e4a5012d55b96afae290242b8fdd (diff)
improved init process
Diffstat (limited to 'fw')
-rw-r--r--fw/fe310/bsp/metal/metal.c9
-rw-r--r--fw/fe310/eos/Makefile2
-rw-r--r--fw/fe310/eos/cell.c2
-rw-r--r--fw/fe310/eos/cell.h2
-rw-r--r--fw/fe310/eos/eos.c35
-rw-r--r--fw/fe310/eos/eve/eve.c1
-rw-r--r--fw/fe310/eos/eve/eve_eos.c58
-rw-r--r--fw/fe310/eos/eve/eve_touch.c1
-rw-r--r--fw/fe310/eos/i2c.c11
-rw-r--r--fw/fe310/eos/i2c.h3
-rw-r--r--fw/fe310/eos/i2c/bq25895.c5
-rw-r--r--fw/fe310/eos/i2s.c49
-rw-r--r--fw/fe310/eos/i2s.h1
-rw-r--r--fw/fe310/eos/lcd.c10
-rw-r--r--fw/fe310/eos/net.c6
-rw-r--r--fw/fe310/eos/power.h23
-rw-r--r--fw/fe310/eos/pwr.c (renamed from fw/fe310/eos/power.c)94
-rw-r--r--fw/fe310/eos/pwr.h25
-rw-r--r--fw/fe310/eos/sock.c2
-rw-r--r--fw/fe310/eos/sock.h2
-rw-r--r--fw/fe310/eos/spi.c10
-rw-r--r--fw/fe310/eos/spi_dev.c2
-rw-r--r--fw/fe310/eos/trap_entry.S2
-rw-r--r--fw/fe310/eos/uart.c20
-rw-r--r--fw/fe310/eos/uart.h6
-rw-r--r--fw/fe310/eos/wifi.c2
-rw-r--r--fw/fe310/eos/wifi.h2
-rw-r--r--fw/fe310/test/Makefile3
-rw-r--r--fw/fe310/test/cam.c4
-rw-r--r--fw/fe310/test/main.c20
-rw-r--r--fw/fe310/test/test.c6
31 files changed, 217 insertions, 201 deletions
diff --git a/fw/fe310/bsp/metal/metal.c b/fw/fe310/bsp/metal/metal.c
index 00849b9..9e1bb3f 100644
--- a/fw/fe310/bsp/metal/metal.c
+++ b/fw/fe310/bsp/metal/metal.c
@@ -6,21 +6,12 @@
extern void eos_trap_entry();
-static void uart_init(size_t baud_rate) {
- GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK;
- GPIO_REG(GPIO_IOF_EN) |= IOF0_UART0_MASK;
- UART0_REG(UART_REG_DIV) = PRCI_get_cpu_freq() / baud_rate - 1;
- UART0_REG(UART_REG_TXCTRL) |= UART_TXEN;
- UART0_REG(UART_REG_RXCTRL) |= UART_RXEN;
-}
-
__attribute__((constructor))
void metal_init(void) {
SPI0_REG(SPI_REG_SCKDIV) = 8;
PRCI_use_default_clocks();
PRCI_use_pll(PLL_REFSEL_HFXOSC, 0, 1, 31, 1, -1, -1, -1);
- uart_init(115200);
write_csr(mtvec, &eos_trap_entry);
if (read_csr(misa) & (1 << ('F' - 'A'))) { // if F extension is present
diff --git a/fw/fe310/eos/Makefile b/fw/fe310/eos/Makefile
index 899fea3..2bf285f 100644
--- a/fw/fe310/eos/Makefile
+++ b/fw/fe310/eos/Makefile
@@ -4,7 +4,7 @@ CRYPTO_DIR = ../../../crypto
CFLAGS += -I. -I../bsp/include -I../bsp/drivers -I$(CRYPTO_DIR)
-obj = trap_entry.o eos.o msgq.o event.o interrupt.o timer.o power.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 wifi.o cell.o sock.o unicode.o
%.o: %.c %.h
diff --git a/fw/fe310/eos/cell.c b/fw/fe310/eos/cell.c
index 2886041..20a9f42 100644
--- a/fw/fe310/eos/cell.c
+++ b/fw/fe310/eos/cell.c
@@ -28,7 +28,7 @@ static void cell_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_cell_init(void) {
+void eos_cell_netinit(void) {
int i;
for (i=0; i<EOS_CELL_MAX_MTYPE; i++) {
diff --git a/fw/fe310/eos/cell.h b/fw/fe310/eos/cell.h
index 0fc2052..b01d4cf 100644
--- a/fw/fe310/eos/cell.h
+++ b/fw/fe310/eos/cell.h
@@ -46,6 +46,6 @@
#define EOS_CELL_SMS_ADDRTYPE_ALPHA 2
#define EOS_CELL_SMS_ADDRTYPE_OTHER 3
-void eos_cell_init(void);
+void eos_cell_netinit(void);
void eos_cell_set_handler(unsigned char mtype, eos_evt_handler_t handler);
eos_evt_handler_t eos_cell_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c
index 68d299a..bf0f0da 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -3,7 +3,7 @@
#include "event.h"
#include "interrupt.h"
#include "timer.h"
-#include "power.h"
+#include "pwr.h"
#include "i2s.h"
#include "i2c.h"
#include "uart.h"
@@ -23,25 +23,24 @@
#include "eos.h"
void eos_init(void) {
- uint8_t wakeup_cause = eos_power_wakeup_cause();
+ uint8_t wakeup_cause = eos_pwr_wakeup_cause();
uint32_t touch_matrix[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0};
int touch_calibrate = 0;
int rv;
printf("INIT:%d\n", wakeup_cause);
- rv = eos_evtq_init(wakeup_cause);
- if (rv) printf("EVTQ INIT ERR:%d\n", rv);
- rv = eos_intr_init(wakeup_cause);
- if (rv) printf("INTR INIT ERR:%d\n", rv);
- rv = eos_timer_init(wakeup_cause);
- if (rv) printf("TIMER INIT ERR:%d\n", rv);
+ eos_evtq_init(wakeup_cause);
+ eos_intr_init(wakeup_cause);
+ eos_timer_init(wakeup_cause);
+ eos_uart_init(wakeup_cause);
+
+ rv = eos_pwr_init(wakeup_cause);
+ if (rv) printf("PWR INIT ERR:%d\n", rv);
rv = eos_i2s_init(wakeup_cause);
if (rv) printf("I2S INIT ERR:%d\n", rv);
rv = eos_i2c_init(wakeup_cause);
if (rv) printf("I2C INIT ERR:%d\n", rv);
- rv = eos_uart_init(wakeup_cause);
- if (rv) printf("UART INIT ERR:%d\n", rv);
rv = eos_spi_init(wakeup_cause);
if (rv) printf("SPI INIT ERR:%d\n", rv);
rv = eos_spi_dev_init(wakeup_cause);
@@ -50,14 +49,13 @@ void eos_init(void) {
if (rv) printf("SDC INIT ERR:%d\n", rv);
rv = eos_net_init(wakeup_cause);
if (rv) printf("NET INIT ERR:%d\n", rv);
- rv = eos_power_init(wakeup_cause);
- if (rv) printf("POWER INIT ERR:%d\n", rv);
+
+ eos_i2c_start();
rv = eos_bq25895_init(wakeup_cause);
+ eos_i2c_stop();
if (rv) printf("BQ25895 INIT ERR:%d\n", rv);
- eos_spi_select(EOS_SPI_DEV_EVE);
rv = eos_eve_init(wakeup_cause, EVE_GPIO_DIR, touch_calibrate, touch_matrix);
- eos_spi_deselect();
if (rv) printf("EVE INIT ERR:%d\n", rv);
rv = eos_lcd_init(wakeup_cause);
@@ -73,14 +71,13 @@ void eos_init(void) {
void eos_run(uint8_t wakeup_cause) {
int rv;
- eos_spi_select(EOS_SPI_DEV_EVE);
rv = eos_eve_run(wakeup_cause);
- eos_spi_deselect();
if (rv) printf("EVE RUN ERR:%d\n", rv);
- eos_wifi_init();
- eos_cell_init();
- eos_sock_init();
+ eos_pwr_netinit();
+ eos_wifi_netinit();
+ eos_cell_netinit();
+ eos_sock_netinit();
rv = eos_net_run(wakeup_cause);
if (rv) printf("NET RUN ERR:%d\n", rv);
}
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 7bb8ff4..91458d8 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include <stdarg.h>
-#include "power.h"
#include "eve.h"
#define EVE_MEM_WRITE 0x800000
diff --git a/fw/fe310/eos/eve/eve_eos.c b/fw/fe310/eos/eve/eve_eos.c
index 35c237e..283aa6a 100644
--- a/fw/fe310/eos/eve/eve_eos.c
+++ b/fw/fe310/eos/eve/eve_eos.c
@@ -5,7 +5,7 @@
#include "eos.h"
#include "interrupt.h"
#include "event.h"
-#include "power.h"
+#include "pwr.h"
#include "board.h"
@@ -38,16 +38,41 @@ static void handle_intr(void) {
eos_evtq_push_isr(EOS_EVT_UI | EVE_ETYPE_INTR, NULL, 0);
}
+
+static void _start(void) {
+ eve_start();
+
+ GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR);
+ GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR);
+
+ GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
+
+ eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR);
+ _run = 1;
+}
+
+static void _stop(void) {
+ _run = 0;
+ eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR);
+
+ GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
+
+ eve_stop();
+}
+
int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, uint32_t *touch_matrix) {
int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
- int rv;
+ int rv = EVE_OK;
+ eve_spi_start();
if (rst) {
rv = eve_init(gpio_dir, touch_calibrate, touch_matrix);
- if (rv) return EOS_ERR;
} else {
eve_active();
}
+ eve_spi_stop();
+
+ if (rv) return EOS_ERR;
eos_evtq_set_handler(EOS_EVT_UI, handle_evt);
eos_timer_set_handler(EOS_TIMER_ETYPE_UI, handle_time);
@@ -58,31 +83,22 @@ int eos_eve_init(uint8_t wakeup_cause, uint8_t gpio_dir, int touch_calibrate, ui
}
int eos_eve_run(uint8_t wakeup_cause) {
- eos_eve_start();
+ eve_spi_start();
+ _start();
eve_start_clk();
+ eve_spi_stop();
return EOS_OK;
}
void eos_eve_start(void) {
- eve_start();
-
- GPIO_REG(GPIO_INPUT_EN) |= (1 << EVE_PIN_INTR);
- GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << EVE_PIN_INTR);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << EVE_PIN_INTR);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << EVE_PIN_INTR);
-
- GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
-
- eos_intr_enable(INT_GPIO_BASE + EVE_PIN_INTR);
- _run = 1;
+ eve_spi_start();
+ _start();
+ eve_spi_stop();
}
void eos_eve_stop(void) {
- _run = 0;
- eos_intr_disable(INT_GPIO_BASE + EVE_PIN_INTR);
-
- GPIO_REG(GPIO_LOW_IE) &= ~(1 << EVE_PIN_INTR);
-
- eve_stop();
+ eve_spi_start();
+ _stop();
+ eve_spi_stop();
} \ No newline at end of file
diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c
index 4f8a543..7c06f81 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -2,7 +2,6 @@
#include <string.h>
#include <math.h>
-#include "power.h"
#include "eve.h"
static int touch_multi;
diff --git a/fw/fe310/eos/i2c.c b/fw/fe310/eos/i2c.c
index 63dd7e6..a507af1 100644
--- a/fw/fe310/eos/i2c.c
+++ b/fw/fe310/eos/i2c.c
@@ -10,19 +10,16 @@
#include "i2c.h"
int eos_i2c_init(uint8_t wakeup_cause) {
- eos_i2c_stop();
eos_i2c_speed(EOS_I2C_SPEED);
+ // eos_i2c_start();
return EOS_OK;
}
-int eos_i2c_start(void) {
- if (eos_i2s_running()) return EOS_ERR_BUSY;
-
- GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK;
+void eos_i2c_start(void) {
I2C0_REGB(I2C_CONTROL) |= I2C_CONTROL_EN;
-
- return EOS_OK;
+ GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_I2C0_MASK;
+ GPIO_REG(GPIO_IOF_EN) |= IOF0_I2C0_MASK;
}
void eos_i2c_stop(void) {
diff --git a/fw/fe310/eos/i2c.h b/fw/fe310/eos/i2c.h
index b407f8d..20d3dc7 100644
--- a/fw/fe310/eos/i2c.h
+++ b/fw/fe310/eos/i2c.h
@@ -3,7 +3,8 @@
#define EOS_I2C_SPEED 100000
int eos_i2c_init(uint8_t wakeup_cause);
-int eos_i2c_start(void);
+int eos_i2c_run(uint8_t wakeup_cause);
+void eos_i2c_start(void);
void eos_i2c_stop(void);
void eos_i2c_speed(uint32_t baud_rate);
int eos_i2c_read8(uint8_t addr, uint8_t reg, uint8_t *buffer, uint16_t len);
diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c
index f8923c6..570e9a0 100644
--- a/fw/fe310/eos/i2c/bq25895.c
+++ b/fw/fe310/eos/i2c/bq25895.c
@@ -3,7 +3,7 @@
#include <stdio.h>
#include "eos.h"
-#include "power.h"
+#include "pwr.h"
#include "i2c.h"
#include "i2c/bq25895.h"
@@ -20,8 +20,6 @@ int eos_bq25895_init(uint8_t wakeup_cause) {
int i, rv = EOS_OK;
uint8_t data = 0;
- rv = eos_i2c_start();
- if (rv) return rv;
if (rst) {
rv = reg_write(0x14, 0x80); // reset
if (rv) printf("I2C ERROR 0x14\n");
@@ -40,7 +38,6 @@ int eos_bq25895_init(uint8_t wakeup_cause) {
rv = reg_read(i, &data);
if (!rv) printf("REG%02x: %02x\n", i, data);
}
- eos_i2c_stop();
return EOS_OK;
}
diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c
index 5623add..5e5eaa7 100644
--- a/fw/fe310/eos/i2s.c
+++ b/fw/fe310/eos/i2s.c
@@ -140,53 +140,48 @@ extern void _eos_i2s_start_pwm(void);
int eos_i2s_init(uint8_t wakeup_cause) {
eos_evtq_set_handler(EOS_EVT_I2S, i2s_handle_evt);
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_CK_SR) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK));
+ eos_i2s_init_mux();
- GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK);
- GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK);
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
+ GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << I2S_PIN_CK_SR);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SW);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SW);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SW);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK_SR);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_CK_SR);
+
+ return EOS_OK;
+}
+
+void eos_i2s_init_mux(void) {
+ GPIO_REG(GPIO_OUTPUT_VAL) &= ~((1 << I2S_PIN_CK) | (1 << I2S_PIN_WS_MIC) | (1 << I2S_PIN_WS_SPK));
+
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK);
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_CK);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_MIC);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_MIC);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_MIC);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_WS_SPK);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_WS_SPK);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_WS_SPK);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
GPIO_REG(GPIO_INPUT_EN) |= (1 << I2S_PIN_SD_IN);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_IN);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_IN);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_IN);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << I2S_PIN_SD_OUT);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_SD_OUT);
-
- GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM;
- GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM;
-
- return EOS_OK;
}
void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
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);
+ GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_IN);
+
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
+ GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << I2S_PIN_SD_OUT);
+
I2S_REG_CK(PWM_CMP0) = i2s_clk_period >> I2S_PWM_SCALE_CK;
I2S_REG_CK(PWM_CMP1) = I2S_REG_CK(PWM_CMP0) / 2;
I2S_REG_CK(PWM_CMP2) = 0;
@@ -219,8 +214,9 @@ void eos_i2s_start(uint32_t sample_rate, unsigned char fmt) {
I2S_REG_WS_SPK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | PWM_CFG_CMP1GANG;
*/
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR);
- GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM;
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SR);
+ GPIO_REG(GPIO_IOF_SEL) |= I2S_PIN_PWM;
+ GPIO_REG(GPIO_IOF_EN) |= I2S_PIN_PWM;
}
void eos_i2s_stop(void) {
@@ -238,7 +234,10 @@ void eos_i2s_stop(void) {
eos_intr_disable(I2S_IRQ_WS_ID);
eos_intr_disable(I2S_IRQ_SD_ID);
+ GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << I2S_PIN_CK_SW);
GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << I2S_PIN_CK_SR);
+
+ GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_WS_SPK);
GPIO_REG(GPIO_IOF_EN) &= ~I2S_PIN_PWM;
}
diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h
index 1cc10e0..f53e183 100644
--- a/fw/fe310/eos/i2s.h
+++ b/fw/fe310/eos/i2s.h
@@ -12,6 +12,7 @@ typedef struct EOSABuf {
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_stop(void);
int eos_i2s_running(void);
diff --git a/fw/fe310/eos/lcd.c b/fw/fe310/eos/lcd.c
index 86dd1e9..cf09018 100644
--- a/fw/fe310/eos/lcd.c
+++ b/fw/fe310/eos/lcd.c
@@ -5,7 +5,6 @@
#include "platform.h"
#include "eos.h"
-#include "power.h"
#include "timer.h"
#include "i2s.h"
#include "net.h"
@@ -33,13 +32,18 @@ int eos_lcd_select(void) {
if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY;
eos_net_stop();
- GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK;
+
+ GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << LCD_PIN_CS);
+
+ GPIO_REG(GPIO_INPUT_EN) &= ~(1 << LCD_PIN_CS);
+ GPIO_REG(GPIO_OUTPUT_EN) |= (1 << LCD_PIN_CS);
+
+ GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK;
return EOS_OK;
}
void eos_lcd_deselect(void) {
- GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI);
GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
eos_net_start();
}
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c
index 4d9aadf..e65bcd2 100644
--- a/fw/fe310/eos/net.c
+++ b/fw/fe310/eos/net.c
@@ -9,7 +9,7 @@
#include "interrupt.h"
#include "event.h"
#include "timer.h"
-#include "power.h"
+#include "pwr.h"
#include "board.h"
@@ -332,16 +332,12 @@ int eos_net_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_CTS);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_CTS);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << NET_PIN_CTS);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << NET_PIN_CTS);
GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_CTS);
eos_intr_set(INT_GPIO_BASE + NET_PIN_CTS, IRQ_PRIORITY_NET_CTS, net_handle_cts);
GPIO_REG(GPIO_INPUT_EN) |= (1 << NET_PIN_RTS);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << NET_PIN_RTS);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << NET_PIN_RTS);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << NET_PIN_RTS);
GPIO_REG(GPIO_RISE_IE) |= (1 << NET_PIN_RTS);
GPIO_REG(GPIO_FALL_IE) |= (1 << NET_PIN_RTS);
diff --git a/fw/fe310/eos/power.h b/fw/fe310/eos/power.h
deleted file mode 100644
index 76b57a8..0000000
--- a/fw/fe310/eos/power.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <stdint.h>
-#include "event.h"
-
-#define EOS_PWR_MTYPE_BUTTON 1
-
-#define EOS_PWR_MAX_MTYPE 2
-
-#define EOS_PWR_WAKE_RST 0
-#define EOS_PWR_WAKE_RTC 1
-#define EOS_PWR_WAKE_BTN 2
-
-#define EOS_PWR_RST_PWRON 0
-#define EOS_PWR_RST_EXT 1
-#define EOS_PWR_RST_WDOG 2
-
-int eos_power_init(uint8_t wakeup_cause);
-uint8_t eos_power_wakeup_cause(void);
-uint8_t eos_power_reset_cause(void);
-int eos_power_sleep(void);
-void eos_power_wake_at(uint32_t msec);
-void eos_power_wake_disable(void);
-void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler);
-eos_evt_handler_t eos_power_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/pwr.c
index 0d6ab0c..f42249d 100644
--- a/fw/fe310/eos/power.c
+++ b/fw/fe310/eos/pwr.c
@@ -13,7 +13,7 @@
#include "lcd.h"
#include "eve/eve.h"
-#include "power.h"
+#include "pwr.h"
#define PWR_RTC_SCALE 15
#define PWR_RTC_SFREQ (EOS_TIMER_RTC_FREQ >> PWR_RTC_SCALE)
@@ -21,44 +21,7 @@
static eos_evt_handler_t evt_handler[EOS_PWR_MAX_MTYPE];
static unsigned char power_btn_down;
-static void power_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char mtype;
-
- if ((buffer == NULL) || (len < 1)) {
- eos_net_bad_handler(type, buffer, len);
- return;
- }
-
- mtype = buffer[0];
- if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) {
- evt_handler[mtype](mtype, buffer, len);
- } else {
- eos_net_bad_handler(type, buffer, len);
- }
-}
-
-static void power_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) {
- unsigned char level = buffer[1];
-
- eos_net_free(buffer, 0);
- if (!level) {
- power_btn_down = 1;
- return;
- }
- if (!power_btn_down) return;
-
- eos_power_sleep();
-}
-
-int eos_power_init(uint8_t wakeup_cause) {
- int i;
-
- for (i=0; i<EOS_PWR_MAX_MTYPE; i++) {
- evt_handler[i] = NULL;
- }
- eos_net_set_handler(EOS_NET_MTYPE_POWER, power_handle_msg);
- eos_power_set_handler(EOS_PWR_MTYPE_BUTTON, power_handle_btn);
-
+int eos_pwr_init(uint8_t wakeup_cause) {
AON_REG(AON_PMUKEY) = 0x51F15E;
AON_REG(AON_PMUIE) = 0x5;
@@ -70,15 +33,15 @@ int eos_power_init(uint8_t wakeup_cause) {
return EOS_OK;
}
-uint8_t eos_power_wakeup_cause(void) {
+uint8_t eos_pwr_wakeup_cause(void) {
return AON_REG(AON_PMUCAUSE) & 0xff;
}
-uint8_t eos_power_reset_cause(void) {
+uint8_t eos_pwr_reset_cause(void) {
return (AON_REG(AON_PMUCAUSE) >> 8) & 0xff;
}
-int eos_power_sleep(void) {
+int eos_pwr_sleep(void) {
int rv;
rv = eos_lcd_sleep();
@@ -97,7 +60,7 @@ int eos_power_sleep(void) {
return EOS_OK;
}
-void eos_power_wake_at(uint32_t msec) {
+void eos_pwr_wake_at(uint32_t msec) {
uint32_t pmuie;
AON_REG(AON_RTCCFG) |= AON_RTCCFG_ENALWAYS;
@@ -108,7 +71,7 @@ void eos_power_wake_at(uint32_t msec) {
AON_REG(AON_PMUIE) = pmuie;
}
-void eos_power_wake_disable(void) {
+void eos_pwr_wake_disable(void) {
uint32_t pmuie;
AON_REG(AON_RTCCMP) = 0xFFFFFFFF;
@@ -121,11 +84,50 @@ void eos_power_wake_disable(void) {
AON_REG(AON_PMUIE) = pmuie;
}
-void eos_power_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
+static void pwr_handle_msg(unsigned char type, unsigned char *buffer, uint16_t len) {
+ unsigned char mtype;
+
+ if ((buffer == NULL) || (len < 1)) {
+ eos_net_bad_handler(type, buffer, len);
+ return;
+ }
+
+ mtype = buffer[0];
+ if ((mtype < EOS_PWR_MAX_MTYPE) && evt_handler[mtype]) {
+ evt_handler[mtype](mtype, buffer, len);
+ } else {
+ eos_net_bad_handler(type, buffer, len);
+ }
+}
+
+static void pwr_handle_btn(unsigned char type, unsigned char *buffer, uint16_t len) {
+ unsigned char level = buffer[1];
+
+ eos_net_free(buffer, 0);
+ if (!level) {
+ power_btn_down = 1;
+ return;
+ }
+ if (!power_btn_down) return;
+
+ eos_pwr_sleep();
+}
+
+void eos_pwr_netinit(void) {
+ int i;
+
+ for (i=0; i<EOS_PWR_MAX_MTYPE; i++) {
+ evt_handler[i] = NULL;
+ }
+ eos_net_set_handler(EOS_NET_MTYPE_POWER, pwr_handle_msg);
+ eos_pwr_set_handler(EOS_PWR_MTYPE_BUTTON, pwr_handle_btn);
+}
+
+void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler) {
if (mtype < EOS_PWR_MAX_MTYPE) evt_handler[mtype] = handler;
}
-eos_evt_handler_t eos_power_get_handler(unsigned char mtype) {
+eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype) {
if (mtype < EOS_PWR_MAX_MTYPE) return evt_handler[mtype];
return NULL;
}
diff --git a/fw/fe310/eos/pwr.h b/fw/fe310/eos/pwr.h
new file mode 100644
index 0000000..264436b
--- /dev/null
+++ b/fw/fe310/eos/pwr.h
@@ -0,0 +1,25 @@
+#include <stdint.h>
+#include "event.h"
+
+#define EOS_PWR_MTYPE_BUTTON 1
+
+#define EOS_PWR_MAX_MTYPE 2
+
+#define EOS_PWR_WAKE_RST 0
+#define EOS_PWR_WAKE_RTC 1
+#define EOS_PWR_WAKE_BTN 2
+
+#define EOS_PWR_RST_PWRON 0
+#define EOS_PWR_RST_EXT 1
+#define EOS_PWR_RST_WDOG 2
+
+int eos_pwr_init(uint8_t wakeup_cause);
+uint8_t eos_pwr_wakeup_cause(void);
+uint8_t eos_pwr_reset_cause(void);
+int eos_pwr_sleep(void);
+void eos_pwr_wake_at(uint32_t msec);
+void eos_pwr_wake_disable(void);
+
+void eos_pwr_netinit(void);
+void eos_pwr_set_handler(unsigned char mtype, eos_evt_handler_t handler);
+eos_evt_handler_t eos_pwr_get_handler(unsigned char mtype); \ No newline at end of file
diff --git a/fw/fe310/eos/sock.c b/fw/fe310/eos/sock.c
index a2e30e3..ef043d1 100644
--- a/fw/fe310/eos/sock.c
+++ b/fw/fe310/eos/sock.c
@@ -34,7 +34,7 @@ static void sock_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_sock_init(void) {
+void eos_sock_netinit(void) {
int i;
for (i=0; i<EOS_SOCK_MAX_SOCK; i++) {
diff --git a/fw/fe310/eos/sock.h b/fw/fe310/eos/sock.h
index 7461473..66fa2e1 100644
--- a/fw/fe310/eos/sock.h
+++ b/fw/fe310/eos/sock.h
@@ -16,7 +16,7 @@ typedef struct EOSNetAddr {
uint16_t port;
} EOSNetAddr;
-void eos_sock_init(void);
+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);
diff --git a/fw/fe310/eos/spi.c b/fw/fe310/eos/spi.c
index 11a0703..05c9448 100644
--- a/fw/fe310/eos/spi.c
+++ b/fw/fe310/eos/spi.c
@@ -59,18 +59,12 @@ int eos_spi_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << IOF_SPI1_SCK);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_SCK);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << IOF_SPI1_SCK);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << IOF_SPI1_SCK);
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << IOF_SPI1_MOSI);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << IOF_SPI1_MOSI);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << IOF_SPI1_MOSI);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << IOF_SPI1_MOSI);
GPIO_REG(GPIO_INPUT_EN) |= (1 << IOF_SPI1_MISO);
GPIO_REG(GPIO_OUTPUT_EN) &= ~(1 << IOF_SPI1_MISO);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << IOF_SPI1_MISO);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << IOF_SPI1_MISO);
SPI1_REG(SPI_REG_SCKMODE) = SPI_MODE0;
SPI1_REG(SPI_REG_FMT) = SPI_FMT_PROTO(SPI_PROTO_S) |
@@ -78,8 +72,8 @@ int eos_spi_init(uint8_t wakeup_cause) {
SPI_FMT_DIR(SPI_DIR_RX) |
SPI_FMT_LEN(8);
- GPIO_REG(GPIO_IOF_SEL) &= ~SPI_IOF_MASK;
- GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
+ GPIO_REG(GPIO_IOF_SEL) &= ~SPI_IOF_MASK;
+ GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
// There is no way here to change the CS polarity.
// SPI1_REG(SPI_REG_CSDEF) = 0xFFFF;
diff --git a/fw/fe310/eos/spi_dev.c b/fw/fe310/eos/spi_dev.c
index 2d3d8f5..c0c21b0 100644
--- a/fw/fe310/eos/spi_dev.c
+++ b/fw/fe310/eos/spi_dev.c
@@ -31,8 +31,6 @@ int eos_spi_dev_init(uint8_t wakeup_cause) {
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << spi_cfg[i].cspin);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << spi_cfg[i].cspin);
- GPIO_REG(GPIO_PULLUP_EN) &= ~(1 << spi_cfg[i].cspin);
- GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << spi_cfg[i].cspin);
}
}
diff --git a/fw/fe310/eos/trap_entry.S b/fw/fe310/eos/trap_entry.S
index 055ae67..96024cb 100644
--- a/fw/fe310/eos/trap_entry.S
+++ b/fw/fe310/eos/trap_entry.S
@@ -428,7 +428,7 @@ handle_intr:
jalr x0, x18
.section .text.entry
- .align 2
+ .align 4
trap_entry_text:
addi sp, sp, -24*REGBYTES
diff --git a/fw/fe310/eos/uart.c b/fw/fe310/eos/uart.c
index 7c676ba..30f76d9 100644
--- a/fw/fe310/eos/uart.c
+++ b/fw/fe310/eos/uart.c
@@ -4,6 +4,7 @@
#include "encoding.h"
#include "platform.h"
+#include "prci_driver.h"
#include "eos.h"
#include "interrupt.h"
@@ -43,9 +44,28 @@ int eos_uart_init(uint8_t wakeup_cause) {
eos_evtq_set_handler(EOS_EVT_UART, uart_handle_evt);
eos_intr_set(INT_UART0_BASE, IRQ_PRIORITY_UART, uart_handle_intr);
+ UART0_REG(UART_REG_TXCTRL) |= UART_TXEN;
+ UART0_REG(UART_REG_RXCTRL) |= UART_RXEN;
+
+ eos_uart_speed(EOS_UART_SPEED);
+ eos_uart_start();
+
return EOS_OK;
}
+void eos_uart_start(void) {
+ GPIO_REG(GPIO_IOF_SEL) &= ~IOF0_UART0_MASK;
+ GPIO_REG(GPIO_IOF_EN) |= IOF0_UART0_MASK;
+}
+
+void eos_uart_stop(void) {
+ GPIO_REG(GPIO_IOF_EN) &= ~IOF0_UART0_MASK;
+}
+
+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) {
if (type && (type <= EOS_UART_MAX_ETYPE)) uart_handler[type - 1] = handler;
}
diff --git a/fw/fe310/eos/uart.h b/fw/fe310/eos/uart.h
index 3bb7cb5..94999e6 100644
--- a/fw/fe310/eos/uart.h
+++ b/fw/fe310/eos/uart.h
@@ -5,9 +5,15 @@
#define EOS_UART_MAX_ETYPE 2
+#define EOS_UART_SPEED 115200
+
typedef void (*eos_uart_handler_t) (unsigned char);
int eos_uart_init(uint8_t wakeup_cause);
+void eos_uart_start(void);
+void eos_uart_stop(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_txwm_set(uint8_t wm);
diff --git a/fw/fe310/eos/wifi.c b/fw/fe310/eos/wifi.c
index ca29a95..d7c1824 100644
--- a/fw/fe310/eos/wifi.c
+++ b/fw/fe310/eos/wifi.c
@@ -26,7 +26,7 @@ static void wifi_handle_msg(unsigned char type, unsigned char *buffer, uint16_t
}
}
-void eos_wifi_init(void) {
+void eos_wifi_netinit(void) {
int i;
for (i=0; i<EOS_WIFI_MAX_MTYPE; i++) {
diff --git a/fw/fe310/eos/wifi.h b/fw/fe310/eos/wifi.h
index bb629ed..87f418f 100644
--- a/fw/fe310/eos/wifi.h
+++ b/fw/fe310/eos/wifi.h
@@ -8,6 +8,6 @@
#define EOS_WIFI_MAX_MTYPE 5
-void eos_wifi_init(void);
+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);
diff --git a/fw/fe310/test/Makefile b/fw/fe310/test/Makefile
index 8476db8..af18dc5 100644
--- a/fw/fe310/test/Makefile
+++ b/fw/fe310/test/Makefile
@@ -5,7 +5,8 @@ CRYPTO_DIR = ../../../crypto
CFLAGS += -I.. -I../eos -I../bsp/include -I../bsp/drivers -I$(CRYPTO_DIR)
LDFLAGS = $(CFLAGS) -L.. -Wl,--gc-sections -nostartfiles -nostdlib -Wl,--start-group -lc -lm -lgcc -leos -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 fs.o test.o
+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
TARGET = phone
all: $(TARGET)
diff --git a/fw/fe310/test/cam.c b/fw/fe310/test/cam.c
index 2cef686..9338ae9 100644
--- a/fw/fe310/test/cam.c
+++ b/fw/fe310/test/cam.c
@@ -141,8 +141,8 @@ void app_cam(EVEWindow *window, EVEViewStack *stack) {
eos_time_sleep(100);
eos_i2c_speed(100000);
- rv = eos_i2c_start();
- if (!rv) rv = eos_ov2640_init();
+ eos_i2c_start();
+ rv = eos_ov2640_init();
if (!rv) rv = eos_ov2640_set_pixfmt(PIXFORMAT_JPEG);
if (!rv) rv = eos_ov2640_set_framesize(FRAMESIZE_VGA);
eos_i2c_stop();
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
index f7c85e5..13c113e 100644
--- a/fw/fe310/test/main.c
+++ b/fw/fe310/test/main.c
@@ -5,7 +5,7 @@
#include <eos.h>
#include <timer.h>
-#include <power.h>
+#include <pwr.h>
#include <eve/eve.h>
#include <eve/eve_kbd.h>
@@ -28,7 +28,8 @@
#include "modem.h"
#include "wifi.h"
#include "cam.h"
-#include "fs.h"
+// #include "fs.h"
+#include "audio.h"
#include "test.h"
void app_home_page(EVEWindow *window, EVEViewStack *stack) {
@@ -63,12 +64,14 @@ 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,
.widget.spec.page.title = "File system",
.widget.spec.page.constructor = app_fs
},
+ */
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
@@ -77,17 +80,13 @@ void app_home_page(EVEWindow *window, EVEViewStack *stack) {
},
};
- EVEForm *form = eve_form_create(window, stack, spec, 7, NULL, NULL, NULL);
+ EVEForm *form = eve_form_create(window, stack, spec, 6, NULL, NULL, NULL);
}
int main() {
- uint8_t wakeup_cause = eos_power_wakeup_cause();
- int rst = (wakeup_cause == EOS_PWR_WAKE_RST);
-
- printf("\nREADY.\n");
- printf("FREQ:%lu\n", PRCI_get_cpu_freq());
-
eos_init();
+ printf("FREQ:%lu\n", PRCI_get_cpu_freq());
+ printf("\nREADY.\n");
app_root_init(app_home_page, 0x20);
app_status_init();
@@ -95,6 +94,7 @@ int main() {
app_wifi_init();
app_cell_dev_init();
app_cell_pdp_init();
- app_fs_init();
+ // app_fs_init();
+ audio_start();
eos_evtq_loop();
}
diff --git a/fw/fe310/test/test.c b/fw/fe310/test/test.c
index 87c1e2b..9cf7605 100644
--- a/fw/fe310/test/test.c
+++ b/fw/fe310/test/test.c
@@ -40,11 +40,7 @@ int app_test_uievt(EVEForm *form, uint16_t evt, void *param) {
case EVE_UIEVT_PAGE_TOUCH:
printf("PAGE TOUCH\n");
printf("BQ25895:\n");
- rv = eos_i2c_start();
- if (rv) {
- printf("I2C BUSY\n");
- return 0;
- }
+ eos_i2c_start();
for (i=0; i<0x15; i++) {
rv = reg_read(i, &data);
if (!rv) printf("REG%02x: %02x\n", i, data);