xQueueReceive Blocks application on LPC2129
i have an application where, a message is posted from an ISR using call “xQueueSendToBackFromISR” which is done successfully. but a task which is waiting on queue to receive the message posted from ISR, blocks the whole application once it receives the message posted from ISR and the application hangs.
xQueueReceive Blocks application on LPC2129
following code shows the creation of task & queue, posting and receiving of queue.
Task waiting on queue: serialRecvTask
Isr Posting message : UART0_Recv_Interrupt_Handler
Message Queue created: serialRecvQueue ************************************
typedef struct _serialRecvQueue
{
unsigned char cmd; }SERIAL_RECV_QUEUE;
************************************* /////##### Task ‘serialRecvTask’ and queue ‘serialRecvQueue’ are created here in main function. ################################ Main function creating Task and queue #########################################
int main(void)
{
APP_SHARED_DATA appSharedData;
int i; initTarget(); //xTaskCreate(ledTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainLED_TASK_PRIORITY + 5, ( xTaskHandle * ) NULL );
// xTaskCreate(serialOutTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY, ( xTaskHandle * ) NULL );
// xTaskCreate(keyTask, “NAME”, configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY + 7, ( xTaskHandle * ) NULL );
// xTaskCreate(adcTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 6, ( xTaskHandle * ) NULL );
// xTaskCreate(dummyTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 4, ( xTaskHandle * ) NULL );
xTaskCreate(serialRecvTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 8, ( xTaskHandle * ) NULL );
// xTaskCreate(canMsgProcessTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 9, ( xTaskHandle * ) NULL );
// xTaskCreate(canControlTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 8, ( xTaskHandle * ) NULL ); /* Create Queue for Serial Input */
serialRecvQueue = xQueueCreate(5, sizeof(SERIAL_RECV_QUEUE));
if(serialRecvQueue == 0)
{
putstr(”Could NOT create serialRecvQueue”);
putchar(’n’);
}
} //##################################################################################### ################ Task waiting on Queue #####################################3 void serialRecvTask(void* pvParameters)
{
SERIAL_RECV_QUEUE recvSerialCmd;
unsigned char levelSensorVal = 0;
unsigned char resistanceVal = 0;
pvParameters = pvParameters; while(1)
{
printf(”Serial Recv Task: Waiting on Queuen”);
//if(xQueueReceive(serialRecvQueue, (void *)&recvSerialCmd, portMAX_DELAY))//If can be taken off as task gets blocked
if(xQueueReceive(serialRecvQueue, (void *)&recvSerialCmd, 1000))//If can be taken off as task gets blocked
{
printf(”Serial Recv Task: Received Msg=%cn”, recvSerialCmd.cmd);
#if 0
switch(recvSerialCmd.cmd)
{
case 0x31:{
printf(”%c%c”, recvSerialCmd.cmd, levelSensorVal++);
levelSensorVal = levelSensorVal % 253;
break;
}
case 0x32:{
printf(”%c%c”, recvSerialCmd.cmd, resistanceVal++);
resistanceVal = resistanceVal % 253;
break;
}
default:{
printf(”%c%c”, recvSerialCmd.cmd, 0xFF);
break;
}
}
#endif
} vTaskDelay(10); // May not be required
} } #################################################################################### //################ Interrupt posting Queue Message ##########################/
void UART0_Recv_Interrupt_Handler(void){ unsigned char recvdChar;
SERIAL_RECV_QUEUE recvdMsg; portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE; recvdChar = U0RBR;
recvdChar = ‘
Isr Posting message : UART0_Recv_Interrupt_Handler
Message Queue created: serialRecvQueue ************************************
typedef struct _serialRecvQueue
{
unsigned char cmd; }SERIAL_RECV_QUEUE;
************************************* /////##### Task ‘serialRecvTask’ and queue ‘serialRecvQueue’ are created here in main function. ################################ Main function creating Task and queue #########################################
int main(void)
{
APP_SHARED_DATA appSharedData;
int i; initTarget(); //xTaskCreate(ledTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainLED_TASK_PRIORITY + 5, ( xTaskHandle * ) NULL );
// xTaskCreate(serialOutTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY, ( xTaskHandle * ) NULL );
// xTaskCreate(keyTask, “NAME”, configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY + 7, ( xTaskHandle * ) NULL );
// xTaskCreate(adcTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 6, ( xTaskHandle * ) NULL );
// xTaskCreate(dummyTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 4, ( xTaskHandle * ) NULL );
xTaskCreate(serialRecvTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 8, ( xTaskHandle * ) NULL );
// xTaskCreate(canMsgProcessTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 9, ( xTaskHandle * ) NULL );
// xTaskCreate(canControlTask, “NAME”, configMINIMAL_STACK_SIZE, (void *)&appSharedData, mainCHECK_TASK_PRIORITY + 8, ( xTaskHandle * ) NULL ); /* Create Queue for Serial Input */
serialRecvQueue = xQueueCreate(5, sizeof(SERIAL_RECV_QUEUE));
if(serialRecvQueue == 0)
{
putstr(”Could NOT create serialRecvQueue”);
putchar(’n’);
}
} //##################################################################################### ################ Task waiting on Queue #####################################3 void serialRecvTask(void* pvParameters)
{
SERIAL_RECV_QUEUE recvSerialCmd;
unsigned char levelSensorVal = 0;
unsigned char resistanceVal = 0;
pvParameters = pvParameters; while(1)
{
printf(”Serial Recv Task: Waiting on Queuen”);
//if(xQueueReceive(serialRecvQueue, (void *)&recvSerialCmd, portMAX_DELAY))//If can be taken off as task gets blocked
if(xQueueReceive(serialRecvQueue, (void *)&recvSerialCmd, 1000))//If can be taken off as task gets blocked
{
printf(”Serial Recv Task: Received Msg=%cn”, recvSerialCmd.cmd);
#if 0
switch(recvSerialCmd.cmd)
{
case 0x31:{
printf(”%c%c”, recvSerialCmd.cmd, levelSensorVal++);
levelSensorVal = levelSensorVal % 253;
break;
}
case 0x32:{
printf(”%c%c”, recvSerialCmd.cmd, resistanceVal++);
resistanceVal = resistanceVal % 253;
break;
}
default:{
printf(”%c%c”, recvSerialCmd.cmd, 0xFF);
break;
}
}
#endif
} vTaskDelay(10); // May not be required
} } #################################################################################### //################ Interrupt posting Queue Message ##########################/
void UART0_Recv_Interrupt_Handler(void){ unsigned char recvdChar;
SERIAL_RECV_QUEUE recvdMsg; portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE; recvdChar = U0RBR;
recvdChar = ‘