Hi list,

the PINx (e.g. PINB, PIND, ...) register holds the input state of the
port pins. This is independent of the DDRx settings.
The register itself is simulated/updated, but not so the VCD trace.

See the attached example that toggles PB1. Compile with

> avr-gcc -g -mmcu=atmega644 -std=gnu11 -O2 -Wall -Wextra -Werror -o 
> pinx-not-traced.elf pinx-not-traced.c

and run simulavr like so

> simulavr --device atmega644 --file pinx-not-traced.elf --terminate exit -c 
> vcd:tracein.txt:pinx-not-traced.vcd

For convenience, I've attached GTKWave screenshots with the bug ("fail")
and with the fix ("pass"). (Other pins being read as '1' is fine because
they are floating/output stage is in tristate, which is converted to '1'
after the simulated/implied Schmitt-trigger)

The fix is a one line change updating the tracer of the PINx register,
see the attached patch file.

(There are more bugs in HWPort and related to the PINx register, and
I'll create separate bug reports for them. This patch is a prerequesite
for the others patches though.)

Cheers,
panic
>From 58be1e2c012cf5fa3d1e3dc26f7c2ab441fbf8f3 Mon Sep 17 00:00:00 2001
From: panic <li...@xandea.de>
Date: Mon, 5 Jun 2017 03:44:09 +0200
Subject: [PATCH] update PINx tracer on portpin update

---
 src/hwport.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/hwport.cpp b/src/hwport.cpp
index 662a47a..ab4c4f8 100644
--- a/src/hwport.cpp
+++ b/src/hwport.cpp
@@ -99,6 +99,7 @@ void HWPort::CalcOutputs(void) { // Calculate the new output value to be transmi
         pintrace[actualBitNo]->change(p[actualBitNo].outState);
     }
     pin = tmpPin;
+    pin_reg.hardwareChange(pin);
 }
 
 string HWPort::GetPortString(void) {
-- 
2.1.4

#include <avr/io.h>
#include <inttypes.h>

int
main(void)
{
  DDRB = _BV(PB1);
  for (uint8_t i = 0; i < 10; ++i)
    PORTB ^= _BV(PB1);
  return 0;
}

Attachment: pinx-not-traced_fail.vcd
Description: application/vnd.gtkwave-vcd

Attachment: pinx-not-traced_pass.vcd
Description: application/vnd.gtkwave-vcd

+ PORTB.PIN
+ PORTB.PORT
+ PORTB.B1-Out
_______________________________________________
Simulavr-devel mailing list
Simulavr-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/simulavr-devel

Reply via email to