4 * A driver for the DBGU serial unit of the Atmel AT91 series.
6 * Copyright (c) 2009 Tran Duy Khanh. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 #include <system_def.h>
21 #include <lib_AT91SAM7XC256.h>
23 #include <system_stub.h>
25 #include "at91_dbgu.h"
27 #define configCPU_CLOCK_HZ ((unsigned long) 48000000)
28 #define DBGU_BAUD_RATE 115200
30 /* Initialization of the serial console. */
31 void at91_dbgu_init(void)
34 ((AT91PS_USART)AT91C_BASE_DBGU)->US_CR = AT91C_US_RSTTX|AT91C_US_RSTRX;
36 (AT91PS_USART)AT91C_BASE_DBGU,
41 /* Enable Transmitter & receiver */
42 ((AT91PS_USART)AT91C_BASE_DBGU)->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
45 /* Put a char to the serial console. */
46 int at91_dbgu_putchar(int ch)
48 /* wait for TX buffer to empty */
49 while (!(AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXRDY))
52 /* put char to Transmit Holding Register */
53 AT91C_BASE_DBGU->DBGU_THR = (uint8_t)ch;
55 /* return a char - stdio.h compatible? */
59 /* Write to the serial console. */
60 int at91_dbgu_write(int file, const char *ptr, int len)
65 for (cnt=0; cnt<len; cnt++,ptr++) {
68 at91_dbgu_putchar(0xd);
69 at91_dbgu_putchar(ch);
75 void at91_dbgu_init_printf(void)
77 /* Debug Unit initialization */
80 system_stub_ops.write = at91_dbgu_write;