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

Atomic like operation (or disble irq)

Posted by Thomas Johansen on February 24, 2012
Hi forum

In my case, I have the classic example of task updating variables, that are used in a different task,
I know the variable update is "atomic" if the variable can be updated in one instruction. (8, 16 or 32 bit)

But in my system I do have 16 bit SDRAM interface, so updating a 32 bit variable, would require more then one instruction.
Or am I wrong about that??

I could, of course use the macros portENTER_CRITICAL and portEXIT_CRITICAL. I would like to avoid this because the variables are written and read often.

When doing the the write and read operation on them I could also disable interrupts. But is that allowed by FreeRTOS? Wouldn't that make the scheduler run unexpected?

Thomas

RE: Atomic like operation (or disble irq)

Posted by David Brown on February 24, 2012
If your cpu is capable of reading and writing 32-bit at a time, then such accesses are atomic - regardless of the width of the memory (unless you have multiple bus masters, and a DRAM controller that splits up such accesses, but that's highly unlikely).

Remember, of course, that only each read or write of each variable is atomic - read/modify/write operations are not atomic on most cpus (though they /are/ atomic on some CISC cpus), and there is no guarantee of atomicity when accessing multiple variables.

Look at the generated assembly code for the source code in question - then you can easily see what instructions are used.

RE: Atomic like operation (or disble irq)

Posted by Thomas Johansen on February 24, 2012
Hi

My CPU is 32 bit. Its a ARM Cortex M3,

I could look at the ASM code generated. But if the used instruction doesn't make the operation atomic?

Also, If need to write variable >32 bit (Could be strings or structs, than I need to do something atomic.

So is using portENTER_CRITICAL and portEXIT_CRITICAL the only way in FreeRTOS

Im using the LPC1788 CPU

Thomas

RE: Atomic like operation (or disble irq)

Posted by Dave on February 24, 2012
If the task is updated in one task, and only used (read, not written) in the other task, then you don't need any mutual exclusion provided the width of the variable is equal to the natural word size of the CPU. In this case the word size is 32 bits, so if your variable is 32 bits then you should be ok without anything.


RE: Atomic like operation (or disble irq)

Posted by Dave on February 24, 2012
Oops. Meant if the variable is updated in one task.

RE: Atomic like operation (or disble irq)

Posted by Richard Damon on February 24, 2012
As it has been said, bus cycle atomisity isn't needed if you have instruction level atomisity unless you have something else that might access the memory (like a multiprocessor system).

If you have a 32 bit processor, and the memory signals that it is only 16 bits wide, it is quite possible that the processor will do the access atomically.

portENTER/EXIT_CRITICAL is the normal way of doing this and is fairly light weight, but if you need to be even faster you could use an interrupt disable/enable pair (which is similar to what what the CRITICAL macros use) if:

1) You know you are not inside a CRITICAL section, or you know that your method is not incompatible with nesting with the CRITICAL section macros (they try to only mask interrupt that might interact with FreeRTOS so there MAY be another way to disable interrupts that can nest with the CRITICAL section macros)

2) You disable interrupt time is short enough that you are not going to unacceptably impact interrupts that the critical section macros leave enabled.

Disabling/Enabling the interrupts will not impact the tick interrupt/scheduler any more than the critical section macros will. The impact that is there is the reason you need to keep critical sections short.


[ 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