biker126 wrote on Tuesday, October 02, 2007:
hi all!
I got a problem with task switch after posting a msg into a queue. I have a simple task called "myTask" that executes every 10 OS ticks and posts a msg into a queue:
void myTask( void* pvParameters)
{
portTickType xLastWakeTime;
const portTickType xFrequency = 10;
uint16 ui16_webMessage = 0x00;
xLastWakeTime = xTaskGetTickCount();
for (;
{
// not sure if that’s needed. maybe when debugging?
if (xLastWakeTime < xTaskGetTickCount())
{
xLastWakeTime = xTaskGetTickCount();
}
vTaskDelayUntil( &xLastWakeTime, xFrequency );
ui16_webMessage = 0xC074;
xQueueSendToBack(msg2WebTask, (void*) &ui16_webMessage, (portTickType)0);
numberOfMsgs = uxQueueMessagesWaiting(msg2WebTask);
portYIELD();
}
}
the other task is reading from the queue with:
if (xQueueReceive(msg2WebTask, (void*) &ui16_webMessage, (portTickType) configTICK_RATE_HZ / 2))
in the main() I create the queue with: msg2WebTask = xQueueCreate(5, sizeof(uint16));
when I debug the programm, that is set a breakpoint at "portYIELD()", then the programm seems to get "trapped" inside the "myTask" function (maybe thats just an GDB problem?). the "myTask" just filles the queue until its full…
when I set a breakpoint at the line where I receive the msg’s then the queue is already full when I get there for the first time! (initial breakpoint is at start of main, then i jump to the queue-receive and the queue is already full!!!)
so it seems to me that there’s a problem with scheduling after the msg has been posted into the queue.
I’ve set the priority of the receiver task higher (actually highest overall) than the priority of the sending task (2nd highest overall). so if I understand it right the receiver task should get scheduled first (at startup), read the queue, its empty, block on w8ing for the queue.
then the sending task is scheduled, puts a msg into queue, context switch to w8ing receiver task…
but as it seem’s thats not what’s happening…
does anyone got an idea what is "messing up" the scheduling? maybe the sending task aint blocking at the "DelayUntil"? or the receiver task doesnt get scheduled at start? (and thus aint w8ing for the queue?) or anything else? :-/
thanks in advance
D. Holzwarth