kdebug_at91.c

Go to the documentation of this file.
00001 
00039 #include "kdebug_at91.h"
00040 #include <hw/hw_cpufreq.h>     /* for CPU_FREQ */
00041 #include "hw/hw_ser.h"     /* Required for bus macros overrides */
00042 
00043 #include "cfg/cfg_debug.h"
00044 #include <cfg/macros.h> /* for BV(), DIV_ROUND */
00045 
00046 #include <io/arm.h>
00047 
00048 #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
00049     #define KDBG_WAIT_READY()     while (!(DBGU_SR & BV(US_TXRDY))) {}
00050     #define KDBG_WAIT_TXDONE()    while (!(DBGU_SR & BV(US_TXEMPTY))) {}
00051 
00052     #define KDBG_WRITE_CHAR(c)    do { DBGU_THR = (c); } while(0)
00053 
00054     /* Debug unit is used only for debug purposes so does not generate interrupts. */
00055     #define KDBG_MASK_IRQ(old)    do { (void)old; } while(0)
00056 
00057     /* Debug unit is used only for debug purposes so does not generate interrupts. */
00058     #define KDBG_RESTORE_IRQ(old) do { (void)old; } while(0)
00059 
00060     typedef uint32_t kdbg_irqsave_t;
00061 
00062 #else
00063     #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
00064 #endif
00065 
00066 
00067 INLINE void kdbg_hw_init(void)
00068 {
00069     #if CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU
00070         /* Disable all DBGU interrupts. */
00071         DBGU_IDR =  0xFFFFFFFF;
00072         /* Reset DBGU */
00073         DBGU_CR =  BV(US_RSTRX) | BV(US_RSTTX) | BV(US_RXDIS) | BV(US_TXDIS);
00074         /* Set baudrate */
00075         DBGU_BRGR = DIV_ROUND(CPU_FREQ, 16 * CONFIG_KDEBUG_BAUDRATE);
00076         /* Set DBGU mode to 8 data bits, no parity and 1 stop bit. */
00077         DBGU_MR =  US_CHMODE_NORMAL | US_CHRL_8 | US_PAR_NO | US_NBSTOP_1;
00078         /* Enable DBGU transmitter. */
00079         DBGU_CR = BV(US_TXEN);
00080         /* Disable PIO on DGBU tx pin. */
00081         PIOA_PDR = BV(DTXD);
00082         PIOA_ASR = BV(DTXD);
00083         
00084         #if 0 /* Disable Rx for now */
00085         /* Enable DBGU receiver. */
00086         DBGU_CR = BV(US_RXEN);
00087         /* Disable PIO on DGBU rx pin. */
00088         PIOA_PDR = BV(DRXD);
00089         PIOA_ASR = BV(DRXD);
00090         #endif
00091     #else
00092         #error CONFIG_KDEBUG_PORT should be KDEBUG_PORT_DBGU
00093     #endif /* CONFIG_KDEBUG_PORT == KDEBUG_PORT_DBGU */
00094 }