2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24 loop_until_bit_is_set(UCSR1A, UDRE1);
29 uart_put(char c, FILE *stream)
38 uart_get(FILE *stream)
40 loop_until_bit_is_set(UCSR1A, RXC1);
41 return (int) UDR1 & 0xff;
45 uart_init(uint16_t baud)
47 PRR1 &= ~(1 << PRUSART1);
51 UCSR1B = ((1 << RXEN1) | /* Enable receiver */
52 (1 << TXEN1)); /* Enable transmitter */
53 UCSR1C = ((0 << UMSEL10) | /* Asynchronous mode */
54 (0 << UPM10) | /* No parity */
55 (0 << USBS1) | /* 1 stop bit */
56 (3 << UCSZ10) | /* 8 bit characters */
57 (0 << UCPOL1)); /* MBZ for async mode */
60 static FILE mystdout = FDEV_SETUP_STREAM(uart_put, NULL, _FDEV_SETUP_WRITE);
62 static FILE mystdin = FDEV_SETUP_STREAM(NULL, uart_get, _FDEV_SETUP_READ);
64 void ao_debug_init(void)
66 uart_init(F_CPU / (16UL * 9600UL) - 1);
71 if (DDRB & AO_LED_RED) {
72 printf ("oops, starting all over\n");
78 printf ("debug initialized\n");