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

📄 commrtos.c

📁 This soucse code is for CodevisionAVR and RF2500 application driver code is all included.The point
💻 C
字号:
#include     "COMMRTOS.H"   
typedef      struct  {
    INT16U   RingBufRxCtr;
    INT8U    *RingBufRxInPtr;   
    INT8U    *RingBufRxOutPtr;  
    INT8U     RingBufRx[COMM_RX_BUF_SIZE];

    INT16U   RingBufTxCtr;	
    INT8U    *RingBufTxInPtr;   
    INT8U    *RingBufTxOutPtr;  
    INT8U     RingBufTx[COMM_TX_BUF_SIZE];
    } COMM_RING_BUF;  
    
    COMM_RING_BUF    MyRingBuf; 

/*
****************************************************************************************************
*                              REMOVE CHARACTER FROM RING BUFFER
*Description: This function is called by your application to obtain a charcter from the communications 
*channel.The function will wait for a character to be received on the serial channel 
*Argument:  
*           c   character obtained
******************************************************************************************************
*/
INT8U CommGetChar (INT8U *err)
{
    INT8U    c;
    COMM_RING_BUF   *pbuf;
    pbuf = &MyRingBuf;
    if(pbuf->RingBufRxCtr > 0){
    	pbuf->RingBufRxCtr--;
    	c=*pbuf->RingBufRxOutPtr++;
    	if(pbuf->RingBufRxOutPtr==&pbuf->RingBufRx[COMM_RX_BUF_SIZE]) {
    		pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];
        }	
        *err=COMM_NO_ERR;                      
        return(c);
    }else  {           
        *err=COMM_TX_EMPTY;  
        return(NUL);
       }
} 


INT8U CommGetTxChar (INT8U *err)
{
    INT8U    c;
    COMM_RING_BUF   *pbuf;
    pbuf = &MyRingBuf;

    if(pbuf->RingBufTxCtr >0) {
    	pbuf->RingBufTxCtr--;
    	c=*pbuf->RingBufTxOutPtr++;
    	if(pbuf->RingBufTxOutPtr==&pbuf->RingBufTx[COMM_TX_BUF_SIZE]) {
    		pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
        }		
        *err=COMM_NO_ERR;
        return(c);
    }else  {           
        *err=COMM_TX_EMPTY;  
        return(NUL);       
       }
} 


void  CommInit(void)
{	 
    COMM_RING_BUF   *pbuf;
    pbuf = &MyRingBuf;       
    
    pbuf->RingBufRxCtr=0;	                 //clear ring buffer counter
    pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];    //initialize ring buffer input pointer
    pbuf->RingBufRxOutPtr=&pbuf->RingBufRx[0];   //initialize ring buffer output pointer

    pbuf->RingBufTxCtr=0;  
    pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];   
    pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0]; 
}      
      
/*
****************************************************************************************************
*                              OUTPUT CHARACTER
*Description: This function is called by your application to send a charcter on the communications 
*channel.The function will wait for the buffer to empty out if the buffer is full.The function returns 
* to your  application if the buffer doesn't empty within the specified buffer to empty out.The 
*character to send is first inserted into the Tx buffer and will be send by the Tx ISR.If this is the 
*first charcter placed into the buffer,the Tx ISR  will be enabled.
*Argument:  
*           c   character to send
******************************************************************************************************
*/

void CommPutChar (INT8U c)
{
    COMM_RING_BUF   *pbuf;
    pbuf = &MyRingBuf;
    pbuf->RingBufTxCtr++;
    *pbuf->RingBufTxInPtr++=c;
    if(pbuf->RingBufTxInPtr==&pbuf->RingBufTx[COMM_RX_BUF_SIZE]) {
    	pbuf->RingBufTxInPtr=&pbuf->RingBufTx[0];        /*wrap in pointer*/
    }		         
} 

/*
****************************************************************************************************
*                              INSERT CHARACTER INTO RING BUFFER
*Description: This function is called by the Rx ISR to insert a charcter into the receive ring buffer
*Argument:  
*           c   character to insert into the ring buffer. If the buffer is full,the character will
*               not be inserted, it will be lost
******************************************************************************************************
*/
void CommPutRxChar (INT8U c)
{
    COMM_RING_BUF   *pbuf;
    pbuf = &MyRingBuf;    

    if(pbuf->RingBufRxCtr <COMM_RX_BUF_SIZE) {
    	pbuf->RingBufRxCtr++;
    	*pbuf->RingBufRxInPtr++=c;
    	if(pbuf->RingBufRxInPtr==&pbuf->RingBufRx[COMM_RX_BUF_SIZE]) {
    		pbuf->RingBufRxInPtr=&pbuf->RingBufRx[0];
        }		 
    }	             
} 

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -