📄 uart_8c-source.html
字号:
00143 {00144 <span class="comment">// get byte from beginning of buffer</span>00145 *rxData = <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>);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 <span class="comment"></span>00161 <span class="comment">//! flush all data out of the receive buffer</span><a name="l00162"></a><a class="code" href="uart_8h.html#a14">00162</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a18">uartFlushReceiveBuffer</a>(<span class="keywordtype">void</span>)00163 {00164 <span class="comment">// flush all data from receive buffer</span>00165 <span class="comment">//bufferFlush(&uartRxBuffer);</span>00166 <span class="comment">// same effect as above</span>00167 <a class="code" href="uart_8c.html#a2">uartRxBuffer</a>.datalength = 0;00168 }00169 <span class="comment"></span>00170 <span class="comment">//! return true if uart receive buffer is empty</span><a name="l00171"></a><a class="code" href="uart_8h.html#a13">00171</a> <span class="comment"></span>u08 <a class="code" href="uart_8c.html#a19">uartReceiveBufferIsEmpty</a>(<span class="keywordtype">void</span>)00172 {00173 <span class="keywordflow">if</span>(<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>.datalength == 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 <span class="comment"></span>00183 <span class="comment">//! add byte to end of uart Tx buffer</span><a name="l00184"></a><a class="code" href="uart_8h.html#a15">00184</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart2_8h.html#a34">uartAddToTxBuffer</a>(u08 data)00185 {00186 <span class="comment">// add data byte to the end of the tx buffer</span>00187 <a class="code" href="buffer_8h.html#a5">bufferAddToEnd</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>, data);00188 }00189 <span class="comment"></span>00190 <span class="comment">//! start transmission of the current uart Tx buffer contents</span><a name="l00191"></a><a class="code" href="uart_8h.html#a16">00191</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="uart_8c.html#a21">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="uart2_8h.html#a26">uartSendByte</a>(<a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>));00197 }00198 <span class="comment">/*</span><span class="comment"></span>00199 <span class="comment">//! transmit nBytes from buffer out the uart</span>00200 <span class="comment"></span>u08 uartSendBuffer(char *buffer, u16 nBytes)00201 {00202 register u08 first;00203 register u16 i;00204 00205 // check if there's space (and that we have any bytes to send at all)00206 if((uartTxBuffer.datalength + nBytes < uartTxBuffer.size) && nBytes)00207 {00208 // grab first character00209 first = *buffer++;00210 // copy user buffer to uart transmit buffer00211 for(i = 0; i < nBytes-1; i++)00212 {00213 // put data bytes at end of buffer00214 bufferAddToEnd(&uartTxBuffer, *buffer++);00215 }00216 00217 // send the first byte to get things going by interrupts00218 uartBufferedTx = TRUE;00219 uartSendByte(first);00220 // return success00221 return TRUE;00222 }00223 else00224 {00225 // return failure00226 return FALSE;00227 }00228 }00229 */<span class="comment"></span>00230 <span class="comment">//! UART Transmit Complete Interrupt Handler</span><a name="l00231"></a><a class="code" href="uart_8c.html#a22">00231</a> <span class="comment"></span>UART_INTERRUPT_HANDLER(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>(<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>.datalength)00238 {00239 <span class="comment">// send byte from top of buffer</span>00240 outp( <a class="code" href="buffer_8h.html#a2">bufferGetFromFront</a>(&<a class="code" href="uart_8c.html#a3">uartTxBuffer</a>), UDR );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 <span class="comment"></span>00258 <span class="comment">//! UART Receive Complete Interrupt Handler</span><a name="l00259"></a><a class="code" href="uart_8c.html#a23">00259</a> <span class="comment"></span>UART_INTERRUPT_HANDLER(SIG_UART_RECV)00260 {00261 u08 c;00262 00263 <span class="comment">// get received char</span>00264 c = inp(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="buffer_8h.html#a5">bufferAddToEnd</a>(&<a class="code" href="uart_8c.html#a2">uartRxBuffer</a>, 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 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 + -