FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [December 2008 Threads] Pic32MX port pragmaticsPosted 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 pragmaticsPosted 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 pragmaticsPosted 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|