summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/esp32/components/eos/net.c')
-rw-r--r--fw/esp32/components/eos/net.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/fw/esp32/components/eos/net.c b/fw/esp32/components/eos/net.c
index 0491b41..73d1c43 100644
--- a/fw/esp32/components/eos/net.c
+++ b/fw/esp32/components/eos/net.c
@@ -59,8 +59,7 @@ static void _post_trans_cb(spi_slave_transaction_t *trans) {
static void net_xchg_task(void *pvParameters) {
int wake = 0;
- int reply = 0;
- int skip_next_msg = 0;
+ int skip_msg = 0;
unsigned char mtype = 0;
unsigned char mtype_flags = 0;
unsigned char *buffer;
@@ -99,12 +98,12 @@ static void net_xchg_task(void *pvParameters) {
if (eos_power_wakeup_cause()) {
wake = 1;
- skip_next_msg = 1;
+ skip_msg = 1;
}
eos_power_wait4init();
while (1) {
- if (!skip_next_msg) {
+ if (!skip_msg) {
xSemaphoreTake(mutex, portMAX_DELAY);
eos_msgq_pop(&net_send_q, &mtype, &buffer, &len);
@@ -126,25 +125,13 @@ static void net_xchg_task(void *pvParameters) {
xSemaphoreGive(mutex);
}
- skip_next_msg = 0;
+ skip_msg = 0;
- if (reply) {
- spi_tr.tx_buffer = buf_recv;
- spi_tr.rx_buffer = NULL;
- } else {
- buf_recv[0] = 0;
- buf_recv[1] = 0;
- buf_recv[2] = 0;
- }
+ buf_recv[0] = 0;
+ buf_recv[1] = 0;
+ buf_recv[2] = 0;
spi_slave_transmit(VSPI_HOST, &spi_tr, portMAX_DELAY);
// ESP_LOGI(TAG, "RECV:%d", buf_recv[0]);
- if (reply) {
- reply = 0;
- spi_tr.tx_buffer = buf_send;
- spi_tr.rx_buffer = buf_recv;
- if (buf_send[0]) skip_next_msg = 1;
- continue;
- }
if (wake) {
eos_power_net_ready();
@@ -176,7 +163,7 @@ static void net_xchg_task(void *pvParameters) {
spi_slave_initialize(VSPI_HOST, &spi_bus_cfg, &spi_slave_cfg, 1);
wake = 1;
- skip_next_msg = 1;
+ skip_msg = 1;
}
continue;
}
@@ -192,11 +179,14 @@ static void net_xchg_task(void *pvParameters) {
bad_handler(mtype, buffer, len);
}
if ((mtype_flags & EOS_NET_MTYPE_FLAG_ONEW) && buf_send[0]) {
- skip_next_msg = 1;
+ skip_msg = 1;
}
- if (mtype_flags & EOS_NET_MTYPE_FLAG_REPW) {
- skip_next_msg = 1;
- reply = 1;
+ if (mtype_flags & EOS_NET_MTYPE_FLAG_REPL) {
+ spi_tr.tx_buffer = buf_recv;
+ spi_tr.rx_buffer = NULL;
+ spi_slave_transmit(VSPI_HOST, &spi_tr, portMAX_DELAY);
+ spi_tr.tx_buffer = buf_send;
+ spi_tr.rx_buffer = buf_recv;
}
}
vTaskDelete(NULL);
@@ -276,6 +266,13 @@ int eos_net_send(unsigned char mtype, unsigned char *buffer, uint16_t len) {
return rv;
}
+void eos_net_reply(unsigned char mtype, unsigned char *buffer, uint16_t len) {
+ buffer -= SPI_SIZE_HDR;
+ buffer[0] = mtype;
+ buffer[1] = len >> 8;
+ buffer[2] = len & 0xFF;
+}
+
void eos_net_set_handler(unsigned char mtype, eos_net_fptr_t handler) {
if (handler == NULL) handler = bad_handler;
if (mtype && (mtype <= EOS_NET_MAX_MTYPE)) net_handler[mtype - 1] = handler;