作者Neo1978 (Neo1978)
看板LinuxDev
标题Re: [问题] 在kernel里,如何直接使用rs232传送资料
时间Sat Jun 16 10:38:39 2007
※ 引述《aher2600 (和)》之铭言:
: 在一般应用程式中,只要
: main()
: {
: int fd;
: fd=open("/dev/ttyS0",....);
: .
: .
: .
: read(fd,....);
: .
: .
: .
: write(fd,...);
: .
: .
: close(fd);
: }
: 大致上就可以透过rs232传送或接收资料了
: 可是小弟现在想在kernel的程式中直接使用"\dev\ttyS0"传送
: 不知道程式该怎麽写
: 烦请版友指点
在 init/do_mount.c 中可以看到这样的 code:
fd = open("/dev/console", O_RDWR, 0);
if (fd >= 0) {
sys_ioctl(fd, TCGETS, (long)&termios);
termios.c_lflag &= ~ICANON;
sys_ioctl(fd, TCSETSF, (long)&termios);
read(fd, &c, 1);
termios.c_lflag |= ICANON;
sys_ioctl(fd, TCSETSF, (long)&termios);
close(fd);
}
在 kernel 中你还是可以用 open/close/read/write/ioctl ...
只是要知道这里的 function 和你平常在 libc 中常用的并不一样...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.70.86