⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart_8c-source.html

📁 单片机的软件
💻 HTML
📖 第 1 页 / 共 2 页
字号:
00143         {00144             <span class="comment">// get byte from beginning of buffer</span>00145             *rxData = <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(&amp;uartRxBuffer);00146             <span class="keywordflow">return</span> TRUE;00147         }00148         <span class="keywordflow">else</span>00149         {00150             <span class="comment">// no data</span>00151             <span class="keywordflow">return</span> FALSE;00152         }00153     }00154     <span class="keywordflow">else</span>00155     {00156         <span class="comment">// no buffer</span>00157         <span class="keywordflow">return</span> FALSE;00158     }00159 }00160 00161 <span class="comment">// flush all data out of the receive buffer</span><a name="l00162"></a><a class="code" href="group__uart.html#ga10">00162</a> <span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga10">uartFlushReceiveBuffer</a>(<span class="keywordtype">void</span>)00163 {00164     <span class="comment">// flush all data from receive buffer</span>00165     <span class="comment">//bufferFlush(&amp;uartRxBuffer);</span>00166     <span class="comment">// same effect as above</span>00167     uartRxBuffer.<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;00168 }00169 00170 <span class="comment">// return true if uart receive buffer is empty</span><a name="l00171"></a><a class="code" href="group__uart.html#ga9">00171</a> u08 <a class="code" href="group__uart.html#ga9">uartReceiveBufferIsEmpty</a>(<span class="keywordtype">void</span>)00172 {00173     <span class="keywordflow">if</span>(uartRxBuffer.<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> == 0)00174     {00175         <span class="keywordflow">return</span> TRUE;00176     }00177     <span class="keywordflow">else</span>00178     {00179         <span class="keywordflow">return</span> FALSE;00180     }00181 }00182 00183 <span class="comment">// add byte to end of uart Tx buffer</span><a name="l00184"></a><a class="code" href="group__uart.html#ga11">00184</a> u08 <a class="code" href="group__uart.html#ga11">uartAddToTxBuffer</a>(u08 data)00185 {00186     <span class="comment">// add data byte to the end of the tx buffer</span>00187     <span class="keywordflow">return</span> <a class="code" href="group__buffer.html#ga5">bufferAddToEnd</a>(&amp;uartTxBuffer, data);00188 }00189 00190 <span class="comment">// start transmission of the current uart Tx buffer contents</span><a name="l00191"></a><a class="code" href="group__uart.html#ga12">00191</a> <span class="keywordtype">void</span> <a class="code" href="group__uart.html#ga12">uartSendTxBuffer</a>(<span class="keywordtype">void</span>)00192 {00193     <span class="comment">// turn on buffered transmit</span>00194     <a class="code" href="uart_8c.html#a1">uartBufferedTx</a> = TRUE;00195     <span class="comment">// send the first byte to get things going by interrupts</span>00196     <a class="code" href="group__uart.html#ga6">uartSendByte</a>(<a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(&amp;uartTxBuffer));00197 }00198 <span class="comment">/*</span>00199 <span class="comment">// transmit nBytes from buffer out the uart</span>00200 <span class="comment">u08 uartSendBuffer(char *buffer, u16 nBytes)</span>00201 <span class="comment">{</span>00202 <span class="comment">    register u08 first;</span>00203 <span class="comment">    register u16 i;</span>00204 <span class="comment"></span>00205 <span class="comment">    // check if there's space (and that we have any bytes to send at all)</span>00206 <span class="comment">    if((uartTxBuffer.datalength + nBytes &lt; uartTxBuffer.size) &amp;&amp; nBytes)</span>00207 <span class="comment">    {</span>00208 <span class="comment">        // grab first character</span>00209 <span class="comment">        first = *buffer++;</span>00210 <span class="comment">        // copy user buffer to uart transmit buffer</span>00211 <span class="comment">        for(i = 0; i &lt; nBytes-1; i++)</span>00212 <span class="comment">        {</span>00213 <span class="comment">            // put data bytes at end of buffer</span>00214 <span class="comment">            bufferAddToEnd(&amp;uartTxBuffer, *buffer++);</span>00215 <span class="comment">        }</span>00216 <span class="comment"></span>00217 <span class="comment">        // send the first byte to get things going by interrupts</span>00218 <span class="comment">        uartBufferedTx = TRUE;</span>00219 <span class="comment">        uartSendByte(first);</span>00220 <span class="comment">        // return success</span>00221 <span class="comment">        return TRUE;</span>00222 <span class="comment">    }</span>00223 <span class="comment">    else</span>00224 <span class="comment">    {</span>00225 <span class="comment">        // return failure</span>00226 <span class="comment">        return FALSE;</span>00227 <span class="comment">    }</span>00228 <span class="comment">}</span>00229 <span class="comment">*/</span>00230 <span class="comment">// UART Transmit Complete Interrupt Handler</span>00231 <a class="code" href="group__uart.html#ga17">UART_INTERRUPT_HANDLER</a>(SIG_UART_TRANS)00232 {00233     <span class="comment">// check if buffered tx is enabled</span>00234     <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">uartBufferedTx</a>)00235     {00236         <span class="comment">// check if there's data left in the buffer</span>00237         <span class="keywordflow">if</span>(uartTxBuffer.<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)00238         {00239             <span class="comment">// send byte from top of buffer</span>00240             outb(UDR, <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(&amp;uartTxBuffer));00241         }00242         <span class="keywordflow">else</span>00243         {00244             <span class="comment">// no data left</span>00245             <a class="code" href="uart_8c.html#a1">uartBufferedTx</a> = FALSE;00246             <span class="comment">// return to ready state</span>00247             <a class="code" href="uart_8c.html#a0">uartReadyTx</a> = TRUE;00248         }00249     }00250     <span class="keywordflow">else</span>00251     {00252         <span class="comment">// we're using single-byte tx mode</span>00253         <span class="comment">// indicate transmit complete, back to ready</span>00254         <a class="code" href="uart_8c.html#a0">uartReadyTx</a> = TRUE;00255     }00256 }00257 00258 <span class="comment">// UART Receive Complete Interrupt Handler</span>00259 <a class="code" href="group__uart.html#ga17">UART_INTERRUPT_HANDLER</a>(SIG_UART_RECV)00260 {00261     u08 c;00262     00263     <span class="comment">// get received char</span>00264     c = inb(UDR);00265 00266     <span class="comment">// if there's a user function to handle this receive event</span>00267     <span class="keywordflow">if</span>(UartRxFunc)00268     {00269         <span class="comment">// call it and pass the received data</span>00270         UartRxFunc(c);00271     }00272     <span class="keywordflow">else</span>00273     {00274         <span class="comment">// otherwise do default processing</span>00275         <span class="comment">// put received char in buffer</span>00276         <span class="comment">// check if there's space</span>00277         <span class="keywordflow">if</span>( !<a class="code" href="group__buffer.html#ga5">bufferAddToEnd</a>(&amp;uartRxBuffer, c) )00278         {00279             <span class="comment">// no space in buffer</span>00280             <span class="comment">// count overflow</span>00281             <a class="code" href="uart_8c.html#a4">uartRxOverflow</a>++;00282         }00283     }00284 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Aug 22 04:29:28 2005 for Procyon AVRlib by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>

⌨️ 快捷键说明

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