STM32F10x 学习笔记6(USART实现串口通讯 2)
时间:11-20
来源:互联网
点击:
- _EMPTY;
- c=0;/*Bufferisempty,return0*/
- return(c);
- }
- }
- /************************************************************
- *function:COMPutCharB
- *parameter:charport,portcanbeCOM1/COM2
- *return:COMM_NO_ERRifthefunctionwassuccessful(thebufferwasnotfull)
- *COMM_TX_FULLifthebufferwasfull
- *COMM_BAD_CHifyouhavespecifiedanincorrectchannel
- *usage:Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
- *channel.ThecharactertosendisfirstinsertedintotheTxbufferandwillbesentby
- *theTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISRwillbe
- *enabled.IftheTxbufferisfull,thecharacterwillnotbesent(i.e.itwillbelost)
- *changelog:
- *1.firstimplimentedbyliyuan2010.11.5
- *************************************************************/
- unsignedcharCOMPutCharB(unsignedcharport,unsignedcharc)
- {
- //unsignedcharcpu_sr;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return(COM_BAD_CH);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufTxCtr
- pbuf->RingBufTxCtr++;/*No,incrementcharactercount*/
- *pbuf->RingBufTxInPtr++=c;/*Putcharacterintobuffer*/
- if(pbuf->RingBufTxInPtr==&pbuf->RingBufTx[COM_TX_BUF_SIZE]){/*WrapINpointer*/
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- }
- if(pbuf->RingBufTxCtr==1){/*Seeifthisisthefirstcharacter*/
- COMEnableTxInt(port);/*Yes,EnableTxinterrupts*/
- OS_EXIT_CRITICAL();
- }else{
- OS_EXIT_CRITICAL();
- }
- return(COM_NO_ERR);
- }else{
- OS_EXIT_CRITICAL();
- return(COM_TX_FULL);
- }
- }
- /************************************************************
- *function:COMBufferInit
- *parameter:
- *return:
- *usage:Thisfunctioniscalledbyyourapplicationtoinitializethecommunicationsmodule.You
- *mustcallthisfunctionbeforecallinganyotherfunctions.
- *changelog:
- *************************************************************/
- voidCOMBufferInit(void)
- {
- COM_RING_BUF*pbuf;
- pbuf=&COM1Buf;/*InitializetheringbufferforCOM0*/
- pbuf->RingBufRxCtr=0;
- pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufTxCtr=0;
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
- pbuf=&COM2Buf;/*InitializetheringbufferforCOM1*/
- pbuf->RingBufRxCtr=0;
- pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
- pbuf->RingBufTxCtr=0;
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
- }
- /************************************************************
- *function:COMBufferIsEmpty
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtosee
- *ifanycharacterisavailablefromthecommunicationschannel.
- *Ifatleastonecharacterisavailable,thefunctionreturns
- *FALSE(0)otherwise,thefunctionreturnsTRUE(1).
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsEmpty(unsignedcharport)
- {
- //unsignedcharcpu_sr;
- unsignedcharempty;
- COM_RING_BUF*pbuf;
- switch(port)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&COM1Buf;
- break;
- caseCOM2:
- pbuf=&COM2Buf;
- break;
- default:
- return(1);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufRxCtr>0)
- {/*Seeifbufferisempty*/
- empty=0;/*BufferisNOTempty*/
- }
- else
- {
- empty=1;/*Bufferisempty*/
- }
- OS_EXIT_CRITICAL();
- return(empty);
- }
- /************************************************************
- *function:COMBufferIsFull
- *parameter:charport,portcanbeCOM1/COM2
- *return:char
- *usage:Thisfunctioniscalledbyyourapplicationtoseeifanymorecharacterscanbeplaced
- *intheTxbuffer.Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
- *Ifthebufferisfull,thefunctionreturnsTRUEotherwise,thefunctionreturnsFALSE.
- *changelog:
- *************************************************************/
- unsignedcharCOMBufferIsFull(unsignedcharport)
- {
- //unsignedcharcpu_sr;
STM32F10xUSAR串口通 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)