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

📄 uart_8c-source.html

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