Commit fc3f0adbd672ce93689710ad8af4af159f2e211a
authorHenrik Lipskoch <forschung@khlipskoch.de>
Mon, 11 Nov 2019 08:38:47 +0000 (09:38 +0100)
committerHenrik Lipskoch <forschung@khlipskoch.de>
Mon, 11 Nov 2019 08:38:47 +0000 (09:38 +0100)
simavr/sim/sim_vcd_file.c

index c0d27674341d9d09ad82c1ff468ba990b94ff67b..14f63d6b72f65fd04ea8efca118c29299bea3c13 100644 (file)
@@ -264,7 +264,8 @@ avr_vcd_init_input(
                        continue;
 
                if (!strcmp(keyword, "$timescale")) {
-                       double cnt = 0;
+                       // sim_vcd header allows only integer factors of us: 1us, 2us, 3us, 10us, 15us, ...
+                       uint64_t cnt = 0;
                        char *si = v->argv[1];
 
                        vcd->vcd_to_us = 1;
@@ -274,9 +275,26 @@ avr_vcd_init_input(
                                si++;
                        if (si && !*si)
                                si = v->argv[2];
-               //      if (!strcmp(si, "ns")) // TODO: Check that,
-               //              vcd->vcd_to_us = cnt;
-               //      printf("cnt %dus; unit %s\n", (int)cnt, si);
+                       if (!strcmp(si, "ns")) {
+                               if (cnt%1000==0) {
+                                       // save for conversion
+                                       cnt/=1000;
+                                       vcd->vcd_to_us = cnt;
+                               } else {
+                                       perror("Cannot convert timescale from ns to us without loss of precision");
+                                       return -1;
+                               }
+                       } else if (!strcmp(si, "us")) {
+                               // no calculation here
+                               vcd->vcd_to_us = cnt;
+                       } else if (!strcmp(si, "ms")) {
+                               cnt*=1000;
+                               vcd->vcd_to_us = cnt;
+                       } else if (!strcmp(si, "s")) {
+                               cnt*=1000000;
+                               vcd->vcd_to_us = cnt;
+                       }
+                       // printf("cnt %dus; unit %s\n", (int)cnt, si);
                } else if (!strcmp(keyword, "$var")) {
                        const char *name = v->argv[4];