#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,\
}
/*
#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,\
}
* 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,
#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)
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));
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,
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;
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;
/*
* 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);
}