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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 loop_until_bit_is_set(UCSR1A, UDRE1);
28 uart_put(char c, FILE *stream)
37 uart_get(FILE *stream)
39 loop_until_bit_is_set(UCSR1A, RXC1);
40 return (int) UDR1 & 0xff;
44 uart_init(uint16_t baud)
46 PRR1 &= ~(1 << PRUSART1);
50 UCSR1B = ((1 << RXEN1) | /* Enable receiver */
51 (1 << TXEN1)); /* Enable transmitter */
52 UCSR1C = ((0 << UMSEL10) | /* Asynchronous mode */
53 (0 << UPM10) | /* No parity */
54 (0 << USBS1) | /* 1 stop bit */
55 (3 << UCSZ10) | /* 8 bit characters */
56 (0 << UCPOL1)); /* MBZ for async mode */
59 static FILE mystdout = FDEV_SETUP_STREAM(uart_put, NULL, _FDEV_SETUP_WRITE);
61 static FILE mystdin = FDEV_SETUP_STREAM(NULL, uart_get, _FDEV_SETUP_READ);
63 void ao_debug_init(void)
65 uart_init(F_CPU / (16UL * 9600UL) - 1);
70 if (DDRB & AO_LED_RED) {
71 printf ("oops, starting all over\n");
77 printf ("debug initialized\n");