FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [March 2015 Threads]
I have a task which is monitoring the status of two push buttons. Called SwitchTask:
while(1) {
//
// Poll the debounced state of the buttons.
//
ui8CurButtonState = ButtonsPoll(0, 0);
//
// Check if previous debounced state is equal to the current state.
//
if(ui8CurButtonState != ui8PrevButtonState)
{
ui8PrevButtonState = ui8CurButtonState;
//
// Check to make sure the change in state is due to button press
// and not due to button release.
//
if((ui8CurButtonState & ALL_BUTTONS) != 0)
{
if((ui8CurButtonState & ALL_BUTTONS) == LEFT_BUTTON)
{
ui8Message = LEFT_BUTTON;
ui8MessageToScreen = LEFT_BUTTON;
//
// Guard UART from concurrent access.
//
xSemaphoreTake(g_pUARTSemaphore, portMAX_DELAY);
UARTprintf("Left Button is pressed.\n");
xSemaphoreGive(g_pUARTSemaphore);
}
else if((ui8CurButtonState & ALL_BUTTONS) == RIGHT_BUTTON)
{
ui8Message = RIGHT_BUTTON;
ui8MessageToScreen = RIGHT_BUTTON;
//
// Guard UART from concurrent access.
//
xSemaphoreTake(g_pUARTSemaphore, portMAX_DELAY);
UARTprintf("Right Button is pressed.\n");
xSemaphoreGive(g_pUARTSemaphore);
}
//
// Pass the value of the button pressed to LEDTask.
//
if(xQueueSend(g_pScreenButtonQueue, &ui8MessageToScreen, portMAX_DELAY) !=
pdPASS)
{
//
// Error. The queue should never be full. If so print the
// error message on UART and wait for ever.
//
UARTprintf("\nScreen Queue full. This should never happen.\n");
while(1)
{
}
}
if(xQueueSendToFront(g_pScreenButtonQueue, &ui8Message, portMAX_DELAY) !=
pdPASS)
{
//
// Error. The queue should never be full. If so print the
// error message on UART and wait for ever.
//
UARTprintf("LED Queue full. This should never happen.\n");
while(1)
{
}
}
}
}
//
// Wait for the required amount of time to check back.
//
vTaskDelayUntil(&ui16LastTime, ui32SwitchDelay / portTICK_RATE_MS);
}
I haev tried xQueueSend, xQueueSendToFront and xQueueSendToBack. The Queues are initialized like this:
g_pLEDQueue = xQueueCreate(5, sizeof(uint8_t));
g_pScreenButtonQueue = xQueueCreate(5, sizeof(uint8_t));
However only the Screen Task actually receives . They are called like this:
if(xQueueReceive(g_pScreenButtonQueue, &i8MessageFromButton,10) == pdPASS) {
// Does stuff
}
if(xQueueReceive(g_pLEDQueue , &i8Message,10) == pdPASS) {
// Does stuff
}
I have tired butting 0 and 10.
If I swap the order of the If statements for the send then it works. Any ideas?
The code you posted never sends on the g_pLEDQueue queue.
Yes that is why. I feel so dumb
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.