提示:
分析注释的部分,一般都会字体加粗或设置为红色字体。
本文包含如下代码:
mediatek/platform/mt6572/lk/platform.c
mediatek/platform/mt6572/lk/include/platform/mt_uart.h
mediatek/platform/mt6572/lk/uart.c
相关的寄存器资料请参考:
MT6572 的UART串口寄存器DATASHEET http://blog.csdn.net/duanlove/article/details/16862901
串口的使用过程:
1. 串口初始化,配置好波特率、工作模式及相关初始化寄存器。
2. 把需要发送的字符写入到串口发送寄存器。或者把串口接收寄存器里的东西读出来。
LK中的printf 就使用了 UART来发送我们程序中打印的log到串口。这样我们可以通过串口终端来查看 lk打印的log。
关于printf的细节请参考:
MT6572的LK printf 与UART串口打印 http://blog.csdn.net/duanlove/article/details/16898097
platform_early_init 函数是 MT6572平台 必须经过的一个初始化函数。
系统开机从preload预加载开始执行,然后把参数传入LK,并进入LK(类似于uboot),进行相应的初始化。串口的初始化便是在platform_early_init 函数里执行的。
在lk的 mediatek/platform/mt6572/lk/platform.c 里的 platform_early_init 函数中进行了串口的初始化。
void platform_early_init(void)
{
#ifdef LK_PROFILING
unsigned int time_led_init;
unsigned int time_pmic6329_init;
unsigned int time_i2c_init;
unsigned int time_disp_init;
unsigned int time_platform_early_init;
unsigned int time_set_clock;
unsigned int time_disp_preinit;
unsigned int time_misc_init;
unsigned int time_clock_init;
unsigned int time_wdt_init;
time_platform_early_init = get_timer(0);
time_set_clock = get_timer(0);
#endif
//mt_gpio_set_default();
//Specific for MT6572. ARMPLL can't set to max speed when L2 is configured as SRAM.
//preloader won't reach max speed. It will done by LK.
if (g_boot_arg->boot_mode != DOWNLOAD_BOOT)
{
mtk_set_arm_clock();
}
/* initialize the uart */
uart_init_early();
printf("arm clock set finished\n");
//printf实际上调用了串口发送的函数。具体请参考MT6572的LK printf 与UART串口打印
printf("uart_init_early init finished\n");
………………
}
uart_init_early() 函数的实现具体请看mediatek/platform/mt6572/lk/uart.c
/*
filename: mediatek/platform/mt6572/lk/uart.c
* Copyright (c) 2008 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include &l