Post by Isaac M. BavarescoIt works well if you are only setting or clearing bits, but if you need
to do both (clearing some bits and setting others) then it takes more
instructions also.
Then you only need 2 instructions.
Post by Isaac M. BavarescoAtomicity is not the same thing as RMW. RMW happens when you are reading
the pins and setting the latches in the same instruction.
Yes it is not the same thing as for reading, modifying and writing back port
registers for 8 or 16 bit PICs
but REGISTER.BIT=value for a PIC32 is actually a
non atomic Read, Modify and Write set of operations. If you do this on a register
that holds e.g. interrupt flags for several interrupts, you can accidentally clear an
interrupt flag that has been set by the hardware just after you have read the
register but before it is written back. This is actually an error that is pretty hard
to debug since it can only
happen in a very narrow time space. You can also
accidentally set an interrupt flag i
f you have a higher priority interrupt
interrupting a lower priority interrupt just when it clears its interrupt flag which
can cause the higher priority interrupt to be executed again when it shouldn't.
Post by Isaac M. BavarescoThe problems caused by atomicity/interrupts can be solved by disabling
the offending interrupts during the operation. It usually is not a
problem because the operation can take just a few instructions and the
interrupt jitter introduced can be just a few micro- or nano-seconds.
A critical section will only help when it is software only that is involved (software
clearing interrupt flags) but it will not help when hardware is also involved (software
clearing interrupt flag inside a critical section will not stop the hardware to set
another interrupt flag in the same register). Only atomicity will help for that.
/Ruben
Post by Isaac M. BavarescoIf you are not accessing a whole byte, the correct way to set/clear/invert bits in an sfrregister for a PIC32 without affecting other bits in the same register is to use the SET, CLR or INV offset addresses for the register and a mask.
It works well if you are only setting or clearing bits, but if you need
to do both (clearing some bits and setting others) then it takes more
instructions also.
Post by Isaac M. BavarescoEven though the REGISTER.BIT=value construct can be used it takes more instructions and is not atomic for a PIC32 (as it is for 8 and 16 bit PICS).
If you use REGISTER.BIT=value you can get caught by the Read Modify Write problem (because it is not atomic).
Atomicity is not the same thing as RMW. RMW happens when you are reading
the pins and setting the latches in the same instruction. Older PIC16Fs
only have the PORT register, so when you do PORTx |= Value, the
processor reads the *pins*, does the OR and then writes the result back
to the output latch register. If some pin is heavily capacitance-loaded
then RMW is more probable.
The newer PIC16F, PIC18F, PIC24/dsPIC and PIC32 all have the LATx
registers, that solves the RMW problem. It is still possible do RMW on
the PORTx registers and suffer from RMW issues, but then it is a
programmer's option.
Post by Isaac M. BavarescoThis is true for registers where bits can be changed from both hardware and software (e.g. interrupt flags for several interrupts that sharesthe same register) and where several interrupts and/or main code accesses bits in the same register.
Look in the header file for your processor to see the correct mask definitions for individual bits. You can OR several mask definitions to manipulate several bits in one instruction.
The problems caused by atomicity/interrupts can be solved by disabling
the offending interrupts during the operation. It usually is not a
problem because the operation can take just a few instructions and the
interrupt jitter introduced can be just a few micro- or nano-seconds.
Cheers,
Isaac
---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership opt