4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
30 #include "avr_eeprom.h"
33 void hdump(const char *w, uint8_t *b, size_t l)
38 for (i = 0; i < l; i++) printf("%02x",b[i]);
41 for (i = 0; i < l; i++) {
42 if (!(i & 0x1f)) printf(" ");
44 if ((i & 0x1f) == 0x1f) {
56 printf("usage: simavr [-t] [-g] [-m <device>] [-f <frequency>] firmware\n");
57 printf(" -t: run full scale decoder trace\n");
58 printf(" -g: listen for gdb connection on port 1234\n");
62 int main(int argc, char *argv[])
72 struct option long_options[] = {
73 {"help", no_argument, 0, 'h'},
74 {"mcu", required_argument, 0, 'm'},
75 {"freq", required_argument, 0, 'f'},
76 {"trace", no_argument, 0, 't'},
77 {"gdb", no_argument, 0, 'g'},
84 while ((option_count = getopt_long(argc, argv, "tghm:f:", long_options, &option_index)) != -1) {
85 switch (option_count) {
104 elf_read_firmware(argv[argc-1], &f);
107 strcpy(f.mmcu.name, name);
109 f.mmcu.f_cpu = f_cpu;
111 printf("firmware %s f=%d mmcu=%s\n", argv[argc-1], (int)f.mmcu.f_cpu, f.mmcu.name);
113 avr_t * avr = avr_make_mcu_by_name(f.mmcu.name);
115 fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu.name);
119 avr->frequency = f.mmcu.f_cpu;
120 avr->codeline = f.codeline;
121 avr_loadcode(avr, f.flash, f.flashsize, 0);
122 avr->codeend = f.flashsize - f.datasize;
123 if (f.eeprom && f.eesize) {
124 avr_eeprom_desc_t d = { .ee = f.eeprom, .offset = 0, .size = f.eesize };
125 avr_ioctl(avr, AVR_IOCTL_EEPROM_SET, &d);
129 // try to enable "local echo" on the first uart, for testing purposes
131 avr_irq_t * src = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_OUTPUT);
132 avr_irq_t * dst = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_INPUT);
133 printf("%s:%s activating uart local echo IRQ src %p dst %p\n", __FILE__, __FUNCTION__, src, dst);
135 avr_connect_irq(avr, src, dst);
139 avr->state = cpu_Stopped;
143 // for (long long i = 0; i < 8000000*10; i++)
144 // for (long long i = 0; i < 80000; i++)