randers wrote on Sunday, 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