Commit 83a52cd4b71baa8b4a0c3af63f5237fa6629af41
authorMichel Pollet <buserror@gmail.com>
Fri, 17 Feb 2017 09:56:18 +0000 (09:56 +0000)
committerMichel Pollet <buserror@gmail.com>
Fri, 17 Feb 2017 09:58:24 +0000 (09:58 +0000)
Simplifed the whole operation

Signed-off-by: Michel Pollet <buserror@gmail.com>
4 files changed:
simavr/sim/avr/avr_mcu_section.h
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h
simavr/sim/sim_vcd_file.c

index cb52dd74f791e6f12e2fc5811c862bec2f60b707..fd4edc1d479ff6c279197863e3575e64e489b324 100644 (file)
@@ -110,7 +110,7 @@ struct avr_mmcu_vcd_trace_t {
 #define AVR_MCU_STRING(_tag, _str) \
        const struct avr_mmcu_string_t _##_tag _MMCU_ = {\
                .tag = _tag,\
-               .len = sizeof(_str),\
+               .len = sizeof(struct avr_mmcu_string_t) - 2,\
                .string = _str,\
        }
 /*
@@ -124,7 +124,7 @@ struct avr_mmcu_vcd_trace_t {
 #define AVR_MCU_LONG(_tag, _val) \
        const struct avr_mmcu_long_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\
                .tag = _tag,\
-               .len = sizeof(uint32_t),\
+               .len = sizeof(struct avr_mmcu_long_t) - 2,\
                .val = _val,\
        }
 
@@ -203,10 +203,14 @@ struct avr_mmcu_vcd_trace_t {
  * port as a character, and not a pointer to a register.
  * AVR_MCU_VCD_PORT_PIN('B', 5);
  */
-#define AVR_MCU_VCD_PORT_PIN(_port, _pin) \
-       AVR_MCU_LONG(AVR_MMCU_TAG_VCD_PORTPIN, \
-               (((unsigned long)((_port)&0xff) << 8) | \
-               ((_pin)&0xff)));
+#define AVR_MCU_VCD_PORT_PIN(_port, _pin, _name) \
+       const struct avr_mmcu_vcd_trace_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\
+               .tag = AVR_MMCU_TAG_VCD_PORTPIN, \
+               .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\
+               .mask = _port, \
+               .what = (void*)_pin, \
+               .name = _name, \
+       }
 
 /*!
  * These allows you to add a trace showing how long an IRQ vector is pending,
@@ -216,11 +220,11 @@ struct avr_mmcu_vcd_trace_t {
 
 #define AVR_MCU_VCD_IRQ_TRACE(_vect_number, __what, _trace_name) \
        const struct avr_mmcu_vcd_trace_t DO_CONCAT(DO_CONCAT(_, _tag), __LINE__) _MMCU_ = {\
-       .tag = AVR_MMCU_TAG_VCD_IRQ, \
-       .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\
-       .mask = _vect_number, \
-       .what = (void*)__what, \
-       .name = _trace_name, \
+               .tag = AVR_MMCU_TAG_VCD_IRQ, \
+               .len = sizeof(struct avr_mmcu_vcd_trace_t) - 2,\
+               .mask = _vect_number, \
+               .what = (void*)__what, \
+               .name = _trace_name, \
        };
 #define AVR_MCU_VCD_IRQ(_irq_name) \
        AVR_MCU_VCD_IRQ_TRACE(_irq_name##_vect_num, 1, #_irq_name)
index 595652caade1e5681cdec67de99f534134c1ee87..991fb4991dad60459cb73f94008476f8c11e2899 100644 (file)
@@ -103,7 +103,7 @@ avr_load_firmware(
        avr_set_console_register(avr, firmware->console_register_addr);
 
        // rest is initialization of the VCD file
-       if (firmware->tracecount == 0 && firmware->traceportcount == 0)
+       if (firmware->tracecount == 0)
                return;
        avr->vcd = malloc(sizeof(*avr->vcd));
        memset(avr->vcd, 0, sizeof(*avr->vcd));
@@ -115,20 +115,20 @@ avr_load_firmware(
        AVR_LOG(avr, LOG_TRACE, "Creating VCD trace file '%s'\n",
                        avr->vcd->filename);
 
-       for (int ti = 0; ti < firmware->traceportcount; ti++) {
-               avr_irq_t * irq = avr_io_getirq(avr,
-                               AVR_IOCTL_IOPORT_GETIRQ(firmware->traceport[ti].port),
-                               firmware->traceport[ti].pin);
-               if (irq) {
-                       char name[16];
-                       sprintf(name, "%c%d", firmware->traceport[ti].port,
-                                       firmware->traceport[ti].pin);
-                       avr_vcd_add_signal(avr->vcd, irq, 1, name);
-               }
-       }
-
        for (int ti = 0; ti < firmware->tracecount; ti++) {
-               if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_IRQ) {
+               if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_PORTPIN) {
+                       avr_irq_t * irq = avr_io_getirq(avr,
+                                       AVR_IOCTL_IOPORT_GETIRQ(firmware->trace[ti].mask),
+                                       firmware->trace[ti].addr);
+                       if (irq) {
+                               char name[16];
+                               sprintf(name, "%c%d", firmware->trace[ti].mask,
+                                               firmware->trace[ti].addr);
+                               avr_vcd_add_signal(avr->vcd, irq, 1,
+                                       firmware->trace[ti].name[0] ?
+                                               firmware->trace[ti].name : name);
+                       }
+               } else if (firmware->trace[ti].kind == AVR_MMCU_TAG_VCD_IRQ) {
                        avr_irq_t * bit = avr_get_interrupt_irq(avr, firmware->trace[ti].mask);
                        if (bit && firmware->trace[ti].addr < AVR_INT_IRQ_COUNT)
                                avr_vcd_add_signal(avr->vcd,
@@ -233,13 +233,14 @@ elf_parse_mmcu_section(
                                                break;
                                        }
                        }       break;
+                       case AVR_MMCU_TAG_VCD_PORTPIN:
                        case AVR_MMCU_TAG_VCD_IRQ:
                        case AVR_MMCU_TAG_VCD_TRACE: {
                                uint8_t mask = src[0];
                                uint16_t addr = src[1] | (src[2] << 8);
                                char * name = (char*)src + 3;
                                AVR_LOG(NULL, LOG_TRACE,
-                                               "AVR_MMCU_TAG_VCD_TRACE %04x:%02x - %s\n",
+                                               "VCD_TRACE %d %04x:%02x - %s\n", tag,
                                                addr, mask, name);
                                firmware->trace[firmware->tracecount].kind = tag;
                                firmware->trace[firmware->tracecount].mask = mask;
@@ -248,14 +249,6 @@ elf_parse_mmcu_section(
                                        sizeof(firmware->trace[firmware->tracecount].name));
                                firmware->tracecount++;
                        }       break;
-                       case AVR_MMCU_TAG_VCD_PORTPIN: {
-                               firmware->traceport[firmware->traceportcount].pin = src[0];
-                               firmware->traceport[firmware->traceportcount].port = src[1];
-                               printf("trace PORT %c pin %d\n",
-                                               firmware->traceport[firmware->traceportcount].port,
-                                               firmware->traceport[firmware->traceportcount].pin);
-                               firmware->traceportcount++;
-                       }       break;
                        case AVR_MMCU_TAG_VCD_FILENAME: {
                                strcpy(firmware->tracename, (char*)src);
                        }       break;
index 6a6b490ea8def794be06626f4d7a0f42de09f816..c58dcf1c534c7212824b66e5a1c29748037a3d84 100644 (file)
@@ -54,11 +54,6 @@ typedef struct elf_firmware_t {
                uint16_t addr;
                char    name[64];
        } trace[32];
-       int traceportcount;
-       struct {
-               char port;
-               int8_t pin;
-       } traceport[16];
 
        struct {
                char port;
index 0999db3ae6ffbec01ecf2c59ccf03449cd1363b5..d710967617de4854abcf2db1ec0028d9735ad77a 100644 (file)
@@ -58,14 +58,14 @@ void _avr_vcd_notify(struct avr_irq_t * irq, uint32_t value, void * param)
 
        /*
         * buffer starts empty, the first trace will resize it to AVR_VCD_LOG_CHUNK_SIZE,
-        * further growth will resize it accordingly. There's a bit of
+        * further growth will resize it accordingly.
         */
        if (vcd->logindex >= vcd->logsize) {
                vcd->logsize += AVR_VCD_LOG_CHUNK_SIZE;
                vcd->log = (avr_vcd_log_p)realloc(vcd->log, vcd->logsize * sizeof(vcd->log[0]));
                AVR_LOG(vcd->avr, LOG_TRACE, "%s trace buffer resized to %d\n",
                                __func__, (int)vcd->logsize);
-               if ((vcd->logsize / AVR_VCD_LOG_CHUNK_SIZE) == 5) {
+               if ((vcd->logsize / AVR_VCD_LOG_CHUNK_SIZE) == 8) {
                        AVR_LOG(vcd->avr, LOG_WARNING, "%s log size runnaway (%d) flush problem?\n",
                                        __func__, (int)vcd->logsize);
                }