4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
33 * \brief ARM debug support (implementation).
36 * \author Francesco Sacchi <batt@develer.com>
39 #include "kdebug_at91.h"
40 #include <hw/hw_cpufreq.h> /* for CPU_FREQ */
41 #include "hw/hw_ser.h" /* Required for bus macros overrides */
43 #include "cfg/cfg_debug.h"
44 #include <cfg/macros.h> /* for BV(), DIV_ROUND */
48 #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
49 #define KDBG_WAIT_READY() while (!(DBGU_SR & BV(US_TXRDY))) {}
50 #define KDBG_WAIT_TXDONE() while (!(DBGU_SR & BV(US_TXEMPTY))) {}
52 #define KDBG_WRITE_CHAR(c) do { DBGU_THR = (c); } while(0)
54 /* Debug unit is used only for debug purposes so does not generate interrupts. */
55 #define KDBG_MASK_IRQ(old) do { (void)old; } while(0)
57 /* Debug unit is used only for debug purposes so does not generate interrupts. */
58 #define KDBG_RESTORE_IRQ(old) do { (void)old; } while(0)
60 typedef uint32_t kdbg_irqsave_t;
63 #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
67 INLINE void kdbg_hw_init(void)
69 #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
70 /* Disable all DBGU interrupts. */
71 DBGU_IDR = 0xFFFFFFFF;
73 DBGU_CR = BV(US_RSTRX) | BV(US_RSTTX) | BV(US_RXDIS) | BV(US_TXDIS);
75 DBGU_BRGR = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE);
76 /* Set DBGU mode to 8 data bits, no parity and 1 stop bit. */
77 DBGU_MR = US_CHMODE_NORMAL | US_CHRL_8 | US_PAR_NO | US_NBSTOP_1;
78 /* Enable DBGU transmitter. */
79 DBGU_CR = BV(US_TXEN);
80 /* Disable PIO on DGBU tx pin. */
84 #if 0 /* Disable Rx for now */
85 /* Enable DBGU receiver. */
86 DBGU_CR = BV(US_RXEN);
87 /* Disable PIO on DGBU rx pin. */
92 #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
93 #endif /* CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU */