From 89facad2201679fbdd6543f5ee4a9c793bfb13b3 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Fri, 21 Feb 2020 08:59:40 -0800 Subject: [PATCH] break receive functionality into own function, call from dio0_task --- main/esp32-lora.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/main/esp32-lora.c b/main/esp32-lora.c index 62fa6ea..ec30995 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -261,6 +261,19 @@ void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t d) { lora32_write_reg(lora, REG_MODEM_CONFIG_1, (lora32_read_reg(lora, REG_MODEM_CONFIG_1) & 0xF1) | (cr << 1)); } +static void lora32_handle_receive(lora32_cfg_t *lora) { + uint8_t len = lora32_read_reg(lora, (lora->implicitHeader ? REG_PAYLOAD_LENGTH : REG_RX_NB_BYTES)); + ESP_LOGD(TAG, "lora32_dio0_task packet length: %d", len); + + // TODO: set FIFO address to RX address + uint8_t fifo_addr = lora32_read_reg(lora, REG_FIFO_RX_CURRENT_ADDR); + ESP_LOGD(TAG, "lora32_dio0_task current FIFO address: %d", fifo_addr); + + lora32_write_reg(lora, REG_FIFO_ADDR_PTR, fifo_addr); + + lora->receive(len); +} + static void IRAM_ATTR lora32_dio0_task(void *arg) { lora32_cfg_t *lora = (lora32_cfg_t*)arg; ESP_LOGD(TAG, "starting DIO0 handler task"); @@ -280,17 +293,9 @@ static void IRAM_ATTR lora32_dio0_task(void *arg) { ESP_LOGD(TAG, "clearing irqs"); lora32_write_reg(lora, REG_IRQ_FLAGS, irqs); + // is this the right check? seems to work but looks off if((irqs & IRQ_RX_DONE_MASK) == IRQ_RX_DONE_MASK) { - uint8_t len = lora32_read_reg(lora, (lora->implicitHeader ? REG_PAYLOAD_LENGTH : REG_RX_NB_BYTES)); - ESP_LOGD(TAG, "lora32_dio0_task packet length: %d", len); - - // TODO: set FIFO address to RX address - uint8_t fifo_addr = lora32_read_reg(lora, REG_FIFO_RX_CURRENT_ADDR); - ESP_LOGD(TAG, "lora32_dio0_task current FIFO address: %d", fifo_addr); - - lora32_write_reg(lora, REG_FIFO_ADDR_PTR, fifo_addr); - - lora->receive(len); + lora32_handle_receive(lora); } } }