Hi,

Klaus Rudolph:
> Hi again,
> 
>> Example:
>> SBI of bit 0 in PINB register should toggle (xor) PORTB.PB0. Using RMW
>> approach, we read PINB = 0xff (because DDRB is input/tristate, read as
>> '1' for each pin), we OR the bitmask (1<<0)=1 on top of it (=0xff) and
>> write it back to PINB, *which toggles all PORTB bits* --> bug.
> 
> PINB register is read only. What you want to achieve?

for many years already, AVR have a PIN toggle feature, for example
ATmega644 datasheet says:

> 12.2.2    Toggling the Pin
> Writing a logic one to PINxn toggles the value of PORTxn, independent on the 
> value of DDRxn.
> Note that the SBI instruction can be used to toggle one single bit in a port.

This makes toggling a pin a 2 cycle/single instruction operation instead
of IN/EOR/OUT.

Simulavr in principle also supports this, although in a buggy way when
using SBI instead of LDI/OUT. Just look at the implementation of HWPort
in hwport.cpp. When I look through git-blame, the feature was introduced
by Thomas K on 2009-12-04, commit 3f6a6882:

>     HWPort: new features PIN toggle PORT and variable port size
>     
>     This change adds also usage of HWPort in python interface (but usefull for
>     debugging only) and sets the right size and type of ports in ATtiny2313.

Cheers,
panic

_______________________________________________
Simulavr-devel mailing list
Simulavr-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/simulavr-devel

Reply via email to