Quality RTOS & Embedded Software

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




Loading

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:
PORTA = ptALL_OFF; PORTASET = uxLEDBit; PORTACLR = uxLEDBit; // ...
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!"

Ralf

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.

ralf


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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