Okay, so, I was wrong. I created another flag, and my original problem was that the queue handle was a null pointer and my initialization function was passing by copy instead of by pointer. However, I have another problem. The queue seems to max out the second I add another button to the code (thus I have a problem past sending/receiving 1 message). Thought maybe same problem, passing by copy instead of by pointer except that doesn’t seem to make any difference in queue overflow whatsoever. I’ve never had this problem before what I’ve used the queue, so not exactly sure what is going on. I thought it removed the dequeued message, right or do I have that wrong? Anyways, not including the code to toggle the LED as it is pretty standard, working and not relevant, but including my code for the queue function library and the tasks, I have the following test code (I included the pointer version, the version by copy just lacks the extra *) that is a little messy and where the LEDs are being used to debug functionality, but hopefully illustrates what’s going on :
//Snips from queue lib
typedef enum {msgSUCCESS=0, msgFAIL=-1, msgOUTOFBOUNDS,
msgFAILTOOMUCHTIME, msgFAILNULLQUEUE} msgSuccess_t;
msgSuccess_t myQueueEnqueueMsg(QueueHandle_t * xPointerTaskMsgQueue,
LED_msg_t msg)
{
//defaults to fail
msgSuccess_t msgStatus = msgFAIL;
//courtesy of FreeRTOS documentation
if ((*xPointerTaskMsgQueue) !=0)
{
if (uxQueueMessagesWaiting((*xPointerTaskMsgQueue)) >= QUEUE_MAX)
{
return msgOUTOFBOUNDS;
}
if (xQueueSendToBack( (*xPointerTaskMsgQueue), (void *) &msg, (TickType_t) 1000u) != pdPASS)
{
msgStatus = msgFAILTOOMUCHTIME;
return msgStatus;
}
else
{
msgStatus = msgSUCCESS;
return msgStatus;
}
}
else
{
msgStatus = msgFAILNULLQUEUE;
return msgStatus;
}
}
msgSuccess_t myQueueDequeueMsg(QueueHandle_t * xPointerTaskMsgQueue,
LED_msg_t * msg_ptr)
{
//defaults to fail
msgSuccess_t msgStatus = msgFAIL;
if ((*xPointerTaskMsgQueue) !=0)
{
if (uxQueueMessagesWaiting((*xPointerTaskMsgQueue)) > 0)
{
if (xQueueReceive( (*xPointerTaskMsgQueue), msg_ptr, (TickType_t) 10u) != pdPASS)
{
msgStatus = msgFAIL;
return msgStatus;
}
else
{
msgStatus = msgSUCCESS;
return msgStatus;
}
}
else
{
msgStatus = msgOUTOFBOUNDS;
return msgStatus;
}
}
else
{
msgStatus = msgFAIL;
return msgStatus;
}
}
//Snips from tasks
void taskMainControl (void * pvParameters)
{
//variable for delay length, same as FreeRTOS documentation
const TickType_t xDebounceDelay = 10 / portTICK_PERIOD_MS;
//variable for delay length, same as FreeRTOS documentation
const TickType_t xPollingDelay = 100 / portTICK_PERIOD_MS;
xPointerTaskMsgQueue = NULL;
//IMPORTANT NOTE: xPointerTaskMsgQueue is a global-scoped variable
//declared in the header file
LED_msg_t msgToSend;
msgSuccess_t msg_success;
myQueueInitMAXDeepLED(&xPointerTaskMsgQueue);
TaskHandle_t xLedBlinkHandler = NULL;
xTaskCreate(ledToggleRecieveMsgQueue,
"Created Main Handler",
configMINIMAL_STACK_SIZE,
NULL,
0,
&xLedBlinkHandler);
while(1)
{
for(uint8_t i = 1; i < 4; i++)
{
//statement to see if button is active
if(readButtonStatus(i) == 1) //1 just means 'true' here
{
uint8_t is_button_pressed = i;
vTaskDelay(xDebounceDelay);
if(readButtonStatus(is_button_pressed) == 1) //verify change before continuing
{
uint8_t button_pressed = is_button_pressed;
//statement for button 1, create led blink tasks
if(button_pressed == 1)
{
msgToSend = DECREASE;
msg_success = myQueueEnqueueMsg(&xPointerTaskMsgQueue, msgToSend);
if (msg_success == msgFAILTOOMUCHTIME)
{
ledToggleTaskHelper(500, 1);
}
if (msg_success == msgFAILNULLQUEUE)
{
ledToggleTaskHelper(500, 4);
}
} //end of if for button 1
//handler for button 2 press
else if (button_pressed == 2)
{
msgToSend = INCREASE;
msg_success = myQueueEnqueueMsg(&xPointerTaskMsgQueue, msgToSend);
if (msg_success == msgFAILTOOMUCHTIME)
{
ledToggleTaskHelper(500, 1);
}
if (msg_success == msgOUTOFBOUNDS)
{
ledToggleTaskHelper(500, 4);
}
} //end of if for button 2
else {} //do-nothing default
} //end of debounce
} //end of button number check
vTaskDelay(xPollingDelay); //delay for polling
} //end of for loop for button poll
} //end of while loop for task
} //end of task
//second nested task
void ledToggleRecieveMsgQueue (void * pvParameters)
{
unsigned long int delayLength = 500;
LED_msg_t msg;
myQueueDequeueMsg(&xPointerTaskMsgQueue, &msg);
if (msg == DECREASE && delayLength >= 200)
{
ledToggleTaskHelper (500, 2);
}
else if (msg == INCREASE && delayLength <= 1000)
{
ledToggleTaskHelper (500, 3);
}
else
{
}
} //end of while
}