Please find the complete source code,
void USART2_IRQHandler(void)
{
uint8_t data;
while ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError | kUSART_RxFifoFullFlag) & USART_GetStatusFlags(USART2))
{
data = USART_ReadByte(USART2);
if (((rxHeadIndex + 1) % BUFFER_SIZE) != rxTailIndex)
{
rxBuffer[rxHeadIndex] = data;
rxHeadIndex++;
rxHeadIndex %= BUFFER_SIZE;
if( '\r' == data )
{
//METHOD-1 (xSemaphoreGiveFromISR)
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(usarrcvDataSemaphore, &xHigherPriorityTaskWoken);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
//METHOD-2 (xTaskResumeFromISR) (Even tried this also)
//BaseType_t xHigherPriorityTaskWoken = pdFALSE;
//xTaskNotifyFromISR(LMCScComRcvTask_handle, 0, eNoAction, &xHigherPriorityTaskWoken);
break;
}
}
}
SDK_ISR_EXIT_BARRIER;
}
void usart_init()
{
USART_GetDefaultConfig(&usart2_config);
usart2_config.baudRate_Bps = 115200U;
usart2_config.enableTx = true;
usart2_config.enableRx = true;
usart2_config.parityMode = kUSART_ParityDisabled;
usart2_config.stopBitCount = kUSART_OneStopBit;
USART_Init(USART2, &usart2_config, USART2_CLK_FREQ);
USART_EnableInterrupts(USART2, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
EnableIRQ(USART2_IRQn);
}
void usartRcvTask(void *voidPtrParameters)
{
for(;;)
{
if(xSemaphoreTake(usarrcvDataSemaphore, portMAX_DELAY) == pdTRUE)
{
// process the received data
}
}
return;
}
void usart_receiveTask_init()
{
xTaskCreate(usartRcvTask, (const char*) "usartRcv", 1024, NULL, 4, NULL);
}
int main()
{
NVIC_SetPriority(USART2_IRQn, 3);
usart_init();
usart_receiveTask_init();
// Start the scheduler so the created tasks start executing
vTaskStartScheduler();
/* The control never reaches here as the scheduler will now be running.
If the control reaches here, then it is likely that there was an
insufficient heap available for the idle task to be created. */
for(;;);
return 0;
}