修改完我之前講過的irq,timer後,渡過了一段console沒有字的debug時間,從頭到尾都用ICE去trace是很悶的,現下我把console的程式碼加上,讓console跑點字出來吧
Kernel所有的訊息都是印在console上的,所以在kernel用printk其實等於直接把buffer content倒在console
但user space的application可不是這樣,當printf印訊息時,其實是透過tty driver呼叫我們的serial driver然後請serial driver幫忙印字
藉由上面的介紹,大概瞭解console driver會用到serial driver的write函式,而serial driver也必需跟tty driver註冊自己
所以serial driver要幹的事有兩件
(1)寫console api
(2)註冊tty driver
詳細的code我不在這邊介紹,我只大略說一下linux driver的寫法
(1)先找一個小,且架構清楚的driver骨架,像我就是用4510的serial driver來修改成2410可用的serial driver
(2)把函式內的程式碼全部清掉,只剩下函式宣告
(3)根據data sheet和參考程式來填寫我們的程式
底下是qt2410 console程式的部份程式碼,只要完成這個部份,kernel就會吐訊息出來了
#ifdef CONFIG_SERIAL_QT2410_CONSOLE
/************** console driver *****************/
static void __qt2410_console_write(struct console *co, const char *s, u_int count)
{
struct uart_port *port = &__qt2410_ports[co->index];
__xmit_string( port, s, count);
}
static int __init __qt2410_console_setup(struct console *co, char *options)
{
struct uart_port *port;
int baud = 115200;
int bits = 8;
int parity = 'n';
int flow = 0;
/*
* Check whether an invalid uart number has been specified, and
* if so, search for the first available port that does have
* console support.
*/
port = uart_get_console(__qt2410_ports, UART_NR, co);
// _DPRINTK("using port = 0x%08x", (unsigned int) port);
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
__qt2410_init(port, baud);
return uart_set_options(port, co, baud, parity, bits, flow);
}
//extern struct uart_driver __qt2410_driver;
static struct console __qt2410_console =
{
name: "ttySAC",
write: __qt2410_console_write,
device: uart_console_device,
setup: __qt2410_console_setup,
flags: CON_PRINTBUFFER,
index: -1,
data: &__qt2410_driver,
};
static int __init __qt2410_console_init(void)
{
register_console(&__qt2410_console);
return 0;
}
console_initcall(__qt2410_console_init);
#endif
static struct uart_driver __qt2410_driver =
{
owner: THIS_MODULE,
driver_name: __DRIVER_NAME,
dev_name: "ttySAC",
major: TTY_MAJOR,
minor: 64,
nr: UART_NR,
#ifdef CONFIG_SERIAL_QT2410_CONSOLE
cons: &__qt2410_console,
#endif
};
下圖是開機的過程

留言