Using Queue in several c files.

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

Using Queue in several c files.

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.

Using Queue in several c files.

If the assert is failing then pxQueue must be NULL.  Are you creating the queue before the interrupt tries to use it? Regards.

Using Queue in several c files.

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.

Using Queue in several c files.

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.

Using Queue in several c files.

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

Using Queue in several c files.

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 ) ) > ( unsigned portBASE_TYPE ) 1 ) did any one have an ideaa, why this is happening? thanx again a lot for the previos answers. Regards,
Mohammad

Using Queue in several c files.

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.

Using Queue in several c files.

thanx a lot Paul.

Using Queue in several c files.

Thanks

Using Queue in several c files.

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 );
}

Using Queue in several c files.

can anyone help in this topic?

Using Queue in several c files.

What is the current problem?  You jumped around a bit there.  Can you still send and recieve only one time? 

Using Queue in several c files.

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… :)

Using Queue in several c files.

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.