64.html

来自「linux 0.11中文版 有注释」· HTML 代码 · 共 114 行

HTML
114
字号
<html>
<head>
<title>kernel/chr_drv/serial.c</title>
<meta name='robots' content='noindex,nofollow'>
<meta name='generator' content='GLOBAL-5.4.1'>
</head>
<body text='#191970' bgcolor='#f5f5dc' vlink='gray'>
<a name='TOP'><h2><a href='../mains.html'>root</a>/<a href='../files/104.html'>kernel</a>/<a href='../files/106.html'>chr_drv</a>/serial.c</h2>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L37'>[^]</a><a href='#L80'>[v]</a>[top]<a href='#BOTTOM'>[bottom]</a><a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
<hr>
<h2>DEFINITIONS</h2>
This source file includes following definitions.
<ol>
<li><a href='#L37' title='Defined at 37.'>init</a>
<li><a href='#L57' title='Defined at 57.'>rs_init</a>
<li><a href='#L80' title='Defined at 80.'>rs_write</a>
</ol>
<hr>
<pre>
<a name='L1'><i><font color='green'>/*</font></i>
<a name='L2'><i><font color='green'>* linux/kernel/serial.c</font></i>
<a name='L3'><i><font color='green'>*</font></i>
<a name='L4'><i><font color='green'>* (C) 1991 Linus Torvalds</font></i>
<a name='L5'><i><font color='green'>*/</font></i>
<a name='L6'>
<a name='L7'><i><font color='green'>/*</font></i>
<a name='L8'><i><font color='green'>* serial.c</font></i>
<a name='L9'><i><font color='green'>*</font></i>
<a name='L10'><i><font color='green'>* This module implements the rs232 io functions</font></i>
<a name='L11'><i><font color='green'>* void rs_write(struct tty_struct * queue);</font></i>
<a name='L12'><i><font color='green'>* void rs_init(void);</font></i>
<a name='L13'><i><font color='green'>* and all interrupts pertaining to serial IO.</font></i>
<a name='L14'><i><font color='green'>*/</font></i>
<a name='L15'><i><font color='green'>/*</font></i>
<a name='L16'><i><font color='green'>* serial.c</font></i>
<a name='L17'><i><font color='green'>* 该程序用于实现rs232 的输入输出功能</font></i>
<a name='L18'><i><font color='green'>* void rs_write(struct tty_struct *queue);</font></i>
<a name='L19'><i><font color='green'>* void rs_init(void);</font></i>
<a name='L20'><i><font color='green'>* 以及与传输IO 有关系的所有中断处理程序。</font></i>
<a name='L21'><i><font color='green'>*/</font></i>
<a name='L22'>
<a name='L23'><font color='darkred'>#include</font> &lt;<a href='38.html'>linux/tty.h</a>&gt;          <i><font color='green'>// tty 头文件,定义了有关tty_io,串行通信方面的参数、常数。</font></i>
<a name='L24'><font color='darkred'>#include</font> &lt;<a href='36.html'>linux/sched.h</a>&gt;        <i><font color='green'>// 调度程序头文件,定义了任务结构task_struct、初始任务0 的数据,</font></i>
<a name='L25'><i><font color='green'>// 还有一些有关描述符参数设置和获取的嵌入式汇编函数宏语句。</font></i>
<a name='L26'><font color='darkred'>#include</font> &lt;<a href='25.html'>asm/system.h</a>&gt;         <i><font color='green'>// 段操作头文件。定义了有关段寄存器操作的嵌入式汇编函数。</font></i>
<a name='L27'><font color='darkred'>#include</font> &lt;<a href='22.html'>asm/io.h</a>&gt;             <i><font color='green'>// io 头文件。定义硬件端口输入/输出宏汇编语句。</font></i>
<a name='L28'>
<a name='L29'><font color='darkred'>#define</font> WAKEUP_CHARS (<a href='../D/487.html' title='Multiple defined in 2 places.'>TTY_BUF_SIZE</a>/4)   <i><font color='green'>// 当写队列中含有WAKEUP_CHARS 个字符时,就开始发送。</font></i>
<a name='L30'>
<a name='L31'><b>extern</b> <b>void</b> rs1_interrupt (<b>void</b>);       <i><font color='green'>// 串行口1 的中断处理程序(rs_io.s, 34)。</font></i>
<a name='L32'><b>extern</b> <b>void</b> rs2_interrupt (<b>void</b>);       <i><font color='green'>// 串行口2 的中断处理程序(rs_io.s, 38)。</font></i>
<a name='L33'>
<a name='L34'><i><font color='green'>//// 初始化串行端口</font></i>
<a name='L35'><i><font color='green'>// port: 串口1 - 0x3F8,串口2 - 0x2F8。</font></i>
<a name='L36'><b>static</b> <b>void</b>
<a name='L37'><a href='../R/501.html' title='Multiple refered from 3 places.'>init</a> (<b>int</b> port)
<a name='L38'><font color='red'>{</font>
<a name='L39'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x80, port + 3);      <i><font color='green'>/* set DLAB of line control reg */</font></i>
<a name='L40'><i><font color='green'>/* 设置线路控制寄存器的DLAB 位(位7) */</font></i>
<a name='L41'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x30, port);          <i><font color='green'>/* LS of divisor (48 -&gt; 2400 bps */</font></i>
<a name='L42'><i><font color='green'>/* 发送波特率因子低字节,0x30-&gt;2400bps */</font></i>
<a name='L43'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x00, port + 1);      <i><font color='green'>/* MS of divisor */</font></i>
<a name='L44'><i><font color='green'>/* 发送波特率因子高字节,0x00 */</font></i>
<a name='L45'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x03, port + 3);      <i><font color='green'>/* reset DLAB */</font></i>
<a name='L46'><i><font color='green'>/* 复位DLAB 位,数据位为8 位 */</font></i>
<a name='L47'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x0b, port + 4);      <i><font color='green'>/* set DTR,RTS, OUT_2 */</font></i>
<a name='L48'><i><font color='green'>/* 设置DTR,RTS,辅助用户输出2 */</font></i>
<a name='L49'>  <a href='../S/22.html#L17' title='Defined at 17 in include/asm/io.h.'>outb_p</a> (0x0d, port + 1);      <i><font color='green'>/* enable all intrs but writes */</font></i>
<a name='L50'><i><font color='green'>/* 除了写(写保持空)以外,允许所有中断源中断 */</font></i>
<a name='L51'>  (<b>void</b>) <a href='../D/842.html' title='Multiple defined in 2 places.'>inb</a> (port);            <i><font color='green'>/* read data port to reset things (?) */</font></i>
<a name='L52'><i><font color='green'>/* 读数据口,以进行复位操作(?) */</font></i>
<a name='L53'><font color='red'>}</font>
<a name='L54'>
<a name='L55'><i><font color='green'>//// 初始化串行中断程序和串行接口。</font></i>
<a name='L56'><b>void</b>
<a name='L57'><a href='../R/579.html' title='Multiple refered from 2 places.'>rs_init</a> (<b>void</b>)
<a name='L58'><font color='red'>{</font>
<a name='L59'>  <a href='../S/25.html#L33' title='Defined at 33 in include/asm/system.h.'>set_intr_gate</a> (0x24, rs1_interrupt);  <i><font color='green'>// 设置串行口1 的中断门向量(硬件IRQ4 信号)。</font></i>
<a name='L60'>  <a href='../S/25.html#L33' title='Defined at 33 in include/asm/system.h.'>set_intr_gate</a> (0x23, rs2_interrupt);  <i><font color='green'>// 设置串行口2 的中断门向量(硬件IRQ3 信号)。</font></i>
<a name='L61'>  <a href='../D/844.html' title='Multiple defined in 2 places.'>init</a> (tty_table[1].read_q.data);      <i><font color='green'>// 初始化串行口1(.data 是端口号)。</font></i>
<a name='L62'>  <a href='../D/844.html' title='Multiple defined in 2 places.'>init</a> (tty_table[2].read_q.data);      <i><font color='green'>// 初始化串行口2。</font></i>
<a name='L63'>  <a href='../S/22.html#L3' title='Defined at 3 in include/asm/io.h.'>outb</a> (<a href='../S/22.html#L25' title='Defined at 25 in include/asm/io.h.'>inb_p</a> (0x21) &amp; 0xE7, 0x21);     <i><font color='green'>// 允许主8259A 芯片的IRQ3,IRQ4 中断信号请求。</font></i>
<a name='L64'><font color='red'>}</font>
<a name='L65'>
<a name='L66'><i><font color='green'>/*</font></i>
<a name='L67'><i><font color='green'>* This routine gets called when tty_write has put something into</font></i>
<a name='L68'><i><font color='green'>* the write_queue. It must check wheter the queue is empty, and</font></i>
<a name='L69'><i><font color='green'>* set the interrupt register accordingly</font></i>
<a name='L70'><i><font color='green'>*</font></i>
<a name='L71'><i><font color='green'>* void _rs_write(struct tty_struct * tty);</font></i>
<a name='L72'><i><font color='green'>*/</font></i>
<a name='L73'><i><font color='green'>/*</font></i>
<a name='L74'><i><font color='green'>* 在tty_write()已将数据放入输出(写)队列时会调用下面的子程序。必须首先</font></i>
<a name='L75'><i><font color='green'>* 检查写队列是否为空,并相应设置中断寄存器。</font></i>
<a name='L76'><i><font color='green'>*/</font></i>
<a name='L77'><i><font color='green'>//// 串行数据发送输出。</font></i>
<a name='L78'><i><font color='green'>// 实际上只是开启串行发送保持寄存器已空中断标志,在UART 将数据发送出去后允许发中断信号。</font></i>
<a name='L79'><b>void</b>
<a name='L80'><a href='../R/580.html' title='Multiple refered from 3 places.'>rs_write</a> (<b>struct</b> tty_struct *tty)
<a name='L81'><font color='red'>{</font>
<a name='L82'>  <a href='../S/25.html#L15' title='Defined at 15 in include/asm/system.h.'>cli</a> ();                       <i><font color='green'>// 关中断。</font></i>
<a name='L83'><i><font color='green'>// 如果写队列不空,则从0x3f9(或0x2f9) 首先读取中断允许寄存器内容,添上发送保持寄存器</font></i>
<a name='L84'><i><font color='green'>// 中断允许标志(位1)后,再写回该寄存器。</font></i>
<a name='L85'>  <b>if</b> (!<a href='../S/38.html#L39' title='Defined at 39 in include/linux/tty.h.'>EMPTY</a> (<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>-&gt;write_q))
<a name='L86'>    <a href='../S/22.html#L3' title='Defined at 3 in include/asm/io.h.'>outb</a> (<a href='../S/22.html#L25' title='Defined at 25 in include/asm/io.h.'>inb_p</a> (<a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>-&gt;write_q.data + 1) | 0x02, <a href='../S/7.html#L44' title='Defined at 44 in fs/char_dev.c.'>tty</a>-&gt;write_q.data + 1);
<a name='L87'>  <a href='../S/25.html#L14' title='Defined at 14 in include/asm/system.h.'>sti</a> ();                       <i><font color='green'>// 开中断。</font></i>
<a name='L88'><font color='red'>}</font>
</pre>
<hr>
<a name='BOTTOM'>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L37'>[^]</a><a href='#L80'>[v]</a><a href='#TOP'>[top]</a>[bottom]<a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?