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

📄 zlg85c30.c

📁 z85c30 DRIVER RUN ON PC104 PC AND VXWORKS SYSTERM.
💻 C
📖 第 1 页 / 共 2 页
字号:
	commandAddrB=commandAddr[iPortNoB];

	sysOutByte(commandAddrB,0x02);
	intflag=(sysInByte(commandAddrB)&0x0e);

	do{
		switch (intflag)
	 	{
		case 0x0:
			if(rngIsEmpty(comS_ring_id[iPortNoB])==FALSE)
			{
				portsending[iPortNoB]=1;
				rngBufGet(comS_ring_id[iPortNoB],&outChar[iPortNoB],1);	
				sysOutByte(dataAddrB,outChar[iPortNoB]);
				portconfig[iPortNoB].SendByteNum++;
			}
			else
			{
				if(comMode[iPortNoB]==0)
					portsending[iPortNoB]=0;
				sysOutByte(commandAddrB,0x0);
				sysOutByte(commandAddrB,0x28);
			}		
		break;
		case 0x02:                      
			portsending[iPortNoB]=0;
			sysOutByte(commandAddrB,0x0);
			sysOutByte(commandAddrB,0x10);
		break;
		case 0x04:                                
			inChar[iPortNoB]=sysInByte(dataAddrB);
			portconfig[iPortNoB].RevByteNum++;
			if(rngFreeBytes(comR_ring_id[iPortNoB])>1)
			{
				rngBufPut(comR_ring_id[iPortNoB],&inChar[iPortNoB],1);
				if(comMode[iPortNoB]==0)semGive(comR_sem_id[iPortNoB]);
			}
		break;
		case 0x06:
			sysOutByte(commandAddrB,0x01);
			rr1=sysInByte(commandAddrB);
			if((rr1&0x10)!=0x10)//Parity
			if((rr1&0x20)!=0x20)//Overrun
			{
				if((rr1&0x80)==0x80)//EOF
				{
					portconfig[iPortNoB].RevFrameNum++;
					if((rr1&0x40)!=0x40)//CRC good message
					{
						sysInByte(dataAddrB);
						if(rngIsEmpty(comR_ring_id[iPortNoB])==FALSE)
							semGive(comR_sem_id[iPortNoB]);
						break;
					}
					else
					{
						portconfig[iPortNoB].RevFrameErrorNum++;
						rngFlush(comR_ring_id[iPortNoB]);
					}
		
				}
			}

			sysInByte(dataAddrB);
		break;

		case 0x08:
			if(rngIsEmpty(comS_ring_id[iPortNoA])==FALSE)
			{
				portsending[iPortNoA]=1;
				rngBufGet(comS_ring_id[iPortNoA],&outChar[iPortNoA],1);	
				sysOutByte(dataAddrA,outChar[iPortNoA]);
				portconfig[iPortNoA].SendByteNum++;
			}
			else
			{
				if(comMode[iPortNoA]==0)
					portsending[iPortNoA]=0;
				sysOutByte(commandAddrA,0x0);
				sysOutByte(commandAddrA,0x28);
			}		
		break;
		case 0x0a:
				portsending[iPortNoA]=0;
				sysOutByte(commandAddrA,0x0);
				sysOutByte(commandAddrA,0x10);
		break;
		case 0x0c:                                
			inChar[iPortNoA]=sysInByte(dataAddrA);
			portconfig[iPortNoA].RevByteNum++;
			if(rngFreeBytes(comR_ring_id[iPortNoA])>1)
			{
				rngBufPut(comR_ring_id[iPortNoA],&inChar[iPortNoA],1);
				if(comMode[iPortNoA]==0)semGive(comR_sem_id[iPortNoA]);
			}
		break;
		case 0x0e:
			sysOutByte(commandAddrA,0x01);
			rr1=sysInByte(commandAddrA);
			if((rr1&0x10)!=0x10)//Parity
			if((rr1&0x20)!=0x20)//Overrun
			{
				if((rr1&0x80)==0x80)//EOF
				{
					portconfig[iPortNoA].RevFrameNum++;
					if((rr1&0x40)!=0x40)//CRC good message
					{
						sysInByte(dataAddrA);
						if(rngIsEmpty(comR_ring_id[iPortNoA])==FALSE)
							semGive(comR_sem_id[iPortNoA]);
						break;
					}
					else
					{
						portconfig[iPortNoA].RevFrameErrorNum++;
						rngFlush(comR_ring_id[iPortNoA]);
					}
				}
			}

			sysInByte(dataAddrA);
		break;
		define: break;
	    	}
		if((intflag&0x08)==0x08)
		{
			sysOutByte(commandAddrA,0x0);
			sysOutByte(commandAddrA,0x30);
			sysOutByte(commandAddrA,0x0);
			sysOutByte(commandAddrA,0x38);
			portconfig[iPortNoA].intNum++;
			//portconfig[iPortNoA].intVectorStatic[portconfig[iPortNoA].pintVectorStatic++]=intflag;
			//if(portconfig[iPortNoA].pintVectorStatic>=ComMaxData)portconfig[iPortNoA].pintVectorStatic=0;

		}
		else
		{
			sysOutByte(commandAddrB,0x0);
			sysOutByte(commandAddrB,0x30);
			sysOutByte(commandAddrB,0x0);
			sysOutByte(commandAddrB,0x38);
			portconfig[iPortNoB].intNum++;
			//portconfig[iPortNoB].intVectorStatic[portconfig[iPortNoB].pintVectorStatic++]=intflag;
			//if(portconfig[iPortNoB].pintVectorStatic>=ComMaxData)portconfig[iPortNoB].pintVectorStatic=0;
		}
		whilenum++;
		if(whilenum>5)break;
		sysOutByte(commandAddrB,0x02);
		intflag=(sysInByte(commandAddrB)&0x0e);
	}
	while(intflag!=0x06);
	
	intUnlock (lockKey);
}*/
LOCAL void ComIntHandle2(int iPortNo)
{
	unsigned char intflag=0,rr1=0;
	int lockKey;
	char tChar;
	//char inChar;
	int dataAddrN;
	int commandAddrN;
	int iPortNoN;
	//int whilenum=0;
	lockKey = intLock ();
	

	//if(iPortNo>=ComMaxUnit)return;
	//if(iPortNo<1)return;


	sysOutByte(commandAddr[iPortNo-1],0x02);
	intflag=(sysInByte(commandAddr[iPortNo-1])&0x0e);

	if((intflag&0x08)==0x08)
	{
		iPortNoN=iPortNo;
	}
	else
	{
		iPortNoN=iPortNo-1;
	}
		//portconfig[iPortNoN].intVectorStatic[portconfig[iPortNoN].pintVectorStatic++]=intflag;
		//if(portconfig[iPortNoN].pintVectorStatic>=ComMaxData)portconfig[iPortNoN].pintVectorStatic=0;
	dataAddrN=dataAddr[iPortNoN];
	commandAddrN=commandAddr[iPortNoN];


	do{
		//portconfig[iPortNoN].intNum++;
		intflag &= 0x07;
		switch (intflag)
	 	{
		case 0x0:
			if(rngBufGet(comS_ring_id[iPortNoN],&tChar,1)==1)
			{
				//portsending[iPortNoN]=1;
				sysOutByte(dataAddrN,tChar);
			}
			else
			{
				if(comMode[iPortNoN]==0)
					portsending[iPortNoN]=0;
				sysOutByte(commandAddrN,0x0);
				sysOutByte(commandAddrN,0x28);
			}		
		break;
		case 0x02:                      
			portsending[iPortNoN]=0;
			sysOutByte(commandAddrN,0x0);
			sysOutByte(commandAddrN,0x10);
		break;
		case 0x04:                                
			tChar=sysInByte(dataAddrN);
			if(rngBufPut(comR_ring_id[iPortNoN],&tChar,1)==1)
			{
				if(comMode[iPortNoN]==0)semGive(comR_sem_id[iPortNoN]);
			}
		break;
		case 0x06:
			sysOutByte(commandAddrN,0x01);
			rr1=sysInByte(commandAddrN);
			if((rr1&0x10)!=0x10)//Parity
			if((rr1&0x20)!=0x20)//Overrun
			{
				if((rr1&0x80)==0x80)//EOF
				{
					portconfig[iPortNoN].RevFrameNum++;
					if((rr1&0x40)!=0x40)//CRC good message
					{
						if(rngIsEmpty(comR_ring_id[iPortNoN])==FALSE)
							semGive(comR_sem_id[iPortNoN]);
						break;
					}
					else
					{
						portconfig[iPortNoN].RevFrameErrorNum++;
						rngFlush(comR_ring_id[iPortNoN]);
					}
		
				}
			}

			sysInByte(dataAddrN);
		break;

		define: break;
	    	}

	     sysOutByte(commandAddrN,0x0);
		sysOutByte(commandAddrN,0x30);
		sysOutByte(commandAddrN,0x0);
		sysOutByte(commandAddrN,0x38);

		sysOutByte(commandAddr[iPortNo-1],0x02);
		intflag=(sysInByte(commandAddr[iPortNo-1])&0x0e);
		if((intflag&0x08)==0x08)
		{
			iPortNoN=iPortNo;
		}
		else
		{
			iPortNoN=iPortNo-1;	
		}
			//portconfig[iPortNoN].intVectorStatic[portconfig[iPortNoN].pintVectorStatic++]=intflag;
			//if(portconfig[iPortNoN].pintVectorStatic>=ComMaxData)portconfig[iPortNoN].pintVectorStatic=0;
		dataAddrN=dataAddr[iPortNoN];
		commandAddrN=commandAddr[iPortNoN];
	}
	while(intflag!=0x06);
	
	intUnlock (lockKey);
}
LOCAL void ComIntHandle31(int iPortNo)
{
	unsigned char intflag=0;
	int iPortNoN;

	//if(iPortNo>=ComMaxUnit)return;
	//if(iPortNo<1)return;
	
	sysOutByte(commandAddr[iPortNo-1],0x02);
	intflag=(sysInByte(commandAddr[iPortNo-1])&0x0e);

	do{
		if((intflag&0x08)==0x08)
		{
			iPortNoN=iPortNo;
		}
		else
		{
			iPortNoN=iPortNo-1;	
		}

		intflag &= 0x07;

		//rngBufPut(comInt_ring_id,&iPortNoN,1);
		//rngBufPut(comInt_ring_id,&intflag,1);
		ComOneIntHandle(iPortNoN,intflag);

	     sysOutByte(commandAddr[iPortNoN],0x0);
		sysOutByte(commandAddr[iPortNoN],0x30);
		sysOutByte(commandAddr[iPortNoN],0x0);
		sysOutByte(commandAddr[iPortNoN],0x38);

		sysOutByte(commandAddr[iPortNo-1],0x02);
		intflag=(sysInByte(commandAddr[iPortNo-1])&0x0e);
	}
	while(intflag!=0x06);
	//semGive(comInt_sem_id);
	
}
LOCAL void ComIntHandle3(int iPortNo)
{
	int lockKey;
	lockKey = intLock ();
	ComIntHandle31(iPortNo);	
	intUnlock (lockKey);
}
/******************************************************
*
*
*
*/
LOCAL void ComOneIntHandle(int iPortNoN,unsigned char intflag)
{
	unsigned char rr1=0;
	char tChar;
	int dataAddrN;
	int commandAddrN;

//	if(iPortNoN>=ComMaxUnit)return;
//	if(iPortNoN<1)return;

	dataAddrN=dataAddr[iPortNoN];
	commandAddrN=commandAddr[iPortNoN];

	switch (intflag)
	{
		case 0x0:
			if(rngBufGet(comS_ring_id[iPortNoN],&tChar,1)==1)
			{
				sysOutByte(dataAddrN,tChar);
			}
			else
			{
				if(comMode[iPortNoN]==0)
					portsending[iPortNoN]=0;
				sysOutByte(commandAddrN,0x0);
				sysOutByte(commandAddrN,0x28);
			}		
		break;
		case 0x02:                      
			portsending[iPortNoN]=0;
			sysOutByte(commandAddrN,0x0);
			sysOutByte(commandAddrN,0x10);
		break;
		case 0x04:                                
			tChar=sysInByte(dataAddrN);
			rngBufPut(comR_ring_id[iPortNoN],&tChar,1);
			if(comMode[iPortNoN]==0)semGive(comR_sem_id[iPortNoN]);
		break;
		case 0x06:
			sysOutByte(commandAddrN,0x01);
			rr1=sysInByte(commandAddrN);
			if((rr1&0x10)!=0x10)//Parity
			if((rr1&0x20)!=0x20)//Overrun
			{
				if((rr1&0x80)==0x80)//EOF
				{
					sysInByte(dataAddrN);
					portconfig[iPortNoN].RevFrameNum++;
					if((rr1&0x40)!=0x40)//CRC good message
					{
						sysInByte(dataAddrN);
						if(rngIsEmpty(comR_ring_id[iPortNoN])==FALSE)
							semGive(comR_sem_id[iPortNoN]);
						break;
					}
					else
					{
						portconfig[iPortNoN].RevFrameErrorNum++;
						rngFlush(comR_ring_id[iPortNoN]);
					}
		
				}
			}
			sysInByte(dataAddrN);
		break;

		define: break;
	}
}
/*****************************************/
LOCAL STATUS ComIntsendtouch(iPortNo)
{
	unsigned char f;
	char str[2];
	unsigned ifor1=0;
	unsigned int strlen=10;
	int lockKey;


	if(iPortNo>=ComMaxUnit)return ERROR;
	if(rngIsEmpty(comS_ring_id[iPortNo])==FALSE)
	//if((rngBufGet(comS_ring_id[iPortNo],str,1))==1)
	{

	if(portsending[iPortNo]==0)
	{
		portsending[iPortNo]=1;
		rngBufGet(comS_ring_id[iPortNo],str,1);
		if((dataAddr[iPortNo]==0x3f8)||(dataAddr[iPortNo]==0x2f8))
		{
			f=sysInByte(dataAddr[iPortNo] + com_lineflag);
			while((f&0x20)==0)f=sysInByte(dataAddr[iPortNo] + com_lineflag);
			sysOutByte(dataAddr[iPortNo]+com_dataport,str[0]);
		}
		else
		{
			sysOutByte(commandAddr[iPortNo],0x00);
			f=sysInByte(commandAddr[iPortNo]);
			while((f&0x44)==0)
			{
				sysOutByte(commandAddr[iPortNo],0x00);
				f=sysInByte(commandAddr[iPortNo]);
			}
			sysOutByte(dataAddr[iPortNo],str[0]);
			//portconfig[iPortNo].SendByteNum++;
			//portconfig[iPortNo].SendFrameNum++;
		}
	}

	}
	return OK;
}
/******************************************************************
*
*
*
*******************************************************************/
int comiocontrol(int iPortNo,int type)
{
	int Rvalue=-1;
	if(iPortNo>=ComMaxUnit)return -1;
	switch(type)
	{
	case GetTxBufNByte:
		Rvalue=rngNBytes(comS_ring_id[iPortNo]);
	break;
	case GetRxBufNByte:
		Rvalue=rngNBytes(comR_ring_id[iPortNo]);
	break;
	case GetTxBufFreeBytes:
		Rvalue=rngFreeBytes(comS_ring_id[iPortNo]);
	break;
	case GetRxBufFreeBytes:
		Rvalue=rngFreeBytes(comR_ring_id[iPortNo]);
	break;
	}
	return Rvalue;
}

int comtakeRTS(int iPortNo)
{
	if(iPortNo>=ComMaxUnit)return 0;
	
	sysOutByte(dataAddr[iPortNo]+com_modemclt,0x0a);

	return 1;
}
int comclearRTS(int iPortNo)
{
	if(iPortNo>=ComMaxUnit)return 0;
	
	sysOutByte(dataAddr[iPortNo]+com_modemclt,0x08);
	return 1;
}

int comgetCTS(int iPortNo)
{

	char mask=0;
	if(iPortNo>=ComMaxUnit)return 0;
		
	mask=sysInByte(dataAddr[iPortNo]+com_modemflag);
			/*if get CTS*/
	if(mask&0x10)return 1;
	else return 0;
}

int comsetcheck(int iPortNo)
{
	if(iPortNo>=ComMaxUnit)return 0;

	sysOutByte(dataAddr[iPortNo]+com_lineclt,(0x7f&sysInByte(dataAddr[iPortNo] + com_lineclt)));
	
	sysOutByte(dataAddr[iPortNo]+com_lineclt,0x1b);

	return 1;
}

int comwrite(int iPortNo,char *str,int len)
{
	if(iPortNo>=ComMaxUnit)return 0;
	if((len<0)||(len>ComMaxData))return 0;

	if(comMode[iPortNo]==1)
	{
		if(rngNBytes(comS_ring_id[iPortNo])==0)
		if(portsending[iPortNo]==0)
		{
			rngBufPut(comS_ring_id[iPortNo],str,len);
			ComIntsendtouch(iPortNo);
			portconfig[iPortNo].SendFrameNum++;
			portconfig[iPortNo].SendByteNum+=len;
			return len;
		}
	}
	else
	{
		if(rngFreeBytes(comS_ring_id[iPortNo])>len)
		{
			rngBufPut(comS_ring_id[iPortNo],str,len);
			/*while(rngNBytes(comS_ring_id[iPortNo])!=0)*/
			ComIntsendtouch(iPortNo);
			portconfig[iPortNo].SendFrameNum++;
			portconfig[iPortNo].SendByteNum+=len;
			return len;
		}	
	}
	return 0;
}
void comErroReset(int iPortNo)
{
	portsending[iPortNo]=0;
	ComIntsendtouch(iPortNo);
}
int comread(int iPortNo,char *str,int Maxlen,int timeout)
{
	int len;
	if(iPortNo>=ComMaxUnit)return 0;
	if(comR_sem_id[iPortNo]<=0)return 0;
	semTake(comR_sem_id[iPortNo],timeout);
	len= rngBufGet(comR_ring_id[iPortNo],str,Maxlen);
	portconfig[iPortNo].RevByteNum+=len;
	return len;
}

void comRRshow(int iPortNo)
{
	int iWR=0;
	printf("Port%d commandAddr:%X\n",iPortNo,commandAddr[iPortNo]);
	
	for(iWR=0;iWR<15;iWR++)
	{
		sysOutByte(commandAddr[iPortNo],iWR);
		printf("RR%d=%X ",iWR,sysInByte(commandAddr[iPortNo]));
	}
	printf("\n");
}

⌨️ 快捷键说明

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