Quality RTOS & Embedded Software

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


Loading

newbie needs semaphore & queue example

Posted by Cirith on 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,

RE: newbie needs semaphore & queue example

Posted by Cirith on 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



RE: newbie needs semaphore & queue example

Posted by Dave on May 29, 2008
Which line does the error relate to?

RE: newbie needs semaphore & queue example

Posted by Cirith on May 29, 2008

the error is on this line,

xSemaphoreGiveFromISR( pxParameters->xSemaphore, &xHigherPriorityTaskWoken );

in the Usart_c_irq_handler.

RE: newbie needs semaphore & queue example

Posted by Dave on 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?

RE: newbie needs semaphore & queue example

Posted by Cirith on 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.


[ 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