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


Pic32MX port pragmatics

Posted by Ralf Anders on December 21, 2008
By analyzing the Pic32 demo I found lines as follows in the demo source partest.c:
This means direct access to the SFR's.
Each access results in three machine instuctions. So it is not atomic.
So, why direct SFR-access is commented with
"Use of the ... register removes the need to use a critical section"?

In the official documentation "Pic32 Family Reference Manual 61132B" is to find:
"A write to a PORT register writes to the corresponding LAT register (PORT data latch)." ...
"A write to a PORT register is the effectively the same as a write to a LAT register."

So I think "PORTA = value;" is effectively the same as "LATA = value".
(Although the resulting machine instructions are not identical!)
Confirming that, isn't it more pragmatic, to use the library functions, documented in
"32-bit-Peripheral-Library-Guide" and implemted in "...\pic32mx\include\peripheral\ports.h"
with defines like
#define mPORTAWrite(_lat) (LATA = (unsigned int)(_lat))

Conclusio: I would prefer to use "mPORTAWrite(value);" instead of "PORTA = value;".
And I need the confirmation: "It is effectively the same!"


RE: Pic32MX port pragmatics

Posted by Dave on December 21, 2008
Using the set and clear registers means you write just the bits you want to set or clear. There is no read modify write operation so there is no mutual exclusion issue. It will work even if the operation is interrupted by another task or an interrupt.

RE: Pic32MX port pragmatics

Posted by Ralf Anders on December 22, 2008
I originally wanted to critisize, that the comment "...removes the need to use a critical section.." could lead to the opinion,
that (only) the special statement "PORTA = value;" is the right way.
For someone, who is new to a CPU/MCU/OS, it is important to understand the "little differences".
But I can not see effective differences between "PORTA = value;", "LATA = value;" and finally "mPORTAWrite(value);".
So I think, in all these ways there is no need for a critical section. (This is by MCU-design...)
And finally, "thinking abstract, thinking in C" I find "mPORTAWrite(value);" is the best pragmatic way for "putting
some LEDs on/off". And of course mPORTASetBits(), mPORTAClearBits(), mPORTAToggleBits(), ...
That is, what I want to have confirmed.


[ 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