diff options
author | Uros Majstorovic <majstor@majstor.org> | 2021-11-17 20:42:47 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2021-11-17 20:42:47 +0100 |
commit | b0e84c72d7a533f62ca750a73445da7fcebe8d18 (patch) | |
tree | d091c2307cd667fc9dd1c22e7c80e9ab9ceed445 | |
parent | 9d1721008fe1d35abdedbff063ef29d35996124c (diff) |
wakeup cause added to init functions
-rw-r--r-- | fw/fe310/eos/eos.c | 39 | ||||
-rw-r--r-- | fw/fe310/eos/eos.h | 3 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve.c | 11 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve_touch.c | 6 | ||||
-rw-r--r-- | fw/fe310/eos/eve/eve_touch.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/event.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/event.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/i2c/bq25895.c | 24 | ||||
-rw-r--r-- | fw/fe310/eos/i2c/bq25895.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/i2s.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/i2s.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/interrupt.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/interrupt.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/net.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/net.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/power.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/power.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/sdcard.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/sdcard.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/spi.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/spi.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/spi_dev.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/spi_dev.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/timer.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/timer.h | 2 | ||||
-rw-r--r-- | fw/fe310/eos/uart.c | 2 | ||||
-rw-r--r-- | fw/fe310/eos/uart.h | 2 |
28 files changed, 73 insertions, 56 deletions
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 <stdint.h> + #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 <stdlib.h> #include <stdarg.h> +#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 <string.h> #include <math.h> +#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 <stdio.h> #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<EOS_PWR_MAX_MTYPE; i++) { diff --git a/fw/fe310/eos/power.h b/fw/fe310/eos/power.h index 3eee817..9f6729c 100644 --- a/fw/fe310/eos/power.h +++ b/fw/fe310/eos/power.h @@ -13,7 +13,7 @@ #define EOS_PWR_RST_EXT 1 #define EOS_PWR_RST_WDOG 2 -void eos_power_init(void); +void eos_power_init(uint8_t wakeup_cause); uint8_t eos_power_wakeup_cause(void); uint8_t eos_power_reset_cause(void); void eos_power_sleep(void); diff --git a/fw/fe310/eos/sdcard.c b/fw/fe310/eos/sdcard.c index 970ab17..82b679b 100644 --- a/fw/fe310/eos/sdcard.c +++ b/fw/fe310/eos/sdcard.c @@ -352,7 +352,7 @@ static int sdc_init(uint32_t timeout) { return EOS_OK; } -void eos_sdc_init(void) { +void eos_sdc_init(uint8_t wakeup_cause) { int rv; eos_spi_select(EOS_SPI_DEV_SDC); diff --git a/fw/fe310/eos/sdcard.h b/fw/fe310/eos/sdcard.h index 0234f65..1204508 100644 --- a/fw/fe310/eos/sdcard.h +++ b/fw/fe310/eos/sdcard.h @@ -11,7 +11,7 @@ #define EOS_SDC_CAP_ERASE_EN 0x20 #define EOS_SDC_CAP_MASK 0xf0 -void eos_sdc_init(void); +void eos_sdc_init(uint8_t wakeup_cause); uint8_t eos_sdc_type(void); uint8_t eos_sdc_cap(void); int eos_sdc_get_sect_count(uint32_t timeout, uint32_t *sectors); diff --git a/fw/fe310/eos/spi.c b/fw/fe310/eos/spi.c index c5e953e..085802c 100644 --- a/fw/fe310/eos/spi.c +++ b/fw/fe310/eos/spi.c @@ -47,7 +47,7 @@ static void spi_handle_evt(unsigned char type, unsigned char *buffer, uint16_t l } } -void eos_spi_init(void) { +void eos_spi_init(uint8_t wakeup_cause) { int i; for (i=0; i<EOS_SPI_MAX_EVT; i++) { diff --git a/fw/fe310/eos/spi.h b/fw/fe310/eos/spi.h index 06db0d0..816f6e6 100644 --- a/fw/fe310/eos/spi.h +++ b/fw/fe310/eos/spi.h @@ -10,7 +10,7 @@ #define EOS_SPI_MAX_EVT 2 -void eos_spi_init(void); +void eos_spi_init(uint8_t wakeup_cause); void eos_spi_start(uint16_t div, uint8_t csid, uint8_t cspin, unsigned char evt); void eos_spi_stop(void); void eos_spi_set_handler(unsigned char evt, eos_evt_handler_t handler); diff --git a/fw/fe310/eos/spi_dev.c b/fw/fe310/eos/spi_dev.c index 0448f76..4daa137 100644 --- a/fw/fe310/eos/spi_dev.c +++ b/fw/fe310/eos/spi_dev.c @@ -21,7 +21,7 @@ static uint8_t spi_dev; static uint8_t spi_lock; static uint16_t spi_div[EOS_SPI_MAX_DEV]; -void eos_spi_dev_init(void) { +void eos_spi_dev_init(uint8_t wakeup_cause) { int i; for (i=0; i<EOS_SPI_MAX_DEV; i++) { diff --git a/fw/fe310/eos/spi_dev.h b/fw/fe310/eos/spi_dev.h index ff0e2a6..2f56149 100644 --- a/fw/fe310/eos/spi_dev.h +++ b/fw/fe310/eos/spi_dev.h @@ -7,7 +7,7 @@ #define EOS_SPI_MAX_DEV 4 -void eos_spi_dev_init(void); +void eos_spi_dev_init(uint8_t wakeup_cause); int eos_spi_select(unsigned char dev); int eos_spi_deselect(void); diff --git a/fw/fe310/eos/timer.c b/fw/fe310/eos/timer.c index d8cf107..dbaaf91 100644 --- a/fw/fe310/eos/timer.c +++ b/fw/fe310/eos/timer.c @@ -46,7 +46,7 @@ void _eos_timer_handle(void) { if (*mtimecmp == 0) clear_csr(mie, MIP_MTIP); } -void eos_timer_init(void) { +void eos_timer_init(uint8_t wakeup_cause) { int i; uint64_t *mtimecmp = (uint64_t *) (CLINT_CTRL_ADDR + CLINT_MTIMECMP); diff --git a/fw/fe310/eos/timer.h b/fw/fe310/eos/timer.h index 99ffa7a..8e846e3 100644 --- a/fw/fe310/eos/timer.h +++ b/fw/fe310/eos/timer.h @@ -11,7 +11,7 @@ typedef void (*eos_timer_handler_t) (unsigned char); -void eos_timer_init(void); +void eos_timer_init(uint8_t wakeup_cause); void eos_timer_set_handler(unsigned char evt, eos_timer_handler_t handler); uint32_t eos_timer_get(unsigned char evt); diff --git a/fw/fe310/eos/uart.c b/fw/fe310/eos/uart.c index c10b6d5..4c8adba 100644 --- a/fw/fe310/eos/uart.c +++ b/fw/fe310/eos/uart.c @@ -34,7 +34,7 @@ static void uart_handle_intr(void) { } } -void eos_uart_init(void) { +void eos_uart_init(uint8_t wakeup_cause) { int i; for (i=0; i<EOS_UART_MAX_ETYPE; i++) { diff --git a/fw/fe310/eos/uart.h b/fw/fe310/eos/uart.h index da5faab..d2e795b 100644 --- a/fw/fe310/eos/uart.h +++ b/fw/fe310/eos/uart.h @@ -7,7 +7,7 @@ typedef void (*eos_uart_handler_t) (unsigned char); -void eos_uart_init(void); +void eos_uart_init(uint8_t wakeup_cause); void eos_uart_set_handler(unsigned char type, eos_uart_handler_t handler); void eos_uart_txwm_set(uint8_t wm); |