在虚拟机下玩中断
记得以前学<<Linux Device Driver>>中断的章节,找了一块PCI转并口的卡,然后焊了一块小板,手动去触发中断.
//typedef irqreturn_t (*irq_handler_t)(int, void *); static irqreturn_t rtc_interrupt(int irq, void * dev_id) { u8 IIR; u8 c; do { IIR = inb(0x2fa); //中断状态寄存器 if((IIR & 0x01) == 0x01) break; //no interrupt if((IIR & 0x06) == 0x06) //receive error { inb(0x2fd); //to clear error printk(KERN_ALERT "receive error, clear it\n"); } else if((IIR & 0x04) == 0x04) //receive data { c = inb(0x2f8); printk(KERN_ALERT "got 0xx: %c\n", c, c); } else if((IIR & 0x02) == 0x02) //can send data { printk(KERN_ALERT "should not happen as we did not enable send data interrupt\n"); } else { printk(KERN_ALERT "unkown interrupt 0xx\n", IIR); } }while(1); return IRQ_HANDLED; } static int hello_init(void) { int ret; printk(KERN_ALERT "Hello kernel\n"); ret = request_irq(3, rtc_interrupt, 0, "uart", NULL); if(ret != 0) { printk("reqiest irq 3 failed\n"); } //2fb 线路控制寄存器 outb(0xe3, 0x2fb);//DLAB=1 to set baudraut outb(0x1, 0x2f8); outb(0x0, 0x2f9); //to set baudraut as 115200 outb(0x63, 0x2fb);//set DLAB=0 and set 8N1 //clear interrupt inb(0x2fd); //read LSR(线路状态寄存器) to clear interrupt status if any error during receive inb(0x2f8); //read |
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |