当前位置:  技术问答>linux和unix

关于内核串口操作

    来源: 互联网  发布时间:2016-06-09

    本文导语:  内核在开发板上运行完后,然后我想在我的应用程序中对串口tty0进行读写操作,但是我在应用程序最开始open("/dev/tty0"),错误提示:找不到这个设备。我发现在内核运行的时候是有串口打印的,请问一下,我应该怎么...

内核在开发板上运行完后,然后我想在我的应用程序中对串口tty0进行读写操作,但是我在应用程序最开始open("/dev/tty0"),错误提示:找不到这个设备。我发现在内核运行的时候是有串口打印的,请问一下,我应该怎么操作串口,内核对串口的初始化是放在哪里的。请高手指教,谢谢!

|
/dev/tty0         Current virtual console
/dev/tty1         First virtual console
/dev/tty63        63rd virtual console
/dev/ttyS0        First UART serial port
/dev/ttyS191      192nd UART serial port


To use a serial port as console you need to compile the support into your
kernel - by default it is not compiled in. For PC style serial ports
it's the config option next to "Standard/generic (dumb) serial support".
You must compile serial support into the kernel and not as a module.

It is possible to specify multiple devices for console output. You can
define a new kernel command line option to select which device(s) to
use for console output.

The format of this option is:

        console=device,options

        device:         tty0 for the foreground virtual console
                        ttyX for any other virtual console
                        ttySx for a serial port
                        lp0 for the first parallel port
                        ttyUSB0 for the first USB serial device

        options:        depend on the driver. For the serial port this
                        defines the baudrate/parity/bits/flow control of
                        the port, in the format BBBBPNF, where BBBB is the
                        speed, P is parity (n/o/e), N is number of bits,
                        and F is flow control ('r' for RTS). Default is
                        9600n8. The maximum baudrate is 115200.

You can specify multiple console= options on the kernel command line.
Output will appear on all of them. The last device will be used when
you open /dev/console. So, for example:

        console=ttyS1,9600 console=tty0

defines that opening /dev/console will get you the current foreground
virtual console, and kernel messages will appear on both the VGA
console and the 2nd serial port (ttyS1 or COM2) at 9600 baud.

Note that you can only define one console per device type (serial, video).

If no console device is specified, the first device found capable of
acting as a system console will be used. At this time, the system
first looks for a VGA card and then for a serial port. So if you don't
have a VGA card in your system the first serial port will automatically
become the console.

You will need to create a new device to use /dev/console. The official
/dev/console is now character device 5,1.

(You can also use a network device as a console.  See
Documentation/networking/netconsole.txt for information on that.)

Here's an example that will use /dev/ttyS1 (COM2) as the console.
Replace the sample values as needed.

1. Create /dev/console (real console) and /dev/tty0 (master virtual
   console):

   cd /dev
   rm -f console tty0
   mknod -m 622 console c 5 1
   mknod -m 622 tty0 c 4 0

2. LILO can also take input from a serial device. This is a very
   useful option. To tell LILO to use the serial port:
   In lilo.conf (global section): 
   serial  = 1,9600n8 (ttyS1, 9600 bd, no parity, 8 bits)

3. Adjust to kernel flags for the new kernel,
   again in lilo.conf (kernel section)

   append = "console=ttyS1,9600" 

4. Make sure a getty runs on the serial port so that you can login to
   it once the system is done booting. This is done by adding a line
   like this to /etc/inittab (exact syntax depends on your getty):

   S1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

5. Init and /etc/ioctl.save

   Sysvinit remembers its stty settings in a file in /etc, called
   `/etc/ioctl.save'. REMOVE THIS FILE before using the serial
   console for the first time, because otherwise init will probably
   set the baudrate to 38400 (baudrate of the virtual console).

6. /dev/console and X
   Programs that want to do something with the virtual console usually
   open /dev/console. If you have created the new /dev/console device,
   and your console is NOT the virtual console some programs will fail.
   Those are programs that want to access the VT interface, and use
   /dev/console instead of /dev/tty0. Some of those programs are:

   Xfree86, svgalib, gpm, SVGATextMode

   It should be fixed in modern versions of these programs though.

   Note that if you boot without a console= option (or with
   console=/dev/tty0), /dev/console is the same as /dev/tty0. In that
   case everything will still work.

|
楼主可以看一下linux内核源代码中Documentation目录下的devices.txt文件中讲的很清楚。

|
ttyS0

    
 
 

您可能感兴趣的文章:

  • 开发板串口与实际内核中的串口文件的对应关系怎么回事?谢谢帮忙
  • 如何编译2.6内核使其支持串口?
  • 请问, android+linux内核 平台上, 有一个串口接口的外设置芯片, 想对它进行初化, 一般根据该平台下什么驱动改写?
  • 请问LINUX内核版本为2.4.31的是什么版本?自己写的串口驱动,是否向下兼容,还是必需版本相同?
  • 求助:usb转serial串口设备在linux内核中创建及生成tty设备的改写
  • 串口读写,双方同时读写控制问题(linux内核)。
  • 想找一个从终端设备以串口接收数据然后在ARM(linux内核)板上做一个透明转发以UDP型式发送到一台PC机上程序的人员。有意详读下文!
  • 【新手求助】关于2.6内核下S3C2410寄存器的访问方法(串口寄存器)
  • 关于内核串口操作!!!!
  • 如何在linux内核模块中对串口进行读写
  • 对于操作系统的程序接口,作业接口,单内核,微内核到底有什么区别?
  • 进程内核栈和操作系统内核栈的关系
  • 谁能告诉我2.6.32内核的操作系统是哪些,坐等回复
  • 微内核多任务分时图形化操作系统 ulios
  • 内核态下 操作字符串
  • 用户和内核对目录写操作有哪里不同
  • 内核操作用户空间内存
  • 高深问题:有了linux内核源代码如何做成一个linux操作系统
  • 写操作系统的时候为什么要重新放置内核啊(来着有分)
  • 微内核操作系统 SGOS
  • Unix操作系统内核 Fiwix
  • 操作系统内核 Runtime.JS
  • 求资料:《Linux操作系统内核实习》
  • 有没有使用最新内核的占用空间较小的linux操作系统
  • 我有一个RedHat7.2 的内核升级文件kernel.zip.请问如何做生机,具体怎么操作.
  • Linux内核中文件进行读写操作的问题
  • 关于<LINUX操作系统内核实习》 安装光盘的问题(散分)
  • 对操作系统内核的一个小困惑
  • linux内核原子量操作的小疑问
  • 那位大侠行行好,能不能告知那里提供《linux操作系统内核实习》的完整下载?
  •  
    本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
    本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • Linux内核中影响tcp三次握手的一些协议配置
  • Fedora Core 2自带的内核升级程序下载下来内核后,要不要再编译一遍内核?
  • TCP协议四次断连过程介绍及Linux内核协议栈中相关设置项
  • Linux中内核线程不访问内核态地址空间?
  • CentOS 6内核升级:下载编译启用新内核版本详细过程
  • 2.6内核下编译2.4内核
  • Linux进程的内核栈和用户栈概念,相互关系及切换过程
  • 谁能提供kgdb内核补丁内核模块的下载
  • linux内核中的likely宏和unlikely宏介绍及用法
  • 编译新内核后怎么进入原来内核
  • CentOS 6.5 下载地址及如何升级内核(kernel)版本到 3.10.28
  • 请问linux中如何判断内核是否已经启动。(在内核中写程序)
  • Linux下c/c++开发之程序崩溃(Segment fault)时内核转储文件(core dump)生成设置方法
  • 内核模块跟内核版本不匹配????????
  • docker使用的技术之Container内核原理介绍
  • 请教:如何安装新内核(rpm包)而不同原来得内核冲突?? 在线等待!!
  • linux为什么要升级内核?升级内核有何作用?
  • 内核升级后,如何在新的内核中加载显卡驱动?
  • 内核源码和结果make过的内核源码有什么区别
  • 不重新编译内核能修改内核函数吗?
  • 如何学好内核?学了内核能应用于哪方面?


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3