Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在内核模块中访问串行端口_C_Linux_Linux Kernel_Serial Port - Fatal编程技术网

C 在内核模块中访问串行端口

C 在内核模块中访问串行端口,c,linux,linux-kernel,serial-port,C,Linux,Linux Kernel,Serial Port,我想访问linux机器上com端口的PIN。 这可以通过内核函数outb/inb实现 我尝试了以下方法: #define COM1_BASE_ADDRESS 0x3F8 unsigned char reg = inb((unsigned char)(COM1_BASE_ADDRESS + UART_MCR)); printk(KERN_INFO "MCR register: 0x%X\n", reg); reg = 1; printk(KERN_INFO "MCR register to w

我想访问linux机器上com端口的PIN。 这可以通过内核函数outb/inb实现

我尝试了以下方法:

#define COM1_BASE_ADDRESS 0x3F8

unsigned char reg = inb((unsigned char)(COM1_BASE_ADDRESS + UART_MCR));
printk(KERN_INFO "MCR register: 0x%X\n", reg);

reg = 1;
printk(KERN_INFO "MCR register to write: 0x%X\n", reg);
outb(reg, (unsigned char)(COM1_BASE_ADDRESS + UART_MCR)); 

reg = inb((unsigned char)(COM1_BASE_ADDRESS + UART_MCR));
printk(KERN_INFO "MCR register: 0x%X\n", reg);
内核模块本身应该正常工作,因为我在内核日志(dmesg)中获得了内核消息。 但由于某种原因,我想写的寄存器没有改变。 inb始终为给定地址返回0xFF


我是否需要为我的进程分配i/o内存之类的东西?

解决方案是删除
inb
outb
的参数列表中的
unsigned char
强制转换,解决方案是删除
inb
outb
的参数列表中的
unsigned char
强制转换,不确定,但是在
outb((无符号字符)(COM1_BASE_ADDRESS+UART_MCR),reg)设置寄存器,然后打印它。你不应该先用
inb
读回吗?对不起,忘了添加行。reg和端口参数在outb函数中也错误。但仍然存在同样的问题,您的解决方案在运行UART的驱动程序时非常快速。我建议考虑在用户空间中做任何事情,或者做UART的从属驱动程序,比如蓝牙。不确定,但是在<代码> OutB((unChar char)(COM1BaseBuffel+UARTHARMCR),Reg);<代码>设置寄存器,然后打印它。你不应该先用
inb
读回吗?对不起,忘了添加行。reg和端口参数在outb函数中也错误。但仍然存在同样的问题,您的解决方案在运行UART的驱动程序时非常快速。我建议考虑在用户空间中做任何事情,或者做UART的从属驱动程序,比如蓝牙。