From 77114fe25a0a39246dc86a25d1a898ba13a65358 Mon Sep 17 00:00:00 2001 From: dernasherbrezon Date: Sun, 1 Dec 2024 10:23:40 +0000 Subject: [PATCH] reduce task switching latency --- README.md | 1 + examples/receive_fsk/main/main.c | 19 +++++++++++-------- examples/receive_fsk_beacon/main/main.c | 19 +++++++++++-------- examples/receive_fsk_filtered/main/main.c | 19 +++++++++++-------- examples/receive_fsk_fixed/main/main.c | 19 +++++++++++-------- examples/receive_lora/main/main.c | 15 +++++++++------ examples/receive_lora_fhss/main/main.c | 19 +++++++++++-------- .../receive_lora_implicit_header/main/main.c | 15 +++++++++------ examples/receive_ook/main/main.c | 19 +++++++++++-------- examples/transmit_fsk/main/main.c | 19 +++++++++++-------- examples/transmit_fsk_fixed/main/main.c | 19 +++++++++++-------- examples/transmit_lora/main/main.c | 19 +++++++++++-------- examples/transmit_lora_fhss/main/main.c | 19 +++++++++++-------- .../transmit_lora_implicit_header/main/main.c | 19 +++++++++++-------- examples/transmit_ook/main/main.c | 19 +++++++++++-------- 15 files changed, 151 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index 1bd5dc3..896e41f 100644 --- a/README.md +++ b/README.md @@ -156,5 +156,6 @@ Run the following command to test: ``` cd test/test_app idf.py build +export ESPBAUD=460800 pytest --target esp32 --port="/dev/ttyACM0|/dev/ttyACM1" pytest_* ``` diff --git a/examples/receive_fsk/main/main.c b/examples/receive_fsk/main/main.c index 421f80e..0802df8 100644 --- a/examples/receive_fsk/main/main.c +++ b/examples/receive_fsk/main/main.c @@ -28,10 +28,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -130,17 +133,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t) DIO0, &device); setup_gpio_interrupts((gpio_num_t) DIO1, &device); setup_gpio_interrupts((gpio_num_t) DIO2, &device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/receive_fsk_beacon/main/main.c b/examples/receive_fsk_beacon/main/main.c index 4034a45..7da3b70 100644 --- a/examples/receive_fsk_beacon/main/main.c +++ b/examples/receive_fsk_beacon/main/main.c @@ -28,10 +28,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -129,17 +132,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device); setup_gpio_interrupts((gpio_num_t)DIO1, &device); setup_gpio_interrupts((gpio_num_t)DIO2, &device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/receive_fsk_filtered/main/main.c b/examples/receive_fsk_filtered/main/main.c index d3304a8..b339a48 100644 --- a/examples/receive_fsk_filtered/main/main.c +++ b/examples/receive_fsk_filtered/main/main.c @@ -28,10 +28,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -121,17 +124,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device); setup_gpio_interrupts((gpio_num_t)DIO1, &device); setup_gpio_interrupts((gpio_num_t)DIO2, &device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/receive_fsk_fixed/main/main.c b/examples/receive_fsk_fixed/main/main.c index adfcd90..116dfc3 100644 --- a/examples/receive_fsk_fixed/main/main.c +++ b/examples/receive_fsk_fixed/main/main.c @@ -28,10 +28,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -121,17 +124,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device); setup_gpio_interrupts((gpio_num_t)DIO1, &device); setup_gpio_interrupts((gpio_num_t)DIO2, &device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_FSK, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/receive_lora/main/main.c b/examples/receive_lora/main/main.c index 80e400c..72a1af4 100644 --- a/examples/receive_lora/main/main.c +++ b/examples/receive_lora/main/main.c @@ -20,10 +20,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -115,15 +118,15 @@ void app_main() { return; } + gpio_install_isr_service(0); + setup_gpio_interrupts((gpio_num_t)DIO0, &device); + + ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, &device)); + TaskHandle_t handle_interrupt; BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); if (task_code != pdPASS) { ESP_LOGE(TAG, "can't create task %d", task_code); return; } - - gpio_install_isr_service(0); - setup_gpio_interrupts((gpio_num_t)DIO0, &device); - - ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, &device)); } diff --git a/examples/receive_lora_fhss/main/main.c b/examples/receive_lora_fhss/main/main.c index ad5460d..e6d96a6 100644 --- a/examples/receive_lora_fhss/main/main.c +++ b/examples/receive_lora_fhss/main/main.c @@ -24,10 +24,13 @@ sx127x device; int total_packets_received = 0; uint64_t frequencies[] = {437700000, 438200000, 437200012}; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -129,17 +132,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t)DIO1, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t)DIO2, &device, GPIO_INTR_POSEDGE); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/receive_lora_implicit_header/main/main.c b/examples/receive_lora_implicit_header/main/main.c index cc2aee4..3654eb1 100644 --- a/examples/receive_lora_implicit_header/main/main.c +++ b/examples/receive_lora_implicit_header/main/main.c @@ -20,10 +20,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -107,15 +110,15 @@ void app_main() { return; } + gpio_install_isr_service(0); + setup_gpio_interrupts((gpio_num_t)DIO0, &device); + + ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, &device)); + TaskHandle_t handle_interrupt; BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); if (task_code != pdPASS) { ESP_LOGE(TAG, "can't create task %d", task_code); return; } - - gpio_install_isr_service(0); - setup_gpio_interrupts((gpio_num_t)DIO0, &device); - - ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_LORA, &device)); } diff --git a/examples/receive_ook/main/main.c b/examples/receive_ook/main/main.c index 0530156..6c24b82 100644 --- a/examples/receive_ook/main/main.c +++ b/examples/receive_ook/main/main.c @@ -28,10 +28,13 @@ static const char *TAG = "sx127x"; sx127x device; int total_packets_received = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -115,17 +118,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device); setup_gpio_interrupts((gpio_num_t)DIO1, &device); setup_gpio_interrupts((gpio_num_t)DIO2, &device); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_RX_CONT, SX127x_MODULATION_OOK, &device)); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_fsk/main/main.c b/examples/transmit_fsk/main/main.c index 3da4bfc..d422098 100644 --- a/examples/transmit_fsk/main/main.c +++ b/examples/transmit_fsk/main/main.c @@ -27,10 +27,13 @@ static const char *TAG = "sx127x"; sx127x device; int messages_sent = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -141,17 +144,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t) DIO0, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t) DIO1, &device, GPIO_INTR_NEGEDGE); setup_gpio_interrupts((gpio_num_t) DIO2, &device, GPIO_INTR_POSEDGE); tx_callback(&device); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_fsk_fixed/main/main.c b/examples/transmit_fsk_fixed/main/main.c index fdc4731..03d6920 100644 --- a/examples/transmit_fsk_fixed/main/main.c +++ b/examples/transmit_fsk_fixed/main/main.c @@ -27,10 +27,13 @@ static const char *TAG = "sx127x"; sx127x device; int messages_sent = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -128,17 +131,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196 * 2, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t) DIO0, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t) DIO1, &device, GPIO_INTR_NEGEDGE); setup_gpio_interrupts((gpio_num_t) DIO2, &device, GPIO_INTR_POSEDGE); tx_callback(&device); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196 * 2, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_lora/main/main.c b/examples/transmit_lora/main/main.c index 6784f34..2ff08ef 100644 --- a/examples/transmit_lora/main/main.c +++ b/examples/transmit_lora/main/main.c @@ -25,10 +25,13 @@ int supported_power_levels[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, int supported_power_levels_count = sizeof(supported_power_levels) / sizeof(int); int current_power_level = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -114,13 +117,6 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device); @@ -131,4 +127,11 @@ void app_main() { ESP_ERROR_CHECK(sx127x_lora_tx_set_explicit_header(&header, &device)); tx_callback(&device); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_lora_fhss/main/main.c b/examples/transmit_lora_fhss/main/main.c index 7051953..aa7605b 100644 --- a/examples/transmit_lora_fhss/main/main.c +++ b/examples/transmit_lora_fhss/main/main.c @@ -23,10 +23,13 @@ sx127x device; int messages_sent = 0; uint64_t frequencies[] = {437700000, 438200000, 437200012}; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -128,13 +131,6 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t)DIO1, &device, GPIO_INTR_POSEDGE); @@ -147,4 +143,11 @@ void app_main() { ESP_ERROR_CHECK(sx127x_lora_tx_set_explicit_header(&header, &device)); tx_callback(&device); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_lora_implicit_header/main/main.c b/examples/transmit_lora_implicit_header/main/main.c index 1b7c6a3..db8cec9 100644 --- a/examples/transmit_lora_implicit_header/main/main.c +++ b/examples/transmit_lora_implicit_header/main/main.c @@ -19,10 +19,13 @@ static const char *TAG = "sx127x"; sx127x device; int messages_sent = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -80,13 +83,6 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_set_direction((gpio_num_t)DIO0, GPIO_MODE_INPUT); gpio_pulldown_en((gpio_num_t)DIO0); gpio_pullup_dis((gpio_num_t)DIO0); @@ -101,4 +97,11 @@ void app_main() { ESP_ERROR_CHECK(sx127x_lora_tx_set_for_transmission(data, sizeof(data), &device)); ESP_ERROR_CHECK(sx127x_set_opmod(SX127x_MODE_TX, SX127x_MODULATION_LORA, &device)); ESP_LOGI(TAG, "transmitting"); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } } diff --git a/examples/transmit_ook/main/main.c b/examples/transmit_ook/main/main.c index c91cdf6..6c8da3a 100644 --- a/examples/transmit_ook/main/main.c +++ b/examples/transmit_ook/main/main.c @@ -27,10 +27,13 @@ static const char *TAG = "sx127x"; sx127x device; int messages_sent = 0; static SemaphoreHandle_t xBinarySemaphore; -static BaseType_t xHigherPriorityTaskWoken = pdFALSE; void IRAM_ATTR handle_interrupt_fromisr(void *arg) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR(xBinarySemaphore, &xHigherPriorityTaskWoken); + if (xHigherPriorityTaskWoken == pdTRUE) { + portYIELD_FROM_ISR(); + } } void handle_interrupt_task(void *arg) { @@ -132,17 +135,17 @@ void app_main() { return; } - TaskHandle_t handle_interrupt; - BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); - if (task_code != pdPASS) { - ESP_LOGE(TAG, "can't create task %d", task_code); - return; - } - gpio_install_isr_service(0); setup_gpio_interrupts((gpio_num_t)DIO0, &device, GPIO_INTR_POSEDGE); setup_gpio_interrupts((gpio_num_t)DIO1, &device, GPIO_INTR_NEGEDGE); setup_gpio_interrupts((gpio_num_t)DIO2, &device, GPIO_INTR_POSEDGE); tx_callback(&device); + + TaskHandle_t handle_interrupt; + BaseType_t task_code = xTaskCreatePinnedToCore(handle_interrupt_task, "handle interrupt", 8196, &device, 2, &handle_interrupt, xPortGetCoreID()); + if (task_code != pdPASS) { + ESP_LOGE(TAG, "can't create task %d", task_code); + return; + } }