Increase ethernet irq priority.
[bertos.git] / bertos / cpu / arm / drv / kdebug_lpc2.c
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
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.
10  *
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.
15  *
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
19  *
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.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief ARM debug support (implementation).
34  *
35  * \author Francesco Sacchi <batt@develer.com>
36  */
37
38 #include <hw/hw_cpufreq.h>     /* for CPU_FREQ */
39 #include "hw/hw_ser.h"     /* Required for bus macros overrides */
40
41 #include "cfg/cfg_debug.h"
42 #include <cfg/macros.h> /* for BV(), DIV_ROUND */
43
44 #include <io/lpc23xx.h>
45
46 #if CONFIG_KDEBUG_PORT == 0
47         #define KDBG_WAIT_READY()     while (!(U0LSR & BV(5))) {}
48         #define KDBG_WAIT_TXDONE()    while (!(U0LSR & BV(6))) {}
49
50         #define KDBG_WRITE_CHAR(c)    do { U0THR = (c); } while(0)
51
52         #define KDBG_MASK_IRQ(old)    do { \
53                 (old) = U0IER; \
54                 U0IER &= ~BV(1); \
55         } while(0)
56
57         #define KDBG_RESTORE_IRQ(old) do { \
58                 KDBG_WAIT_TXDONE(); \
59                 U0IER = (old); \
60         } while(0)
61
62         typedef uint32_t kdbg_irqsave_t;
63
64 #else
65         #error CONFIG_KDEBUG_PORT should be 0
66 #endif
67
68
69 INLINE void kdbg_hw_init(void)
70 {
71         #if CONFIG_KDEBUG_PORT == 0
72                 /* Enable clock for UART0 */
73                 PCONP = BV(3);
74                 /* Set UART0 clk to CPU_FREQ */
75                 PCLKSEL0 &= ~0xC0;
76                 PCLKSEL0 |= 0x40;
77                 /* Set 8bit, 1 stop bit, no parity, DLAB = 1 (enable divisor modify) */
78                 U0LCR = 0x83;
79                 U0DLL = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) & 0xFF;
80                 U0DLM = (DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) >> 8) & 0xFF;
81                 U0FDR = 0x10;
82                 /* Assign TX pin to UART0*/
83                 PINSEL0 &= ~0x30;
84                 PINSEL0 |= 0x10;
85                 /* Set 8bit, 1 stop bit, no parity, DLAB = 0 (disable divisor modify) */
86                 U0LCR = 0x03;
87                 /* Enable transmitter */
88                 U0TER = BV(7);
89         #else
90                 #error CONFIG_KDEBUG_PORT should be 0
91         #endif /* CONFIG_KDEBUG_PORT == 0 */
92 }