From d6237d52ce0553c1cf811c67807e956043fceed4 Mon Sep 17 00:00:00 2001 From: batt Date: Wed, 31 Mar 2010 22:08:09 +0000 Subject: [PATCH] LPC2: add debug. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3368 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/arm/drv/kdebug_arm.c | 2 + bertos/cpu/arm/drv/kdebug_lpc2.c | 92 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 bertos/cpu/arm/drv/kdebug_lpc2.c diff --git a/bertos/cpu/arm/drv/kdebug_arm.c b/bertos/cpu/arm/drv/kdebug_arm.c index 9e16ba22..5ec3cded 100644 --- a/bertos/cpu/arm/drv/kdebug_arm.c +++ b/bertos/cpu/arm/drv/kdebug_arm.c @@ -41,6 +41,8 @@ #if CPU_ARM_AT91 #include "kdebug_at91.c" +#elif CPU_ARM_LPC2 + #include "kdebug_lpc2.c" /*#elif Add other ARM families here */ #else #error Unknown CPU diff --git a/bertos/cpu/arm/drv/kdebug_lpc2.c b/bertos/cpu/arm/drv/kdebug_lpc2.c new file mode 100644 index 00000000..0de6fb33 --- /dev/null +++ b/bertos/cpu/arm/drv/kdebug_lpc2.c @@ -0,0 +1,92 @@ +/** + * \file + * + * + * \brief ARM debug support (implementation). + * + * \author Francesco Sacchi + */ + +#include /* for CPU_FREQ */ +#include "hw/hw_ser.h" /* Required for bus macros overrides */ + +#include "cfg/cfg_debug.h" +#include /* for BV(), DIV_ROUND */ + +#include + +#if CONFIG_KDEBUG_PORT == 0 + #define KDBG_WAIT_READY() while (!(U0LSR & BV(5))) {} + #define KDBG_WAIT_TXDONE() while (!(U0LSR & BV(6))) {} + + #define KDBG_WRITE_CHAR(c) do { U0THR = (c); } while(0) + + #define KDBG_MASK_IRQ(old) do { \ + (old) = U0IER; \ + U0IER &= ~BV(1); \ + } while(0) + + #define KDBG_RESTORE_IRQ(old) do { \ + KDBG_WAIT_TXDONE(); \ + U0IER = (old); \ + } while(0) + + typedef uint32_t kdbg_irqsave_t; + +#else + #error CONFIG_KDEBUG_PORT should be 0 +#endif + + +INLINE void kdbg_hw_init(void) +{ + #if CONFIG_KDEBUG_PORT == 0 + /* Enable clock for UART0 */ + PCONP = BV(3); + /* Set UART0 clk to CPU_FREQ */ + PCLKSEL0 &= ~0xC0; + PCLKSEL0 |= 0x40; + /* Set 8bit, 1 stop bit, no parity, DLAB = 1 (enable divisor modify) */ + U0LCR = 0x83; + U0DLL = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) & 0xFF; + U0DLM = (DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE) >> 8) & 0xFF; + U0FDR = 0x10; + /* Assign TX pin to UART0*/ + PINSEL0 &= ~0x30; + PINSEL0 |= 0x10; + /* Set 8bit, 1 stop bit, no parity, DLAB = 0 (disable divisor modify) */ + U0LCR = 0x03; + /* Enable transmitter */ + U0TER = BV(7); + #else + #error CONFIG_KDEBUG_PORT should be 0 + #endif /* CONFIG_KDEBUG_PORT == 0 */ +} -- 2.25.1