X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Farm%2Fdrv%2Fkdebug_lpc2.c;fp=bertos%2Fcpu%2Farm%2Fdrv%2Fkdebug_lpc2.c;h=0de6fb33ab60b8e0d1a0f4850550fae338ba2263;hb=d6237d52ce0553c1cf811c67807e956043fceed4;hp=0000000000000000000000000000000000000000;hpb=e70f6f970d71ec732182636bfb8086cdc6ec3e10;p=bertos.git 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 */ +}