2012-10-25 07:17 AM
What is the best way to change the irqhandler to be used. I have a number of situations where the operations need to change depending on what the board is doing. Don't want to have a load of ifs or switches inside the isr, so my idea was to simply stop irq, change default handler and then resume. Is this possible?
Thanks Michael2012-10-25 08:03 AM
You'd need to place the vector table in RAM (512 byte boundary), or have multiple copies of the table in flash.
You could also keep a function pointer, and have the routine call that, adding a single indirect jump. Using a switch/case or if-else-if construct wouldn't be that inefficient.2012-10-25 10:36 AM
Thanks for the answer clive1. Would I be correct that if it was you doing it you would go with the switch, if else option
Thanks Michael2012-10-25 12:16 PM
If I have 4, or more, different behaviours I'd probably go with a switch/case
For 2 or 3, the if/elsevoid DMA2_Stream0_IRQHandler(void)
{
if (mode == 1)
{
/* Test on DMA Stream Half Transfer interrupt */
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_HTIF0))
{
/* Clear DMA Stream Half Transfer interrupt pending bit */
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_HTIF0);
// Process first half of sample buffer
}
/* Test on DMA Stream Transfer Complete interrupt */
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0))
{
/* Clear DMA Stream Transfer Complete interrupt pending bit */
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
// Process second half of sample buffer
}
}
else if (mode == 2)
{
// ..
}
else
{
// ..
}
}
2012-10-25 12:21 PM
Thank you ever so much for your help.
-Michael