From d69aae90ede578aaebc355dafd3496993ccea126 Mon Sep 17 00:00:00 2001
From: QuakeGod <QuakeGod@sina.com>
Date: 星期一, 17 十月 2022 03:02:12 +0800
Subject: [PATCH] fix 2

---
 Src/main.c |  589 +++++++++++++---------------------------------------------
 1 files changed, 134 insertions(+), 455 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 4648ad1..81f5051 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -42,6 +42,7 @@
 
 /* USER CODE BEGIN Includes */
 #include "Globaldef.h"
+#include "debug.h"
 #include "Functions.h"
 #include "KMachine.h"
 #include "PLCfunctions.h"
@@ -50,11 +51,18 @@
 #include "string.h"
 #include "BSP.h"
 #include "ModbusRTU.h"
+#if (BOARD_TYPE == 12)
+#include "FP0.h"
+#elif (BOARD_TYPE == 13)
+#include "w5500_port.h"
+#include "../src/Ethernet/socket.h"
+#include "../src/Ethernet/loopback.h"
+#endif
 
 /* USER CODE END Includes */
 
 /* Private variables ---------------------------------------------------------*/
-#define ADCrefAddr 0x1FFFF7BA
+
 /* USER CODE BEGIN PV */
 /* Private variables ---------------------------------------------------------*/
 
@@ -67,42 +75,14 @@
 unsigned char Uart2RxBuf[RX2BUFSIZE];
 unsigned char Uart2TxBuf[TX2BUFSIZE];
 
-//unsigned char buf1[128];	
-
-unsigned char Datas[128];		
-
 unsigned int SlowFlicker=0;
 unsigned int FastFlicker=0;
 
-volatile int PacketLength = 0;
-
-char str1[256];
-
-int TimeOutCount=0;
-int Clk3=0;
 int ContinueSend=0;
-int Uart1baudval=0;	
-int Uart2baudval=0;	
-
-int repeater=0;
-
-int SendTime,Latancy,LatancyClk,SendClk;	
-
-int LineCount=0;
-
-int LastCircleStartTime=0;
-int CircleTime=0;
 
 stBinProg1 * pProgs = (stBinProg1 *)STORE_PRG_BASE;
-//volatile unsigned int nRunCount=0;
-volatile int nCount2=0;
 
 uint32_t us1,us2,us3,us4,us5,us6;
-const unsigned char buf1[16]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff,0x00};
-
-volatile int PowerDownEvent=0;
-volatile int OldPowerDownEvent=0;
-volatile int OldPowerDownEventTime=0;
 
 /* USER CODE END PV */
 
@@ -121,11 +101,6 @@
 /* USER CODE END PFP */
 
 /* USER CODE BEGIN 0 */
-__asm int add1(int a,int b)
-{
-	add r0,r1,r0
-	BLX    lr
-}
 
 int HexToInt(char ch)
 {
@@ -152,373 +127,6 @@
 	return;
 }
 
-int FormatHex(char * buf1,uchar * data,int n)
-{
-	int len1=0;
-		for (int i=0;i<n;i++)
-		{len1+=sprintf(buf1+len1,"%02X ",data[i]);}
-		len1+=sprintf(buf1+len1,"\r\n");	
-	return len1;
-}
-
-int RepeaterFunc()
-{
-		KMem.WY[0]=KMem.WX[0];
-		if ((KMem.nRunCount &0x7f) == 88) 
-		{ 
-			nCount2++;	
-			ToggleRunLed();
-//		int len1=sprintf(str1,"%d %d Cfg %02X  Input %02X  \r\n",nCount,nCount2,EffJumperSW,MyKeyStat1);
-//		PutStr(str1,len1);
-		}				
-	return 0;
-}
-
-
-int ShowInitInfo()
-{
-	int len1=0;
-	clearscreen();
-//	Locate(1,1);
-
-/*	
-	LoadFlashDatas();
-	
-	LoadAndUpdateStoreCfg();
-	
-	HAL_StatusTypeDef res;	
-	stStoreCfg * pFCfg = (stStoreCfg *) GetCurStoreCfgAddr();
-	stStoreCfg * pFCfg2 = GetNextStoreCfgAddr(pFCfg);	
-
-int t11=GetuS();
-	
-	for (int i=0;i<20;i++)
-	{
-		tims[i]=GetuS();
-	}		
-	clearscreen();
-	len1+=sprintf(str1+len1," Ver 001 \r\n");
-	len1+=sprintf(str1+len1," Uart1Baud %d Uart2Baud %d  UID  %08x %08x %08x \r\n",Uart1Baud,Uart2Baud,pUID[0],pUID[1],pUID[2]);
-	len1+=sprintf(str1+len1," Flash = %d %d %d %d  res = %d   ",FlashDatas[0],FlashDatas[1],FlashDatas[2],FlashDatas[3],res);
-	len1+=sprintf(str1+len1,"flash operation = %u %u %u\r\n",t11-t10,t10,t11);
-	PutStr(str1,len1);
-	len1=0;
-	len1+=sprintf(str1+len1,"%08X  %X %X , PowerOn %X  UpTime %X %X %X %X \r\n",
-	(uint32_t)pFCfg,pFCfg[0].Sign1,pFCfg[0].SN1,pFCfg[0].PowerCount,pFCfg[0].UpTime,pFCfg[0].UserData1,pFCfg[0].CRC1,pFCfg[0].EndSign1);
-	len1+=sprintf(str1+len1,"%08X  %X %X , PowerOn %X  UpTime %X %X %X %X \r\n",
-	(uint32_t)pFCfg2,Cfg2.Sign1,Cfg2.SN1,Cfg2.PowerCount,Cfg2.UpTime,Cfg2.UserData1,Cfg2.CRC1,Cfg2.EndSign1);
-	PutStr(str1,len1);
-*/	
-	len1=0;
-/*	
-	for (int i=0;i<8;i++)
-	{
-		len1=0;
-		len1+=sprintf(str1+len1,"%02X:",i*32);
-		for (int j=0;j<8;j++)
-		{
-				len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
-		}
-				len1+=sprintf(str1+len1,"  %02X",pFlash1[i*32+8]);
-		for (int j=9;j<16;j++)
-		{
-				len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
-		}
-				len1+=sprintf(str1+len1," | %02X",pFlash1[i*32+16]);
-		for (int j=17;j<24;j++)
-		{
-				len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
-		}
-				len1+=sprintf(str1+len1,"  %02X",pFlash1[i*32+24]);
-		for (int j=25;j<32;j++)
-		{
-				len1+=sprintf(str1+len1," %02X",pFlash1[i*32+j]);
-		}
-		len1+=sprintf(str1+len1,"\r\n");
-		PutStr(str1,len1);
-	}
-*/	
-	us1=GetuS();
-	int crc1 = crc_check(buf1,16);
-	us2=GetuS();
-	int crc2 = crc16bitbybit(buf1,16);
-	us3=GetuS();
-	int crc3 = crc16table(buf1, 16);
-	us4=GetuS();
-  int crc4 = crc16tablefast(buf1, 16);
-	us5=GetuS();
-	LL_CRC_ResetCRCCalculationUnit(CRC);
-	LL_CRC_SetInitialData(CRC,0xFFFFFFFF);
-	LL_CRC_SetInitialData(CRC,0xA001);
-	for (int i=0;i<16;i++)
-	{
-		LL_CRC_FeedData8(CRC,buf1[i]);
-	}
-	int crc5 = LL_CRC_ReadData32(CRC);
-	us6=GetuS();
-	
-		len1+=sprintf(str1+len1,"CRC  %04X  %04X  %04X  %04X  %04X\r\n",crc1,crc2,crc3,crc4,crc5);
-		len1+=sprintf(str1+len1,"time %04d  %04d  %04d  %04d  %04d\r\n",us2-us1,us3-us2,us4-us3,us5-us4,us6-us5);
-		
-		PutStr(str1,len1);
-
-//	InitTimer(0,0);
-//	InitTimer(1,1);
-//	InitTimer(2,2);
-//	InitTimer(3,3);
-	
-//	RunTimer(0,1000);
-//	StartTimer(2,1000);
-	Locate(13,1);LineCount=3;
-	return 0;
-}
-int sprintftime = 0;
-int putstrtime = 0;
-
-int ADCProcess()
-{
-	// ADC channels
-	//  0 -- 24V  --> 0
-	//  1 -- 5V   --> 2
-	//	2 -- 
-	//  3 -- 
-	//  4 -- 
-	//  5 -- 
-	//  6 -- 
-	//  7 -- 
-	//  8 -- 
-	//						 --> 5
-	// 16 -- Temp  --> 6
-	// 17 -- Vref  --> 7
-
-	uint16_t ADC_ConvertedValue=0;
-static int CurChannel=LL_ADC_CHANNEL_0;
-//static int waitcount = 0;
-	
-				if (!LL_ADC_REG_IsConversionOngoing(ADC1))
-				{
-					//waitcount++;
-					//if (waitcount<2) return 0;
-					//waitcount=0;
-					ADC_ConvertedValue = LL_ADC_REG_ReadConversionData12(ADC1);
-					
-		//			ADC_RegularChannelConfig(LL_ADC_CHANNEL_17,);
-					int channels = CurChannel ;//LL_ADC_REG_GetSequencerChannels(ADC1);
-					int nextchannel = LL_ADC_CHANNEL_0;
-					if ((channels & LL_ADC_CHANNEL_0) == LL_ADC_CHANNEL_0)
-					{
-						KMem.ADCValues[0] = ADC_ConvertedValue;
-						nextchannel = LL_ADC_CHANNEL_8;
-					}else if ((channels & LL_ADC_CHANNEL_8) == LL_ADC_CHANNEL_8)
-					{
-						KMem.ADCValues[2] = ADC_ConvertedValue;						
-						nextchannel = LL_ADC_CHANNEL_TEMPSENSOR;
-						if (KMem.ADCValues[2] < 2200) 
-						{
-							PowerDownEvent=1;
-						}else 
-						{
-							PowerDownEvent=0;
-						}
-					}else if ((channels & LL_ADC_CHANNEL_16) == LL_ADC_CHANNEL_16)
-					{
-						KMem.ADCValues[6] = ADC_ConvertedValue;		
-							nextchannel = LL_ADC_CHANNEL_VREFINT;
-					}else if ((channels & LL_ADC_CHANNEL_17) == LL_ADC_CHANNEL_17)
-					{
-						KMem.ADCValues[7] = ADC_ConvertedValue;						
-						KMem.ADCValues[5] = *((unsigned short *)ADCrefAddr);
-						
-						nextchannel = LL_ADC_CHANNEL_0;
-					}else
-					{
-						//ADCValues[0] = ADC_ConvertedValue;						
-					}
-					//nextchannel = LL_ADC_CHANNEL_VREFINT;
-					LL_ADC_REG_SetSequencerChannels(ADC1,nextchannel);					
-					LL_ADC_REG_StartConversion(ADC1);
-					CurChannel = nextchannel;
-				}	
-	return 0;
-}
-
-int PowerDownProcess(void )
-{
-	AddEventLog(KMem.CurTimeSec,EventTypePowerDown,1,12345);
-	SaveRunStat(&KMRunStat);
-	KMem.PwrFailCount++;
-	KMem.LastPwrFailTime = KMem.CurTimeSec;
-	return 0;
-}
-
-int PowerRecoverProcess(void)
-{
-	KMem.PwrFailCount++;
-	
-	return 0;
-}
-int ShowRunningInfo()
-{
-			int Clk1=SysTick->VAL;			
-			if (Uart1BaudFirstGot)
-			{
-				Uart1baudval = HAL_RCC_GetPCLK1Freq() / USART1->BRR;
-				Uart1BaudFirstGot=0;
-			}
-			if (Uart2BaudFirstGot)
-			{
-				Uart2baudval = HAL_RCC_GetPCLK1Freq() / USART2->BRR;
-				Uart2BaudFirstGot=0;
-			}		
-			int Reload=SysTick->LOAD;
-
-			int Clk2=SysTick->VAL;
-			//int us2=GetuS();
-			int haltick=HAL_GetTick();
-			int len1=0;
-			uint32_t theUs = GetuS();
-			int nRunCount2=KMem.nRunCount;
-			if (!Uart1Stat.QTx.bEmpty) return 0;
-			
-			if ( (nRunCount2 & 0xff) == 0x03)
-			{
-				Locate(13,1);LineCount=3;
-			} else	if ((nRunCount2 & 0xff) == 0x0f)
-			{
-				int timeus1;
-				int timeus2;
-		
-				len1=sprintf((char *)str1," N %8d Tk %8d %9u CFG %02X R %d M %d S %d %4d IN %04X OUT %04X  \r\n",
-					KMem.nRunCount, haltick, theUs, KMem.EffJumperSW, repeater, bMaster, bSlave, Clk2, KMem.WX[0],KMem.WY[0]);
-				//len1=sprintf((char *)str1,"U%02X%02XA",x2,x2);
-				// Locate(10,1);
-				timeus1=GetuS();
-				PutStr(str1,len1);
-				timeus2=GetuS();
-				sprintftime = timeus1 - theUs;
-				putstrtime = timeus2 - timeus1;
-				if (IsTimerOn(0)) {RunTimer(1,1000);StopTimer(3);}
-				if (IsTimerOn(1)) {RunTimer(2,100);StopTimer(0);}
-				if (IsTimerOn(2)) {RunTimer(3,10);StopTimer(1);}
-				if (IsTimerOn(3)) {RunTimer(0,10000);StopTimer(2);}
-		  }
-			if ((nRunCount2 & 0xff) == 0x2f && 0)
-			{
-
-		  }	
-			if ((nRunCount2 & 0xff) == 0x0af)
-			{
-				
-		  }				
-			return 0;
-}
-
-int MasterFunc()
-{
-		uint32_t tick1=HAL_GetTick();
-		uint32_t thisuS=GetuS();
-	
-			int len1=0;
-
-			if ((MasterRecved && MasterRecvOK && thisuS-SendTimeuS>50) || thisuS-SendTimeuS>1000u)
-			{
-				if (!MasterRecvOK) 
-				{
-					TimeOutCount++;
-					Uart2Stat.TimeOutErr++; 
-					ChnStats[nCurPollId].LostPackets++;
-					ChnStats[nCurPollId].CtnLstPkts++;
-					if (!MasterRecved) {ChnStats[nCurPollId].TimeOutErr++;}
-					if (ChnStats[nCurPollId].CtnLstPkts>ChnStats[nCurPollId].MaxCtnLstPkts)
-					{ChnStats[nCurPollId].MaxCtnLstPkts=ChnStats[nCurPollId].CtnLstPkts;}
-					if (ChnStats[nCurPollId].CtnLstPkts>3)
-					{
-						ChnStats[nCurPollId].Stat=0;
-						KMem.ErrStat=200;
-						 
-						{BufferIn[nCurPollId]=0;}
-					}
-				//	LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_7);
-				}else
-				{
-					ChnStats[nCurPollId].Stat=1;
-					
-					KMem.RunStat=100;
-				}
-				nCurPollId ++;
-				if (nCurPollId > nChilds)
-				{
-					CircleTime=thisuS-LastCircleStartTime;
-					LastCircleStartTime=thisuS;
-					nSeq++;
-					nCurPollId=1;
-				}
-				if (KMRunStat.WorkMode==0)
-				{
-					KMem.WX[0]= GetInput();
-					KMem.WY[1]=KMem.WX[0]&0xff;
-					KMem.WY[2]=(KMem.WX[0]>>8)&0xff;		
-				}
-				BufferOut[1]=KMem.WY[1];
-				BufferOut[2]=KMem.WY[2];		
-				
-				Datas[0]=BufferOut[nCurPollId];
-				Datas[1]=BufferOut[nCurPollId+1];;
-				Datas[2]=ChnStats[nCurPollId].Stat;
-				Datas[3]=0;
-				Datas[4]=tick1&0xff;
-				Datas[5]=(tick1>>8)&0xff;
-				Datas[6]=(tick1>>16)&0xff;
-				Datas[7]=(tick1>>24)&0xff;
-				
-				SendTimeuS=thisuS;				
-				len1=MakePacket((pPacket)PacketBuf1,0,nCurPollId,cmdExChgData,nSeq,8,Datas);
-				SendPacket2((pPacket)PacketBuf1,len1);
-				ChnStats[nCurPollId].SendPackets++;
-				ChnStats[nCurPollId].SendTimeInterval=SendTimeuS-ChnStats[nCurPollId].LastSentTimeuS;
-				ChnStats[nCurPollId].LastSentTimeuS=SendTimeuS;
-				PacketLength = len1;
-				SendTime=tick1;
-
-				MasterRecved=0;
-				MasterRecvOK=0;
-			//	LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_5);		
-				//ToggleErrLed();
-//				ToggleOut8();
-
-			}
-		
-			Clk3=SysTick->VAL;
-		//	LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_4);
-	//	HAL_Delay(1);				
-	return 0;
-}
-
-int SlaveFunc()
-{
-		int ThisuS=GetuS();
-		int thisRecvTime=RecvTimeuS;
-		if (SlaveRecved)
-		{
-			KMem.RunStat=8000;
-			SlaveRecved=0;
-		}else if ((ThisuS - thisRecvTime) >12000u)
-		{
-			KMem.ErrStat=8000;
-			KMem.SDD[17]=1;
-			KMem.SDD[18]=ThisuS;
-			KMem.SDD[19]=RecvTimeuS;
-		}else if ( ThisuS > (thisRecvTime + 12000u))
-		{
-			KMem.ErrStat=8000;
-			KMem.SDD[17]=2;
-			KMem.SDD[18]=ThisuS;
-			KMem.SDD[19]=RecvTimeuS;
-		}
-		
-	return 0;
-}
-
 /* USER CODE END 0 */
 
 /**
@@ -541,7 +149,7 @@
 
   /* USER CODE BEGIN Init */
 
-	for (int i=0;i<16;i++)
+	for (int i=0;i<9;i++)
 	{
 //		memset(ChnStats[i],0,0);		
 		ChnStats[i].SendPackets=0;
@@ -592,20 +200,41 @@
 	ReadSysCfgFromFlash(&KMSysCfg);
 	
 	KMem.EffJumperSW=ReadJumperSW();
+#if (BOARD_TYPE == 12)
+	KMem.EffJumperSW|=0x10;
+	nAddr=KMem.EffJumperSW&0x0f;
+  if ((KMem.EffJumperSW&0x10)!=0) {bMaster=1;bSlave=0;}
+	else{bMaster=0;bSlave=1;}
+	nChilds=nAddr;
+	FP0_Init();
+#else
 	nAddr=KMem.EffJumperSW&0x7;
-	if (KMem.EffJumperSW == 0x0f) {repeater=1;bMaster=1;bSlave=0;}
+	if (KMem.EffJumperSW == 0x0f) {bRepeater=1;bMaster=1;bSlave=0;}
   else if ((KMem.EffJumperSW&0x08)!=0) {bMaster=1;bSlave=0;}
-	else{bMaster=0;bSlave=1;}	
+	else{bMaster=0;bSlave=1;}
+#endif
 	nChilds=nAddr;
 	nCurPollId=1;
-	if (KMem.EffJumperSW == 0x00) Uart1Baud = DefaultUart1Baud;
+	//if (KMem.EffJumperSW == 0x00)
+		Uart1Baud = DefaultUart1Baud;
   MX_USART1_UART_Init();
   MX_USART2_UART_Init();
+
 	MX_SPI1_Init();
-	
+	LL_SPI_EnableIT_RXNE(SPI1);
+
+#if (BOARD_TYPE == 12)
+//	MX_SPI2_Init();
+//  MX_ADC_Init();
+#else
 	MX_SPI2_Init();
   MX_ADC_Init();
+#endif
+
 	MX_IWDG_Init();
+
+	MX_TIM6_Init();
+	LL_TIM_EnableCounter(TIM6);
 	
   /* USER CODE BEGIN 2 */
 	LL_USART_EnableIT_RXNE(USART1);
@@ -616,7 +245,16 @@
 	Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1));	
 	LL_USART_EnableIT_IDLE(USART2);
 	LL_USART_EnableIT_TC(USART2);
+#if (BOARD_TYPE == 13)
+	int res;
+	res = w5500_init();
+	KMem.SDD[28]=res;
 	
+//	res=socket(0,Sn_MR_TCP,5000,0);
+	KMem.SDD[29]=res;	
+	
+//	res = listen(0);
+#endif	
 //	if (bSlave)
 	{
 	//	LL_USART_EnableAutoBaudRate(USART1);
@@ -634,8 +272,15 @@
 	HAL_Delay(10);				
 	SetRunLed(1);				//Turn On Run Led
 	SetErrLed(0);				//Turn Off Err Led
+
+#if (BOARD_TYPE == 12)
+//	PutOutput (0);					//Clear all Output
+//	Enable595(1);						//Enable 595 Output 
+#else
 	PutOutput (0);					//Clear all Output
 	Enable595(1);						//Enable 595 Output 
+#endif
+
 		if (GetBoardType() == 7 || GetBoardType() ==8 
 			|| GetBoardType() == 9 || GetBoardType() ==10 ) 
 		{
@@ -645,38 +290,21 @@
 	SetOutStat(0);			//OK Good, signal
 	ShowInitInfo();
 	KMem.LastScanTime = GetuS();
-/*		
-	int time1=GetuS();	
-	PutOutput(0x01);
-	int x;
-	while (1)
-	{
-		x = GetInput();
-		if (x&0x1) break;
+
+	KMRunStat.WorkMode=0;
+	if (KMRunStat.WorkMode == 1){
+		InitPLC();
+		StartPLC();
 	}
-	int time2=GetuS();
-	
-	KMem.SDD[17]=time2-time1;
-	PutOutput(0x00);
-	while (1)
-	{
-		x = GetInput();
-		if ((x&0x1) == 0) break;
-	}	
-	int time3=GetuS();
-	
-	KMem.SDD[18]=time3-time2;	
-*/	
-	InitPLC();
-	StartPLC();
-	KMRunStat.WorkMode=1;
-	KMem.WX[5]=0x5a;
+	KMem.WX[7]=0x5a;
+
   while (1)
   {
 		//int MyKeyStat1,MyKeyStat2;
 		//MyKeyStat1=GetInput();
-
-
+#if (BOARD_TYPE == 12)
+		FP0_Proc();
+#endif
 		//*((unsigned int *)&(PLCMem.SDT[10]))=nRunCount;
 	//	KMem.nRunCount=nRunCount;
 		SlowFlicker=0;
@@ -694,7 +322,11 @@
 //		KMem.SDD[13]=PendSvCount;
 //		KMem.SDD[14]=RCC->CSR;		
 
+#if (BOARD_TYPE == 12)
+//		KMem.WX[0]= GetInput();		
+#else
 		KMem.WX[0]= GetInput();		
+#endif
 		
 		if (GetBoardType() == 7 || GetBoardType() ==8 
 			|| GetBoardType() == 9 || GetBoardType() ==10 ) 
@@ -705,18 +337,19 @@
 		
 		
 //		pProgs = (stBinProg1 *) STORE_PRG_BASE;
+
 		if (	KMRunStat.WorkMode==1)
 		{
+			if (KMRunStat.nBinProgBank == 0){
+				pProgs=(stBinProg1 *)STORE_PRG_BASE;
+			}else {
+				pProgs=(stBinProg1 *)ALT_PRG_BASE;
+			}
+			nSizeProg1=KMRunStat.nBinProgSize;
 			
-		if (KMRunStat.nBinProgBank == 0){
-			pProgs=(stBinProg1 *)STORE_PRG_BASE;
-		}else {
-			pProgs=(stBinProg1 *)ALT_PRG_BASE;
+			ProcessPLCBinProg(pProgs, nSizeProg1);
 		}
-		nSizeProg1=KMRunStat.nBinProgSize;
-		
-		ProcessPLCBinProg(pProgs, nSizeProg1);
-		}
+
 		KMem.ScanTimeuS=us2-KMem.LastScanTime;
 		KMem.LastScanTime = us2;
 		if (KMem.ScanTimeuS < KMem.MinScanTimeuS) {KMem.MinScanTimeuS = KMem.ScanTimeuS;}
@@ -724,6 +357,7 @@
 //		if (repeater)		{	RepeaterFunc();	}
 
 		us3=GetuS();
+
 		if ((KMem.nRunCount &0x1f) == 0x02)
 		{
 			ADCProcess();
@@ -745,24 +379,34 @@
 				}
 			}
 		}
+
 		if (bMaster)		
 		{
+#if (BOARD_TYPE == 12)
+			for (int i=0;i<nOutputBytes;i++)
+			{BufferOut[i+1]=KMem.WYB[i];}
+#else
 //			BufferOut[1]=KMem.WX[0]&0xff;
 //			BufferOut[2]=(KMem.WX[0]>>8)&0xff;
-			MasterFunc();
-			
-//			KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8);
+#endif
+			if (nChilds>0) {		MasterFunc(2); }
 
+#if (BOARD_TYPE == 12)			
+//			KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8);
+#else
+//			KMem.WY[0]=BufferIn[1]+(BufferIn[2]<<8);
+#endif
+
+		}
 			if (haltick&0x00002000) SlowFlicker=1;
 			else SlowFlicker=0;
 			if (haltick&0x00000800) FastFlicker=1;
 			else FastFlicker=0;	
-			
-		}
+
 		if (bSlave)		
 		{
 //			BufferOut[0]=KMem.WX[0];
-			SlaveFunc();	
+			SlaveFunc(2);	
 			if (! KMem.RunStat) {BufferIn[0]=0;}
 			KMem.WY[0]=BufferIn[0];
 			
@@ -772,10 +416,11 @@
 			else FastFlicker=0;			
 
 		}
+
 //		KMem.WY[0]=nCount2>>5;
 		if (KMem.RunStat) {KMem.RunStat--;}
 		if (KMem.ErrStat) {KMem.ErrStat--;}
-		
+
 		if (!KMem.RunStat) SetRunLed(SlowFlicker);
 		else SetRunLed(FastFlicker);
 		
@@ -797,7 +442,11 @@
 		us4=GetuS();
 //		EffJumperSW = GetInput(20)&0xff;
 
+#if (BOARD_TYPE == 12)
 		PutOutput (KMem.WY[0]);
+#else
+//		PutOutput (KMem.WY[0]);
+#endif
 		//PutOutput (KMem.nRunCount>>8);
 		//PutOutput(0x0f70);
 		
@@ -811,18 +460,18 @@
 //			ProcessTimer(i);
 		}
 		KMem.nRunCount++;
-		int nSize=sizeof(stChnStat);
-		memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
-		memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
+//		int nSize=sizeof(stChnStat);
+//		memcpy(&KMem.SDT[64],&ChnStats[1],nSize);
+//		memcpy(&KMem.SDT[64+nSize/2],&ChnStats[2],nSize);
 //		for (int i=0;i<128;i++)	{		SDT[i]=i;	}
 //		SDT[48]=55;
 		if (Uart1RecvBuf1DataLen >0 && Uart1Stat.bPacketRecved)
 		{
 			int res1 = -1;
-			res1 = ModBusSlaveParsePkg(Uart1RecvBuf1,Uart1RecvBuf1DataLen);
+			res1 = ModBusSlaveParsePkg(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen);
 			if (res1 !=0)
 			{
-				KLParsePacket(Uart1RecvBuf1,Uart1RecvBuf1DataLen);
+				KLParsePacket(1, Uart1RecvBuf1, Uart1RecvBuf1DataLen);
 			}
 			Uart1RecvBuf1DataLen=0;
 			Uart1Stat.bPacketRecved=0;
@@ -837,7 +486,30 @@
 				clearscreen();
 			}
 		}
-*/	
+*/
+
+#if (BOARD_TYPE == 12)
+		//process 6 output
+		{
+				// mapping bits.
+			if (KMem.WXB[0]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_12);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_12);}
+			if (KMem.WXB[1]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_13);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_13);}
+			if (KMem.WXB[2]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_14);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_14);}
+			if (KMem.WXB[3]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_15);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_15);}
+			if (KMem.WXB[4]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_0);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_0);}
+			if (KMem.WXB[5]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_1);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_1);}			
+			if (KMem.WXB[5]&0x1){ LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_2);}
+			else {LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_2);}			
+		}
+#endif
+
+		{
 		unsigned char pos,seg;
 		unsigned short val;
 		pos=((KMem.nRunCount)&0x3);
@@ -853,7 +525,14 @@
 		//pos=1;
 		//seg=2;
 		seg=~seg;
-		PutOutputSPI1(pos|(seg<<8));
+		//	PutOutputSPI1(pos|(seg<<8));
+	}
+#if (BOARD_TYPE == 13)	
+	 w5500_network_info_show();
+	
+//	 loopback_tcps(0,str1,5000);
+#endif
+
 	 LL_IWDG_ReloadCounter(IWDG);
 		
   }	//while (1) ;

--
Gitblit v1.9.1