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).
35 * \author Francesco Sacchi <batt@develer.com>
38 #include "kdebug_at91.h"
39 #include <hw/hw_cpufreq.h> /* for CPU_FREQ */
40 #include "hw/hw_ser.h" /* Required for bus macros overrides */
42 #include "cfg/cfg_debug.h"
43 #include <cfg/macros.h> /* for BV(), DIV_ROUND */
47 #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
48 #define KDBG_WAIT_READY() while (!(DBGU_SR & BV(US_TXRDY))) {}
49 #define KDBG_WAIT_TXDONE() while (!(DBGU_SR & BV(US_TXEMPTY))) {}
51 #define KDBG_WRITE_CHAR(c) do { DBGU_THR = (c); } while(0)
53 /* Debug unit is used only for debug purposes so does not generate interrupts. */
54 #define KDBG_MASK_IRQ(old) do { (void)old; } while(0)
56 /* Debug unit is used only for debug purposes so does not generate interrupts. */
57 #define KDBG_RESTORE_IRQ(old) do { (void)old; } while(0)
59 typedef uint32_t kdbg_irqsave_t;
62 #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
66 INLINE void kdbg_hw_init(void)
68 #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
69 /* Disable all DBGU interrupts. */
70 DBGU_IDR = 0xFFFFFFFF;
72 DBGU_CR = BV(US_RSTRX) | BV(US_RSTTX) | BV(US_RXDIS) | BV(US_TXDIS);
74 DBGU_BRGR = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE);
75 /* Set DBGU mode to 8 data bits, no parity and 1 stop bit. */
76 DBGU_MR = US_CHMODE_NORMAL | US_CHRL_8 | US_PAR_NO | US_NBSTOP_1;
77 /* Enable DBGU transmitter. */
78 DBGU_CR = BV(US_TXEN);
79 /* Disable PIO on DGBU tx pin. */
83 #if 0 /* Disable Rx for now */
84 /* Enable DBGU receiver. */
85 DBGU_CR = BV(US_RXEN);
86 /* Disable PIO on DGBU rx pin. */
91 #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
92 #endif /* CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU */