dmh3006 wrote on Tuesday, June 16, 2015:
Hi.
I have a queue between 2 tasks in which one writes certain commands to it and the other reads it (one is an application, the other is the task responsible for the display).
The tasks App sends a command to the task Display. Everything works well and it does as desired. After this the task Display waits for 5 seconds for a new command, if none is received it switches the display off and waits indefinitely for a new command on the queue.
This last part is where my program crashes as it “immediately” (I can’t determine the exact time but as soon as I do a step over in debug it goes to the HardFault_Handler).
I check my main task App data structure and its values remain correct. I cast the xQueueHandle to xQUEUE * and its values are also correct (I’m only checking its length value and size of each item value).
The issue seems to be the xQueueReceived line after a command has been given.
However I’ve verified the code and I’m unable to find any fault whatsoever with it.
Both tasks are allocated 2KB of ram which do not even come close to fully using (the task App consumes the most ram and uses at most 640bytes) so I’ve ruled out stack overflow.
The task App has a priority of tskIDLE_PRIORITY and the task Display has a priority of tskIDLE_PRIORITY+2.
void taskDisplay(xQueueHandle queue)
{
bool previousCommand = false;
uint16_t color;
portTickType time = configTICK_RATE_HZ * TIME_TO_DISPLAY_OFF;
DisplayCommand command;
signed portBASE_TYPE queueResult;
for (;;){
queueResult = xQueueReceive(queue,(void *)&command,previousCommand ? time : portMAX_DELAY);
if (queueResult == errQUEUE_EMPTY){
Display_Backlight(false);
previousCommand = false;
} else {
switch (command.command){
case DISPLAY_ON:
Display_WriteStr(command.DisplayOnData.lineTemps,font6x8,DISPLAY_ON_FIRST_LINE,FOREGROUND_COLOR,BACKGROUND_COLOR);
Display_WriteStr(command.DisplayOnData.lineDate,font6x8,DISPLAY_ON_SECOND_LINE,FOREGROUND_COLOR,BACKGROUND_COLOR);
Display_Backlight(true);
previousCommand = true;
break;
case DISPLAY_WRITE_LINE:
Display_ClearLine(command.DisplayWriteLineData.line,font6x8);
Display_WriteStr(command.DisplayWriteLineData.lineText,font6x8,command.DisplayWriteLineData.line,FOREGROUND_COLOR,BACKGROUND_COLOR);
Display_Backlight(true);
strncpy(internalBuffer[command.DisplayWriteLineData.line-1],command.DisplayWriteLineData.lineText,NUM_CHAR_PER_LINE);
previousCommand = false;
break;
case DISPLAY_HIGHLIGHT_LINE:
color = command.DisplayHighlightLineData.highlight ? HIGHLIGHT_COLOR : BACKGROUND_COLOR;
if (command.DisplayHighlightLineData.useInternalBuffer){
Display_WriteStr(internalBuffer[command.DisplayHighlightLineData.line-1],font6x8,command.DisplayHighlightLineData.line,FOREGROUND_COLOR,color);
} else {
Display_WriteStr(command.DisplayHighlightLineData.lineText,font6x8,command.DisplayHighlightLineData.line,FOREGROUND_COLOR,color);
strncpy(internalBuffer[command.DisplayHighlightLineData.line-1],command.DisplayHighlightLineData.lineText,NUM_CHAR_PER_LINE);
}
previousCommand = false;
break;
case DISPLAY_CLEAR:
Display_Backlight(command.DisplayClearData.turnOffDisplay);
if (command.DisplayClearData.firstLineToClear == 1 && command.DisplayClearData.lastLineToClear == 16){
Display_Clear(BACKGROUND_COLOR);
} else {
for (int i = command.DisplayClearData.firstLineToClear; i <= command.DisplayClearData.lastLineToClear; i++){
Display_ClearLine(i,font6x8);
}
}
previousCommand = false;
break;
}
}
}
}