summaryrefslogtreecommitdiff
path: root/fw/fe310
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2021-02-28 18:38:37 +0100
committerUros Majstorovic <majstor@majstor.org>2021-02-28 18:38:37 +0100
commit6a4c8a1f11f6a7bd57b0fd618f455bcdecbfe538 (patch)
tree6d16dbc38b3bac0e91d39f3e86bb6810761ddb84 /fw/fe310
parent468e81e6da66f6dfec3a4857dc6e2f370ab180f1 (diff)
net send will do selected spi dev pause/resume if more is set and netowk is not active
Diffstat (limited to 'fw/fe310')
-rw-r--r--fw/fe310/eos/app/root.c12
-rw-r--r--fw/fe310/eos/app/root.h3
-rw-r--r--fw/fe310/eos/eos.c4
-rw-r--r--fw/fe310/eos/eve/eve.c4
-rw-r--r--fw/fe310/eos/eve/eve_platform.c12
-rw-r--r--fw/fe310/eos/eve/eve_platform.h17
-rw-r--r--fw/fe310/eos/eve/eve_touch.c11
-rw-r--r--fw/fe310/eos/net.c33
-rw-r--r--fw/fe310/eos/power.c4
-rw-r--r--fw/fe310/eos/spi.c22
-rw-r--r--fw/fe310/eos/spi.h7
-rw-r--r--fw/fe310/eos/spi_dev.c32
-rw-r--r--fw/fe310/eos/spi_dev.h4
-rw-r--r--fw/fe310/test/main.c2
-rw-r--r--fw/fe310/test/modem.c4
-rw-r--r--fw/fe310/test/status.c6
-rw-r--r--fw/fe310/test/wifi.c4
17 files changed, 131 insertions, 50 deletions
diff --git a/fw/fe310/eos/app/root.c b/fw/fe310/eos/app/root.c
index a86b291..43bab11 100644
--- a/fw/fe310/eos/app/root.c
+++ b/fw/fe310/eos/app/root.c
@@ -46,11 +46,11 @@ static uint8_t kbd_draw(EVEView *v, uint8_t tag0) {
return tag0;
}
-void app_root_init(eve_view_constructor_t home_page) {
+void app_screen_init(eve_view_constructor_t home_page) {
EVERect g;
_app_font_default = &font;
- eos_spi_dev_start(EOS_DEV_DISP);
+ eve_spi_start();
eve_brightness(0x40);
@@ -86,11 +86,17 @@ void app_root_init(eve_view_constructor_t home_page) {
eve_screen_hide_kbd(&screen);
eve_screen_draw(&screen);
- eos_spi_dev_stop();
+ eve_spi_stop();
eos_net_acquire_for_evt(EOS_EVT_UI | EVE_ETYPE_INTR, 1);
}
+void app_screen_refresh(void) {
+ eve_spi_start();
+ eve_screen_draw(app_screen());
+ eve_spi_stop();
+}
+
static void widgets_destroy(EVEWidget *widget, uint16_t widget_size) {
int i;
diff --git a/fw/fe310/eos/app/root.h b/fw/fe310/eos/app/root.h
index 2b6fc63..69624e7 100644
--- a/fw/fe310/eos/app/root.h
+++ b/fw/fe310/eos/app/root.h
@@ -22,7 +22,8 @@ typedef struct APPWidgetSpec {
} APPWidgetSpec;
EVEScreen *app_screen(void);
-void app_root_init(eve_view_constructor_t home_page);
+void app_screen_init(eve_view_constructor_t home_page);
+void app_screen_refresh(void);
EVEForm *app_form_create(EVEWindow *window, EVEViewStack *stack, APPWidgetSpec spec[], uint16_t spec_size, eve_form_action_t action, eve_form_destructor_t destructor);
void app_form_destroy(EVEForm *form);
diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c
index b02abed..6214203 100644
--- a/fw/fe310/eos/eos.c
+++ b/fw/fe310/eos/eos.c
@@ -37,7 +37,7 @@ void eos_init(void) {
eos_net_wake(wakeup_cause);
eve_set_touch_calibration(eve_touch);
- eos_spi_dev_start(EOS_DEV_DISP);
+ eos_spi_dev_select(EOS_DEV_DISP);
eve_init(wakeup_cause == EOS_PWR_WAKE_RST);
- eos_spi_dev_stop();
+ eos_spi_dev_deselect();
}
diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c
index 6b3943e..f35ccf7 100644
--- a/fw/fe310/eos/eve/eve.c
+++ b/fw/fe310/eos/eve/eve.c
@@ -103,6 +103,7 @@ void eve_dl_start(uint32_t addr, char burst) {
_dl_addr = addr;
_dl_burst = burst;
if (burst) {
+ eve_spi_lock();
eve_spi_cs_set();
eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX);
}
@@ -121,6 +122,7 @@ void eve_dl_end(void) {
if (_dl_burst) {
eve_spi_flush();
eve_spi_cs_clear();
+ eve_spi_unlock();
_dl_burst = 0;
}
}
@@ -266,6 +268,7 @@ int eve_cmd_exec(int w) {
void eve_cmd_burst_start(void) {
uint32_t addr = EVE_RAM_CMD + _cmd_offset;
+ eve_spi_lock();
eve_spi_cs_set();
eve_spi_xchg24(addr | EVE_MEM_WRITE, EVE_SPI_FLAG_TX);
_cmd_burst = 1;
@@ -274,6 +277,7 @@ void eve_cmd_burst_start(void) {
void eve_cmd_burst_end(void) {
eve_spi_flush();
eve_spi_cs_clear();
+ eve_spi_unlock();
_cmd_burst = 0;
}
diff --git a/fw/fe310/eos/eve/eve_platform.c b/fw/fe310/eos/eve/eve_platform.c
index 7f1b775..cfaf6d5 100644
--- a/fw/fe310/eos/eve/eve_platform.c
+++ b/fw/fe310/eos/eve/eve_platform.c
@@ -11,15 +11,11 @@
#include "irq_def.h"
static void handle_time(unsigned char type) {
- eos_spi_dev_start(EOS_DEV_DISP);
eve_handle_time();
- eos_spi_dev_stop();
}
static void handle_evt(unsigned char type, unsigned char *buffer, uint16_t len) {
- eos_spi_dev_start(EOS_DEV_DISP);
eve_handle_touch();
- eos_spi_dev_stop();
GPIO_REG(GPIO_LOW_IP) = (1 << EVE_PIN_INTR);
GPIO_REG(GPIO_LOW_IE) |= (1 << EVE_PIN_INTR);
@@ -62,6 +58,14 @@ void eve_platform_init(void) {
eos_spi_dev_set_div(EOS_DEV_DISP, 4);
}
+void eve_spi_start(void) {
+ eos_spi_dev_select(EOS_DEV_DISP);
+}
+
+void eve_spi_stop(void) {
+ eos_spi_dev_deselect();
+}
+
#include <stdio.h>
void *eve_malloc(size_t size) {
diff --git a/fw/fe310/eos/eve/eve_platform.h b/fw/fe310/eos/eve/eve_platform.h
index 7d085db..48ea00b 100644
--- a/fw/fe310/eos/eve/eve_platform.h
+++ b/fw/fe310/eos/eve/eve_platform.h
@@ -11,6 +11,15 @@
#define EVE_SPI_FLAG_BSWAP EOS_SPI_FLAG_BSWAP
#define EVE_SPI_FLAG_TX EOS_SPI_FLAG_TX
+void *eve_malloc(size_t);
+void eve_free(void *);
+
+//#define eve_malloc malloc
+//#define eve_free free
+
+void eve_spi_start(void);
+void eve_spi_stop(void);
+
#define eve_spi_cs_set eos_spi_cs_set
#define eve_spi_cs_clear eos_spi_cs_clear
#define eve_spi_flush eos_spi_flush
@@ -18,6 +27,8 @@
#define eve_spi_xchg16 eos_spi_xchg16
#define eve_spi_xchg24 eos_spi_xchg24
#define eve_spi_xchg32 eos_spi_xchg32
+#define eve_spi_lock eos_spi_lock
+#define eve_spi_unlock eos_spi_unlock
void eve_time_sleep(uint32_t ms);
void eve_timer_set(uint32_t ms);
@@ -25,9 +36,3 @@ void eve_timer_clear(void);
uint64_t eve_time_get_tick(void);
void eve_platform_init(void);
-
-//#define eve_malloc malloc
-//#define eve_free free
-
-void *eve_malloc(size_t);
-void eve_free(void *); \ 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 e3dae58..fff1eec 100644
--- a/fw/fe310/eos/eve/eve_touch.c
+++ b/fw/fe310/eos/eve/eve_touch.c
@@ -69,8 +69,11 @@ void eve_handle_touch(void) {
char int_ccomplete = 0;
uint8_t tag0 = _tag0;
uint8_t touch_last = 0;
- uint8_t flags = eve_read8(REG_INT_FLAGS) & _intr_mask;
+ uint8_t flags;
+ eve_spi_start();
+
+ flags = eve_read8(REG_INT_FLAGS) & _intr_mask;
if (!_multitouch && (flags & EVE_INT_TOUCH)) _multitouch = 1;
for (i=0; i<EVE_MAX_TOUCH; i++) {
uint8_t touch_tag;
@@ -261,9 +264,13 @@ void eve_handle_touch(void) {
_touch_handler(_touch_handler_param, tag0, i);
}
}
+
+ eve_spi_stop();
}
void eve_handle_time(void) {
+ eve_spi_start();
+
if (_touch_handler && _touch_timer.tag) {
EVETouch *touch = &_touch[_touch_timer.idx];
@@ -296,6 +303,8 @@ void eve_handle_time(void) {
_touch_timer_clear();
}
}
+
+ eve_spi_stop();
}
void eve_touch_init(void) {
diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c
index 46700e8..eb5e6f2 100644
--- a/fw/fe310/eos/net.c
+++ b/fw/fe310/eos/net.c
@@ -486,17 +486,36 @@ 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 rv = EOS_OK;
- if (more) {
- type |= EOS_NET_MTYPE_FLAG_ONEW;
- }
+ if (more) type |= EOS_NET_MTYPE_FLAG_ONEW;
+
clear_csr(mstatus, MSTATUS_MIE);
- if ((net_state_flags & NET_STATE_FLAG_RUN) && (net_state_flags & NET_STATE_FLAG_CTS)) {
+ if ((type & EOS_NET_MTYPE_FLAG_ONEW) && !(net_state_flags & NET_STATE_FLAG_RUN)) {
+ uint8_t spi_dev;
+
+ set_csr(mstatus, MSTATUS_MIE);
+ spi_dev = eos_spi_dev();
+ rv = eos_spi_dev_deselect();
+ if (rv) return rv;
+
+ clear_csr(mstatus, MSTATUS_MIE);
+ while (!(net_state_flags & NET_STATE_FLAG_CTS)) {
+ asm volatile ("wfi");
+ set_csr(mstatus, MSTATUS_MIE);
+ clear_csr(mstatus, MSTATUS_MIE);
+ }
net_xchg_start(type, buffer, len);
+ set_csr(mstatus, MSTATUS_MIE);
+
+ eos_spi_dev_select(spi_dev);
} else {
- rv = eos_msgq_push(&net_send_q, type, buffer, len);
- if (rv) eos_bufq_push(&net_buf_q, buffer);
+ if ((net_state_flags & NET_STATE_FLAG_RUN) && (net_state_flags & NET_STATE_FLAG_CTS)) {
+ net_xchg_start(type, buffer, len);
+ } else {
+ rv = eos_msgq_push(&net_send_q, type, buffer, len);
+ if (rv) eos_bufq_push(&net_buf_q, buffer);
+ }
+ set_csr(mstatus, MSTATUS_MIE);
}
- set_csr(mstatus, MSTATUS_MIE);
return rv;
}
diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c
index 8717553..55960c9 100644
--- a/fw/fe310/eos/power.c
+++ b/fw/fe310/eos/power.c
@@ -74,9 +74,9 @@ uint8_t eos_power_reset_cause(void) {
}
void eos_power_sleep(void) {
- eos_spi_dev_start(EOS_DEV_DISP);
+ eos_spi_dev_select(EOS_DEV_DISP);
eve_sleep();
- eos_spi_dev_stop();
+ eos_spi_dev_deselect();
eos_net_sleep(1000);
AON_REG(AON_PMUKEY) = 0x51F15E;
diff --git a/fw/fe310/eos/spi.c b/fw/fe310/eos/spi.c
index fb47313..29970bd 100644
--- a/fw/fe310/eos/spi.c
+++ b/fw/fe310/eos/spi.c
@@ -20,6 +20,7 @@
static uint8_t spi_dev;
static uint8_t spi_dev_cs_pin;
+static uint8_t spi_lock;
static volatile uint8_t spi_state_flags;
static unsigned char spi_in_xchg;
@@ -61,7 +62,7 @@ void eos_spi_init(void) {
// SPI1_REG(SPI_REG_CSDEF) = 0xFFFF;
}
-void eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin) {
+int eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin) {
spi_dev = dev;
spi_state_flags = 0;
SPI1_REG(SPI_REG_SCKDIV) = div;
@@ -73,11 +74,28 @@ void eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin)
spi_dev_cs_pin = pin;
}
eos_intr_set_handler(INT_SPI1_BASE, eos_spi_handle_xchg);
+
+ return EOS_OK;
}
-void eos_spi_stop(void) {
+int eos_spi_stop(void) {
+ if (spi_lock) return EOS_ERR_BUSY;
eos_spi_flush();
spi_dev = 0;
+
+ return EOS_OK;
+}
+
+uint8_t eos_spi_dev(void) {
+ return spi_dev;
+}
+
+void eos_spi_lock(void) {
+ spi_lock = 1;
+}
+
+void eos_spi_unlock(void) {
+ spi_lock = 0;
}
void eos_spi_set_handler(unsigned char dev, eos_evt_handler_t handler) {
diff --git a/fw/fe310/eos/spi.h b/fw/fe310/eos/spi.h
index b291ad3..7cbff08 100644
--- a/fw/fe310/eos/spi.h
+++ b/fw/fe310/eos/spi.h
@@ -9,8 +9,11 @@
#define EOS_SPI_FLAG_BSWAP 0x04
void eos_spi_init(void);
-void eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin);
-void eos_spi_stop(void);
+int eos_spi_start(unsigned char dev, uint32_t div, uint32_t csid, uint8_t pin);
+int eos_spi_stop(void);
+uint8_t eos_spi_dev(void);
+void eos_spi_lock(void);
+void eos_spi_unlock(void);
void eos_spi_set_handler(unsigned char dev, eos_evt_handler_t handler);
void _eos_spi_xchg_init(unsigned char *buffer, uint16_t len, uint8_t flags);
diff --git a/fw/fe310/eos/spi_dev.c b/fw/fe310/eos/spi_dev.c
index aed26bc..abb616d 100644
--- a/fw/fe310/eos/spi_dev.c
+++ b/fw/fe310/eos/spi_dev.c
@@ -4,6 +4,7 @@
#include "encoding.h"
#include "platform.h"
+#include "eos.h"
#include "spi.h"
#include "net.h"
@@ -22,24 +23,41 @@
static uint16_t spi_dev_div[EOS_DEV_MAX_DEV];
-void eos_spi_dev_start(unsigned char dev) {
- eos_net_stop();
+int eos_spi_dev_select(unsigned char dev) {
+ uint8_t spi_dev = eos_spi_dev();
+ int rv = EOS_ERR;
+
+ if (spi_dev) {
+ int rv;
+
+ rv = eos_spi_stop();
+ if (rv) return rv;
+ } else {
+ eos_net_stop();
+ }
switch (dev) {
case EOS_DEV_DISP:
- eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_DISP, 0);
+ rv = eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_DISP, 0);
break;
case EOS_DEV_CARD:
- eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_CARD, 0);
+ rv = eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_CARD, 0);
break;
case EOS_DEV_CAM:
- eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_NONE, SPI_CSPIN_CAM);
+ rv = eos_spi_start(dev, spi_dev_div[dev-1], SPI_CSID_NONE, SPI_CSPIN_CAM);
break;
}
+
+ return rv;
}
-void eos_spi_dev_stop(void) {
- eos_spi_stop();
+int eos_spi_dev_deselect(void) {
+ int rv;
+
+ rv = eos_spi_stop();
+ if (rv) return rv;
eos_net_start();
+
+ return EOS_OK;
}
void eos_spi_dev_init(void) {
diff --git a/fw/fe310/eos/spi_dev.h b/fw/fe310/eos/spi_dev.h
index 21dcee9..7882e51 100644
--- a/fw/fe310/eos/spi_dev.h
+++ b/fw/fe310/eos/spi_dev.h
@@ -5,7 +5,7 @@
#define EOS_DEV_MAX_DEV 3
void eos_spi_dev_init(void);
-void eos_spi_dev_start(unsigned char dev);
-void eos_spi_dev_stop(void);
+int eos_spi_dev_select(unsigned char dev);
+int eos_spi_dev_deselect(void);
void eos_spi_dev_set_div(unsigned char dev, uint16_t div);
diff --git a/fw/fe310/test/main.c b/fw/fe310/test/main.c
index 6801b97..7516fe8 100644
--- a/fw/fe310/test/main.c
+++ b/fw/fe310/test/main.c
@@ -74,7 +74,7 @@ int main() {
eos_init();
- app_root_init(app_home_page);
+ app_screen_init(app_home_page);
app_status_init();
app_phone_init();
app_wifi_init();
diff --git a/fw/fe310/test/modem.c b/fw/fe310/test/modem.c
index 6453b24..2a2ee7c 100644
--- a/fw/fe310/test/modem.c
+++ b/fw/fe310/test/modem.c
@@ -89,7 +89,7 @@ static void handle_cell_msg(unsigned char type, unsigned char *buffer, uint16_t
EVEText *text = &param->text;
int i;
- eos_spi_dev_start(EOS_DEV_DISP);
+ eve_spi_start();
for (i=1; i<len; i++) {
if (buffer[i] != '\r') eve_text_putc(text, buffer[i]);
}
@@ -97,7 +97,7 @@ static void handle_cell_msg(unsigned char type, unsigned char *buffer, uint16_t
text->dirty = 0;
eve_screen_draw(window->screen);
}
- eos_spi_dev_stop();
+ eve_spi_stop();
eos_net_free(buffer, 0);
} else {
param->cell_dev_handler(type, buffer, len);
diff --git a/fw/fe310/test/status.c b/fw/fe310/test/status.c
index 489bf78..2f44842 100644
--- a/fw/fe310/test/status.c
+++ b/fw/fe310/test/status.c
@@ -78,11 +78,7 @@ static uint8_t status_draw(EVEView *v, uint8_t tag0) {
void app_status_msg_set(char *msg, int refresh) {
strcpy(status_msg, msg);
- if (refresh) {
- eos_spi_dev_start(EOS_DEV_DISP);
- eve_screen_draw(app_screen());
- eos_spi_dev_stop();
- }
+ if (refresh) app_screen_refresh();
}
void app_status_init(void) {
diff --git a/fw/fe310/test/wifi.c b/fw/fe310/test/wifi.c
index 86f6b62..5306d37 100644
--- a/fw/fe310/test/wifi.c
+++ b/fw/fe310/test/wifi.c
@@ -68,9 +68,7 @@ void wifi_scan_handler(unsigned char type, unsigned char *buffer, uint16_t size)
eve_selectw_option_set(select, buffer + 1, size - 1);
eos_net_free(buffer, 0);
- eos_spi_dev_start(EOS_DEV_DISP);
- eve_screen_draw(app_screen());
- eos_spi_dev_stop();
+ app_screen_refresh();
}
static void wifi_connect_handler(unsigned char type, unsigned char *buffer, uint16_t size) {