break receive functionality into own function, call from dio0_task

This commit is contained in:
Morgan 'ARR\!' Allen 2020-02-21 08:59:40 -08:00
parent 9bb9eb0a41
commit 89facad220

View file

@ -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);
}
}
}