From: Jakob Gruber Date: Wed, 29 Aug 2012 12:16:59 +0000 (+0200) Subject: ioport: Restore PIN to PORT values when DDR is set to output X-Git-Tag: v1.0~11 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=a367ebb0e3cb1b8325d4a0e6a8d616238852a7d4;p=sx%2Fsimavr.git ioport: Restore PIN to PORT values when DDR is set to output --- diff --git a/simavr/sim/avr_ioport.c b/simavr/sim/avr_ioport.c index 6e0966e..24a8a9b 100644 --- a/simavr/sim/avr_ioport.c +++ b/simavr/sim/avr_ioport.c @@ -61,7 +61,8 @@ static void avr_ioport_pin_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t /* * This is a the callback for the DDR register. There is nothing much to do here, apart - * from triggering an IRQ in case any 'client' code is interested in the information. + * from triggering an IRQ in case any 'client' code is interested in the information, + * and restoring all PIN bits marked as output to PORT values. */ static void avr_ioport_ddr_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param) { @@ -69,6 +70,14 @@ static void avr_ioport_ddr_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t avr_raise_irq(p->io.irq + IOPORT_IRQ_DIRECTION_ALL, v); avr_core_watch_write(avr, addr, v); + + const uint8_t oldpin = avr->data[p->r_pin]; + const uint8_t pin = (oldpin & ~v) | (avr->data[p->r_port] & v); + avr_core_watch_write(avr, p->r_pin, pin); + for (int i = 0; i < 8; i++) + if (((oldpin ^ pin) >> i) & 1) + avr_raise_irq(p->io.irq + i, (pin >> i) & 1); + avr_raise_irq(p->io.irq + IOPORT_IRQ_PIN_ALL, pin); } /*