From 285ddd410a559449b7e2cbab9b2b10e850efbd08 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 7 Jan 2026 22:13:36 +0100 Subject: added APP <-> FE310 bridge SPI messages; enabled esp32 wake from deep sleep; IP tunnel for app module supports NAT and port forwadring; introduced EOSMessage struct for SPI messages; --- fw/esp32/components/eos/app.c | 102 ++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 38 deletions(-) (limited to 'fw/esp32/components/eos/app.c') diff --git a/fw/esp32/components/eos/app.c b/fw/esp32/components/eos/app.c index 662da17..ab04c2c 100644 --- a/fw/esp32/components/eos/app.c +++ b/fw/esp32/components/eos/app.c @@ -16,48 +16,62 @@ #include "eos.h" #include "msgq.h" #include "power.h" +#include "net.h" #include "app.h" #include "net_priv.h" -#define SPI_GPIO_CTS 9 #define SPI_GPIO_RTS 47 +#define SPI_GPIO_CTS 9 #define SPI_GPIO_MOSI 11 #define SPI_GPIO_MISO 13 #define SPI_GPIO_SCLK 12 #define SPI_GPIO_CS 10 -#define SPI_SIZE_BUF (EOS_APP_SIZE_BUF + 4) -#define SPI_SIZE_HDR 3 - #define SPI_HOST SPI2_HOST +#define APP_SIZE_BUFQ 16 +#define APP_SIZE_SNDQ 16 + static EOSBufQ app_buf_q; -static unsigned char *app_bufq_array[EOS_APP_SIZE_BUFQ]; +static unsigned char *app_bufq_array[APP_SIZE_BUFQ]; static EOSMsgQ app_send_q; -static EOSMsgItem app_sndq_array[EOS_APP_SIZE_SNDQ]; +static EOSMsgItem app_sndq_array[APP_SIZE_SNDQ]; static NETConfig app_config; static eos_net_handler_t app_handler[EOS_APP_MAX_MTYPE]; static spi_bus_config_t app_spi_bus_cfg; static spi_slave_interface_config_t app_spi_iface_cfg; -static spi_slave_transaction_t app_spi_tr_cfg; static const char *TAG = "EOS APP"; -static void bad_handler(unsigned char mtype, unsigned char *buffer, uint16_t len) { - ESP_LOGE(TAG, "bad handler: 0x%.2X len: %d", mtype, len); +static void bad_handler(unsigned char mtype, EOSMessage *msg, uint16_t len) { + ESP_LOGE(TAG, "BAD HANDLER: 0x%.2X LEN: %d", mtype, len); +} + +static void IRAM_ATTR app_bridge(unsigned char mtype, EOSMessage *msg, uint16_t len) { + EOSMessage _msg; + int rv; + + eos_net_alloc(&_msg); + if (len > _msg.size) { + eos_net_free(&_msg); + return; + } + memcpy(_msg.buffer, msg->buffer, len); + rv = eos_net_send(mtype & EOS_NET_MTYPE_MASK, &_msg, len); + if (rv) ESP_LOGE(TAG, "BRIDGE ERR: %d", rv); } -static void app_msg_handler(unsigned char mtype, unsigned char *buffer, uint16_t buf_len) { +static void IRAM_ATTR app_msg_handler(unsigned char mtype, EOSMessage *msg, uint16_t len) { uint8_t idx; - idx = mtype & EOS_NET_MTYPE_MASK; - if (idx && (idx <= EOS_APP_MAX_MTYPE) && (buf_len <= EOS_APP_MTU)) { - app_handler[idx - 1](mtype, buffer, buf_len); + idx = mtype & EOS_NET_MTYPE_FLAG_BRIDGE ? EOS_NET_MTYPE_BRIDGE : mtype & EOS_NET_MTYPE_MASK; + if ((idx < EOS_APP_MAX_MTYPE) && (len <= msg->size)) { + app_handler[idx](mtype, msg, len); } else { - bad_handler(mtype, buffer, buf_len); + bad_handler(mtype, msg, len); } } @@ -67,12 +81,12 @@ void eos_app_init(void) { SemaphoreHandle_t bufq_semaph; int i; - eos_msgq_init(&app_send_q, app_sndq_array, EOS_APP_SIZE_SNDQ); - eos_bufq_init(&app_buf_q, app_bufq_array, EOS_APP_SIZE_BUFQ); - for (i=0; i