summaryrefslogtreecommitdiff
path: root/code/esp32/components/eos/cell_modem.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2019-12-07 17:13:23 +0100
committerUros Majstorovic <majstor@majstor.org>2019-12-07 17:13:23 +0100
commit040f4333678f46f3558e604014d460076244af6b (patch)
tree084b8a41eef67a9bf45a5c21124fc393061f88fb /code/esp32/components/eos/cell_modem.c
parent8cdc7528c800a3f10bca3e875e76f6d9661ab88f (diff)
added net_alloc; fixed cell modem driver
Diffstat (limited to 'code/esp32/components/eos/cell_modem.c')
-rw-r--r--code/esp32/components/eos/cell_modem.c78
1 files changed, 65 insertions, 13 deletions
diff --git a/code/esp32/components/eos/cell_modem.c b/code/esp32/components/eos/cell_modem.c
index 7e3131f..26748a1 100644
--- a/code/esp32/components/eos/cell_modem.c
+++ b/code/esp32/components/eos/cell_modem.c
@@ -8,19 +8,33 @@
#include <driver/gpio.h>
#include <esp_log.h>
-
#include "eos.h"
+#include "net.h"
+#include "cell.h"
+
+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
+#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
+
+#define UART_BUF_SIZE 1024
-#define BUF_SIZE 1024
+#define UART_GPIO_TXD 16
+#define UART_GPIO_RXD 17
#define UART_GPIO_DTR 32
+#define UART_GPIO_RI 35
+
+
+#define UART_EVENT_MODE_NONE 0
+#define UART_EVENT_MODE_PPP 1
+#define UART_EVENT_MODE_RELAY 2
+
static QueueHandle_t uart_queue;
+// static uint8_t *uart_data[UART_BUF_SIZE];
static void uart_event_task(void *pvParameters) {
+ char mode = 0;
uart_event_t event;
size_t len;
-
- // Reserve a buffer and process incoming data
- uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
+ unsigned char *buf;
while (1) {
/* Waiting for UART event.
@@ -30,22 +44,51 @@ static void uart_event_task(void *pvParameters) {
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);
+ switch (mode) {
+ case UART_EVENT_MODE_PPP:
+ break;
+
+ case UART_EVENT_MODE_RELAY:
+ buf = eos_net_alloc();
+ buf[0] = EOS_CELL_MTYPE_DATA;
+ len = uart_read_bytes(UART_NUM_2, buf+1, MIN(event.size, EOS_NET_SIZE_BUF-1), 100 / portTICK_RATE_MS);
+ eos_net_send(EOS_NET_MTYPE_CELL, buf, len, 0);
+ break;
+
+ default:
+ break;
}
+
+ case UART_EVENT_MAX:
+ /* Mode change
+ */
+ mode = (char)event.size;
break;
+
default:
break;
}
}
}
- free(data);
vTaskDelete(NULL);
}
+static void modem_handler(unsigned char _mtype, unsigned char *buffer, uint16_t size) {
+ uint8_t mtype = buffer[0];
+
+ switch (mtype) {
+ case EOS_CELL_MTYPE_DATA:
+ eos_modem_write(buffer+1, size-1);
+ break;
+ case EOS_CELL_MTYPE_DATA_START:
+ eos_modem_set_mode(UART_EVENT_MODE_RELAY);
+ break;
+ case EOS_CELL_MTYPE_DATA_STOP:
+ eos_modem_set_mode(0);
+ break;
+ }
+}
+
void eos_modem_init(void) {
/* Configure parameters of an UART driver,
* communication pins and install the driver */
@@ -57,8 +100,8 @@ void eos_modem_init(void) {
.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);
+ uart_set_pin(UART_NUM_2, UART_GPIO_TXD, UART_GPIO_RXD, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
+ uart_driver_install(UART_NUM_2, UART_BUF_SIZE, UART_BUF_SIZE, 10, &uart_queue, 0);
// Configuration for the DTR/RI lines
gpio_config_t io_conf;
@@ -71,8 +114,17 @@ void eos_modem_init(void) {
// Create a task to handle uart event from ISR
xTaskCreate(uart_event_task, "uart_event_task", 2048, NULL, EOS_IRQ_PRIORITY_UART, NULL);
+
+ eos_net_set_handler(EOS_NET_MTYPE_CELL, modem_handler);
}
ssize_t eos_modem_write(void *data, size_t size) {
return uart_write_bytes(UART_NUM_2, (const char *)data, size);
}
+
+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);
+}