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

📄 drvinterface.c

📁 该接口主要描述了关于应用层与90820之间的收发数据控制
💻 C
字号:
/************************************************************************
*************************************************************************
*
* MODULE:  
* VERSION: V600_0,
* $Revision:   1.16.1.0  $ $Modtime:   
* DESCRIPTION: 
* Drivers
*
*************************************************************************
****copyright_c**********************************************************
                                   
                         COPYRIGHT STATEMENT

*************************************************************************
description:
*************************************************************************
*************************************************************************
*/

#include "taskLib.h"
#include "msgQLib.h"
#ifdef Consys
#include "s3c2410.h"
#endif

/************************************************************************
*                M  A  C  R  O
*************************************************************************
*/
/*loop test*//*
#define PliLoopTest*/
#define DISPDEBUG

#define MT9075BINIT 0x01
#define MT9075BLOCK 0x02
#define MT9075BLOOP 0x03
#define MT9075BSYNCHECK 0x04


#define OFFSETPTR  512

int PRINTFLAG=0;
int DIFFFLAG=0;

/*RAM address*/
unsigned long FIRSTSENDADDR[]={0, 0x080e4800, 0x080eb800};
unsigned long ENDSENDADDR[]={0, 0x080e7fff, 0x080eefff};
unsigned long FIRSTRECVADDR[]={0, 0x080e1000, 0x080e8000};
unsigned long ENDRECVADDR[]={0, 0x080e47ff, 0x080eb7ff};
/************************************************************************
*                F U N C T I O N S
*************************************************************************
*/
#ifdef PliLoopTest
static int DRVLOOPFLAG=1;
MSG_Q_ID testMsgQ;
void CrtTestMsgQ(void);
void AppendQuene(int length, unsigned char* recvmsg);
unsigned char* LOOPMSGTRANS(unsigned char* message);
#endif

void Snddebug(int link, int length, unsigned char* printmsg);
void debugDiffer(int link, int length, unsigned char* printmsg);
void ReportMTP3State(int link, int len);
int CompareDiff(int link, unsigned char* comMsg);
int FilterPack(unsigned char* filtMsg);
void ReportPliState(int link, int state);
void StartRecvTask(int link);
void StartCheck(int link);


/************************************************************************
*                E X T E R N
*************************************************************************
*/
extern int SendTrkMsg(int iTrkPort, int iMsgLength, char*  pchMsg);
extern void Dvr_ChanIsr(int portid, int chanid, unsigned char* recvmsg);
extern void ReportLinkState(int link, int state);
extern unsigned char* SendPacket_Isr(int portid, int chanid);
extern void Dvr_DatCnf(int portid, int chanid);

/***********************************************************************
* port chan 和E1的Link对应关系  
***********************************************************************/
int PoChan2Link(int port,int chan)
{
	return (port*64+chan);
}

void Link2PoChan(int link, int * port,int * chan)
{
	*port=(link) / 64;
	*chan=((link) % 64);
}

/***************************************************************
*						SndSignaltoDrv
****************************************************************
*  send all control signaling to driver.
*/
void SndSigtoDrv(unsigned char* sigmsg)
{
	/*Add Code Here*/
	int Length;
	
	Length = *(sigmsg+1)+2;
	/*send to COM2*/
	SendTrkMsg(1, Length, sigmsg);
}

/***************************************************************
*						InitMT9075B
****************************************************************
*	initialize MT9075B driver.
*/
void InitMT9075B(int link)
{
	/*Add init signaling to MT9075B*/
	unsigned char InitMsg[10];
	InitMsg[0] = MT9075BINIT;
	InitMsg[1] = 0x01;
	InitMsg[2] = (unsigned char)link;
	SndSigtoDrv(InitMsg);
}

/***************************************************************
*						SetE1Lock
****************************************************************
* 
*/
void SetE1Lock(int link, int num)
{
	/*Add Code Here*/
	unsigned char LockMsg[10];
	LockMsg[0] = MT9075BLOCK;
	LockMsg[1] = 0x02;
	LockMsg[2] = (unsigned char)link;
	LockMsg[3] = (unsigned char)num;
	SndSigtoDrv(LockMsg);
}

/***************************************************************
*						SetE1Loop
****************************************************************
* num: 00--unloop; 01--loop
*/
void SetE1Loop(int link, int num)
{
	/*Add Code Here*/
	unsigned char LoopMsg[10];
	LoopMsg[0] = MT9075BLOOP;
	LoopMsg[1] = 0x02;
	LoopMsg[2] = (unsigned char)link;
	LoopMsg[3] = (unsigned char)num;
	SndSigtoDrv(LoopMsg);	
}

/***************************************************************
*						SynchroCheck
****************************************************************
* num: 00--unloop; 01--loop
*/
void SynchroCheck(int link)
{
	/*Add Code Here*/
	unsigned char LoopMsg[10];
	LoopMsg[0] = MT9075BSYNCHECK;
	LoopMsg[1] = 0x01;
	LoopMsg[2] = (unsigned char)link;
	SndSigtoDrv(LoopMsg);	
}

/***************************************************************
*						Recv51Msg
****************************************************************
*  receive message from mcs51.
*/
void Recv51Msg(unsigned char* f51msg, int len)
{
	int funcCode;
	int link;

	funcCode = (int)*(f51msg+0);
	link = (int)*(f51msg+2);
	switch(funcCode)
	{
		case MT9075BINIT:
			printf("\nMT9075BINIT\n");
			StartRecvTask(link);
			break;
		case MT9075BLOCK:
			printf("\nMT9075BLOCK\n");
			break;
		case MT9075BLOOP:
			printf("\nMT9075BLOOP\n");
			break;
		case MT9075BSYNCHECK:
			if(*(f51msg+3)==0x01)
				{GciDvr_ChanCtlInd(0,1,5);}
			else/*底层接收断开时,要通知协议层,否则链路恢复时,程序不能自动恢复*/
				{GciDvr_ChanCtlInd(0,1,6);}
				
			ReportPliState(link, *(f51msg+3));
			break;
		default:
			
			break;
		
	}
}

/***************************************************************
*						SndtoRAM
****************************************************************
*  send FSU LSSU MSU to driver-RAM.
*/
void SndtoRAM(int link)
{
	unsigned char* sendPtr;
	unsigned char* sendfstPtr;
	unsigned char* sendendPtr;
	unsigned char* tmpMsg;
	unsigned char* rammsg;
	int           length,i;
	int          port,chan;
	int         result;
	

  sendPtr = (unsigned char*)FIRSTSENDADDR[link];
	sendfstPtr = (unsigned char*)FIRSTSENDADDR[link];
	sendendPtr = (unsigned char*)ENDSENDADDR[link];

	Link2PoChan(link,&port,&chan);
	while(1)
	{
		rammsg = SendPacket_Isr(port,chan);
		if(rammsg==NULL)
			goto end;
	  Dvr_DatCnf(port,chan);
	  length = (int)*(rammsg+2)+3;
#ifdef DISPDEBUG
	  Snddebug(link, length, rammsg);
#endif
	  ReportMTP3State(link, length);
#ifdef PliLoopTest
	  if(DRVLOOPFLAG==1)
		 {
			 tmpMsg = LOOPMSGTRANS(rammsg);
			 AppendQuene(length, tmpMsg);
		 }
	 else
#endif
		 {/*
		 	if((result=CompareDiff(link, rammsg))==1)
		 		{*/
#ifdef DISPDEBUG
		 			debugDiffer(3, length, rammsg);
#endif
		 			*(sendPtr+1) = length % 256;
			    *(sendPtr+2) = length / 256;
			    for(i=0; i<length; i++)
			     {
			  	   *(sendPtr+3+i) = *(rammsg+i);
			     }
			     *sendPtr = 1;
			     if((sendendPtr-sendPtr)>OFFSETPTR)
		 	 	    {				      
				      sendPtr += OFFSETPTR;
			      }
			     else
			 	    {
				      sendPtr = sendfstPtr;
			 	    }
			 	   *sendPtr = 0;
	 	 		/*}	*/					
		 }
end:
		taskDelay(10);
	}
}


/***************************************************************
*						RecvfromRAM
****************************************************************
* receive message from driver-RAM to SS7 protocol stack.
*/
void RecvfromRAM(int link)
{
	unsigned char* RecvPtr;
	unsigned char* RecvFstPtr;
	unsigned char* RecvendPtr;
	
	int   length,i;
	int   port,chan;
	char recvbuf[300];
	unsigned char RecvFlag,RecvFlag1;
	unsigned char* tmpMsg;
	int     result;

	RecvPtr = (unsigned char*)FIRSTRECVADDR[link];
	RecvFstPtr = (unsigned char*)FIRSTRECVADDR[link];
	RecvendPtr = (unsigned char*)ENDRECVADDR[link];
	
	Link2PoChan(link,&port,&chan);
	while(1)
	{
#ifdef PliLoopTest
		if(DRVLOOPFLAG==1)
			{
				msgQReceive(testMsgQ,recvbuf,256,WAIT_FOREVER);
				Dvr_ChanIsr(port,chan,recvbuf);
			}
		else
#endif
			{
				/*add code here*/
				RecvFlag = *RecvPtr;
				RecvFlag1 = *(RecvPtr-1);
				if(RecvFlag == 1)
				 {
				   length = ((*(RecvPtr+2))*256 + (*(RecvPtr+1)));
				   *RecvPtr = 0x00;
				   if(length>275)
				   	{
				   		goto NEXT;
				   	}
				   for(i=0; i<length; i++)
				   {
				   	recvbuf[i] = *(RecvPtr+3+i);
				   	*(RecvPtr+3+i) = 0x00;
				   }
				   if( (result=FilterPack(recvbuf))==1 )
				   	{
				   		Dvr_ChanIsr(port,chan,recvbuf);
#ifdef DISPDEBUG
				   		debugDiffer(4, length, recvbuf);
				   	}
				   else
				   	{
				   		printf("\nwrong!!");
				   		debugDiffer(4, length, recvbuf);
#endif
				   	}
NEXT:
  			   if(RecvendPtr-RecvPtr-OFFSETPTR>OFFSETPTR)
				   	{
				   		RecvPtr += OFFSETPTR;
				   	}
				   else
				   	{
				   		RecvPtr = RecvFstPtr;
				   	}
				 }
			}
		taskDelay(1);
	}
}


/***************************************************************
*						StartRecvTask
****************************************************************
* start receive task.
*/
int t9075RxId[3];
int t9075TxId[3];
char Str[15];
void StartRecvTask(int link)
{
	sprintf(Str,"tRx9075_%d",link);
	t9075RxId[link] = taskSpawn (Str, 80, VX_SUPERVISOR_MODE,
		10000, (FUNCPTR)RecvfromRAM, link, 0, 0, 0, 0, 0, 0, 0, 0, 0);
		
	sprintf(Str,"tTx9075_%d",link);
	t9075TxId[link] = taskSpawn (Str, 80, VX_SUPERVISOR_MODE,
		10000, (FUNCPTR)SndtoRAM, link, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}

/***************************************************************
*						StopRecvTask
****************************************************************
* stop receive task.
*/
void StopRecvTask(int link)
{
	taskDelete(t9075RxId[link]);
	taskDelete(t9075TxId[link]);
}

/***************************************************************
*						MT9075BSrvAdd
****************************************************************
* called by SS7 protocol stack to active driver.
*/
void MT9075BSrvAdd(int link)
{
#ifdef PliLoopTest
	if(DRVLOOPFLAG==1)
		{
			GciDvr_ChanCtlInd(0,1,5);
			ReportLinkState(5, 3);
			CrtTestMsgQ();
			StartRecvTask(link);
		}
	else
#endif
		{
			SetE1Lock(link,1);
			StartCheck(link);
			StartRecvTask(link);
	  }
}

/****************************************************
*		CompareDiff
*****************************************************
* compare different message.
*/
unsigned char diffMsg[5][4];
int CompareDiff(int link, unsigned char* comMsg)
{
	if((diffMsg[link][0]==*(comMsg+0)) &&
		(diffMsg[link][1]==*(comMsg+1)) &&
		(diffMsg[link][2]==*(comMsg+2)) &&
		(diffMsg[link][3]==*(comMsg+3)))
		{
			return 0;
		}
	else
		{
			diffMsg[link][0]=*(comMsg+0);
			diffMsg[link][1]=*(comMsg+1);
			diffMsg[link][2]=*(comMsg+2);
			diffMsg[link][3]=*(comMsg+3);
			
			return 1;
		}
}


/****************************************************
*		FilterPack
*****************************************************
* filter improper messages.
*/
int FilterPack(unsigned char* filtMsg)
{
	if( (int)*(filtMsg+2)==0 )
		{return 1;/*FSU*/}
	else if( ((int)*(filtMsg+2)==1)&&((int)*(filtMsg+3)<6) )
		{return 1;/*LSSU*/}
	else if( ((int)*(filtMsg+2)>2)&&((*(filtMsg+3) & 0xcf)==0x80) )
		{return 1;/*SNM*/}
	else if( ((int)*(filtMsg+2)>2)&&((*(filtMsg+3) & 0xcf)==0x81) )
		{return 1;/*SNT*/}
	else if( ((int)*(filtMsg+2)>2)&&((*(filtMsg+3) & 0xcf)==0x83) )
		{return 1;/*SCCP*/}
	else if( ((int)*(filtMsg+2)>2)&&((*(filtMsg+3) & 0xcf)==0x84) )
		{return 1;/*TUP*/}
	else if( ((int)*(filtMsg+2)>2)&&((*(filtMsg+3) & 0xcf)==0x85) )
		{return 1;/*ISUP*/}
	else
		{return 0;/*error*/}
}

/***************************************************************
*						ReportMTP3State
****************************************************************
* link state report to MPU. if sending FSU and MSU, link state
* is OK, if sending LSSU, link state is FAIL.
*/
static int REPORTFLAG[3];
void ReportMTP3State(int link, int len)
{

  if(len!=REPORTFLAG[link])
  {
  	if( len==4 )
  		{
  			ReportLinkState(link+4, 2);
  		}
  	else
  		{
  			ReportLinkState(link+4, 1);
  		}
  }
  REPORTFLAG[link]=len;
}

/***************************************************************
*						ReportPliState
****************************************************************
* 
*/
static int PLIFLAG[3];
void ReportPliState(int link, int state)
{
	if(PLIFLAG[link]!=state)
		{
			if(state==1)
				{
					ReportLinkState(link+4,3);
				}
			else
				{
					ReportLinkState(link+4,4);
				}
			PLIFLAG[link]=state;
		}
}

/***************************************************************
*						SYNCheck
****************************************************************
* synchronize check process.
*/
void SYNCheck(int Id)
{
	while(1)
	{
		if(REPORTFLAG[Id]==4)
			{/*当前发送LSSU时,不断检测E1链路连接状态*/
				SynchroCheck(Id);
				taskDelay(60);
			}
		else
			{/*链路连接正常时,尽量少频繁检测链路*/
				SynchroCheck(Id);
				taskDelay(240);
			}
	}
}






⌨️ 快捷键说明

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