USART2_IRQHandler

This ISR is also slightly more involved since it is required to keep track of the position in a queue:

  1. Private globals are used by USART2_IRQHandler because they need to be accessible by both the ISR and used by both USART2_IRQHandler  and startReceiveInt:
static bool rxInProgress = false;
static uint_fast16_t rxLen = 0;
static uint8_t* rxBuff = NULL;
static uint_fast16_t rxItr = 0;
  1. The same paradigm for storing xHigherPriorityTaskWoken and SEGGER SystemView tracing is used in this ISR, just like in the last example:
void USART2_IRQHandler( void )
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
SEGGER_SYSVIEW_RecordEnterISR();
  1. Next, errors are checked by reading the overrun (ORE), noise error (NE), framing error (FE), and parity error (PE) bits in the interrupt state register (USART2->ISR). 

If an error is present, it is cleared by a write to the interrupt clear register (USART2->ICR) and the rxDone semaphore is given. It is the responsibility of the caller code to check the number of bits in the buffer by looking at the rxItr variable (shown in the next code block) to ensure the correct number of bits were successfully received:


if( USART2->ISR & ( USART_ISR_ORE_Msk |
USART_ISR_NE_Msk |
USART_ISR_FE_Msk |
USART_ISR_PE_Msk ))
{
USART2->ICR |= (USART_ICR_FECF |
USART_ICR_PECF |
USART_ICR_NCF |
USART_ICR_ORECF);
if(rxInProgress)
{
rxInProgress = false;
xSemaphoreGiveFromISR(rxDone,
&xHigherPriorityTaskWoken);
}
}
  1. Next, the ISR checks whether a new byte has been received (by reading the RXNE bit of USART2->ISR). If a new byte is available, it is pushed into the rxBuff buffer and the rxItr iterator is incremented. 

After the desired number of bytes have been added to the buffer, the rxDone semaphore is given to notify uartPrintOutTask:

if( USART2->ISR & USART_ISR_RXNE_Msk)
{
uint8_t tempVal = (uint8_t) USART2->RDR;
if(rxInProgress)
{
rxBuff[rxItr++] = tempVal;
if(rxItr >= rxLen)
{
rxInProgress = false;
xSemaphoreGiveFromISR(rxDone, &xHigherPriorityTaskWoken);
}
}
}
SEGGER_SYSVIEW_RecordExitISR();
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);

Don't forget to put a breakpoint in the ISR to make sure it is being called.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.69.152