From 602d0d803eb9607dcd949f3ea5ff27c14db4085b Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 8 Dec 2019 17:47:58 +0100 Subject: fixed uart data relay bug; fixed all xCreateTask to use new macros for stack size; fixed err type for msgq; --- code/esp32/components/eos/cell_modem.c | 8 ++++++-- code/esp32/components/eos/cell_pcm.c | 16 +++++++++++----- code/esp32/components/eos/i2c.c | 1 + code/esp32/components/eos/include/eos.h | 17 ++++++++++++----- code/esp32/components/eos/include/net.h | 4 ++-- code/esp32/components/eos/msgq.c | 2 +- code/esp32/components/eos/net.c | 8 ++++---- code/esp32/components/eos/sock.c | 7 ++++--- code/esp32/components/eos/wifi.c | 1 + code/esp32/main/app_main.c | 4 ++-- 10 files changed, 44 insertions(+), 24 deletions(-) diff --git a/code/esp32/components/eos/cell_modem.c b/code/esp32/components/eos/cell_modem.c index 26748a1..2534eb1 100644 --- a/code/esp32/components/eos/cell_modem.c +++ b/code/esp32/components/eos/cell_modem.c @@ -30,6 +30,8 @@ static QueueHandle_t uart_queue; // static uint8_t *uart_data[UART_BUF_SIZE]; +static const char *TAG = "EOS MODEM"; + static void uart_event_task(void *pvParameters) { char mode = 0; uart_event_t event; @@ -58,6 +60,7 @@ static void uart_event_task(void *pvParameters) { default: break; } + break; case UART_EVENT_MAX: /* Mode change @@ -113,9 +116,10 @@ void eos_modem_init(void) { gpio_set_level(UART_GPIO_DTR, 1); // Create a task to handle uart event from ISR - xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, EOS_IRQ_PRIORITY_UART, NULL); + xTaskCreate(uart_event_task, "uart_event", EOS_TASK_SSIZE_UART, NULL, EOS_TASK_PRIORITY_UART, NULL); eos_net_set_handler(EOS_NET_MTYPE_CELL, modem_handler); + ESP_LOGI(TAG, "INIT"); } ssize_t eos_modem_write(void *data, size_t size) { @@ -126,5 +130,5 @@ void eos_modem_set_mode(char mode) { uart_event_t evt; evt.type = UART_EVENT_MAX; /* my type */ evt.size = mode; - xQueueSend(&uart_queue, (void *)&evt, portMAX_DELAY); + xQueueSend(uart_queue, (void *)&evt, portMAX_DELAY); } diff --git a/code/esp32/components/eos/cell_pcm.c b/code/esp32/components/eos/cell_pcm.c index 0c9dfc9..961a322 100644 --- a/code/esp32/components/eos/cell_pcm.c +++ b/code/esp32/components/eos/cell_pcm.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "eos.h" @@ -22,6 +23,8 @@ static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1}; static QueueHandle_t i2s_queue; +static const char *TAG = "EOS PCM"; + static void i2s_event_task(void *pvParameters) { size_t size_out; i2s_event_t event; @@ -54,7 +57,7 @@ static void i2s_event_task(void *pvParameters) { i2s_write(I2S_NUM_0, (const void *)data, BUF_SIZE, &size_out, 1000 / portTICK_RATE_MS); break; case I2S_EVENT_DMA_ERROR: - printf("*** I2S DMA ERROR ***"); + ESP_LOGE(TAG, "*** I2S DMA ERROR ***"); break; default: break; @@ -108,15 +111,18 @@ void eos_pcm_init(void) { .data_out_num = PCM_GPIO_DOUT }; i2s_driver_install(I2S_NUM_0, &i2s_config, 10, &i2s_queue); //install and start i2s driver - i2s_set_pin(I2S_NUM_0, &pin_config); i2s_stop(I2S_NUM_0); + i2s_set_pin(I2S_NUM_0, &pin_config); + gpio_matrix_in(pin_config.ws_io_num, I2S0I_WS_IN_IDX, 1); + gpio_matrix_in(pin_config.bck_io_num, I2S0I_BCK_IN_IDX, 1); I2S[I2S_NUM_0]->conf.tx_mono = 1; I2S[I2S_NUM_0]->conf.rx_mono = 1; - i2s_start(I2S_NUM_0); // Create a task to handle i2s event from ISR - xTaskCreate(i2s_event_task, "i2s_event_task", 2048, NULL, EOS_IRQ_PRIORITY_I2S, NULL); - // xTaskCreate(i2s_write_task, "i2s_write_task", 2048, NULL, EOS_IRQ_PRIORITY_I2S, NULL); + xTaskCreate(i2s_event_task, "i2s_event", EOS_TASK_SSIZE_I2S, NULL, EOS_TASK_PRIORITY_I2S, NULL); + // xTaskCreate(i2s_write_task, "i2s_write_task", EOS_TASK_SSIZE_I2S, NULL, EOS_TASK_PRIORITY_I2S, NULL); + ESP_LOGI(TAG, "INIT"); + i2s_start(I2S_NUM_0); } ssize_t eos_pcm_write(void *data, size_t size) { diff --git a/code/esp32/components/eos/i2c.c b/code/esp32/components/eos/i2c.c index 1182431..38ad6ba 100644 --- a/code/esp32/components/eos/i2c.c +++ b/code/esp32/components/eos/i2c.c @@ -32,6 +32,7 @@ void eos_i2c_init(void) { conf.master.clk_speed = I2C_MASTER_FREQ_HZ; i2c_param_config(I2C_MASTER_NUM, &conf); i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0); + ESP_LOGI(TAG, "INIT"); } /** diff --git a/code/esp32/components/eos/include/eos.h b/code/esp32/components/eos/include/eos.h index a21985a..e9a67d4 100644 --- a/code/esp32/components/eos/include/eos.h +++ b/code/esp32/components/eos/include/eos.h @@ -1,9 +1,16 @@ #define EOS_OK 0 #define EOS_ERR -1 -#define EOS_ERR_Q_FULL -10 +#define EOS_ERR_FULL -10 +#define EOS_ERR_EMPTY -11 + +#define EOS_TASK_PRIORITY_UART 1 +#define EOS_TASK_PRIORITY_I2S 1 +#define EOS_TASK_PRIORITY_NET_XCHG 1 +#define EOS_TASK_PRIORITY_UDP_RCVR 1 + +#define EOS_TASK_SSIZE_UART 4096 +#define EOS_TASK_SSIZE_I2S 4096 +#define EOS_TASK_SSIZE_NET_XCHG 4096 +#define EOS_TASK_SSIZE_UDP_RCVR 4096 -#define EOS_IRQ_PRIORITY_UART 1 -#define EOS_IRQ_PRIORITY_I2S 1 -#define EOS_IRQ_PRIORITY_NET_XCHG 1 -#define EOS_IRQ_PRIORITY_UDP_RCVR 1 diff --git a/code/esp32/components/eos/include/net.h b/code/esp32/components/eos/include/net.h index d6f3f34..abf2893 100644 --- a/code/esp32/components/eos/include/net.h +++ b/code/esp32/components/eos/include/net.h @@ -13,8 +13,8 @@ #define EOS_NET_MTYPE_FLAG_ONEW 0x10 #define EOS_NET_SIZE_BUF 1500 -#define EOS_NET_SIZE_BUFQ 8 -#define EOS_NET_SIZE_SNDQ 16 +#define EOS_NET_SIZE_BUFQ 4 +#define EOS_NET_SIZE_SNDQ 4 #define EOS_NET_FLAG_BFREE 0x1 #define EOS_NET_FLAG_BCOPY 0x2 diff --git a/code/esp32/components/eos/msgq.c b/code/esp32/components/eos/msgq.c index 6fda261..30fb0ad 100644 --- a/code/esp32/components/eos/msgq.c +++ b/code/esp32/components/eos/msgq.c @@ -13,7 +13,7 @@ void eos_msgq_init(EOSMsgQ *msgq, EOSMsgItem *array, uint8_t size) { } int eos_msgq_push(EOSMsgQ *msgq, unsigned char type, unsigned char *buffer, uint16_t len, uint8_t flags) { - if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_Q_FULL; + if ((uint8_t)(msgq->idx_w - msgq->idx_r) == msgq->size) return EOS_ERR_FULL; uint8_t idx = EOS_MSGQ_IDX_MASK(msgq->idx_w, msgq->size); msgq->array[idx].type = type; diff --git a/code/esp32/components/eos/net.c b/code/esp32/components/eos/net.c index 3c7877d..be4d0f1 100644 --- a/code/esp32/components/eos/net.c +++ b/code/esp32/components/eos/net.c @@ -37,7 +37,6 @@ typedef struct EOSNetBufQ { } EOSNetBufQ; static EOSNetBufQ net_buf_q; -static unsigned char net_bufq_array[EOS_NET_SIZE_BUFQ][EOS_NET_SIZE_BUF]; static EOSMsgQ net_send_q; static EOSMsgItem net_sndq_array[EOS_NET_SIZE_SNDQ]; @@ -59,7 +58,7 @@ static void net_bufq_init(void) { net_buf_q.idx_r = 0; net_buf_q.idx_w = EOS_NET_SIZE_BUFQ; for (i=0; i