从内核模块直接写入16550A串口

时间:2012-06-25 12:05:35

标签: c linux-device-driver uart

我需要直接写入串口(我试图在irq处理程序中调试挂起,因此想要写入串口而不通过我假设使用中断的普通驱动程序)。

无论如何,我已经编写了这段小代码来尝试测试写入串口。 我已经执行了

setserial /dev/ttyS0 uart none

从普通驱动程序中释放端口。

代码:

#define PORT 0x3f8

static int test_module_init(void) {
        if(request_region(0x3f8, 5, "test_module") == NULL) {
                printk("<1> Failed to request_region\n");
        } else {
                printk("<1> Request region success!\n");
                outb(0x00, PORT + 1);    // Disable all interrupts
                outb(0x80, PORT + 3);    // Enable DLAB (set baud rate divisor)
                outb(0x01, PORT + 0);    // Set divisor to 1 (lo byte) 115200 baud
                outb(0x00, PORT + 1);    //                  (hi byte)
                outb(0x03, PORT + 3);    // 8 bits, no parity, one stop bit

                outb(0x00, PORT + 2);    // Disable fifo
                outb('a', PORT);
                outb('\n', PORT);
                printk("<1> Sent a\n");
        }
        return 0;
}

成功请求该区域,但我没有通过串口获得数据。有谁知道我做错了什么?我尝试了各种设置(fifo启用/禁用等),但没有运气。

0 个答案:

没有答案
相关问题