From 6a4b3ef0e72ee134b81a523ce41fd4c45f3b4429 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 4 Sep 2022 18:43:50 +0200 Subject: fixed wifi and cell --- fw/esp32/components/eos/net.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'fw/esp32/components/eos/net.c') diff --git a/fw/esp32/components/eos/net.c b/fw/esp32/components/eos/net.c index 73d1c43..56ec940 100644 --- a/fw/esp32/components/eos/net.c +++ b/fw/esp32/components/eos/net.c @@ -28,7 +28,8 @@ #define SPI_SIZE_BUF (EOS_NET_SIZE_BUF + 4) #define SPI_SIZE_HDR 3 -static volatile char net_sleep = 0; +static volatile int net_sleep = 0; +static volatile int net_wake = 0; static EOSBufQ net_buf_q; static unsigned char *net_bufq_array[EOS_NET_SIZE_BUFQ]; @@ -96,7 +97,7 @@ static void net_xchg_task(void *pvParameters) { spi_tr.rx_buffer = buf_recv; spi_tr.length = SPI_SIZE_BUF * 8; - if (eos_power_wakeup_cause()) { + if (eos_power_wakeup_cause() != EOS_PWR_WAKE_RST) { wake = 1; skip_msg = 1; } @@ -143,22 +144,20 @@ static void net_xchg_task(void *pvParameters) { if (buf_recv[0] == 0xFF) { // Sleep req if (buf_send[0] == 0) { - int abort = 0; + spi_slave_free(VSPI_HOST); + eos_power_sleep(); xSemaphoreTake(mutex, portMAX_DELAY); net_sleep = 1; - if (eos_msgq_len(&net_send_q)) abort = 1; + if (eos_msgq_len(&net_send_q)) net_wake = 1; xSemaphoreGive(mutex); - spi_slave_free(VSPI_HOST); - - eos_power_sleep(); - if (abort) eos_power_wake(EOS_PWR_WAKE_MSG); - + if (net_wake) eos_power_wake(EOS_PWR_WAKE_NETQ); vTaskSuspend(NULL); xSemaphoreTake(mutex, portMAX_DELAY); net_sleep = 0; + net_wake = 0; xSemaphoreGive(mutex); spi_slave_initialize(VSPI_HOST, &spi_bus_cfg, &spi_slave_cfg, 1); @@ -174,9 +173,9 @@ static void net_xchg_task(void *pvParameters) { len |= (uint16_t)buf_recv[2] & 0xFF; buffer = buf_recv + SPI_SIZE_HDR; if ((mtype <= EOS_NET_MAX_MTYPE) && (len <= EOS_NET_MTU)) { - net_handler[mtype - 1](mtype, buffer, len); + net_handler[mtype - 1](buf_recv[0], buffer, len); } else { - bad_handler(mtype, buffer, len); + bad_handler(buf_recv[0], buffer, len); } if ((mtype_flags & EOS_NET_MTYPE_FLAG_ONEW) && buf_send[0]) { skip_msg = 1; @@ -196,7 +195,7 @@ void eos_net_init(void) { int i; // Configuration for the handshake lines - gpio_config_t io_conf; + gpio_config_t io_conf = {}; io_conf.intr_type = GPIO_INTR_DISABLE; io_conf.mode = GPIO_MODE_OUTPUT; @@ -254,14 +253,14 @@ int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len) { int sleep; xSemaphoreTake(mutex, portMAX_DELAY); - sleep = net_sleep; + sleep = net_sleep && !net_wake; gpio_set_level(SPI_GPIO_RTS, 1); rv = eos_msgq_push(&net_send_q, mtype, buffer, len); xSemaphoreGive(mutex); if (rv) eos_net_free(buffer); - if (sleep) eos_power_wake(EOS_PWR_WAKE_MSG); + if (sleep) eos_power_wake(EOS_PWR_WAKE_NETQ); return rv; } @@ -278,7 +277,7 @@ void eos_net_set_handler(unsigned char mtype, eos_net_fptr_t handler) { if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) net_handler[mtype - 1] = handler; } -void eos_net_sleep_done(uint8_t mode) { +void eos_net_sleep(void) { gpio_set_level(SPI_GPIO_CTS, 1); vTaskDelay(200 / portTICK_PERIOD_MS); gpio_set_level(SPI_GPIO_CTS, 0); -- cgit v1.2.3