5 Right now just handle "write" to the serial port at any speed
6 and printf to the console when '\n' is written.
8 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
10 This file is part of simavr.
12 simavr is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 simavr is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with simavr. If not, see <http://www.gnu.org/licenses/>.
29 static void avr_uart_run(avr_t * avr, avr_io_t * port)
31 // printf("%s\n", __FUNCTION__);
34 static uint8_t avr_uart_read(struct avr_t * avr, uint8_t addr, void * param)
36 // avr_uart_t * p = (avr_uart_t *)param;
37 uint8_t v = avr->data[addr];
38 // printf("** PIN%c = %02x\n", p->name, v);
42 static void avr_uart_write(struct avr_t * avr, uint8_t addr, uint8_t v, void * param)
44 avr_uart_t * p = (avr_uart_t *)param;
46 if (addr == p->r_udr) {
47 // printf("UDR%c(%02x) = %02x\n", p->name, addr, v);
48 avr_core_watch_write(avr, addr, v);
49 avr_regbit_set(avr, p->udre);
53 buf[l++] = v < ' ' ? '.' : v;
55 if (v == '\n' || l == 127) {
57 printf("\e[32m%s\e[0m\n", buf);
62 void avr_uart_reset(avr_t * avr, struct avr_io_t *io)
64 avr_uart_t * p = (avr_uart_t *)io;
65 avr_regbit_set(avr, p->udre);
68 static avr_io_t _io = {
71 .reset = avr_uart_reset,
74 void avr_uart_init(avr_t * avr, avr_uart_t * p)
77 avr_register_io(avr, &p->io);
79 printf("%s UART%c UDR=%02x\n", __FUNCTION__, p->name, p->r_udr);
81 avr_register_io_write(avr, p->r_udr, avr_uart_write, p);
82 avr_register_io_read(avr, p->r_udr, avr_uart_read, p);