From 040f4333678f46f3558e604014d460076244af6b Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sat, 7 Dec 2019 17:13:23 +0100 Subject: added net_alloc; fixed cell modem driver --- code/esp32/components/eos/net.c | 91 ++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 19 deletions(-) (limited to 'code/esp32/components/eos/net.c') diff --git a/code/esp32/components/eos/net.c b/code/esp32/components/eos/net.c index bad078a..3c7877d 100644 --- a/code/esp32/components/eos/net.c +++ b/code/esp32/components/eos/net.c @@ -19,8 +19,9 @@ #include "msgq.h" #include "net.h" -static EOSMsgQ net_send_q; -static EOSMsgItem net_sndq_array[EOS_NET_SIZE_BUFQ]; +#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) +#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) +#define NET_BUFQ_IDX_MASK(IDX) ((IDX) & (EOS_NET_SIZE_BUFQ - 1)) #define SPI_GPIO_RTS 22 #define SPI_GPIO_CTS 21 @@ -29,9 +30,22 @@ static EOSMsgItem net_sndq_array[EOS_NET_SIZE_BUFQ]; #define SPI_GPIO_SCLK 18 #define SPI_GPIO_CS 5 +typedef struct EOSNetBufQ { + uint8_t idx_r; + uint8_t idx_w; + unsigned char *array[EOS_NET_SIZE_BUFQ]; +} 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]; + static SemaphoreHandle_t mutex; +static SemaphoreHandle_t semaph; -static const char *TAG = "EOS"; +static const char *TAG = "EOS NET"; static eos_net_fptr_t mtype_handler[EOS_NET_MAX_MTYPE]; @@ -39,6 +53,25 @@ static void bad_handler(unsigned char mtype, unsigned char *buffer, uint16_t len ESP_LOGE(TAG, "NET RECV: bad handler: %d", mtype); } +static void net_bufq_init(void) { + int i; + + net_buf_q.idx_r = 0; + net_buf_q.idx_w = EOS_NET_SIZE_BUFQ; + for (i=0; i> 3)); repeat = 0; if (buf_recv[0] != 0) { mtype = (buf_recv[0] >> 3); @@ -92,10 +131,7 @@ static void exchange(void *pvParameters) { } else { bad_handler(mtype, buffer, len); } - } else { - // ESP_LOGI(TAG, "NET RECV NULL"); } - // vTaskDelay(5000 / portTICK_PERIOD_MS); } } @@ -110,6 +146,7 @@ static void _post_trans_cb(spi_slave_transaction_t *trans) { } void eos_net_init(void) { + int i; esp_err_t ret; // Configuration for the handshake lines @@ -144,30 +181,46 @@ void eos_net_init(void) { .post_trans_cb = _post_trans_cb }; - //Enable pull-ups on SPI lines so we don't detect rogue pulses when no master is connected. - gpio_set_pull_mode(SPI_GPIO_MOSI, GPIO_PULLUP_ONLY); - gpio_set_pull_mode(SPI_GPIO_SCLK, GPIO_PULLUP_ONLY); - gpio_set_pull_mode(SPI_GPIO_CS, GPIO_PULLUP_ONLY); + //Initialize SPI slave interface + ret=spi_slave_initialize(HSPI_HOST, &buscfg, &slvcfg, 1); + assert(ret==ESP_OK); + + net_bufq_init(); + eos_msgq_init(&net_send_q, net_sndq_array, EOS_NET_SIZE_SNDQ); - int i; for (i=0; i