Hi,
I am currenly integrating an 8051 soft core into our ASIC and we have a number of GPIO ports (which are placed in the bit addressable SFR space).
When a bit of the GPIO port is configured as an O/P
1 - Any write to the bit appears on the pin (obviously) 2 - A read of the bit returns the current value *at the pin*Item (2) seemed to make perfect sense when performing the design (and is how the PIC works), but now I have a doubt, and would like to solicit the opinion of embedded engineers which a wide breadth of H/W and S/W.
Q : When reading a GPIO bit configured as an O/P, should I return the value on the pin, or the value in the register?
In theory, these shoud be the same. However, I had a discussion with a collegue who had a bug caused by the current implementation (in a PIC based system). The GPIO pad was low current drive, and very heavily loaded, giving a very long rise time. The S/W was perfoming a write ('1') to this bit, and then to another bit in the GPIO port via a RMW (which is bit addressable registers are implemented in 8051). The RMW was performed before the first bit had reached a '1', therefore the next write cleared this bit. i.e. SETB GPIO_0 ; // Set BIT0. This is very heavily loaded O/P SETB GPIO_1 ; // Implemented in H/W as RMW. Occurrs before bit 0 has reached High, therefore // after ths instruction Bit 0 = 0, Bit 1 =
1The alternative solution would solve this problem (it would return the data that *should* be on the register). However, I am not sure I like this solution from a purely philisophical point of view i.e. Reading GPIO should return the *actual* value, not the *expected* value.
Opinions/Comments/Suggestions welcome.
Thanks,
Steven