Quality RTOS & Embedded Software

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


Loading

Using Queue in several c files.

Posted by Mohammad on February 24, 2012
Hallo everyone!

i want to use a queue in two different c files and in one of it is ISR and from it i am sending an queue item.
but the task in the another c file cannot receive the item in this queue.

did anybody know what can be the problem?

i hope someone can help me in answering this.

Regards,
Mohammad

RE: Using Queue in several c files.

Posted by Mohammad on February 24, 2012
for more details:

i am working on MSP430f5438 with CC.

in the hal_usb.c i added this code to the ISR and the ISR is now:

#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR (void)
{
char cChar= NULL;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
cChar = UCA1RXBUF;
xQueueSendFromISR( xPROTQueue, &cChar, &xHigherPriorityTaskWoken );
__bic_SR_register_on_exit(LPM3_bits);
}

the xQueueSendFromISR stops and dont send the queue.
with the debugging tool i find out that the code stops at the following part in queue.c:

signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition )
{
signed portBASE_TYPE xReturn;
unsigned portBASE_TYPE uxSavedInterruptStatus;

configASSERT( pxQueue );


i hope that it is now more clear and some one can explain what the is problem.

RE: Using Queue in several c files.

Posted by Richard on February 24, 2012
If the assert is failing then pxQueue must be NULL. Are you creating the queue before the interrupt tries to use it?

Regards.

RE: Using Queue in several c files.

Posted by Mohammad on February 24, 2012
Hi richard,

yes, i am creating it bevor the interrupt tries to use it.
the creation as i said is done in the other c file. in which i placed the receiving task too.

RE: Using Queue in several c files.

Posted by Richard Damon on February 24, 2012
Since the code is in two files, make sure the queue handle is in a global and both files are accessing the same exact variable. if a file declares that handle as static, or inside of a function, then the other file will use a different version of the variable even if they have the same name.

there should probably be an extern declaration in a header they both include, and a global definition in just one file.

RE: Using Queue in several c files.

Posted by Mohammad on February 24, 2012
thank you a lot for your reply.

i declare the variable as extern in the hal_usb.c and i write the defintion in the other c file.
now it works for the first sending and receiving and then it stops for abother problem due to micro controller i think.

thanks again.

Regards.
Mohammad

RE: Using Queue in several c files.

Posted by Mohammad on February 25, 2012
Hallo again,

i have now a new problem:

after sending the first queue item, the application stops in the next sending at this line of code in tasks.c :

if( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ tskIDLE_PRIORITY ] ) ) > ( unsigned portBASE_TYPE ) 1 )

did any one have an ideaa, why this is happening?

thanx again a lot for the previos answers.

Regards,
Mohammad


RE: Using Queue in several c files.

Posted by Paul Coleman on February 27, 2012
Is your problem caused by the fact that you are not returning xHigherPriorityTaskWoken from your ISR? I had a similar problem where a task wasn't responding to a queue and it was because I didn't understand how that mechanism works and therefore the task was not getting unblocked. My ISRs all have the following format...

__attribute__((__noinline__))
portBASE_TYPE IntHandlerNonNaked(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

portENTER_CRITICAL();
xQueueSendFromISR(..., &xHigherPriorityTaskWoken);
portEXIT_CRITICAL();

return xHigherPriorityTaskWoken; // this does actually get used!!!!
}

__attribute__((__naked__))
void IntHandler(void)
{
portENTER_SWITCHING_ISR();
IntHandlerNonNaked();
portEXIT_SWITCHING_ISR();
}

It looks as though return xHigherPriorityTaskWoken doesn't actually get used but it does!!! The macro portEXIT_SWITCHING_ISR retrieves the value directly from the register. All of this is port specific so you need to check the demo for your particular architecture.

Paul.

RE: Using Queue in several c files.

Posted by Mohammad on March 15, 2012
thanx a lot Paul.

RE: Using Queue in several c files.

Posted by Christian on March 15, 2012
Thanks

RE: Using Queue in several c files.

Posted by Mohammad on April 27, 2012
Hallo Everyone again,

i tried your suggestion Paul, but it did not work.

did anyone have an idea, how to use the queue from isr?
here is my code, that cosing problems:

#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
portBASE_TYPE xHigherPriorityTaskWoken= pdFALSE;
char ReceivedByte;
ReceivedByte = UCA1RXBUF;
xQueueSendFromISR( xprotReceiveByteQueue, &ReceivedByte, &xHigherPriorityTaskWoken );
__bic_SR_register_on_exit(LPM3_bits);
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}

RE: Using Queue in several c files.

Posted by Mohammad on April 29, 2012
can anyone help in this topic?

RE: Using Queue in several c files.

Posted by rafleury on April 30, 2012
What is the current problem? You jumped around a bit there. Can you still send and recieve only one time?

RE: Using Queue in several c files.

Posted by Nathan Wiebe on May 1, 2012
Can you post a simplified version of the two files? It is probably something obvious to an experienced user of FreeRTOS. Try to hack out any application-specific code until you have nothing but the creation and reception from your queue in one file and the ISR in the other. If you can do that without your error going away, I would be happy to look at your code... :)

RE: Using Queue in several c files.

Posted by Mohammad on May 2, 2012
i think, i found the reason for the problem now.

it was not detected stackoverflow, the freertos could not find it out every time it happend.

here is the code:

the receiving task:

void SemaphorTestTask(void *pvParameters)
{
int count=0;
char ReceivedByte;
for( ;; )
{

if (xQueueReceive(xPROTQueue,&ReceivedByte,portMAX_DELAY)== pdPASS)
{
halLcdPrintSingleChar('P',0);
++ count;
if (count == 136)
{
halLcdClearScreen();
halLcdPrintLine( " www.FreeRTOS.org", 0, OVERWRITE_TEXT );
count=0;
}
}
}
}

and here ist the ISR:

#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
char ReceivedByte;
ReceivedByte = UCA1RXBUF;
xQueueSendFromISR(xPROTQueue,&ReceivedByte,&xHigherPriorityTaskWoken );
__bic_SR_register_on_exit(LPM3_bits);
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}

this implementation is working without any problem.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner