/* for UART */
bl uart_asm_init 具体的源码在同一个文件中,如下所示:
/*
* uart_asm_init: Initialize UART in asm mode, 115200bps fixed.
* void uart_asm_init(void)
*/
uart_asm_init:
/* set GPIO to enable UART */
@ GPIO setting for UART
ldrr0, =ELFIN_GPIO_BASE
ldrr1, =0x220022
str r1, [r0, #GPACON_OFFSET]------看下面:主要是对UART0和UART1的GPIO进行配置,因为很多GPIO都是复用的
ldrr1, =0x2222
str r1, [r0, #GPBCON_OFFSET] ------和上面一样,这里是UART2和UART3,看下图:
ldrr0, =ELFIN_UART_CONSOLE_BASE@0x7F005000 ------这是UART LINE CONTROL REGISTER的基地址
movr1, #0x0
strr1, [r0, #UFCON_OFFSET]
strr1, [r0, #UMCON_OFFSET] ------这两个寄存器主要和FIFO有关,这里应该是禁止了
movr1, #0x3 @was 0. 对UART0进行配置,8位,无校验,1停止位,普通模式(非红外)
strr1, [r0, #ULCON_OFFSET]
#if defined(CONFIG_CLKSRC_CLKUART) ---- 定义了
ldrr1, =0xe45/* UARTCLK SRC = 11 => EXT_UCLK1*/
#else
ldrr1, =0x245/* UARTCLK SRC = x0 => PCLK */
#endif
strr1, [r0, #UCON_OFFSET]-------主要是对下面这个寄存器进行操作,主要是对接收和发送方式的设置,还有时钟的选择
#if defined(CONFIG_UART_50)
ldrr1, =0x1A
#elif defined(CONFIG_UART_66) 定义了这个#define CONFIG_UART_66/* default clock value of CLK_UART */
ldrr1, =0x22
#else
ldrr1, =0x1A
#endif
strr1, [r0, #UBRDIV_OFFSET]---- 和波特率设置有关,有如下公式:
DIV_VAL1) = (EXT_UCLK1 / (bps x 16) ) –1
DIV_VAL = UBRDIVn + (num of 1’s in UDIVSLOTn)/16. Refer to UART Baud Rate Configure Registers.
#if defined(CONFIG_UART_50)
ldrr1, =0x3
#elif defined(CONFIG_UART_66)
ldrr1, =0x1FFF
#else
ldrr1, =0x3
#endif
strr1, [r0, #UDIVSLOT_OFFSET]------ 和上面一样,都和波特率设置有关
ldrr1, =0x4f4f4f4f
strr1, [r0, #UTXH_OFFSET]@'O' 发送字符‘O’
movpc, lr ----------返回
ldrr0, =ELFIN_UART_BASE 发送‘K’
ldrr1, =0x4b4b4b4b
strr1, [r0, #UTXH_OFFSET]