6 /* baud rate: BAUDDIV = (UART_CLK / (16 * baud)) */
7 #define UART_CLK 3000000
9 void init_serial(int baud)
14 REG_CR = 0; /* disable UART */
16 /* disable pullups for GPIO 14 & 15 */
17 gpio_pullups(0xc000, 0, PUD_DISABLE);
18 /* select alt0 function for GPIO 14 & 15 */
19 /*gpio_fsel(14, FSEL_ALT0);
20 gpio_fsel(15, FSEL_ALT0);*/
22 REG_ICR = 0x7ff; /* clear pending interrupts */
24 /* calculate baud rate divisor */
25 bdiv_fp6 = (UART_CLK << 6) / (16 * baud);
26 REG_IBRD = (bdiv_fp6 >> 6) & 0xffff; /* 16 bits integer part */
27 REG_FBRD = bdiv_fp6 & 0x3f; /* 6 bits fractional precision */
29 /* line control: fifo enable, 8n1 */
30 REG_LCRH = LCRH_FIFOEN | LCRH_8BITS;
31 /* mask all interrupts */
32 REG_IMSC = I_CTS | I_RX | I_TX | I_RTIME | I_FRM | I_PAR | I_BRK | I_OVR;
34 /* enable UART RX&TX */
35 REG_CR = CR_UARTEN | CR_TXEN | CR_RXEN;
39 void ser_putchar(int c)
41 if(c == '\n') ser_putchar('\r');
44 while(REG_FR & FR_TXFF);
52 while(REG_FR & FR_RXFE);
59 return (REG_FR & FR_RXFE) == 0;
62 void ser_printstr(const char *s)