Fellows,
I am studying two situations here to which I am unsure how safe is the interrupt behaviour. Although they are two questions, I'll leave them together are they are somewhat related and quite specific...
First, inside the typical interrupt service routines:
void UARTInt_U5Handler(void) { uint32_t ui32Status; ui32Status = MAP_UARTIntStatus(UART5_BASE, true); // Get interrupt status /* What if the original IRQ was RX, and right now a TX happens? */ MAP_UARTIntClear(UART5_BASE, ui32Status); // Clear interrupts if ((ui32Status & UART_INT_RX) || (ui32Status & UART_INT_RT)) // Rx interrupt flag was set { while(MAP_UARTCharsAvail(UART5_BASE)) { pc_UARTInt_RxBuf[5][ui32_UARTInt_RxRec[5]] = MAP_UARTCharGet(UART5_BASE); ui32_UARTInt_RxRec[5]++; ui32_UARTInt_RxRec[5]%=UARTINT_RXBUFSIZE; ui32_UARTInt_RxFlag[5] = true; } } if (ui32Status & UART_INT_TX) // Tx interrupt flag was set { TransmitMoreBytesFromTxBuffer(); } }
What if the next interrupt event happens exactly between the int status read and the clearing? Will I clear the unserviced bit and ignore it forever, correct? It's usually good to post a question, as adding a FIFO level check on the second if() will make sure that the second situation is still serviced, but I'll appreciate if someone can confirm that the TX event would actually be missed with the code above.
The second one is: if I briefly enable the interrutpt for a certain peripheral, and right away disables it, will these few clock cycles in the middle be enough to let code detour to ISR? Is there a risk that some sort of optimization prevents that?
HWREG(UART0_BASE + UART_O_IM) &= ~(UART_INT_TX | UART_INT_RX | UART_INT_RT); // Disable UARTInt ExecuteCriticalTask1(); HWREG(UART0_BASE + UART_O_IM) |= (UART_INT_TX | UART_INT_RX | UART_INT_RT); // Re-enable UARTInt /* Is this interval enough to detour code in case the UART interrupt flags were set? */ HWREG(UART0_BASE + UART_O_IM) &= ~(UART_INT_TX | UART_INT_RX | UART_INT_RT); // Disable UARTInt ExecuteCriticalTask2(); HWREG(UART0_BASE + UART_O_IM) |= (UART_INT_TX | UART_INT_RX | UART_INT_RT); // Re-enable UARTInt
Thanks for the attention!
Bruno