6 /* baud rate: BAUDDIV = (UART_CLK / (16 * baud)) */
7 #define UART_CLK 3000000
9 void init_serial(int baud)
13 REG_CR = 0; /* disable UART */
15 /* disable pullups for GPIO 14 & 15 */
16 gpio_pullups(0xc000, 0, PUD_DISABLE);
18 REG_ICR = 0; /* clear pending interrupts */
20 /* calculate baud rate divisor */
21 bdiv_fp6 = (UART_CLK << 6) / (16 * baud);
22 REG_IBRD = (bdiv_fp6 >> 6) & 0xffff; /* 16 bits integer part */
23 REG_FBRD = bdiv_fp6 & 0x3f; /* 6 bits fractional precision */
25 /* line control: fifo enable, 8n1 */
26 REG_LCRH = LCRH_FIFOEN | LCRH_8BITS;
27 /* mask all interrupts */
28 REG_IMSC = I_CTS | I_RX | I_TX | I_RTIME | I_FRM | I_PAR | I_BRK | I_OVR;
30 /* enable UART RX&TX */
31 REG_CR = CR_UARTEN | CR_TXEN | CR_RXEN;
34 void ser_putchar(int c)
36 while(REG_FR & FR_TXFF);
42 while(REG_FR & FR_RXFE);
46 void ser_printstr(const char *s)