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

📄 common.c

📁 电力系统中的保护装置全部代码
💻 C
字号:
/*************************************************************************/
/* Warning:                                                              */
/*       Pls don't remodify this File.                                   */
/*       If you have something exhausted,  pls contact with me.          */
/*                       GauTsuanFar----2001/12/22                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/*        Copyright (c) 2001-2001 XJ electric corporation.               */
/*                                                                       */
/* PROPRIETARY RIGHTS of XJ Group are involved in the                    */
/* subject matter of this material.  All manufacturing, reproduction,    */
/* use, and sales rights pertaining to this subject matter are governed  */
/* by the license agreement.  The recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      common.c                                           ver1.0        */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      Rchar16c554 - Receive char of 16C554                             */
/*      Tchar16c554 - Transmit char of 16C554                            */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the  communication task of monitor.           */
/*                                                                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      GauTsuanFar, XJ electric corporation.                            */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      Interrupt Receive buffer of A channel, Serio0Addr of 16c554      */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      Rchar16c554                     Receive a char                   */
/*      Tchar16c554                     transmit a char                  */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      Initial16C554A                  initial 16c554 A channel         */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*   NAME               DATE                    REMARKS           	 */
/*   GauTsuanFar       2001-08-22     complete Rchar16c554 and        	 */
/*                                    Tchar16c554 Function            	 */ 
/*   GauTsuanFar       2001-12-22     complete communication loop     	 */
/*                                    and communication simulation    	 */
/*                                                                       */
/*************************************************************************/
#include  "nucleus.h"
#include  "comm.h"
#include  "BaseVariable.h" 

int    	Initial_16c554JK1(unsigned char *COM_PORT);   
int    	Construct_StructJK1 (unsigned char *COM_PORT);
int 	Rchar16c554JK1(unsigned char char2[2],unsigned char *COM_PORT);
void 	Tchar16c554JK1(unsigned char *COM_PORT,unsigned char char1);
volatile struct	Buffer_Struct ReceBuff;

volatile int  	TimeCount1 = 0;
volatile int  	TimeCount2 = 0; 		
unsigned char   CommunStatusJK1 = 0;    


/* This function has been inspected.GauTsunFar 2001-12-22 

函数功能:Initial communication component ; 

输入参数: Commu port------------------- COM_PORT

输出参数: no
         
返回数值: no need mention;

*/                                           
int Initial_16c554JK1(unsigned char *COM_PORT)
{
    if     (COM_PORT == Com_Port1)
    {	
       	Init_16c554A();   
    }	
	else if(COM_PORT == Com_Port2)
    {
        Init_16c554B();
    }        
    else if(COM_PORT == Com_Port3)
    {        
        Init_16c554C();
    }        
    else   
    { 
        Init_16c554D();     
    }            
    return(1);
}                                           
/* This function has been inspected.GauTsunFar 2001-12-22 

函数功能:Construct the interrupt receive buffer structure;

输入参数:commu port-------------------------------- COM_PORT;
         
输出参数:

返回数值: no need mention;

*/                
int     Construct_StructJK1 (unsigned char *COM_PORT)
{
	if(COM_PORT == Com_Port1)
    {
       	ReceBuff.pInBuffer= pInReceBuffA;      /*input pointer*/
 		ReceBuff.pOutBuffer= pOutReceBuffA;     /*output pointer*/
 		ReceBuff.Buffer	= ReceiveBuffA;      /*Buffer address pointer*/
 		ReceBuff.Length	= ReceBuffALen;      /*buffer length*/
    }
	else if(COM_PORT == Com_Port2)
    {
       	ReceBuff.pInBuffer=	pInReceBuffB;      /*input pointer*/
 		ReceBuff.pOutBuffer=pOutReceBuffB;     /*output pointer*/
 		ReceBuff.Buffer	= ReceiveBuffB;      /*Buffer address pointer*/
 		ReceBuff.Length	= ReceBuffBLen;      /*buffer length*/
    }
    else if(COM_PORT == Com_Port3)
    {
       	ReceBuff.pInBuffer= pInReceBuffC;      /*input pointer*/
 		ReceBuff.pOutBuffer= pOutReceBuffC;     /*output pointer*/
 		ReceBuff.Buffer	= ReceiveBuffC;      /*Buffer address pointer*/
 		ReceBuff.Length	= ReceBuffCLen;      /*buffer length*/
    }
    else   
    {
       	ReceBuff.pInBuffer= pInReceBuffD;      /*input pointer*/
 		ReceBuff.pOutBuffer= pOutReceBuffD;     /*output pointer*/
 		ReceBuff.Buffer	=	ReceiveBuffD;      /*Buffer address pointer*/
 		ReceBuff.Length	= 	ReceBuffDLen;      /*buffer length*/
    }
    return(1); 
}                            

/* This function has been inspected.GauTsunFar 2001-12-22 

函数功能:receive a character;

输入参数:receiving interrupt buffer structure----- *ReceBuff; 
         commu port-------------------------------- COM_PORT;
         
输出参数:receive character-------------- char2[0];
         receiveing status-------------- char2[1]{:=0 normal;:=0xff overtime}

返回数值: no need mention;

*/  

int Rchar16c554JK1(unsigned char char2[2],unsigned char *COM_PORT)
{                                                                      
int timecount;                          
OPTION          old_preempt;     	      
//---------------------------------------------------------------- 
	
	timecount = TMD_System_Clock; 

	while(1)
 	{
        if((TMD_System_Clock - timecount)>300)
        {
         	TimeCount1++;
         	timecount = TMD_System_Clock;  
         	if(TimeCount1 >= 30)
           	{
           		Initial_16c554JK1(COM_PORT);    /*reset communication unit*/
           		TimeCount1 = 0;
           		CommunStatusJK1 |= _Rxd_Error;
       old_preempt = NU_Change_Preemption(NU_NO_PREEMPT);
        if(COM_PORT==Com_Port3)        
 	{	
 	 
// 		CtrlPortBuf  &= (~_485_OE1);  /*485OE1 unSelected*/ 
// 	    *RDY_OE = CtrlPortBuf;  
        disable485()
 	}
 	if(COM_PORT==Com_Port4)        
 	{
// 		CtrlPortBuf &= (~_485_OE1);   /*485OE2 unSelected*/ 
//      *RDY_OE = CtrlPortBuf;
        disable485()
    }
    NU_Change_Preemption(old_preempt);
               	}
        	char2[1] = 0x0ff;                 /*time out */

    	 	return(1); 
    	}
                 
  		if(*(ReceBuff.pInBuffer) != *(ReceBuff.pOutBuffer))	/*Have char*/ 
    	{                           
     	   	TimeCount1 = 0;
     	   	CommunStatusJK1 &= _Rxd_Error^0xff;
     	   	char2[0] = **(ReceBuff.pOutBuffer);  	/*read character*/
     	   	*(ReceBuff.pOutBuffer) = *(ReceBuff.pOutBuffer)+1;
		  	char2[1] = 0;               		/*receive char reliable*/
	                                                /*judge the buffer boundary*/
		  	if(*(ReceBuff.pOutBuffer) >= (ReceBuff.Buffer+ReceBuff.Length-1))  
		   	{	
		   		*(ReceBuff.pOutBuffer)  = ReceBuff.Buffer; /*reset output pointer*/
     	    }
     	   	return(1);                
     	}
   //  	NU_Relinquish(); 
	} 
 	
}        

/* This function has been inspected.GauTsunFar 2001-12-22

函数功能: transmit a character; 

输入参数: serial port address----------------- COM_PORT;
          character that transmited------------char1

输出参数: no.
         
返回数值: no need mention;

*/
void   Tchar16c554JK1(unsigned char *COM_PORT,unsigned char char1)
{
unsigned char *address1,*address2;  
int  flag;      
int  timecount;
//----------------------------------------------------------------               
   	address1 = COM_PORT+5;              /* LineSR */
   	address2 = COM_PORT+0;              /* TransmitBR */
   	
   	timecount = TMD_System_Clock;
   	flag = *address1;
    TimeCount2 = 0;
   	while(!((flag&TransReady_)&&(HoldRegEmpty_&flag)))
    {
       	flag = *address1;            	  /* TransmitBR empty */
    /*
    	if((TMD_System_Clock - timecount) > 200)
       	{
       	 	TimeCount2++;
       	 	timecount = TMD_System_Clock;  
       	 	if(TimeCount2 >= 50)
        	{
        		TimeCount2 = 50;
        		CommunStatusJK1 |= _Txd_Error;
        	}
      	}  
     */ 	
    }	
    CommunStatusJK1 &= (~_Txd_Error);
   	*address2 = char1;                    /* transmit char */
}     

⌨️ 快捷键说明

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