From b0e84c72d7a533f62ca750a73445da7fcebe8d18 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 17 Nov 2021 20:42:47 +0100 Subject: wakeup cause added to init functions --- fw/fe310/eos/eos.c | 39 +++++++++++++++++++++------------------ fw/fe310/eos/eos.h | 3 +++ fw/fe310/eos/eve/eve.c | 11 ++++++----- fw/fe310/eos/eve/eve.h | 2 +- fw/fe310/eos/eve/eve_touch.c | 6 ++++-- fw/fe310/eos/eve/eve_touch.h | 2 +- fw/fe310/eos/event.c | 2 +- fw/fe310/eos/event.h | 2 +- fw/fe310/eos/i2c/bq25895.c | 24 ++++++++++++++++-------- fw/fe310/eos/i2c/bq25895.h | 2 +- fw/fe310/eos/i2s.c | 2 +- fw/fe310/eos/i2s.h | 2 +- fw/fe310/eos/interrupt.c | 2 +- fw/fe310/eos/interrupt.h | 2 +- fw/fe310/eos/net.c | 2 +- fw/fe310/eos/net.h | 2 +- fw/fe310/eos/power.c | 2 +- fw/fe310/eos/power.h | 2 +- fw/fe310/eos/sdcard.c | 2 +- fw/fe310/eos/sdcard.h | 2 +- fw/fe310/eos/spi.c | 2 +- fw/fe310/eos/spi.h | 2 +- fw/fe310/eos/spi_dev.c | 2 +- fw/fe310/eos/spi_dev.h | 2 +- fw/fe310/eos/timer.c | 2 +- fw/fe310/eos/timer.h | 2 +- fw/fe310/eos/uart.c | 2 +- fw/fe310/eos/uart.h | 2 +- 28 files changed, 73 insertions(+), 56 deletions(-) (limited to 'fw/fe310') diff --git a/fw/fe310/eos/eos.c b/fw/fe310/eos/eos.c index 929a66f..e394862 100644 --- a/fw/fe310/eos/eos.c +++ b/fw/fe310/eos/eos.c @@ -24,31 +24,34 @@ void eos_init(void) { uint8_t wakeup_cause = eos_power_wakeup_cause(); uint32_t touch_matrix[6] = {0xfa46,0xfffffcf6,0x422fe,0xffffff38,0x10002,0xf3cb0}; int touch_calibrate = 0; + int rst = (wakeup_cause == EOS_PWR_WAKE_RST); printf("WAKE:%d\n", wakeup_cause); - eos_evtq_init(); - eos_intr_init(); - eos_timer_init(); - eos_i2s_init(); - eos_uart_init(); - eos_spi_init(); - eos_spi_dev_init(); - eos_sdc_init(); - eos_net_init(); - eos_power_init(); - eos_wifi_init(); - eos_cell_init(); - eos_sock_init(); - eos_bq25895_init(); - - eos_net_start(wakeup_cause); - - int rv = eve_init(wakeup_cause == EOS_PWR_WAKE_RST, touch_calibrate, touch_matrix, EVE_GPIO_DIR); + eos_evtq_init(wakeup_cause); + eos_intr_init(wakeup_cause); + eos_timer_init(wakeup_cause); + eos_i2s_init(wakeup_cause); + eos_uart_init(wakeup_cause); + eos_spi_init(wakeup_cause); + eos_spi_dev_init(wakeup_cause); + eos_sdc_init(wakeup_cause); + eos_net_init(wakeup_cause); + eos_power_init(wakeup_cause); + eos_bq25895_init(wakeup_cause); + int rv = eve_init(wakeup_cause, touch_calibrate, touch_matrix, EVE_GPIO_DIR); printf("EVE INIT: %d\n", rv); if (touch_calibrate) { printf("TOUCH MATRIX:\n"); printf("uint32_t touch_matrix[6] = {0x%x,0x%x,0x%x,0x%x,0x%x,0x%x}\n", touch_matrix[0], touch_matrix[1], touch_matrix[2], touch_matrix[3], touch_matrix[4], touch_matrix[5]); } + eos_start(wakeup_cause); +} + +void eos_start(uint8_t wakeup_cause) { + eos_wifi_init(); + eos_cell_init(); + eos_sock_init(); + eos_net_start(wakeup_cause); } diff --git a/fw/fe310/eos/eos.h b/fw/fe310/eos/eos.h index 2a295f1..44570dc 100644 --- a/fw/fe310/eos/eos.h +++ b/fw/fe310/eos/eos.h @@ -1,3 +1,5 @@ +#include + #define EOS_OK 0 #define EOS_ERR -1 #define EOS_ERR_TIMEOUT -2 @@ -10,3 +12,4 @@ #define EOS_ERR_NET -20 void eos_init(void); +void eos_start(uint8_t wakeup_cause); \ No newline at end of file diff --git a/fw/fe310/eos/eve/eve.c b/fw/fe310/eos/eve/eve.c index f4aae01..0fb55d4 100644 --- a/fw/fe310/eos/eve/eve.c +++ b/fw/fe310/eos/eve/eve.c @@ -1,6 +1,7 @@ #include #include +#include "power.h" #include "eve.h" #define EVE_MEM_WRITE 0x800000 @@ -434,12 +435,12 @@ static int _init(int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) return EVE_OK; } -int eve_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) { - eve_spi_start(); +int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir) { + int rst = (wakeup_cause == EOS_PWR_WAKE_RST); - pwr_on = 1; // override this for now + eve_spi_start(); - if (pwr_on) { + if (rst) { int rv = _init(touch_calibrate, touch_matrix, gpio_dir); if (rv) return rv; } else { @@ -447,7 +448,7 @@ int eve_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix, uint8_t gp eve_active(); } - eve_touch_init(pwr_on, touch_calibrate, touch_matrix); + eve_touch_init(wakeup_cause, touch_calibrate, touch_matrix); eve_platform_init(); eve_spi_stop(); diff --git a/fw/fe310/eos/eve/eve.h b/fw/fe310/eos/eve/eve.h index 2f26edf..11d59cd 100644 --- a/fw/fe310/eos/eve/eve.h +++ b/fw/fe310/eos/eve/eve.h @@ -67,4 +67,4 @@ void eve_sleep(void); void eve_wake(void); void eve_brightness(uint8_t b); -int eve_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir); +int eve_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix, uint8_t gpio_dir); diff --git a/fw/fe310/eos/eve/eve_touch.c b/fw/fe310/eos/eve/eve_touch.c index aaa3788..77a0bf9 100644 --- a/fw/fe310/eos/eve/eve_touch.c +++ b/fw/fe310/eos/eve/eve_touch.c @@ -2,6 +2,7 @@ #include #include +#include "power.h" #include "eve.h" static int touch_intr_mask = EVE_INT_TAG | EVE_INT_TOUCH; @@ -340,7 +341,8 @@ static void _init(int touch_calibrate, uint32_t *touch_matrix) { while(eve_read8(REG_INT_FLAGS)); } -void eve_touch_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix) { +void eve_touch_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix) { + int rst = (wakeup_cause == EOS_PWR_WAKE_RST); int i; eve_vtrack_init(); @@ -350,7 +352,7 @@ void eve_touch_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix) { touch->eevt |= EVE_TOUCH_EETYPE_NOTOUCH; } - if (pwr_on) _init(touch_calibrate, touch_matrix); + if (rst) _init(touch_calibrate, touch_matrix); } void eve_touch_set_handler(eve_touch_handler_t handler, void *param) { diff --git a/fw/fe310/eos/eve/eve_touch.h b/fw/fe310/eos/eve/eve_touch.h index d9e9c9a..148ed48 100644 --- a/fw/fe310/eos/eve/eve_touch.h +++ b/fw/fe310/eos/eve/eve_touch.h @@ -101,7 +101,7 @@ typedef void (*eve_touch_handler_t) (EVETouch *, uint16_t, uint8_t, void *); void eve_handle_touch(void); void eve_handle_time(void); -void eve_touch_init(int pwr_on, int touch_calibrate, uint32_t *touch_matrix); +void eve_touch_init(uint8_t wakeup_cause, int touch_calibrate, uint32_t *touch_matrix); void eve_touch_set_handler(eve_touch_handler_t handler, void *handler_param); EVETouch *eve_touch_get(int i); int8_t eve_touch_get_idx(EVETouch *touch); diff --git a/fw/fe310/eos/event.c b/fw/fe310/eos/event.c index e0a185f..1b08acc 100644 --- a/fw/fe310/eos/event.c +++ b/fw/fe310/eos/event.c @@ -24,7 +24,7 @@ static void evtq_handler(unsigned char type, unsigned char *buffer, uint16_t len } } -void eos_evtq_init(void) { +void eos_evtq_init(uint8_t wakeup_cause) { int i; evt_handler[0] = evtq_handler; diff --git a/fw/fe310/eos/event.h b/fw/fe310/eos/event.h index c9edd03..02250a5 100644 --- a/fw/fe310/eos/event.h +++ b/fw/fe310/eos/event.h @@ -4,7 +4,7 @@ typedef void (*eos_evt_handler_t) (unsigned char, unsigned char *, uint16_t); -void eos_evtq_init(void); +void eos_evtq_init(uint8_t wakeup_cause); int eos_evtq_push(unsigned char type, unsigned char *buffer, uint16_t len); int eos_evtq_push_isr(unsigned char type, unsigned char *buffer, uint16_t len); void eos_evtq_pop(unsigned char *type, unsigned char **buffer, uint16_t *len); diff --git a/fw/fe310/eos/i2c/bq25895.c b/fw/fe310/eos/i2c/bq25895.c index 934b5e7..2b45f88 100644 --- a/fw/fe310/eos/i2c/bq25895.c +++ b/fw/fe310/eos/i2c/bq25895.c @@ -3,20 +3,28 @@ #include #include "eos.h" +#include "power.h" #include "i2c.h" #include "i2c/bq25895.h" -void eos_bq25895_init(void) { - uint8_t data = 0; +void eos_bq25895_init(uint8_t wakeup_cause) { + int rst = (wakeup_cause == EOS_PWR_WAKE_RST); int i, ret = EOS_OK; + uint8_t data = 0; eos_i2c_start(100000); - ret = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog - if (ret) printf("I2C ERROR 0x07\n"); - ret = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current - if (ret) printf("I2C ERROR 0x00\n"); - ret = eos_i2c_write8(BQ25895_ADDR, 0x03, 0x1e); // sysmin 3.7, disable otg - if (ret) printf("I2C ERROR 0x03\n"); + if (rst) { + ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x80); // reset + if (ret) printf("I2C ERROR 0x14\n"); + ret = eos_i2c_write8(BQ25895_ADDR, 0x14, 0x00); // disable watchdog + if (ret) printf("I2C ERROR 0x14\n"); + ret = eos_i2c_write8(BQ25895_ADDR, 0x07, 0x8d); // disable watchdog + if (ret) printf("I2C ERROR 0x07\n"); + ret = eos_i2c_write8(BQ25895_ADDR, 0x00, 0x28); // 2.1A input current + if (ret) printf("I2C ERROR 0x00\n"); + ret = eos_i2c_write8(BQ25895_ADDR, 0x02, 0x20); // disaable MaxCharge, ICO and + if (ret) printf("I2C ERROR 0x02\n"); + } printf("BQ25895:\n"); for (i=0; i<0x15; i++) { diff --git a/fw/fe310/eos/i2c/bq25895.h b/fw/fe310/eos/i2c/bq25895.h index f61a46f..39c6b68 100644 --- a/fw/fe310/eos/i2c/bq25895.h +++ b/fw/fe310/eos/i2c/bq25895.h @@ -2,4 +2,4 @@ #define BQ25895_ADDR 0x6A -void eos_bq25895_init(void); +void eos_bq25895_init(uint8_t wakeup_cause); diff --git a/fw/fe310/eos/i2s.c b/fw/fe310/eos/i2s.c index b4fd277..f4d6b99 100644 --- a/fw/fe310/eos/i2s.c +++ b/fw/fe310/eos/i2s.c @@ -135,7 +135,7 @@ static void _spk_vol_set(uint8_t vol) { extern void _eos_i2s_start_pwm(void); -void eos_i2s_init(void) { +void eos_i2s_init(uint8_t wakeup_cause) { eos_evtq_set_handler(EOS_EVT_I2S, i2s_handle_evt); GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_CK); diff --git a/fw/fe310/eos/i2s.h b/fw/fe310/eos/i2s.h index 47dc3e2..c5a6c1a 100644 --- a/fw/fe310/eos/i2s.h +++ b/fw/fe310/eos/i2s.h @@ -11,7 +11,7 @@ typedef struct EOSABuf { typedef void (*eos_i2s_handler_t) (unsigned char); -void eos_i2s_init(void); +void eos_i2s_init(uint8_t wakeup_cause); void eos_i2s_start(uint32_t sample_rate, unsigned char fmt); void eos_i2s_stop(void); void eos_i2s_mic_init(uint8_t *mic_arr, uint16_t mic_arr_size); diff --git a/fw/fe310/eos/interrupt.c b/fw/fe310/eos/interrupt.c index 820d1fa..5eeace8 100644 --- a/fw/fe310/eos/interrupt.c +++ b/fw/fe310/eos/interrupt.c @@ -25,7 +25,7 @@ uintptr_t eos_intr_handle(uintptr_t int_num) { return int_num; } -void eos_intr_init(void) { +void eos_intr_init(uint8_t wakeup_cause) { for (int i = 0; i < PLIC_NUM_INTERRUPTS; i++){ ext_interrupt_handler[i] = NULL; } diff --git a/fw/fe310/eos/interrupt.h b/fw/fe310/eos/interrupt.h index feaf277..603f0e1 100644 --- a/fw/fe310/eos/interrupt.h +++ b/fw/fe310/eos/interrupt.h @@ -4,7 +4,7 @@ typedef void (*eos_intr_handler_t) (void); -void eos_intr_init(void); +void eos_intr_init(uint8_t wakeup_cause); void eos_intr_set(uint8_t int_num, uint8_t priority, eos_intr_handler_t handler); void eos_intr_set_handler(uint8_t int_num, eos_intr_handler_t handler); void eos_intr_set_priority(uint8_t int_num, uint8_t priority); diff --git a/fw/fe310/eos/net.c b/fw/fe310/eos/net.c index d42686d..5caac38 100644 --- a/fw/fe310/eos/net.c +++ b/fw/fe310/eos/net.c @@ -305,7 +305,7 @@ static void net_resume(void) { } } -void eos_net_init(void) { +void eos_net_init(uint8_t wakeup_cause) { int i; eos_msgq_init(&net_send_q, net_sndq_array, EOS_NET_SIZE_BUFQ); diff --git a/fw/fe310/eos/net.h b/fw/fe310/eos/net.h index 574d179..c26706e 100644 --- a/fw/fe310/eos/net.h +++ b/fw/fe310/eos/net.h @@ -22,7 +22,7 @@ /* fe310 specific */ #define EOS_NET_SIZE_BUFQ 2 -void eos_net_init(void); +void eos_net_init(uint8_t wakeup_cause); void eos_net_start(uint8_t wakeup_cause); void eos_net_stop(void); int eos_net_sleep(uint32_t timeout); diff --git a/fw/fe310/eos/power.c b/fw/fe310/eos/power.c index 5f44a94..539749b 100644 --- a/fw/fe310/eos/power.c +++ b/fw/fe310/eos/power.c @@ -49,7 +49,7 @@ static void power_handle_btn(unsigned char type, unsigned char *buffer, uint16_t eos_power_sleep(); } -void eos_power_init(void) { +void eos_power_init(uint8_t wakeup_cause) { int i; for (i=0; i