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/>.
32 void hdump(const char *w, uint8_t *b, size_t l)
37 for (i = 0; i < l; i++) printf("%02x",b[i]);
40 for (i = 0; i < l; i++) {
41 if (!(i & 0x1f)) printf(" ");
43 if ((i & 0x1f) == 0x1f) {
55 printf("usage: simavr [-t] [-g] [-m <device>] [-f <frequency>] firmware\n");
56 printf(" -t: run full scale decoder trace\n");
57 printf(" -g: listen for gdb connection on port 1234\n");
61 int main(int argc, char *argv[])
71 struct option long_options[] = {
72 {"help", no_argument, 0, 'h'},
73 {"mcu", required_argument, 0, 'm'},
74 {"freq", required_argument, 0, 'f'},
75 {"trace", no_argument, 0, 't'},
76 {"gdb", no_argument, 0, 'g'},
83 while ((option_count = getopt_long(argc, argv, "tghm:f:", long_options, &option_index)) != -1) {
84 switch (option_count) {
103 elf_read_firmware(argv[argc-1], &f);
106 strcpy(f.mmcu, name);
110 printf("firmware %s f=%d mmcu=%s\n", argv[argc-1], (int)f.frequency, f.mmcu);
112 avr_t * avr = avr_make_mcu_by_name(f.mmcu);
114 fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu);
118 avr_load_firmware(avr, &f);
121 // try to enable "local echo" on the first uart, for testing purposes
123 avr_irq_t * src = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_OUTPUT);
124 avr_irq_t * dst = avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ('0'), UART_IRQ_INPUT);
126 printf("%s:%s activating uart local echo IRQ src %p dst %p\n", __FILE__, __FUNCTION__, src, dst);
127 avr_connect_irq(src, dst);
130 // even if not setup at startup, activate gdb if crashing
131 avr->gdb_port = 1234;
133 avr->state = cpu_Stopped;