summaryrefslogtreecommitdiff
path: root/code/esp32
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2018-01-22 15:31:04 +0100
committerUros Majstorovic <majstor@majstor.org>2018-01-22 15:31:04 +0100
commit7e209672e005b911166f27b691acfc6c988e93fb (patch)
treef3200c9f282a9e4f9c08e7e6615fdd543ec2307b /code/esp32
parentaee07a08bfdfd32a777a8cdd1f5f84fe56783461 (diff)
fixed esp32 driver: moved xSemaphoreTake from ISR
Diffstat (limited to 'code/esp32')
-rw-r--r--code/esp32/components/eos/fe310.c22
-rw-r--r--code/esp32/components/eos/include/eos.h5
-rwxr-xr-xcode/esp32/components/eos/transport.c5
3 files changed, 17 insertions, 15 deletions
diff --git a/code/esp32/components/eos/fe310.c b/code/esp32/components/eos/fe310.c
index b13d653..aa1b66f 100644
--- a/code/esp32/components/eos/fe310.c
+++ b/code/esp32/components/eos/fe310.c
@@ -16,6 +16,7 @@
#include <esp_heap_caps.h>
#include <driver/spi_slave.h>
+#include "eos.h"
#include "msgq.h"
#include "transport.h"
#include "fe310.h"
@@ -40,7 +41,7 @@ static void bad_handler(unsigned char cmd, unsigned char *buffer, uint16_t len)
ESP_LOGI(TAG, "FE310 RECV: bad handler: %d", cmd);
}
-static void worker(void *pvParameters) {
+static void transceiver(void *pvParameters) {
int repeat = 0;
esp_err_t ret;
unsigned char cmd = 0;
@@ -51,13 +52,14 @@ static void worker(void *pvParameters) {
spi_slave_transaction_t t;
memset(&t, 0, sizeof(t));
+
t.length = EOS_FE310_SIZE_BUF*8;
t.tx_buffer = buf_send;
t.rx_buffer = buf_recv;
-
- xSemaphoreTake(mutex, portMAX_DELAY);
for (;;) {
if (!repeat) {
+ xSemaphoreTake(mutex, portMAX_DELAY);
+
eos_msgq_pop(&send_q, &cmd, &buffer, &len);
if (cmd) {
buf_send[0] = ((cmd << 3) | (len >> 8)) & 0xFF;
@@ -68,14 +70,14 @@ static void worker(void *pvParameters) {
buf_send[0] = 0;
buf_send[1] = 0;
}
+
+ xSemaphoreGive(mutex);
}
+
memset(buf_recv, 0, EOS_FE310_SIZE_BUF);
ret = spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
-
repeat = 0;
if (buf_recv[0] != 0) {
- xSemaphoreGive(mutex);
-
cmd = (buf_recv[0] >> 3);
len = ((buf_recv[0] & 0x07) << 8);
len |= buf_recv[1];
@@ -89,25 +91,20 @@ static void worker(void *pvParameters) {
} else {
bad_handler(cmd, buffer, len);
}
-
- xSemaphoreTake(mutex, portMAX_DELAY);
} else {
// ESP_LOGI(TAG, "FE310 RECV NULL");
}
// vTaskDelay(5000 / portTICK_PERIOD_MS);
}
- xSemaphoreGive(mutex);
}
// Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
static void _post_setup_cb(spi_slave_transaction_t *trans) {
- xSemaphoreGive(mutex);
WRITE_PERI_REG(GPIO_OUT_W1TS_REG, (1 << SPI_GPIO_CTS));
}
// Called after transaction is sent/received. We use this to set the handshake line low.
static void _post_trans_cb(spi_slave_transaction_t *trans) {
- xSemaphoreTake(mutex, portMAX_DELAY);
WRITE_PERI_REG(GPIO_OUT_W1TC_REG, (1 << SPI_GPIO_CTS));
}
@@ -163,7 +160,8 @@ void eos_fe310_init(void) {
eos_msgq_init(&send_q, send_q_array, EOS_FE310_SIZE_Q);
mutex = xSemaphoreCreateBinary();
xSemaphoreGive(mutex);
- xTaskCreatePinnedToCore(&worker, "fe310_receiver", 4096, NULL, 5, NULL, 1);
+ xTaskCreate(&transceiver, "fe310_transceiver", 4096, NULL, EOS_PRIORITY_SPI, NULL);
+ // xTaskCreatePinnedToCore(&transceiver, "fe310_transceiver", 4096, NULL, EOS_PRIORITY_SPI, NULL, 1);
}
int eos_fe310_send(unsigned char cmd, unsigned char *buffer, uint16_t len) {
diff --git a/code/esp32/components/eos/include/eos.h b/code/esp32/components/eos/include/eos.h
index a272ac8..1d35584 100644
--- a/code/esp32/components/eos/include/eos.h
+++ b/code/esp32/components/eos/include/eos.h
@@ -1,2 +1,5 @@
#define EOS_OK 0
-#define EOS_ERR_Q_FULL -10 \ No newline at end of file
+#define EOS_ERR_Q_FULL -10
+
+#define EOS_PRIORITY_WIFI 1
+#define EOS_PRIORITY_SPI 1 \ No newline at end of file
diff --git a/code/esp32/components/eos/transport.c b/code/esp32/components/eos/transport.c
index 597be61..e0a913a 100755
--- a/code/esp32/components/eos/transport.c
+++ b/code/esp32/components/eos/transport.c
@@ -158,7 +158,8 @@ static esp_err_t esp32_wifi_event_handler(void *ctx, system_event_t *event) {
ESP_LOGI(TAG, "* - Our IP address is: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip));
ESP_LOGI(TAG, "********************************************");
t_open();
- xTaskCreatePinnedToCore(&receiver, "receiver", 4096, NULL, 5, &receiver_task, 1);
+ xTaskCreate(&receiver, "wifi_receiver", 4096, NULL, EOS_PRIORITY_WIFI, &receiver_task);
+ // xTaskCreatePinnedToCore(&receiver, "wifi_receiver", 4096, NULL, EOS_PRIORITY_WIFI, &receiver_task, 1);
eos_fe310_send(EOS_FE310_CMD_CONNECT, NULL, 0);
break;
@@ -175,7 +176,7 @@ void eos_net_init(void) {
memset(&wifi_config, 0, sizeof(wifi_config));
tcpip_adapter_init();
-// ESP_ERROR_CHECK( nvs_flash_init() );
+ // ESP_ERROR_CHECK( nvs_flash_init() );
ESP_ERROR_CHECK( esp_event_loop_init(esp32_wifi_event_handler, NULL) );
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );