C47D/nRF24_Component

nRF24_get_irq_flag should return all the IRQ flags

C47D opened this issue · 0 comments

C47D commented

The current nRF24_get_irq_flag() implementation doesn't work with 2 or 3 asserted IRQ flags on the STATUS register, @Boland1776 suggested changing the implementation of the nRF24_get_irq_flag() from:

nrf_irq nRF24_get_irq_flag(void)
{
    nrf_irq irq = NRF_NONE_IRQ;

    // Get the STATUS register
    uint8_t sts = nRF24_cmd_nop();

    // We only care if bits 4, 5 or 6 are set, so we mask the STATUS with 0x0111_0000
    switch (sts & NRF_ALL_IRQ_MASK) {
    case NRF_STATUS_RX_DR_MASK:
        irq = NRF_RX_DR_IRQ;
        break;
    case NRF_STATUS_TX_DS_MASK:
        irq = NRF_TX_DS_IRQ;
        break;
    case NRF_STATUS_MAX_RT_MASK:
        irq = NRF_MAX_RT_IRQ;
        break;
    default:
        irq = NRF_ALL_IRQ_MASK;
        break;
    }

    return irq;
}

to

uint8_t nRF24_get_irq_flag(void)
{
    return NRF_ALL_IRQ_MASK & nRF24_cmd_nop();
}

So the user will get all the IRQ flags and check which one is asserted like so:

int main(void)
{
   ....
   uint8_t irqs = nRF24_get_irq_flag();
   process_IRQs(irqs);
   ....
}

void process_IRQs(uint8_t irqs) {
    if (0u == irqs) {
        return;
    }

    if (irqs & NRF_TX_DS_IRQ) {
        // do something
        nRF24_clear_irq_flag(NRF_TX_DS_IRQ);
    }
    if (irqs & NRF_MAX_RT_IRQ) {
        // do something else
       nRF24_clear_irq_flag(NRF_MAX_RT_IRQ);
    }
    if (irqs & NRF_RX_DR_IRQ) {
        // do something else
       nRF24_clear_irq_flag(NRF_RX_DR_IRQ);
    }
    .....
}