newbie needs semaphore & queue example

gloin34 wrote on Thursday, May 29, 2008:

I m currently working with at91sam7x-ek dev board. I saw the freertos demo for IAR and I succesfully modified it for my own 5 tasks, simply flashing leds, controlling buttons now. I want to try the queue and semaphore in order to get usart or can peripheral messages, but semaphore and queue files in demo seemed to me very complex to understand. Could someone send me a basic example about getting messages by semaphores or queues?

regards,

gloin34 wrote on Thursday, May 29, 2008:

Hello,

I want to send part of my code;

void Usart_c_irq_handler(void)
{
    xSemaphoreParameters *pxParameters;
    volatile unsigned portLONG *pulSharedVariable, ulExpectedValue;
    static portBASE_TYPE xHigherPriorityTaskWoken;
   
    xSemaphoreGiveFromISR( pxParameters->xSemaphore, &xHigherPriorityTaskWoken );
}

static void vUsart0( void *pvParameters )
{
    volatile unsigned long pio_pdsr;
    AT91PS_USART USART_pt = AT91C_BASE_US0;
    unsigned int status;
    xSemaphoreParameters *pxParameters;
    volatile unsigned portLONG *pulSharedVariable, ulExpectedValue;
   
    for( ;; )
    {
        if( xSemaphoreTake( pxParameters->xSemaphore, 100 ) == pdTRUE )
        {
            //* get Usart status register
        status = USART_pt->US_CSR;
          if ( status & AT91C_US_RXRDY){
        //* Get byte and send
        AT91F_US_PutChar (USART_pt, AT91F_US_GetChar(USART_pt));
        }

        if ( status & AT91C_US_OVRE) {
        //* clear US_RXRDY
        AT91F_US_GetChar(USART_pt);
        AT91F_US_PutChar (USART_pt, ‘O’);
        }

        //* Check error
        if ( status & AT91C_US_PARE) {
         AT91F_US_PutChar (USART_pt, ‘P’);
        }

        if ( status & AT91C_US_FRAME) {
         AT91F_US_PutChar (USART_pt, ‘F’);
        }

        if ( status & AT91C_US_TIMEOUT){
        USART_pt->US_CR = AT91C_US_STTTO;
        AT91F_US_PutChar (USART_pt, ‘T’);
        }

        //* Reset the satus bit
        USART_pt->US_CR = AT91C_US_RSTSTA;  
        } 
    }
}

void vSemTask( unsigned portBASE_TYPE uxPriority )
{
    AT91PS_USART USART_pt = AT91C_BASE_US0;
    unsigned int status;
 
    xSemaphoreParameters *pxFirstSemaphoreParameters;
    const portTickType xBlockTime = ( portTickType ) 100;
   
    /* Create the structure used to pass parameters to the first two tasks. */
    pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
   
    if( pxFirstSemaphoreParameters->xSemaphore != NULL )
    {
        /* Create the variable which is to be shared by the first two tasks. */
        pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned portLONG * ) pvPortMalloc( sizeof( unsigned portLONG ) );

            if( pxFirstSemaphoreParameters->xSemaphore != NULL )
        { 
                /* Initialise the share variable to the value the tasks expect. */
            *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;

                /* The first two tasks do not block on semaphore calls. */
            pxFirstSemaphoreParameters->xBlockTime = ( portTickType ) 0;

            /* Spawn the first two tasks.  As they poll they operate at the idle priority. */
            xTaskCreate( vUsart0, ( signed portCHAR * ) "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, uxPriority, ( xTaskHandle * ) NULL );   
        }
     }
   
}

with this code I m trying to get a binary semaphore, and let it run vUsart0 task. I m getting "Error[Pe167]: argument of type "long *" is incompatible with parameter of type "signed long"

Could someone enlighten me?

Regards,
Cirith

davedoors wrote on Thursday, May 29, 2008:

Which line does the error relate to?

gloin34 wrote on Thursday, May 29, 2008:

the error is on this line,

xSemaphoreGiveFromISR( pxParameters->xSemaphore, &xHigherPriorityTaskWoken );

in the Usart_c_irq_handler.

davedoors wrote on Thursday, May 29, 2008:

That error does not make sense. The parameter is of type "signed portBASE_TYPE *", which on your system would be "signed long *", but the error is saying it should be of type "signed long". Are you sure it does not say should be of type "signed long *"? If so, can you just just change the declaration of the variable to signed long from just long.

Its not normal for a compiler to warn about that. Which compiler are you using?

gloin34 wrote on Thursday, May 29, 2008:

I m using IAR 4.0 Kickstart, I changed the isr code like this;

void Usart_c_irq_handler(void)
{
    AT91PS_USART USART_pt = AT91C_BASE_US0;
    xSemaphoreParameters *pxParameters;
    volatile unsigned portLONG *pulSharedVariable, ulExpectedValue;
    static portBASE_TYPE xHigherPriorityTaskWoken;
   
    xSemaphoreGiveFromISR( pxParameters->xSemaphore, pdFALSE);
    USART_pt->US_CR = AT91C_US_RSTSTA;
}

the rest of code is same as I already sent, after this modif. I send something from the hyperterminal and my leds stop flashing (controlled by the other tasks), when I checked with the debugger, it stopped on the undefined vector address. So something began  happening:) if you have a simple code for a semaphore, I think I can get the idea.