A few questions on goto-statements, encapsulation, etc
I am working with the STM32F405 microcontroller and I am trying to have a software UART use the same interrupt line (
EXTI15_10_IRQn) as other interrupts (for example, button press interrupts). In a perfect world, my code would look something like this:
void EXTI15_10_IRQHandler(void) {
clearInterruptFlag();
if (EXTI->PR & 0x0400) {
receiveUARTbyte();
} else if (
EXTI->PR & 0x0800) {
handleButtonPress();
} else if (
EXTI->PR & 0x1000) {
handleOtherExternalInterrupt();
}
}
However, I need to run the UART at a high speed (115200 Baud) and the system clock at a low speed (to save power). This means I can't use the stack in the interrupt routine, because pushing stuff onto the stack will make me miss the first UART-bit. So, instead of a calling a function, I need to do something else. We all learned in school that we should try to encapsulate our code as much as possible and that's why I don't want a full software UART implementation inside the interrupt routine. I could create a software interrupt (NVIC->STIR) to a dummy interrupt (with more urgent priority than
EXTI15_10_IRQn
) to transfer control to my UART.c file, but isn't there a lot of overhead associated with that? Could I use a goto instead? If so, can I use a goto without locking myreceiveUARTbyte
() function to a specific address? In other works, can I goto a 'global' goto-label somehow? Other thoughts about solving this and at the same time having well-encapsulated code (except using macros)?
