#include #include #include #include #include #include #include #include #include #include #include #include #include "eos.h" #include "msgq.h" #include "power.h" #include "net.h" #include "app.h" #include "net_priv.h" #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_HOST SPI2_HOST #define APP_SIZE_BUFQ 16 #define APP_SIZE_SNDQ 16 static EOSBufQ app_buf_q; static unsigned char *app_bufq_array[APP_SIZE_BUFQ]; static EOSMsgQ app_send_q; 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 const char *TAG = "EOS APP"; 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 IRAM_ATTR app_msg_handler(unsigned char mtype, EOSMessage *msg, uint16_t len) { uint8_t idx; 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, msg, len); } } void eos_app_init(void) { SemaphoreHandle_t mutex; SemaphoreHandle_t bufq_mutex; SemaphoreHandle_t bufq_semaph; int i; eos_msgq_init(&app_send_q, app_sndq_array, APP_SIZE_SNDQ); eos_bufq_init(&app_buf_q, app_bufq_array, APP_SIZE_BUFQ); for (i=0; i