STM32F10x 学习笔记7(USART实现串口通讯 3)
时间:11-20
来源:互联网
点击:
- dbyyourapplicationtoseeifanymorecharacterscanbeplaced
- *intheTxbuffer.Inotherwords,thisfunctionchecktoseeiftheTxbufferisfull.
- *Ifthebufferisfull,thefunctionreturnsTRUEotherwise,thefunctionreturnsFALSE.
- *Arguments:chistheCOMMportchannelnumberandcaneitherbe:
- *COMM1
- *COMM2
- *Returns:TRUEifthebufferISfull.
- *FALSEifthebufferISNOTfulloryouhavespecifiedanincorrectchannel.
- *********************************************************************************************************
- */
- unsignedcharCommIsFull(unsignedcharch)
- {
- unsignedcharfull;
- COMM_RING_BUF*pbuf;
- OS_CPU_SRcpu_sr;
- switch(ch)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&Comm1Buf;
- break;
- caseCOM2:
- pbuf=&Comm2Buf;
- break;
- default:
- return(TRUE);
- }
- OS_ENTER_CRITICAL();
- if(pbuf->RingBufTxCtr
- {/*Seeifbufferisfull*/
- full=FALSE;/*BufferisNOTfull*/
- }
- else
- {
- full=TRUE;/*Bufferisfull*/
- }
- OS_EXIT_CRITICAL();
- return(full);
- }
- /*
- *********************************************************************************************************
- *OUTPUTCHARACTER
- *
- *
- *Description:Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
- *channel.Thefunctionwillwaitforthebuffertoemptyoutifthebufferisfull.
- *Thefunctionreturnstoyourapplicationifthebufferdoesntemptywithinthespecified
- *timeout.Atimeoutvalueof0meansthatthecallingfunctionwillwaitforeverforthe
- *buffertoemptyout.ThecharactertosendisfirstinsertedintotheTxbufferandwill
- *besentbytheTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISR
- *willbeenabled.
- *Arguments:chistheCOMMportchannelnumberandcaneitherbe:
- *COMM1
- *COMM2
- *cisthecharactertosend.
- *toisthetimeout(inclockticks)towaitincasethebufferisfull.Ifyou
- *specifyatimeoutof0,thefunctionwillwaitforeverforthebuffertoempty.
- *Returns:COMM_NO_ERRifthecharacterwasplacedintheTxbuffer
- *COMM_TX_TIMEOUTifthebufferdidntemptywithinthespecifiedtimeoutperiod
- *COMM_BAD_CHifyouspecifyaninvalidchannelnumber
- *********************************************************************************************************
- */
- unsignedcharCommPutChar(unsignedcharch,unsignedcharc,unsignedshortto)
- {
- unsignedcharoserr;
- COMM_RING_BUF*pbuf;
- OS_CPU_SRcpu_sr;
- switch(ch)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&Comm1Buf;
- break;
- caseCOM2:
- pbuf=&Comm2Buf;
- break;
- default:
- return(COMM_BAD_CH);
- }
- OSSemPend(pbuf->RingBufTxSem,to,&oserr);/*WaitforspaceinTxbuffer*/
- if(oserr==OS_TIMEOUT)
- {
- return(COMM_TX_TIMEOUT);/*Timedout,returnerrorcode*/
- }
- OS_ENTER_CRITICAL();
- pbuf->RingBufTxCtr++;/*No,incrementcharactercount*/
- *pbuf->RingBufTxInPtr++=c;/*Putcharacterintobuffer*/
- if(pbuf->RingBufTxInPtr==&pbuf->RingBufTx[COMM_TX_BUF_SIZE])
- {/*WrapINpointer*/
- pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];
- }
- if(pbuf->RingBufTxCtr==1)
- {/*Seeifthisisthefirstcharacter*/
- COMEnableTxInt(ch);/*Yes,EnableTxinterrupts*/
- }
- OS_EXIT_CRITICAL();
- return(COMM_NO_ERR);
- }
- /*
- *********************************************************************************************************
- *INSERTCHARACTERINTORINGBUFFER
- *
- *
- *Description:ThisfunctioniscalledbytheRxISRtoinsertacharacterintothereceiveringbuffer.
- *Arguments:chistheCOMMportchannelnumberandcaneitherbe:
- *COMM1
- *COMM2
- *cisthecharactertoinsertintotheringbuffer.Ifthebufferisfull,the
- *characterwillnotbeinserted,itwillbelost.
- *********************************************************************************************************
- */
- staticvoidCOMPutRxChar(unsignedcharch,unsignedcharc)
- {
- COMM_RING_BUF*pbuf;
- switch(ch)
- {/*Obtainpointertocommunicationschannel*/
- caseCOM1:
- pbuf=&Comm1Buf;
- break;
- caseCOM2:
- pbuf=&Comm2Buf;
- break;
- default:
- return;
- }
- if(pbuf->RingBufRxCtr
- {/*Seeifbufferisfull*/
- pbuf->RingBufRxCtr++;/*No,incrementcharactercount*/
- *pbuf->RingBufRxInPtr++=c;/*Putcharacterintobuffer*/
- if(pbuf->RingBufRxInPtr==&pbuf->if(pbuf->RingBufRxInPtr==&pbuf->R
STM32F10xUSART串口通 相关文章:
- STM32F10x 学习笔记8(USART实现串口通讯 DMA 方式)(11-20)
- STM32F10x 学习笔记5(USART实现串口通讯 1)(11-20)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)