I am working with a NRF52 DK and I want to alter the SAADC_IRQHandler
nrfx_saadc_irq_handler
.
References:
- ..modulesnrfxsocnrfx_irqs_nrf52832.h:
#define nrfx_saadc_irq_handler SAADC_IRQHandler
- ..modulesnrfxmodulessrcnrfx_saadc.c:
void nrfx_saadc_irq_handler(void) { ... }
- ..modulesnrfxmodulesincludenrfx_saadc.h:
void nrfx_saadc_irq_handler(void);
I am using Nordic’s nrfx_saadc driver, but found a flaw for my application’s use. I am using the SAADC where a timer comparison triggers the SAMPLE task via the PPI peripheral. If I need to perform an early stop, I would like to still know how many samples were taken at that time and there is currently no accessible way for me to retrieve this value.
I see a couple options for this:
-
I can replace the PPI peripheral to just control the timer’s callback to still call a SAMPLE task on the SAADC, in this way, I can still capture the number of samples taken.
- My concern is with the power consumption. If I go this route, I am making is so the timer wakes interrupts the CPU to call the sample task whereas the PPI peripheral performs a direct write to the SAADC register and gets the interrupt from the SAADC completing the measurement only.
-
I can replace Nordic’s SAADC implementation with my own to cause the behavior I want
-
Instead of rewriting the nrf_saadc driver, I was thinking I could just overwrite the
SAADC_IRQHandler
to call:
#define app_saadc_irq_handler SAADC_IRQHandler
static uint32_t irq_iterations = 0U;
void app_saadc_irq_handler(void)
{
// capture STOPPED signal before nrfx_saadc_irq_handler clears
if (nrf_saadc_event_check(NRF_SAADC_EVENT_STARTED))
{
irq_iterations++;
}
// still perform IRQ handling
nrfx_saadc_irq_handler();
}
This would in turn allow me to control the local variable irq_iterations
for my use while still allowing the underlying SAADC driver to control as before.
What I’m struggling with is replacing the Nordic’s SAADC_IRQHandler
reference to my own instance without affecting the library files.
Is this good practice for me to do? Is there another option? Any suggestions?