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 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief ARM debug support (implementation).
35 * \author Francesco Sacchi <batt@develer.com>
38 #include <hw/hw_cpufreq.h> /* for CPU_FREQ */
39 #include "hw/hw_ser.h" /* Required for bus macros overrides */
41 #include "cfg/cfg_debug.h"
42 #include <cfg/macros.h> /* for BV(), DIV_ROUND */
44 #include <io/lpc23xx.h>
46 #if CONFIG_KDEBUG_PORT == 0
47 #define KDBG_WAIT_READY() while (!(U0LSR & BV(5))) {}
48 #define KDBG_WAIT_TXDONE() while (!(U0LSR & BV(6))) {}
50 #define KDBG_WRITE_CHAR(c) do { U0THR = (c); } while(0)
52 #define KDBG_MASK_IRQ(old) do { \
57 #define KDBG_RESTORE_IRQ(old) do { \
62 typedef uint32_t kdbg_irqsave_t;
65 #error CONFIG_KDEBUG_PORT should be 0
69 INLINE void kdbg_hw_init(void)
71 #if CONFIG_KDEBUG_PORT == 0
72 /* Enable clock for UART0 */
74 /* Set UART0 clk to CPU_FREQ */
77 /* Set 8bit, 1 stop bit, no parity, DLAB = 1 (enable divisor modify) */
79 U0DLL = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) & 0xFF;
80 U0DLM = (DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) >> 8) & 0xFF;
82 /* Assign TX pin to UART0*/
85 /* Set 8bit, 1 stop bit, no parity, DLAB = 0 (disable divisor modify) */
87 /* Enable transmitter */
90 #error CONFIG_KDEBUG_PORT should be 0
91 #endif /* CONFIG_KDEBUG_PORT == 0 */