avr_register_io_write(avr, addr, _avr_io_command_write, NULL);
}
+static void _avr_io_console_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, void * param)
+{
+ static char * buf = NULL;
+ static int size = 0, len = 0;
+
+ if (v == '\r') {
+ printf("O:" "%s" "" "\n", buf);
+ fflush(stdout);
+ }
+ if (len + 1 >= size) {
+ size += 128;
+ buf = (char*)realloc(buf, size);
+ }
+ buf[len++] = v;
+}
+
+void avr_set_console_register(avr_t * avr, avr_io_addr_t addr)
+{
+ if (addr)
+ avr_register_io_write(avr, addr, _avr_io_console_write, NULL);
+}
+
void avr_loadcode(avr_t * avr, uint8_t * code, uint32_t size, uint32_t address)
{
memcpy(avr->flash + address, code, size);
// set an IO register to receive commands from the AVR firmware
// it's optional, and uses the ELF tags
void avr_set_command_register(avr_t * avr, avr_io_addr_t addr);
+
+// specify the "console register" -- output sent to this register
+// is printed on the simulator console, without using a UART
+void avr_set_console_register(avr_t * avr, avr_io_addr_t addr);
+
// load code in the "flash"
void avr_loadcode(avr_t * avr, uint8_t * code, uint32_t size, uint32_t address);
#if CONFIG_SIMAVR_TRACE
avr->codeline = firmware->codeline;
#endif
+
avr_loadcode(avr, firmware->flash, firmware->flashsize, firmware->flashbase);
avr->codeend = firmware->flashsize + firmware->flashbase - firmware->datasize;
if (firmware->eeprom && firmware->eesize) {
}
avr_set_command_register(avr, firmware->command_register_addr);
+ avr_set_console_register(avr, firmware->console_register_addr);
+
+ // rest is initialization of the VCD file
+
if (firmware->tracecount == 0)
return;
avr->vcd = malloc(sizeof(*avr->vcd));
case AVR_MMCU_TAG_SIMAVR_COMMAND: {
firmware->command_register_addr = src[0] | (src[1] << 8);
} break;
+ case AVR_MMCU_TAG_SIMAVR_CONSOLE: {
+ firmware->console_register_addr = src[0] | (src[1] << 8);
+ } break;
}
size -= next;
src += next - 2; // already incremented
// register to listen to for commands from the firmware
uint16_t command_register_addr;
+ uint16_t console_register_addr;
uint32_t flashbase; // base address
uint8_t * flash;