Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Queue Task Crashing - Please Help

Posted by groger57 on October 22, 2015

Hi,

My function and/or call to the queue task is crashing, and I cannot understand why. I am using the same, identical code in other applications and it works fine there. I checked the FreeRTOS config file, and all looks OK, including stack size. This is being compiled in Atollic TrueStudio. Please see below for how I am using the calls. I have tried queueing messages from different tasks, but the same result. The task I am currently calling it from cycles every 225ms, and if there's a new message to send, it places it (or tries to) on the queue. From the debug code, it never reaches there, as it appears to crash somewhere between the start of the scheduler and before queueing the message. I have also set the queue delay to some other value, i.e., ( TickType_t ) 10, but no luck there. It must be crashing before it even gets to the first call to queue, because it never prints the message just before it - see code. FreeRTOS version 8.2.0

Can someone please advise as to where the issue might be? I really need this to work, and I can't beleive that it is not functioning as it should - again, having used it in other applications I know it works very well.

Thank you!

//message task will wait forever for queue to clear

define rxQueueRATE ( portMAX_DELAY )

static void vTxQueueFunction( void *pvParameters ); QueueHandle_t xQueueTask;

//create transmit queue xQueueTask = xQueueCreate( 1, sizeof(uint8_t) ); if(xQueueTask == 0) printf("Failed to create xQueueTaskn"); if( xTaskCreate( vTxQueueFunction, "rxDataQueue", 80, NULL, 2, &xQueueTask ) != pdPASS ) printf("Cannot create queue taskn"); printf("Scheduler starting, free heap size = %in", xPortGetFreeHeapSize()); vTaskStartScheduler(); while(1) { i++; }

 ///* queue function *////

static void vTxQueueFunction( void *pvParameters ) { uint8t rxValue; portBASETYPE xStatus; for(;;) { if( uxQueueMessagesWaiting( xQueueTask ) != 0 ) { ///printf("Queue should be empty, but %i messages in queuen", uxQueueMessagesWaiting( xQueueTask ) ); }

    xStatus = xQueueReceive( xQueueTask, &rxValue, rxQueueRATE );

    if( xStatus == pdPASS )
    {
        printf("Rcvd in signal active queue: %i\n", rxValue);

        if( rxValue == 1 )
        {
        	//do this
        	printf("Received 1 in message queue\n");

        }
        else if(rxValue == 2)
        {
        	//do that
        	printf("Received 2 in message queue\n");
        }
        else
        {
        	printf("received junk\n");
        }
    }
    else
    {
        printf("Could not receive from queue\n");
    }


}

}

/* the call to queue a message */ uint8_t typeVal = 1; printf("Going to queuen"); if( xQueueSendToBack(xQueueTask, &typeVal, rxQueueRATE ) != pdPASS ) { printf("Failed to insert to queuen"); } else { printf("Queuedn"); }


Queue Task Crashing - Please Help

Posted by heinbali01 on October 22, 2015

Hi Roger,

There is probably a typo in your code:

~~~~~ //create transmit queue xQueueTask = xQueueCreate( 1, sizeof(uint8_t) ); if(xQueueTask == 0) { printf("Failed to create xQueueTaskn"); } if( xTaskCreate( vTxQueueFunction, "rxDataQueue", 80, NULL, 2, &xQueueTask ) != pdPASS ) ~~~~~

You are passing the address of 'xQueueTask' to xTaskCreate(), which wlll fill that variable with the task handle. See tasks.h for the correct syntax of xTaskCreate()

Regards.


Queue Task Crashing - Please Help

Posted by heinbali01 on October 22, 2015

Hi Roger,

A bit more about your code fragment.

Here below the queue handle is passed as a task parameter to the vTxQueueFunction. You can pass any data of the size of a pointer. In fact TaskHandle_t is also a pointer.

It also declares TaskHandle_t xTaskHandle. The address of this handle is passed to xTaskCreate which fills in the handle of the newly created task.

~~~~~ //message task will wait forever for queue to clear

define rxQueueRATE portMAX_DELAY

static void vTxQueueFunction( void *pvParameters ); TaskHandle_t xTaskHandle;

int main() { QueueHandle_t xQueueHandle;

//create transmit queue
xQueueHandle = xQueueCreate( 1, sizeof(uint8_t) );
xTaskCreate( vTxQueueFunction, "rxDataQueue", 80,
    ( void * ) xQueueHandle, 2, &xTaskHandle );

vTaskStartScheduler();

while(1)
{
    i++;
}

}

/* queue function */

static void vTxQueueFunction( void pvParameters ) { uint8t rxValue; portBASETYPE xStatus; / The queue handle has been passed as a task parameter. */ QueueHandlet xQueueHandle = ( QueueHandlet ) pvParameters;

for(;;)
{
    xStatus = xQueueReceive( xQueueHandle, &rxValue, rxQueueRATE );
    if( xStatus == pdPASS )
    {
    }
}

} ~~~~~

Regards.


Queue Task Crashing - Please Help

Posted by groger57 on October 23, 2015

Fantastic, thanks for your help. Stupid me....I was using the queue handle in the task, no wonder it was breaking!


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS