Skip to content

Commit

Permalink
reduce task switching latency
Browse files Browse the repository at this point in the history
  • Loading branch information
dernasherbrezon committed Dec 1, 2024
1 parent 6faeb13 commit 77114fe
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 108 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_*
```
19 changes: 11 additions & 8 deletions examples/receive_fsk/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions examples/receive_fsk_beacon/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions examples/receive_fsk_filtered/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions examples/receive_fsk_fixed/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
15 changes: 9 additions & 6 deletions examples/receive_lora/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
19 changes: 11 additions & 8 deletions examples/receive_lora_fhss/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
15 changes: 9 additions & 6 deletions examples/receive_lora_implicit_header/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
19 changes: 11 additions & 8 deletions examples/receive_ook/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions examples/transmit_fsk/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
19 changes: 11 additions & 8 deletions examples/transmit_fsk_fixed/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit 77114fe

Please sign in to comment.