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

📄 ge_maincommand.c

📁 程序是一个vxworks下对PMC公司3386千兆MAC芯片的驱动和配置
💻 C
📖 第 1 页 / 共 2 页
字号:
        			}

				while(BDCOM_FLAG)
				{
					taskDelay(sysClkRateGet()*2);
					printf("tMainCommand is waitting for SYS_CONNECT_REQ...\n");
					if(GE_BoardInfoReport(2,0)==ERROR)/*2:hot initstart;0:selfTest succeed!*/
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_ALARM,"GE_MainCommand:GE_BoardInfoReport failed!\n");
						continue;
					}
					taskDelay(60);
					if(msgQNumMsgs(GE_MainCommandMsgQId)>0)
					{						
						break;
					}					
				}							
			break;
			
			case	SYS_MGMT_REQ:
				subType=CommandMsg.msgBuf[0];
				port = GE_swiport;
				ackMsg = (MSG_STRUCTURE*)malloc(SYS_BDCOM_HEAD_SIZE+12);
				if(ackMsg== NULL)
		     		{
					if(GE_CMD_DEBUG)
						GE_printf(GE_ALARM,"GE_MainCommand:memory allocation failed!\n");
					break;
	             		}
	             		if(subType>6)
				{
					if(GE_CMD_DEBUG)
						GE_printf(GE_ALARM,"GE_MainCommand:receice SYS_MGMT_REQ--subType: %d,Invalid!\n",subType);
					free((void*)ackMsg);
					break;
				}
				if(subType==MGMT_SELF_TEST_REQ)
				{
					GE_SuspendAll();
					result=GE_SelfTest(SYS_LOOP);
					GE_ResumeAll();
					bfill((char*)&ackMsg->blank[0],SYS_BDCOM_HEAD_SIZE,0);
					/*memset((ackMsg->blank), 0,SYS_BDCOM_HEAD_SIZE);*/
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_SELF_TEST_REP;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
					
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11 ) == ERROR)
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_SELF_TEST_REP to BDCOM failed!\n");
						free((void*)ackMsg);
						break;
					}
					else
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_SELF_TEST_REP to BDCOM succeed!\n");
						break;
					}
				}				
				if(subType==MGMT_STAT_FREQ_REQ)
				{
					netIf[0].statFreq = CommandMsg.msgBuf[1];
					netIf[1].statFreq = CommandMsg.msgBuf[1];
					
					port = GE_swiport;
					result=0;
					memset(ackMsg->blank, 0,SYS_BDCOM_HEAD_SIZE);
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_STAT_FREQ_REP;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
				
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11 ) == ERROR)
                        		{
                        			if(GE_CMD_DEBUG)
                        				GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_STAT_FREQ_REP to BDCOM failed!\n");
						free((void*)ackMsg);
						break;
					}
					else 
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_STAT_FREQ_REP to BDCOM succeed!\n");
						break;
					}
				}
				if(subType==MGMT_LINE_IP_REQ)
				{
					unit=CommandMsg.msgBuf[1];
					netIf[unit].ipAddr = *(ULONG *)(&CommandMsg.msgBuf[2]);
					netIf[unit].ipMask = *(ULONG *)(&CommandMsg.msgBuf[6]);
					result=0;
						
					port = GE_swiport;
					memset(ackMsg->blank, 0,SYS_BDCOM_HEAD_SIZE);
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_LINE_IP_REP;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
						
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11) == ERROR)
                        		{
                        			if(GE_CMD_DEBUG)
                        				GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_LINE_IP_REQ to BDCOM failed!\n");
						free((void*)ackMsg);
						break;
					}
					else
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_LINE_IP_REQ to BDCOM succeed!\n");
						break;
					}
				}
				if(subType==MGMT_ARP_FRE_REQ)
				{
					netIf[0].arpFreq=*(USHORT*)(&CommandMsg.msgBuf[1]);
					netIf[1].arpFreq=*(USHORT*)(&CommandMsg.msgBuf[1]);
					result=0;
					port = GE_swiport;
					memset(ackMsg->blank, 0,SYS_BDCOM_HEAD_SIZE);
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_ARP_FRE_REP;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11) == ERROR)
                        		{
                        			if(GE_CMD_DEBUG)	
                        				GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_ARP_FRE_REP to BDCOM failed!\n");
						free((void*)ackMsg);
						break;
					}
					else
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_ARP_FRE_REP to BDCOM succeed!\n");
						break;
					}
					
				}
				if(subType==MGMT_LINE_STATE_REQ) 
				{
					unit=CommandMsg.msgBuf[0];
					state=netIf[unit].adminStatus;
					if(CommandMsg.msgBuf[1]==NET_PORT_DOWN && state!=NET_PORT_DOWN)
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_ALARM,"GE_MainCommand:the port %d is DOWN!\n",unit);
						netIf[unit].adminStatus=NET_PORT_DOWN;
						GE_EventReport(4,unit,REPORT_LINE_STATE,NET_PORT_DOWN);
					}
					if(CommandMsg.msgBuf[1]==NET_PORT_UP && state!=NET_PORT_UP)
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_ALARM,"GE_MainCommand:the port %d is UP!\n",unit);
						netIf[unit].adminStatus=NET_PORT_UP;
						GE_EventReport(4,unit,REPORT_LINE_STATE,NET_PORT_UP);
					}
					port = GE_swiport;
					result=SYS_OK;
					memset(ackMsg->blank, 0,SYS_BDCOM_HEAD_SIZE);
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_LINE_STATE_REP;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11 ) == ERROR)
                        		{
                        			if(GE_CMD_DEBUG)	
                        				GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_STAT_FREQ_REP to BDCOM failed!\n");
						free(ackMsg);
						break;
					}
					else
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_STAT_FREQ_REP to BDCOM failed!\n");
						break;
					}
				}

				if(subType==MGMT_LINE_MTU_REQ)
				{
					netIf[0].mtu=*(USHORT*)(&CommandMsg.msgBuf[1]);
					netIf[1].mtu=*(USHORT*)(&CommandMsg.msgBuf[1]);
					result=SYS_OK;
					port = GE_swiport;
					memset(ackMsg->blank, 0,SYS_BDCOM_HEAD_SIZE);
					ackMsg->type = SYS_MGMT_REP;
					ackMsg->length = 3;
					ackMsg->data[0] = MGMT_LINE_MTU_REQ;
					ackMsg->data[1] = port;
					ackMsg->data[2] = result;
					if (BDCOM_UpReceive ( 	BDCOM_STREAM,
                        					sysClkRateGet(),
                        					MSG_PRI_NORMAL,
                        					SYS_BDCOM_HEAD_SIZE + 11,
                        					(UCHAR *) ackMsg,
                        					SYS_BDCOM_HEAD_SIZE,
                        					11) == ERROR)
                        		{
                        			if(GE_CMD_DEBUG)
                        				GE_printf(GE_ALARM,"GE_MainCommand: send MGMT_LINE_MTU_REQ to BDCOM failed!\n");
						free((void*)ackMsg);
						break;
					}
					else
					{
						if(GE_CMD_DEBUG)
							GE_printf(GE_EVENT,"GE_MainCommand: send MGMT_LINE_MTU_REQ to BDCOM succeed!\n");
						break;
					}
					
				}

			break;

			default:
				if(GE_CMD_DEBUG)
				{	
					GE_printf(GE_ALARM,"GE_MainCommand:receice type is %x:,Invalid!\n",CommandMsg.type);
					GE_printf(GE_DATA,"%8x,%8x,%8x,%8x,%8x,%8x\n",CommandMsg.taskCode,CommandMsg.type,CommandMsg.length,CommandMsg.msgBuf[0],CommandMsg.msgBuf[1],CommandMsg.msgBuf[2]);
				}
			break;
     		}
	}
	return OK;
}
/********************************************************************************
*suspend all task
*/
STATUS GE_SuspendAll()
{
	int	i;
    	if(SBSL_SuspendMonitor()==ERROR)
    	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_SuspendAll:Suspend tMonitor failed!\n");
		return ERROR;            
    	}
    	if(SBSL_SuspendTimer()==ERROR)
    	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_SuspendAll:Suspend tTimer failed!\n");
		return ERROR;            
    	}        
	if(GE_SuspendArp()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_SuspendAll:Suspend tARP failed!\n");
		return ERROR;
	}
	if(GE_SuspendEventStatistic()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_SuspendAll:Suspend tEventStatistic failed!\n");
		return ERROR;
	}
	if(GE_SuspendProtoReceive()==ERROR)
	{
		if(GE_CMD_DEBUG)
			if(GE_CMD_DEBUG)(GE_ALARM,"GE_SuspendAll:Suspend tProtoReceive failed!\n");
		return ERROR;
	}
	if(GE_SuspendProtoSend()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_SuspendAll:Suspend tProtoSend failed!\n");
		return ERROR;
	}
	netIf[0].adminStatus=NET_PORT_DOWN;
	netIf[1].adminStatus=NET_PORT_DOWN;
	return OK;
}
/**********************************************************************************
*resume  all suspended  task
*/
STATUS    GE_ResumeAll()
{
	int 	i;
	if(GE_ResumeProtoSend()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeProtoSend:Resume tProtoSend failed!\n");
		return ERROR;
	}
	if(GE_ResumeArp()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeArp:Resume tARP failed!\n");
		return ERROR;
	}
	if(GE_ResumeEventStatistic()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeEventStatistic:Resume tEventStatistic failed!\n");
		return ERROR;
	}
	if(GE_ResumeProtoReceive()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeProtoReceive:Resume tProtoReceive failed!\n");
		return ERROR;
	}
	if(SBSL_ResumeTimer()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeProtoSend:Resume tTimer failed!\n");
		return ERROR;	        
	}
	if(SBSL_ResumeMonitor()==ERROR)
	{
		if(GE_CMD_DEBUG)
			GE_printf(GE_ALARM,"GE_ResumeProtoSend:Resume tMonitor failed!\n");
		return ERROR;	        
	}		
	for(i=0;i<2;i++)
	{
		netIf[i].adminStatus=NET_PORT_UP;
		if(GE_EventReport(4,i,REPORT_LINE_STATE,NET_PORT_UP)==ERROR)
		{
			return ERROR;
		}
	}	
	return OK;
}
void show_ipaddr()
{
	unsigned char i;
	unsigned char j=0;
	printf("=================================32 ip=========================================\n");
	for(i=0;i<32;i++)
	{
		printf("%2d    %.8x    ",i,IPAddr[i]);
		j++;
		if(j%4==0)
		{
			printf("\n");
		}
	}
	printf("===============================================================================\n");
	return;
}                            

/* end of file GE_MainCommand.c */

⌨️ 快捷键说明

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