📄 uart2_8c-source.html
字号:
00184 <span class="keywordflow">return</span> -1;00185 }00186 00187 <span class="keywordtype">int</span> uart1GetByte(<span class="keywordtype">void</span>)00188 {00189 <span class="comment">// get single byte from receive buffer (if available)</span>00190 u08 c;00191 <span class="keywordflow">if</span>(<a class="code" href="uart2_8h.html#a31">uartReceiveByte</a>(1,&c))00192 <span class="keywordflow">return</span> c;00193 <span class="keywordflow">else</span>00194 <span class="keywordflow">return</span> -1;00195 }00196 00197 <a name="l00198"></a><a class="code" href="uart2_8h.html#a31">00198</a> u08 <a class="code" href="uart2_8h.html#a31">uartReceiveByte</a>(u08 nUart, u08* rxData)00199 {00200 <span class="comment">// make sure we have a receive buffer</span>00201 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>[nUart].size)00202 {00203 <span class="comment">// make sure we have data</span>00204 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>[nUart].datalength)00205 {00206 <span class="comment">// get byte from beginning of buffer</span>00207 *rxData = <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>[nUart]);00208 <span class="keywordflow">return</span> TRUE;00209 }00210 <span class="keywordflow">else</span>00211 <span class="keywordflow">return</span> FALSE; <span class="comment">// no data</span>00212 }00213 <span class="keywordflow">else</span>00214 <span class="keywordflow">return</span> FALSE; <span class="comment">// no buffer</span>00215 }00216 <a name="l00217"></a><a class="code" href="uart2_8h.html#a33">00217</a> <span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a18">uartFlushReceiveBuffer</a>(u08 nUart)00218 {00219 <span class="comment">// flush all data from receive buffer</span>00220 <a class="code" href="buffer_8h.html#a7">bufferFlush</a>(&<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>[nUart]);00221 }00222 <a name="l00223"></a><a class="code" href="uart2_8h.html#a32">00223</a> u08 <a class="code" href="uart_8c.html#a19">uartReceiveBufferIsEmpty</a>(u08 nUart)00224 {00225 <span class="keywordflow">return</span> (<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>[nUart].datalength == 0);00226 }00227 <a name="l00228"></a><a class="code" href="uart2_8h.html#a34">00228</a> <span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a34">uartAddToTxBuffer</a>(u08 nUart, u08 data)00229 {00230 <span class="comment">// add data byte to the end of the tx buffer</span>00231 <a class="code" href="buffer_8h.html#a5">bufferAddToEnd</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart], data);00232 }00233 <a name="l00234"></a><a class="code" href="uart2_8h.html#a35">00234</a> <span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a35">uart0AddToTxBuffer</a>(u08 data)00235 {00236 <a class="code" href="uart2_8h.html#a34">uartAddToTxBuffer</a>(0,data);00237 }00238 00239 <span class="keywordtype">void</span> uart1AddToTxBuffer(u08 data)00240 {00241 <a class="code" href="uart2_8h.html#a34">uartAddToTxBuffer</a>(1,data);00242 }00243 <a name="l00244"></a><a class="code" href="uart2_8h.html#a37">00244</a> <span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a21">uartSendTxBuffer</a>(u08 nUart)00245 {00246 <span class="comment">// turn on buffered transmit</span>00247 <a class="code" href="uart_8c.html#a1">uartBufferedTx</a>[nUart] = TRUE;00248 <span class="comment">// send the first byte to get things going by interrupts</span>00249 <a class="code" href="uart2_8h.html#a26">uartSendByte</a>(nUart, <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart]));00250 }00251 <a name="l00252"></a><a class="code" href="uart2_8h.html#a38">00252</a> u08 <a class="code" href="uart2_8h.html#a38">uartSendBuffer</a>(u08 nUart, <span class="keywordtype">char</span> *buffer, u16 nBytes)00253 {00254 <span class="keyword">register</span> u08 first;00255 <span class="keyword">register</span> u16 i;00256 00257 <span class="comment">// check if there's space (and that we have any bytes to send at all)</span>00258 <span class="keywordflow">if</span>((<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart].datalength + nBytes < <a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart].size) && nBytes)00259 {00260 <span class="comment">// grab first character</span>00261 first = *buffer++;00262 <span class="comment">// copy user buffer to uart transmit buffer</span>00263 <span class="keywordflow">for</span>(i = 0; i < nBytes-1; i++)00264 {00265 <span class="comment">// put data bytes at end of buffer</span>00266 <a class="code" href="buffer_8h.html#a5">bufferAddToEnd</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart], *buffer++);00267 }00268 00269 <span class="comment">// send the first byte to get things going by interrupts</span>00270 <a class="code" href="uart_8c.html#a1">uartBufferedTx</a>[nUart] = TRUE;00271 <a class="code" href="uart2_8h.html#a26">uartSendByte</a>(nUart, first);00272 <span class="comment">// return success</span>00273 <span class="keywordflow">return</span> TRUE;00274 }00275 <span class="keywordflow">else</span>00276 {00277 <span class="comment">// return failure</span>00278 <span class="keywordflow">return</span> FALSE;00279 }00280 }00281 00282 <span class="comment">// UART Transmit Complete Interrupt Function</span><a name="l00283"></a><a class="code" href="uart2_8h.html#a39">00283</a> <span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a39">uartTransmitService</a>(u08 nUart)00284 {00285 <span class="comment">// check if buffered tx is enabled</span>00286 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a1">uartBufferedTx</a>[nUart])00287 {00288 <span class="comment">// check if there's data left in the buffer</span>00289 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[nUart].datalength)00290 {00291 <span class="comment">// send byte from top of buffer</span>00292 <span class="keywordflow">if</span>(nUart)00293 outb(UDR1, <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[1]) );00294 <span class="keywordflow">else</span>00295 outb(UDR0, <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>[0]) );00296 }00297 <span class="keywordflow">else</span>00298 {00299 <span class="comment">// no data left</span>00300 <a class="code" href="uart_8c.html#a1">uartBufferedTx</a>[nUart] = FALSE;00301 <span class="comment">// return to ready state</span>00302 <a class="code" href="uart_8c.html#a0">uartReadyTx</a>[nUart] = TRUE;00303 }00304 }00305 <span class="keywordflow">else</span>00306 {00307 <span class="comment">// we're using single-byte tx mode</span>00308 <span class="comment">// indicate transmit complete, back to ready</span>00309 <a class="code" href="uart_8c.html#a0">uartReadyTx</a>[nUart] = TRUE;00310 }00311 }00312 00313 <span class="comment">// UART Receive Complete Interrupt Function</span>00314 <span class="keywordtype">void</span> uartReceiveService(u08 nUart)00315 {00316 u08 c;00317 <span class="comment">// get received char</span>00318 <span class="keywordflow">if</span>(nUart)00319 c = inb(UDR1);00320 <span class="keywordflow">else</span>00321 c = inb(UDR0);00322 00323 <span class="comment">// if there's a user function to handle this receive event</span>00324 <span class="keywordflow">if</span>(UartRxFunc[nUart])00325 {00326 <span class="comment">// call it and pass the received data</span>00327 UartRxFunc[nUart](c);00328 }00329 <span class="keywordflow">else</span>00330 {00331 <span class="comment">// otherwise do default processing</span>00332 <span class="comment">// put received char in buffer</span>00333 <span class="comment">// check if there's space</span>00334 <span class="keywordflow">if</span>( !<a class="code" href="buffer_8h.html#a5">bufferAddToEnd</a>(&uartRxBuffer[nUart], c) )00335 {00336 <span class="comment">// no space in buffer</span>00337 <span class="comment">// count overflow</span>00338 <a class="code" href="uart_8c.html#a4">uartRxOverflow</a>[nUart]++;00339 }00340 }00341 }00342 00343 UART_INTERRUPT_HANDLER(SIG_UART0_TRANS) 00344 {00345 <span class="comment">// service UART0 transmit interrupt</span>00346 <a class="code" href="uart2_8h.html#a39">uartTransmitService</a>(0);00347 }00348 00349 UART_INTERRUPT_HANDLER(SIG_UART1_TRANS) 00350 {00351 <span class="comment">// service UART1 transmit interrupt</span>00352 <a class="code" href="uart2_8h.html#a39">uartTransmitService</a>(1);00353 }00354 00355 UART_INTERRUPT_HANDLER(SIG_UART0_RECV) 00356 {00357 <span class="comment">// service UART0 receive interrupt</span>00358 uartReceiveService(0);00359 }00360 00361 UART_INTERRUPT_HANDLER(SIG_UART1_RECV) 00362 {00363 <span class="comment">// service UART1 receive interrupt</span>00364 uartReceiveService(1);00365 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Oct 15 03:50:22 2004 for Procyon AVRlib by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.6 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -