164 lines
13 KiB
HTML
Executable File
164 lines
13 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="generator" content="TempleOS V5.03">
|
|
<meta name="viewport" content="width=device-width">
|
|
<link rel="stylesheet" href="/style/templeos.css">
|
|
<script src="/script/templeos.js"></script>
|
|
<style type="text/css">
|
|
.cF0{color:#000000;background-color:#ffffff;}
|
|
.cF1{color:#0000aa;background-color:#ffffff;}
|
|
.cF2{color:#00aa00;background-color:#ffffff;}
|
|
.cF3{color:#00aaaa;background-color:#ffffff;}
|
|
.cF4{color:#aa0000;background-color:#ffffff;}
|
|
.cF5{color:#aa00aa;background-color:#ffffff;}
|
|
.cF6{color:#aa5500;background-color:#ffffff;}
|
|
.cF7{color:#aaaaaa;background-color:#ffffff;}
|
|
.cF8{color:#555555;background-color:#ffffff;}
|
|
.cF9{color:#5555ff;background-color:#ffffff;}
|
|
.cFA{color:#55ff55;background-color:#ffffff;}
|
|
.cFB{color:#55ffff;background-color:#ffffff;}
|
|
.cFC{color:#ff5555;background-color:#ffffff;}
|
|
.cFD{color:#ff55ff;background-color:#ffffff;}
|
|
.cFE{color:#ffff55;background-color:#ffffff;}
|
|
.cFF{color:#ffffff;background-color:#ffffff;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre id="content">
|
|
<a name="l1"></a><span class=cF2>/* RS232 serial ports no longer exist.</span><span class=cF0>
|
|
<a name="l2"></a></span><span class=cF2>Be sure to Adam Include this by placing</span><span class=cF0>
|
|
<a name="l3"></a></span><span class=cF2>it in your start-up scripts.</span><span class=cF0>
|
|
<a name="l4"></a></span><span class=cF2>*/</span><span class=cF0>
|
|
<a name="l5"></a>
|
|
<a name="l6"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>"Comm"</span><span class=cF0>
|
|
<a name="l7"></a>
|
|
<a name="l8"></a>#</span><span class=cF1>define</span><span class=cF0> UART_THR 0
|
|
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> UART_RDR 0
|
|
<a name="l10"></a>#</span><span class=cF1>define</span><span class=cF0> UART_BRDL 0
|
|
<a name="l11"></a>#</span><span class=cF1>define</span><span class=cF0> UART_IER 1
|
|
<a name="l12"></a>#</span><span class=cF1>define</span><span class=cF0> UART_BRDH 1
|
|
<a name="l13"></a>#</span><span class=cF1>define</span><span class=cF0> UART_IIR 2
|
|
<a name="l14"></a>#</span><span class=cF1>define</span><span class=cF0> UART_LCR 3
|
|
<a name="l15"></a>#</span><span class=cF1>define</span><span class=cF0> UART_MCR 4
|
|
<a name="l16"></a>#</span><span class=cF1>define</span><span class=cF0> UART_LSR 5
|
|
<a name="l17"></a>#</span><span class=cF1>define</span><span class=cF0> UART_MSR 6
|
|
<a name="l18"></a>
|
|
<a name="l19"></a>#</span><span class=cF1>define</span><span class=cF0> COMf_ENABLED 0
|
|
<a name="l20"></a></span><span class=cF1>class</span><span class=cF0> CComm
|
|
<a name="l21"></a>{
|
|
<a name="l22"></a> </span><span class=cF9>I64</span><span class=cF0> base,
|
|
<a name="l23"></a> flags;
|
|
<a name="l24"></a> </span><span class=cF9>CFifoU8</span><span class=cF0> *RX_fifo;
|
|
<a name="l25"></a> </span><span class=cF9>CFifoU8</span><span class=cF0> *TX_fifo;
|
|
<a name="l26"></a>} comm_ports[5];
|
|
<a name="l27"></a>
|
|
<a name="l28"></a></span><span class=cF1>U0</span><span class=cF0> CommHndlr(</span><span class=cF9>I64</span><span class=cF0> port)
|
|
<a name="l29"></a>{
|
|
<a name="l30"></a> CComm *c=&comm_ports[port];
|
|
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> b=0,stat;
|
|
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&c->flags,COMf_ENABLED</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l33"></a> stat=</span><span class=cF5>InU8</span><span class=cF0>(c->base+UART_IIR);
|
|
<a name="l34"></a> </span><span class=cF1>if</span><span class=cF0> (stat & 4) </span><span class=cF2>//RX</span><span class=cF0>
|
|
<a name="l35"></a> </span><span class=cF5>FifoU8Ins</span><span class=cF0>(c->RX_fifo,</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>c->base+UART_RDR</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l36"></a> </span><span class=cF1>if</span><span class=cF0> (stat & 2) { </span><span class=cF2>//TX</span><span class=cF0>
|
|
<a name="l37"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>FifoU8Rem</span><span class=cF7>(</span><span class=cF0>c->TX_fifo,&b</span><span class=cF7>)</span><span class=cF0>)
|
|
<a name="l38"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_THR,b);
|
|
<a name="l39"></a> </span><span class=cF1>else</span><span class=cF0>
|
|
<a name="l40"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_IER,1); </span><span class=cF2>//RX but no THR empty</span><span class=cF0>
|
|
<a name="l41"></a> }
|
|
<a name="l42"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l43"></a>}
|
|
<a name="l44"></a>
|
|
<a name="l45"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> IRQComm3()
|
|
<a name="l46"></a>{
|
|
<a name="l47"></a> CommHndlr(2);
|
|
<a name="l48"></a> CommHndlr(4);
|
|
<a name="l49"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x20,0x20);
|
|
<a name="l50"></a>}
|
|
<a name="l51"></a>
|
|
<a name="l52"></a></span><span class=cF1>interrupt</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> IRQComm4()
|
|
<a name="l53"></a>{
|
|
<a name="l54"></a> CommHndlr(1);
|
|
<a name="l55"></a> CommHndlr(3);
|
|
<a name="l56"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x20,0x20);
|
|
<a name="l57"></a>}
|
|
<a name="l58"></a>
|
|
<a name="l59"></a></span><span class=cF1>U0</span><span class=cF0> CommInit()
|
|
<a name="l60"></a>{
|
|
<a name="l61"></a> </span><span class=cF5>MemSet</span><span class=cF0>(&comm_ports,0,</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>comm_ports</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l62"></a> comm_ports[1].base=0x3F8;
|
|
<a name="l63"></a> comm_ports[2].base=0x2F8;
|
|
<a name="l64"></a> comm_ports[3].base=0x3E8;
|
|
<a name="l65"></a> comm_ports[4].base=0x2E8;
|
|
<a name="l66"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(0x23,&IRQComm3);
|
|
<a name="l67"></a> </span><span class=cF5>IntEntrySet</span><span class=cF0>(0x24,&IRQComm4);
|
|
<a name="l68"></a>}
|
|
<a name="l69"></a>CommInit;
|
|
<a name="l70"></a>
|
|
<a name="l71"></a></span><span class=cF1>public</span><span class=cF0> CComm *CommInit8n1(</span><span class=cF9>I64</span><span class=cF0> port,</span><span class=cF9>I64</span><span class=cF0> baud)
|
|
<a name="l72"></a>{
|
|
<a name="l73"></a> CComm *c=&comm_ports[port];
|
|
<a name="l74"></a>
|
|
<a name="l75"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l76"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l77"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&c->flags,COMf_ENABLED</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l78"></a> </span><span class=cF5>FifoU8Del</span><span class=cF0>(c->RX_fifo);
|
|
<a name="l79"></a> </span><span class=cF5>FifoU8Del</span><span class=cF0>(c->TX_fifo);
|
|
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l81"></a> c->RX_fifo=</span><span class=cF5>FifoU8New</span><span class=cF0>(256);
|
|
<a name="l82"></a> c->TX_fifo=</span><span class=cF5>FifoU8New</span><span class=cF0>(256);
|
|
<a name="l83"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_LCR,0); </span><span class=cF2>//Set for IER</span><span class=cF0>
|
|
<a name="l84"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_IER,0); </span><span class=cF2>//Disable all IRQ</span><span class=cF0>
|
|
<a name="l85"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_LCR,0x80); </span><span class=cF2>//Enable baud rate control</span><span class=cF0>
|
|
<a name="l86"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_BRDL,</span><span class=cF7>(</span><span class=cF0>0x180/(baud/300)</span><span class=cF7>)</span><span class=cF0> & 0xFF); </span><span class=cF2>//LSB</span><span class=cF0>
|
|
<a name="l87"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_BRDH,</span><span class=cF7>(</span><span class=cF0>0x180/(baud/300)</span><span class=cF7>)</span><span class=cF0> / 256); </span><span class=cF2>//MSB</span><span class=cF0>
|
|
<a name="l88"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_LCR,3); </span><span class=cF2>//8-none-1</span><span class=cF0>
|
|
<a name="l89"></a>
|
|
<a name="l90"></a> </span><span class=cF5>InU8</span><span class=cF0>(c->base+UART_RDR); </span><span class=cF2>//read garbage</span><span class=cF0>
|
|
<a name="l91"></a> </span><span class=cF5>InU8</span><span class=cF0>(c->base+UART_LSR);
|
|
<a name="l92"></a>
|
|
<a name="l93"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_MCR,4);
|
|
<a name="l94"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_IER,0); </span><span class=cF2>//Disable all IRQ</span><span class=cF0>
|
|
<a name="l95"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_MCR,0xA); </span><span class=cF2>//out2 and rts</span><span class=cF0>
|
|
<a name="l96"></a> </span><span class=cF5>OutU8</span><span class=cF0>(0x21,</span><span class=cF5>InU8</span><span class=cF7>(</span><span class=cF0>0x21</span><span class=cF7>)</span><span class=cF0> & </span><span class=cF7>(</span><span class=cF0>0xFF-0x18</span><span class=cF7>)</span><span class=cF0>); </span><span class=cF2>//Enable 8259 IRQ 3 & 4</span><span class=cF0>
|
|
<a name="l97"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_IER,1); </span><span class=cF2>//RX but no THR empty</span><span class=cF0>
|
|
<a name="l98"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l99"></a>
|
|
<a name="l100"></a> </span><span class=cF1>return</span><span class=cF0> c;
|
|
<a name="l101"></a>}
|
|
<a name="l102"></a>
|
|
<a name="l103"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> CommPutChar(</span><span class=cF9>I64</span><span class=cF0> port,</span><span class=cF1>U8</span><span class=cF0> b)
|
|
<a name="l104"></a>{
|
|
<a name="l105"></a> CComm *c=&comm_ports[port];
|
|
<a name="l106"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
|
|
<a name="l107"></a> </span><span class=cF1>CLI</span><span class=cF0>
|
|
<a name="l108"></a> </span><span class=cF5>FifoU8Ins</span><span class=cF0>(c->TX_fifo,b);
|
|
<a name="l109"></a> </span><span class=cF5>OutU8</span><span class=cF0>(c->base+UART_IER,3); </span><span class=cF2>//RX and THR empty</span><span class=cF0>
|
|
<a name="l110"></a> </span><span class=cF1>POPFD</span><span class=cF0>
|
|
<a name="l111"></a> </span><span class=cF5>Sleep</span><span class=cF0>(10); </span><span class=cF2>//!!! Remove this line!!!</span><span class=cF0> </span><span class=cF2>Linux echo_socket is too slow.</span><span class=cF0>
|
|
<a name="l112"></a>}
|
|
<a name="l113"></a>
|
|
<a name="l114"></a></span><span class=cF1>U0</span><span class=cF0> CommPutS(</span><span class=cF9>I64</span><span class=cF0> port,</span><span class=cF1>U8</span><span class=cF0> *st)
|
|
<a name="l115"></a>{
|
|
<a name="l116"></a> </span><span class=cF9>I64</span><span class=cF0> b;
|
|
<a name="l117"></a> </span><span class=cF1>while</span><span class=cF0> (b=*st++)
|
|
<a name="l118"></a> CommPutChar(port,b);
|
|
<a name="l119"></a>}
|
|
<a name="l120"></a>
|
|
<a name="l121"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> CommPutBlk(</span><span class=cF9>I64</span><span class=cF0> port,</span><span class=cF1>U8</span><span class=cF0> *buf,</span><span class=cF9>I64</span><span class=cF0> cnt)
|
|
<a name="l122"></a>{
|
|
<a name="l123"></a> </span><span class=cF1>while</span><span class=cF0> (cnt--)
|
|
<a name="l124"></a> CommPutChar(port,*buf++);
|
|
<a name="l125"></a>}
|
|
<a name="l126"></a>
|
|
<a name="l127"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> CommPrint(</span><span class=cF9>I64</span><span class=cF0> port,</span><span class=cF1>U8</span><span class=cF0> *fmt,...)
|
|
<a name="l128"></a>{
|
|
<a name="l129"></a> </span><span class=cF1>U8</span><span class=cF0> *buf=</span><span class=cF5>StrPrintJoin</span><span class=cF0>(</span><span class=cF3>NULL</span><span class=cF0>,fmt,argc,argv);
|
|
<a name="l130"></a> CommPutS(port,buf);
|
|
<a name="l131"></a> </span><span class=cF5>Free</span><span class=cF0>(buf);
|
|
<a name="l132"></a>}
|
|
</span></pre></body>
|
|
</html>
|