dnewby wrote on Friday, December 04, 2015:
FRTOS v8.2.0
DEV HW: Freescale TWR-K60D100M (ARM Cortex M4)
I have a simple producer consumer set up:
Producer and Consumer task priorities are equal.
void vMsgProducerTask(task_param_t pvParameters)
{
char message[MSG_SIZE];
printf(“starting producer task\n\r”);
uint32_t x = 0;
for(;
{
sprintf(message,“Message # %d”,x);
printf(“producing message %d\n\r”,x);
CHECK_ERR(OSA_MsgQPut(msgQ1_handle,message) != kStatus_OSA_Success);
x++;
OSA_TimeDelay(3000);
}
OSA_TaskBlock();
}
void vMsgConsumerTask(task_param_t pvParameters)
{
char message[MSG_SIZE];
printf("\n\rstarting consumer task\n\r");
for(;
{
memset(message,0,MSG_SIZE);
CHECK_ERR(OSA_MsgQGet(msgQ1_handle,message,OSA_WAIT_FOREVER) != kStatus_OSA_Success);
printf(“consuming message: %s\n\r”,message);
}
OSA_TaskBlock();
}
int main(void)
{
hardware_init();
TaskCreate(CONSUMER);
TaskCreate(PRODUCER);
vTaskStartScheduler();
}
OSA_MsgQPut() maps to xQueueSendToBack()
OSA_MsgQGet() maps to xQueueReceive()
So when this code is ran, the following happens:
- Consumer task starts, blocks waiting for message. Queue adds consumer task to xTasksWaitingToReceive.
- Producer task starts, creates message. uxMessagesWaiting increments. Producer task yields.
- Consumer task resumes. Consumer task runs and blocks for new message.
- Producer task resumes. Break before generating message. This time, the queue has added the producer task to the xTasksWaitingToReceive list.
In xTaskRemoveFromEventList(), the xEventListItem next and previous values are 0’s and this causes a hard fault in uxListRemove().
I would think that the consumer task should be added to the waiting list for the message queue (as was done in the first iteration), but the producer task was added instead. And the producer task doesnt need to wait for the queue…
Any thoughts, suggestions, etc for this?