Quality RTOS & Embedded Software

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




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists