目錄
零、概述
一、init_baudrate
二、serial_init
三、console_init_f
四、devices_init
五、console_init_r
六、打印信息
七、為什麼要使用devlist,std_device[]?
零、概述
上面這張圖是U-Boot中串口設備驅動的流程,從寄存器級別的設置到最後終端信息的輸出。下面我們詳細講解每一個步驟。
一、init_baudrate
該函數設置了gd->bd->bi_baudrate。
- static int init_baudrate (void)
- {
- char tmp[64]; /* long enough for environment variables */
- int i = getenv_r ("baudrate", tmp, sizeof (tmp));
- gd->bd->bi_baudrate = gd->baudrate = (i > 0)
- ? (int) simple_strtoul (tmp, NULL, 10)
- : CONFIG_BAUDRATE;
- //#define CONFIG_BAUDRATE 115200 定義在/include/configs/smdk2410.c中
- //如果環境中沒有保存,則使用宏定義的參數
- return (0);
- }
二、serial_init
UART控制器的初始化。
- void serial_setbrg (void)
- {
- S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);
- int i;
- unsigned int reg = 0;
-
- /* value is calculated so : (int)(PCLK/16./baudrate) -1 */
- reg = get_PCLK() / (16 * gd->baudrate) - 1;
-
- /* FIFO enable, Tx/Rx FIFO clear */
- uart->UFCON = 0x07;
- uart->UMCON = 0x0;
- /* Normal,No parity,1 stop,8 bit */
- uart->ULCON = 0x3;
- /*
- * tx=level,rx=edge,disable timeout int.,enable rx error int.,
- * normal,interrupt or polling
- */
- uart->UCON = 0x245;
- uart->UBRDIV = reg;
-
- #ifdef CONFIG_HWFLOW
- uart->UMCON = 0x1; /* RTS up */
- #endif
- for (i = 0; i < 100; i++);
- }
-
- /*
- * Initialise the serial port with the given baudrate. The settings
- * are always 8 data bits, no parity, 1 stop bit, no start bits.
- *
- */
- int serial_init (void)
- {
- serial_setbrg ();//UART寄存器設置
-
- return (0);
- }