summaryrefslogtreecommitdiff
path: root/fw/fe310/phone
diff options
context:
space:
mode:
Diffstat (limited to 'fw/fe310/phone')
-rw-r--r--fw/fe310/phone/Makefile6
-rw-r--r--fw/fe310/phone/flash.c160
-rw-r--r--fw/fe310/phone/flash.h3
-rw-r--r--fw/fe310/phone/main.c18
-rw-r--r--fw/fe310/phone/phone.c2
-rw-r--r--fw/fe310/phone/test.c23
-rw-r--r--fw/fe310/phone/test.h1
7 files changed, 196 insertions, 17 deletions
diff --git a/fw/fe310/phone/Makefile b/fw/fe310/phone/Makefile
index 8624962..65de081 100644
--- a/fw/fe310/phone/Makefile
+++ b/fw/fe310/phone/Makefile
@@ -1,5 +1,5 @@
include ../common.mk
-DEPS = main.o mem.o wifi.o cell.o phone.o modem.o timer.o test.o
+DEPS = main.o mem.o wifi.o cell.o phone.o modem.o timer.o test.o flash.o
lib_eos = eve eos eos-soc eos-dev eos-net eos-ext eos-bsp
lib_ecp =
@@ -30,3 +30,7 @@ upload: $(TARGET)
upload_jlink: $(TARGET)
$(OBJCOPY) $(TARGET) -O binary $(TARGET).bin
../bsp/upload --bin ./$(TARGET).bin --addr 0x20000000 --jlink JLinkExe
+
+upload_my: $(TARGET)
+ $(OBJCOPY) $(TARGET) -O binary $(TARGET).bin
+ ../../../util/upload /dev/cu.usbserial-14140 $(TARGET).bin
diff --git a/fw/fe310/phone/flash.c b/fw/fe310/phone/flash.c
new file mode 100644
index 0000000..e78576a
--- /dev/null
+++ b/fw/fe310/phone/flash.c
@@ -0,0 +1,160 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <encoding.h>
+#include <platform.h>
+
+#include <eos.h>
+
+#include <soc/timer.h>
+#include <dev/flash.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 "app/app.h"
+#include "app/status.h"
+
+#include "flash.h"
+
+static const uint8_t magic[] =
+ {0x2D, 0xC0, 0x3B, 0x5F, 0xEA, 0xE3, 0x1A, 0x3A, 0x83, 0x11, 0x6A, 0x33, 0x98, 0x46, 0x1C, 0x47};
+
+#define ACK 0x05
+#define NACK 0x0A
+#define BLK_SIZE 256
+
+__attribute__ ((section (".itim")))
+static uint32_t crc32x(unsigned char *buf, size_t len, uint32_t crc) {
+ int i;
+
+ crc = ~crc;
+ while (len--) {
+ crc ^= *buf++;
+ for (i=0; i<8; i++) {
+ uint32_t t = ~((crc & 1) - 1);
+ crc = (crc >> 1) ^ (0xEDB88320 & t);
+ }
+ }
+
+ return ~crc;
+}
+
+__attribute__ ((section (".itim")))
+void flash_write(void) {
+ volatile uint32_t r;
+ uint32_t crc32, crc32_b;
+ uint32_t addr;
+ uint8_t buf[BLK_SIZE + 2 * sizeof(uint32_t)];
+ int i;
+
+ clear_csr(mstatus, MSTATUS_MIE);
+ SPI0_REG(SPI_REG_FCTRL) = 0;
+ SPI0_REG(SPI_REG_FMT) &= ~SPI_FMT_DIR(SPI_DIR_TX);
+
+ do {
+ for (i=0; i<sizeof(buf); i++) {
+ while ((r = UART0_REG(UART_REG_RXFIFO)) & 0x80000000);
+ buf[i] = r;
+ }
+
+ addr = 0;
+ addr |= (uint32_t)buf[0] << 24;
+ addr |= (uint32_t)buf[1] << 16;
+ addr |= (uint32_t)buf[2] << 8;
+ addr |= (uint32_t)buf[3];
+
+ crc32_b = 0;
+ crc32_b |= (uint32_t)buf[BLK_SIZE + 4] << 24;
+ crc32_b |= (uint32_t)buf[BLK_SIZE + 5] << 16;
+ crc32_b |= (uint32_t)buf[BLK_SIZE + 6] << 8;
+ crc32_b |= (uint32_t)buf[BLK_SIZE + 7];
+ crc32 = crc32x(buf, BLK_SIZE + sizeof(uint32_t), 0xffffffff);
+ if (crc32 != crc32_b) {
+ *buf = NACK;
+ goto write_rep;
+ }
+
+ if (addr != -1) {
+ if (addr % 4096 == 0) {
+ eos_flash_wren();
+ eos_flash_ser(addr);
+ eos_flash_wip();
+ }
+ eos_flash_wren();
+ eos_flash_pp(addr, buf + sizeof(uint32_t));
+ eos_flash_wip();
+ }
+ *buf = ACK;
+write_rep:
+ while (UART0_REG(UART_REG_TXFIFO) & 0x80000000);
+ UART0_REG(UART_REG_TXFIFO) = *buf;
+ } while (addr != -1);
+
+ while(1);
+}
+
+void flash_write_init(void) {
+ volatile uint32_t r;
+ uint8_t buf[sizeof(magic)];
+ int i;
+
+ while (!(UART0_REG(UART_REG_RXFIFO) & 0x80000000));
+ app_status_set_msg("READY!");
+ eve_window_root_draw(app_root());
+
+ for (i=0; i<sizeof(magic); i++) {
+ while ((r = UART0_REG(UART_REG_RXFIFO)) & 0x80000000);
+ buf[i] = r;
+ }
+ if (memcmp(buf, magic, sizeof(magic)) == 0) {
+ *buf = ACK;
+ app_status_set_msg("FLASH START");
+ } else {
+ *buf = NACK;
+ app_status_set_msg("FLASH FAIL");
+ }
+ eve_window_root_draw(app_root());
+
+ while (UART0_REG(UART_REG_TXFIFO) & 0x80000000);
+ UART0_REG(UART_REG_TXFIFO) = *buf;
+}
+
+int flash_app(EVEWindow *window, EVEViewStack *stack) {
+ EVEFormSpec spec[] = {
+ APP_SPACERW(1,1),
+ };
+ EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), flash_uievt, flash_close);
+ if (page == NULL) return EVE_ERR_NOMEM;
+
+ return EVE_OK;
+}
+
+int flash_uievt(EVEPage *page, uint16_t evt, void *param) {
+ int ret = 0;
+
+ switch (evt) {
+ case EVE_UIEVT_GEST_TOUCH: {
+ flash_write_init();
+ flash_write();
+ break;
+ }
+
+ default: {
+ ret = eve_form_uievt(page, evt, param);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+void flash_close(EVEPage *page) {
+ eve_form_destroy(page);
+}
diff --git a/fw/fe310/phone/flash.h b/fw/fe310/phone/flash.h
new file mode 100644
index 0000000..7c6946b
--- /dev/null
+++ b/fw/fe310/phone/flash.h
@@ -0,0 +1,3 @@
+int flash_app(EVEWindow *window, EVEViewStack *stack);
+int flash_uievt(EVEPage *page, uint16_t evt, void *param);
+void flash_close(EVEPage *page);
diff --git a/fw/fe310/phone/main.c b/fw/fe310/phone/main.c
index 125a9d2..8696ebe 100644
--- a/fw/fe310/phone/main.c
+++ b/fw/fe310/phone/main.c
@@ -3,9 +3,14 @@
#include <unistd.h>
#include <string.h>
+#include <encoding.h>
+#include <platform.h>
#include <prci_driver.h>
#include <eos.h>
+#include <soc/pwr.h>
+#include <dev/flash.h>
+#include <dev/gt911.h>
#include <dev/eve.h>
#include <eve/eve.h>
@@ -23,6 +28,7 @@
#include "phone.h"
#include "modem.h"
#include "timer.h"
+#include "flash.h"
#include "test.h"
static const uint32_t touch_matrix[6] = {0xf7ac,0x440,0x3e704,0xfffff718,0x108a3,0xfff76d42};
@@ -56,6 +62,12 @@ static int home_page(EVEWindow *window, EVEViewStack *stack) {
{
.widget.type = EVE_WIDGET_TYPE_PAGE,
.widget.g.w = APP_SCREEN_W,
+ .widget.tspec.page.title = "Flash",
+ .widget.tspec.page.constructor = flash_app,
+ },
+ {
+ .widget.type = EVE_WIDGET_TYPE_PAGE,
+ .widget.g.w = APP_SCREEN_W,
.widget.tspec.page.title = "Test",
.widget.tspec.page.constructor = test_app,
},
@@ -69,9 +81,8 @@ static int home_page(EVEWindow *window, EVEViewStack *stack) {
void mem_print(void);
-#include <dev/gt911.h>
-
int main() {
+ int i;
uint8_t wakeup_cause;
wakeup_cause = eos_init();
@@ -80,9 +91,12 @@ int main() {
printf("FREQ:%lu\n", PRCI_get_cpu_freq());
printf("\nREADY.\n");
+
mem_print();
eos_gt911_cfg_print();
+ // eos_flash_fast();
+
wifi_init();
cell_init();
phone_init();
diff --git a/fw/fe310/phone/phone.c b/fw/fe310/phone/phone.c
index 53d36ae..a8d5a86 100644
--- a/fw/fe310/phone/phone.c
+++ b/fw/fe310/phone/phone.c
@@ -29,7 +29,6 @@ static uint8_t spk_arr[ABUF_SIZE];
static unsigned char phone_state = 0;
-__attribute__ ((section (".itim")))
static void handle_mic(unsigned char type) {
uint16_t offset, size;
unsigned char *buf;
@@ -39,7 +38,6 @@ static void handle_mic(unsigned char type) {
eos_cell_send_buffer(buf, size, offset, 0);
}
-__attribute__ ((section (".itim")))
static void handle_cell_voice(unsigned char type, unsigned char *buffer, uint16_t len) {
switch (type) {
case EOS_CELL_MTYPE_VOICE_RING: {
diff --git a/fw/fe310/phone/test.c b/fw/fe310/phone/test.c
index df3871e..72f575f 100644
--- a/fw/fe310/phone/test.c
+++ b/fw/fe310/phone/test.c
@@ -28,6 +28,17 @@ static int reg_write(uint8_t reg, uint8_t data) {
return eos_i2c_write8(BQ25895_ADDR, reg, &data, 1);
}
+int test_app(EVEWindow *window, EVEViewStack *stack) {
+ EVEFormSpec spec[] = {
+ APP_SPACERW(1,1),
+ };
+ EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), test_uievt, test_close);
+ if (page == NULL) return EVE_ERR_NOMEM;
+ app_status_set_msg("TEST!");
+
+ return EVE_OK;
+}
+
int test_uievt(EVEPage *page, uint16_t evt, void *param) {
int ret = 0;
@@ -36,7 +47,6 @@ int test_uievt(EVEPage *page, uint16_t evt, void *param) {
uint8_t data = 0;
int rv, i;
- printf("PAGE TOUCH\n");
printf("BQ25895:\n");
for (i=0; i<0x15; i++) {
rv = reg_read(i, &data);
@@ -54,17 +64,6 @@ int test_uievt(EVEPage *page, uint16_t evt, void *param) {
return ret;
}
-int test_app(EVEWindow *window, EVEViewStack *stack) {
- EVEFormSpec spec[] = {
- APP_SPACERW(1,1),
- };
- EVEPage *page = eve_form_create(window, stack, spec, APP_SPEC_SIZE(spec), test_uievt, test_close);
- if (page == NULL) return EVE_ERR_NOMEM;
- app_status_set_msg("TEST!");
-
- return EVE_OK;
-}
-
void test_close(EVEPage *page) {
eve_form_destroy(page);
}
diff --git a/fw/fe310/phone/test.h b/fw/fe310/phone/test.h
index 66b380d..61bc5e2 100644
--- a/fw/fe310/phone/test.h
+++ b/fw/fe310/phone/test.h
@@ -1,2 +1,3 @@
int test_app(EVEWindow *window, EVEViewStack *stack);
+int test_uievt(EVEPage *page, uint16_t evt, void *param);
void test_close(EVEPage *page); \ No newline at end of file