PINA instead of INA
Alexander (Sandy) Hapgood
Posts: 360
Wouldn't it make sense to rename INA and INB to PINA and PINB?
TEST MASK, INA doesn't seem intuitive to me when I'm monitoring the output state of a pin from another cog. Wouldn't TEST MASK, PINA be clearer?
Sandy
TEST MASK, INA doesn't seem intuitive to me when I'm monitoring the output state of a pin from another cog. Wouldn't TEST MASK, PINA be clearer?
Sandy
Comments
It's assumed that an INput or an OUTput or DIRection are associated to an I/O pin so PINA, POUTA, or PDIRA are not used and may not convey the same meaning as you might think to others.
-Phil
-Phil
Oh, wait, is BIN reserved?
IN0, IN1, IN2, IN3
OUT0, OUT1, OUT2, OUT3
DIR0, DIR1, DIR2, DIR3
But then we'd have Spin expressions like OUT0[1] and OUT1[0]. 'Dunno: is there potential there for confusion?
-Phil
That actually looks pretty nice.
INx holds the current value of the pin regardless of whether it's an input or an output so why not call it what it is.
Pin 0 will always be the first thing that comes to my mind if you go with IN0, OUT0 and DIR0.
I'm just learning PASM so I need things to be as simple and intuitive as possible haha.
Sandy
That looks best, I think. Any dissenters?
-Phil
It's in OUR minds here, but probably in nobody else's.
-Phil
For the P8X32A, INx registers are read-only so Phil's concerns should be adequately addressed if the P2 'PINx' registers are read-only as well.
Sandy
-Phil
Recent changes has split IN and OUT to their own addresses on the P2. So there are 14 special registers now. The two index registers, 4x IN, 4x OUT, and 4X DIR.
Roy
Ah so. The original advantage of combining them was that it permitted them to be directly addressable without resorting to special instructions, given the limted address space for SFRs. Has this advantage now been negated?
-Phil
Andy
Early on, I analyzed nearly a thousand PASM programs for OUTx usage. In only two or three cases did I find OUTx used in the source field of an instruction, and those could easily have been modified to eliminate that usage. For that reason, it seemed reasonable to combine OUTx and INx to share addresses, since the context of their usage completely determined which physical register was being addressed. The direct advantage for the P2 was that they could then all fit in the 16-register SFR block and be accessed by normal instructions (e.g. and outa,mask). I guess it's not clear to me what changed.
-Phil
If the compiler isn't smart enough to turn that into a single OR instruction you get something like this:
But it's different for high level languages. Also in Spin1 if you do someting like: !OUTA[5] or OUTA[9..6] := %1011, the Spin interpreter reads the OUTx register and calculates the new bit states with shifting and masking. How will you do that without knowng the OUTA bit states. With the combined PINx registers there was no way to read the output-latches, so you need to hold a copy in a register and update the PINx and the pseudeo OUTx which complicates that instructions.
Andy
Edit: Okay David was faster..
What if DIRA is not set up so that the bit you are trying to OR is not set as an output?
would seem to do what you want, assuming dira is set up to output on $100
With a separate OUTA, you would likely read the "shadow register", or $100, and write out $100 to the pins - clobbering any other outputs active in the cog.
IMHO, the best solution is have the compiler generate
OR pinsa,#$100
(which still would not work if DIRA is not set up correctly)
- should we do the operation based on what the cog was trying to output
- or based on the current state of the pins, which may have been modified due to ORing other cogs outputs, or an external signal
-Phil
Definitly the first option.
With all the modes we can choose on the Prop2 pins (drive strength, open drain..) there are many possibilties that you read not the same state at the input as you have in the output latch.
Say task1 uses bit 5 of OUTA and task2 want to change bit 0..3 of OUTA. Task1 sets OUTA[5] to high, but the pin is an open drain and driven low by an external device. Now when Task2 does an AND OUTA,#%1111 for example the OUTA[5] gets cleared, so task2 messes with the bits of task1.
Andy