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

question about static and volatile

Posted by natanel on August 12, 2007
Hi

I just started using freeRTOS and I have few questions

1) if I want to keep the value of an array between task switch
that the array will have the same values after task return

what is the best way to do it
I am using "static" right now, is it ok?

2) I am almost sure that those values are not pushed to the stack (array can be very big)
so were exactly they are kept between calls?

3) reading examples I found that parameters sent to task use memory allocation
when does it is exactly needed? way?
for example telling task to ran with delay of N msec.
do it need to be used by parameters sending with memory allocation?

do I need to use parameters with memory allocation for solving question number 1 ?

4) finally "volatile". on which variables it should be used
does the array from 1 should be declared as volatile to keep its data between task switch?
does all the variables in a task should be volatile?

thanks

RE: question about static and volatile

Posted by Richard on August 13, 2007
> 1) if I want to keep the value of an array between task switch
> that the array will have the same values after task return
>
> what is the best way to do it
> I am using "static" right now, is it ok?


If the array is declared on the stack then it will automatically have the same value between context switches - but be aware that the stack must be dimensioned to be large enough to hold the array.

If you declare the array static then it will not be on the stack, but will retain its value because it is just a block of memory. Be aware doint this though that the code will not be reentrant. It will only hold its value if no other tasks write to the array.

> 2) I am almost sure that those values are not pushed to the
> stack (array can
> be very big)
> so were exactly they are kept between calls?


Wherever your linker places the array in your RAM. Look at the map generated by the build if you need to know where this is.


> 3) reading examples I found that parameters sent to task use
> memory allocation

Some examples do this, it is not mandatory.


> when does it is exactly needed? way?
> for example telling task to ran with delay of N msec.
> do it need to be used by parameters sending with memory allocation?

You do not need to pass anything in if you don't need to.


> do I need to use parameters with memory allocation for
> solving question number
> 1 ?

No.

>
> 4) finally "volatile". on which variables it should be used
> does the array from 1 should be declared as volatile to keep
> its data between
> task switch?
> does all the variables in a task should be volatile?

The array need not be declared volatile unless values in it are going to be changed in a way that is unexpected by the sequential flow of your program - for example, by another task or by an interrupt. This is just the normal use of the volatile qualifier.

Regards.

RE: question about static and volatile

Posted by natanel on August 13, 2007
Hi

1) may I be more specific

I am using two task
one filling an array (with high priority) from the ADC
and the other read from the array (lower priority)

the writing task must be accurate and put new data every msec
the reading task should read data every msec (if there is a new one)

what will be the right way to handle it in the freeRTOS

right now the array is declared as
Static in the first task
and
extern in the second one

is it ok?

2) I want to learn when the "volatile" is uses
is there any link for examples explain when it should be used and when not.

3) can you advice for a link which give concept of good programming at RTOS
(already read the one in the freeRTOS)

Thankas

RE: question about static and volatile

Posted by sashiono on August 14, 2007
I would use a queue to pass data between tasks, this prevents any data corruption. in addition the read task can block while data is not ready.

look at how the serial code works, you should try to do it in a similar style.

RE: question about static and volatile

Posted by natanel on August 15, 2007
so if I want the writer to keep in the queue only the last updated data
not considering if the reader read the data

how to do it

writer:
check queue is empty
yes -> write data
no -> read to empty queue -> write new data

reader:


RE: question about static and volatile

Posted by natanel on August 15, 2007
sorry

so if I want the writer to keep in the queue only the last updated data
not considering if the reader read the data

how do I do it?

writer:
check if queue is empty
yes -> write data
no -> read in order to empty queue -> write new data

reader:
read. if queue us empty? wait N tick

thanks


[ 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