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