From 8cdc7528c800a3f10bca3e875e76f6d9661ab88f Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 7 Dec 2019 17:12:27 +0100 Subject: added net_alloc; fixed cell modem driver --- code/esp32/components/eos/cell_modem.c | 78 +++++++++++++++++ code/esp32/components/eos/cell_pcm.c | 134 ++++++++++++++++++++++++++++++ code/esp32/components/eos/include/cell.h | 18 ++++ code/esp32/components/eos/include/modem.h | 4 - code/esp32/components/eos/include/pcm.h | 6 -- code/esp32/components/eos/modem.c | 78 ----------------- code/esp32/components/eos/pcm.c | 134 ------------------------------ 7 files changed, 230 insertions(+), 222 deletions(-) create mode 100644 code/esp32/components/eos/cell_modem.c create mode 100644 code/esp32/components/eos/cell_pcm.c create mode 100644 code/esp32/components/eos/include/cell.h delete mode 100644 code/esp32/components/eos/include/modem.h delete mode 100644 code/esp32/components/eos/include/pcm.h delete mode 100644 code/esp32/components/eos/modem.c delete mode 100644 code/esp32/components/eos/pcm.c (limited to 'code/esp32') diff --git a/code/esp32/components/eos/cell_modem.c b/code/esp32/components/eos/cell_modem.c new file mode 100644 index 0000000..7e3131f --- /dev/null +++ b/code/esp32/components/eos/cell_modem.c @@ -0,0 +1,78 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + + +#include "eos.h" + +#define BUF_SIZE 1024 +#define UART_GPIO_DTR 32 +static QueueHandle_t uart_queue; + +static void uart_event_task(void *pvParameters) { + uart_event_t event; + size_t len; + + // Reserve a buffer and process incoming data + uint8_t *data = (uint8_t *) malloc(BUF_SIZE); + + while (1) { + /* Waiting for UART event. + */ + if (xQueueReceive(uart_queue, (void * )&event, (portTickType)portMAX_DELAY)) { + switch (event.type) { + case UART_DATA: + /* Event of UART receiving data + */ + len = 0; + uart_get_buffered_data_len(UART_NUM_2, &len); + if (len) { + len = uart_read_bytes(UART_NUM_2, data, len, 100 / portTICK_RATE_MS); + // eos_net_send(EOS_FE310_CMD_MODEM_DATA, data, len); + } + break; + default: + break; + } + } + } + free(data); + vTaskDelete(NULL); +} + +void eos_modem_init(void) { + /* Configure parameters of an UART driver, + * communication pins and install the driver */ + uart_config_t uart_config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE + }; + uart_param_config(UART_NUM_2, &uart_config); + uart_set_pin(UART_NUM_2, 17, 16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); + uart_driver_install(UART_NUM_2, BUF_SIZE, BUF_SIZE, 10, &uart_queue, 0); + + // Configuration for the DTR/RI lines + gpio_config_t io_conf; + + io_conf.intr_type = GPIO_INTR_DISABLE; + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = ((uint64_t)1 << UART_GPIO_DTR); + gpio_config(&io_conf); + 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); +} + +ssize_t eos_modem_write(void *data, size_t size) { + return uart_write_bytes(UART_NUM_2, (const char *)data, size); +} diff --git a/code/esp32/components/eos/cell_pcm.c b/code/esp32/components/eos/cell_pcm.c new file mode 100644 index 0000000..edfcf88 --- /dev/null +++ b/code/esp32/components/eos/cell_pcm.c @@ -0,0 +1,134 @@ +#include +#include + +#include +#include +#include +#include +#include + +#include "eos.h" +#include "modem.h" + +static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1}; + +#define BUF_SIZE 2048 + +static QueueHandle_t i2s_queue; + +static void i2s_event_task(void *pvParameters) { + size_t size_out; + i2s_event_t event; + // Reserve a buffer and process incoming data + uint8_t *data = (uint8_t *) malloc(BUF_SIZE); + + int first = 1; + uint8_t *data_first = NULL; + + while (1) { + // Waiting for I2S event. + if (xQueueReceive(i2s_queue, (void * )&event, (portTickType)portMAX_DELAY)) { + switch (event.type) { + case I2S_EVENT_RX_DONE: + // Event of I2S receiving data + // printf("*** I2S DATA RECEIVED: %d\n ***", event.size); + i2s_read(I2S_NUM_0, (void *)data, BUF_SIZE, &size_out, 1000 / portTICK_RATE_MS); + if (first) { + if (data_first) { + first = 0; + i2s_write(I2S_NUM_0, (const void *)data_first, BUF_SIZE, &size_out, 1000 / portTICK_RATE_MS); + free(data_first); + data_first = NULL; + } else { + data_first = (uint8_t *) malloc(BUF_SIZE); + memcpy(data_first, data, BUF_SIZE); + } + + } + 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 ***"); + break; + default: + break; + } + } + } + free(data); + vTaskDelete(NULL); +} + +static void i2s_write_task(void *pvParameters) { + uint8_t *data = (uint8_t *) malloc(BUF_SIZE); + memset(data, 0x0, BUF_SIZE); + + int i; + for (i=0; iconf.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); +} + +ssize_t eos_pcm_write(void *data, size_t size) { + size_t size_out; + + esp_err_t ret = i2s_write(I2S_NUM_0, (const void *)data, size, &size_out, portMAX_DELAY); + if (ret != ESP_OK) return EOS_ERR; + return size_out; +} + +void eos_pcm_call(void) { + const char *s = "ATD0631942317;\r"; + + i2s_zero_dma_buffer(I2S_NUM_0); + eos_modem_write((void *)s, strlen(s)); + vTaskDelay(1000 / portTICK_RATE_MS); + i2s_start(I2S_NUM_0); +} + diff --git a/code/esp32/components/eos/include/cell.h b/code/esp32/components/eos/include/cell.h new file mode 100644 index 0000000..61da67a --- /dev/null +++ b/code/esp32/components/eos/include/cell.h @@ -0,0 +1,18 @@ +#include + +#define EOS_CELL_MTYPE_DATA 0 +#define EOS_CELL_MTYPE_AUDIO 1 + +#define EOS_CELL_MTYPE_DATA_START 2 +#define EOS_CELL_MTYPE_DATA_STOP 3 + +#define EOS_CELL_MTYPE_AUDIO_START 2 +#define EOS_CELL_MTYPE_AUDIO_STOP 3 + +void eos_pcm_init(void); +ssize_t eos_pcm_write(void *data, size_t size); +void eos_pcm_call(void); + +void eos_modem_init(void); +ssize_t eos_modem_write(void *data, size_t size); +void eos_modem_set_mode(char mode); diff --git a/code/esp32/components/eos/include/modem.h b/code/esp32/components/eos/include/modem.h deleted file mode 100644 index 6a80918..0000000 --- a/code/esp32/components/eos/include/modem.h +++ /dev/null @@ -1,4 +0,0 @@ -#include - -void eos_modem_init(void); -ssize_t eos_modem_write(void *data, size_t size); \ No newline at end of file diff --git a/code/esp32/components/eos/include/pcm.h b/code/esp32/components/eos/include/pcm.h deleted file mode 100644 index dcccea7..0000000 --- a/code/esp32/components/eos/include/pcm.h +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -void eos_pcm_init(void); -ssize_t eos_pcm_write(void *data, size_t size); -void eos_pcm_call(void); diff --git a/code/esp32/components/eos/modem.c b/code/esp32/components/eos/modem.c deleted file mode 100644 index 7e3131f..0000000 --- a/code/esp32/components/eos/modem.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - - -#include "eos.h" - -#define BUF_SIZE 1024 -#define UART_GPIO_DTR 32 -static QueueHandle_t uart_queue; - -static void uart_event_task(void *pvParameters) { - uart_event_t event; - size_t len; - - // Reserve a buffer and process incoming data - uint8_t *data = (uint8_t *) malloc(BUF_SIZE); - - while (1) { - /* Waiting for UART event. - */ - if (xQueueReceive(uart_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - switch (event.type) { - case UART_DATA: - /* Event of UART receiving data - */ - len = 0; - uart_get_buffered_data_len(UART_NUM_2, &len); - if (len) { - len = uart_read_bytes(UART_NUM_2, data, len, 100 / portTICK_RATE_MS); - // eos_net_send(EOS_FE310_CMD_MODEM_DATA, data, len); - } - break; - default: - break; - } - } - } - free(data); - vTaskDelete(NULL); -} - -void eos_modem_init(void) { - /* Configure parameters of an UART driver, - * communication pins and install the driver */ - uart_config_t uart_config = { - .baud_rate = 115200, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE - }; - uart_param_config(UART_NUM_2, &uart_config); - uart_set_pin(UART_NUM_2, 17, 16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); - uart_driver_install(UART_NUM_2, BUF_SIZE, BUF_SIZE, 10, &uart_queue, 0); - - // Configuration for the DTR/RI lines - gpio_config_t io_conf; - - io_conf.intr_type = GPIO_INTR_DISABLE; - io_conf.mode = GPIO_MODE_OUTPUT; - io_conf.pin_bit_mask = ((uint64_t)1 << UART_GPIO_DTR); - gpio_config(&io_conf); - 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); -} - -ssize_t eos_modem_write(void *data, size_t size) { - return uart_write_bytes(UART_NUM_2, (const char *)data, size); -} diff --git a/code/esp32/components/eos/pcm.c b/code/esp32/components/eos/pcm.c deleted file mode 100644 index edfcf88..0000000 --- a/code/esp32/components/eos/pcm.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -#include "eos.h" -#include "modem.h" - -static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1}; - -#define BUF_SIZE 2048 - -static QueueHandle_t i2s_queue; - -static void i2s_event_task(void *pvParameters) { - size_t size_out; - i2s_event_t event; - // Reserve a buffer and process incoming data - uint8_t *data = (uint8_t *) malloc(BUF_SIZE); - - int first = 1; - uint8_t *data_first = NULL; - - while (1) { - // Waiting for I2S event. - if (xQueueReceive(i2s_queue, (void * )&event, (portTickType)portMAX_DELAY)) { - switch (event.type) { - case I2S_EVENT_RX_DONE: - // Event of I2S receiving data - // printf("*** I2S DATA RECEIVED: %d\n ***", event.size); - i2s_read(I2S_NUM_0, (void *)data, BUF_SIZE, &size_out, 1000 / portTICK_RATE_MS); - if (first) { - if (data_first) { - first = 0; - i2s_write(I2S_NUM_0, (const void *)data_first, BUF_SIZE, &size_out, 1000 / portTICK_RATE_MS); - free(data_first); - data_first = NULL; - } else { - data_first = (uint8_t *) malloc(BUF_SIZE); - memcpy(data_first, data, BUF_SIZE); - } - - } - 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 ***"); - break; - default: - break; - } - } - } - free(data); - vTaskDelete(NULL); -} - -static void i2s_write_task(void *pvParameters) { - uint8_t *data = (uint8_t *) malloc(BUF_SIZE); - memset(data, 0x0, BUF_SIZE); - - int i; - for (i=0; iconf.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); -} - -ssize_t eos_pcm_write(void *data, size_t size) { - size_t size_out; - - esp_err_t ret = i2s_write(I2S_NUM_0, (const void *)data, size, &size_out, portMAX_DELAY); - if (ret != ESP_OK) return EOS_ERR; - return size_out; -} - -void eos_pcm_call(void) { - const char *s = "ATD0631942317;\r"; - - i2s_zero_dma_buffer(I2S_NUM_0); - eos_modem_write((void *)s, strlen(s)); - vTaskDelay(1000 / portTICK_RATE_MS); - i2s_start(I2S_NUM_0); -} - -- cgit v1.2.3