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/functions.c |  143 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 118 insertions(+), 25 deletions(-)

diff --git a/Src/functions.c b/Src/functions.c
index 8ba8fe2..7d7c303 100644
--- a/Src/functions.c
+++ b/Src/functions.c
@@ -8,6 +8,9 @@
 #include "functions.h"
 #include "string.h"
 #include "stm32f0xx_hal.h"
+#if (BOARD_TYPE == 12)
+#include "fp0.h"
+#endif
 extern __IO uint32_t uwTick;
 //#include "Myprotocol.h"
 int TickFreq=10000;
@@ -89,10 +92,10 @@
 unsigned short crc_check(const unsigned char * data, unsigned int  length)
 {
 unsigned short crc_reg = 0xFFFF;
-while (length--)
-{
-crc_reg = (crc_reg >> 8) ^ crc16_table[(crc_reg ^ *data++) & 0xff];
-}
+	while (length--)
+	{
+	crc_reg = (crc_reg >> 8) ^ crc16_table[(crc_reg ^ *data++) & 0xff];
+	}
 return (~crc_reg) & 0xFFFF;
 }
 
@@ -266,14 +269,82 @@
 
 void PendSvCallBack()
 {
+#if (BOARD_TYPE == 12)
+///*	
+		if (bSPI1RecvDone)
+		{
+			bSPI1RecvDone=0;
+			ParseFP0Pkg(SPI1RecvBuf,nSPI1RecvLenInBuf);
+		}
+//*/	
+#endif		
 	if (Uart2Stat.bPacketRecved)
 	{
-		ParsePacket((pPacket)Uart2RecvBuf1,Uart2RecvBuf1DataLen);		
+		ParsePacket(2, (pPacket)Uart2RecvBuf1, Uart2RecvBuf1DataLen);		
 		Uart2RecvBuf1DataLen=0;
 		Uart2Stat.bPacketRecved=0;
 		Uart2RecvDMA(Uart2RecvBuf1,sizeof(Uart2RecvBuf1));		
 	}
 }
+
+void SPI1_IRQ_CallBack()
+{
+		uint8_t value;
+//	LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_7);
+	 if (LL_SPI_IsActiveFlag_RXNE(SPI1))
+	 {
+		 	value = LL_SPI_ReceiveData8( SPI1);
+#if (BOARD_TYPE == 12)
+			KMem.SDD[62]++;
+			KMem.SDT[122]++;
+		 if (!bSPI1Sending)
+		 {
+		 	 KMem.SDB[128+KMem.SDT[123]] = value;
+			 KMem.SDT[123]++; 	 if (KMem.SDT[123]>=100) {KMem.SDT[123]=81;}
+		 }
+		 if (!bSPI1Sending && (1 || bSPI1Recving))
+		 {
+			 SPI1RecvBuf[nSPI1RecvPos]=value;
+			 nSPI1RecvPos++;
+			 
+			 if (value==0x0d)
+			 {
+		 	 KMem.SDB[128+KMem.SDT[123]] = nSPI1RecvPos;
+			 KMem.SDT[123]++; 	 if (KMem.SDT[123]>=100) {KMem.SDT[123]=81;}
+
+				 nSPI1RecvLenInBuf=nSPI1RecvPos;
+				 bSPI1RecvDone=1;
+				 nSPI1RecvPos=0;
+				 bSPI1Recving=0;
+				 
+			 
+				 TriggerPendSV();
+			 }
+		 }
+		 if (bSPI1Sending)
+		 {
+				 nSPI1SentLen++;
+				 KMem.SDD[63]++;
+			 
+			 if (nSPI1SentLen >= nSPI1ToSendLen) {
+				 SetACKPin_1();
+				 bSPI1Sending=0;
+				 bSPI1SendDone=1;
+				 bSPI1Recving=1;
+				 nSPI1RecvPos=0;
+				 SetFP0DEPin_0();
+			 }
+			 else {
+				 value = SPI1SendBuf[nSPI1SentLen];
+				 LL_SPI_TransmitData8(SPI1,value);
+				 KMem.SDB[128+KMem.SDT[123]] = value;
+				 KMem.SDT[123]++; 	 if (KMem.SDT[123]>=100) {KMem.SDT[123]=81;}			 
+			 }
+		 }
+#endif		 
+	 }	 
+}
+
 void Uart1SendDone()
 {
 	Uart1Stat.TcCount++;
@@ -312,10 +383,10 @@
 int PutStr(char * str1, int len1)
 {
 //	Uart1SendDMA(str1,len1);
-	//PushIn(&Uart1Stat.QTx,str1,len1);
+	PushIn(&Uart1Stat.QTx,str1,len1);
 //	LL_USART_EnableIT_TXE(USART1);   
 //	LL_USART_EnableIT_TC(USART1); 	
-	//Uart1TriggerSendDMA();
+	Uart1TriggerSendDMA();
 	return len1;
 }
 int PutStr1(char * str1, int len1)
@@ -337,21 +408,22 @@
 	return len1;
 }
 
-void clearscreen()
+int SendPacket(int nChn, void * pBuf,int len1)
 {
-	PutStr("\33[2J\33[0;0H",10);
-	return;
+	if (nChn==1) 	{
+		PutStr1((char *)pBuf,len1);
+//	PushIn(&Uart1Stat.QTx,p1,len1);
+//	Uart1TriggerSendDMA();
+		Uart1Stat.SentPacket++;		
+	}else if (nChn==2){
+		PutStr2((char *)pBuf,len1);	
+//	PushIn(&Uart2Stat.QTx,p1,len1);
+//	Uart2TriggerSendDMA();	
+		Uart2Stat.SentPacket++;		
+	}
+		return len1;
 }
-
-void Locate(int y,int x)
-{
-		char str[16];
-		int len;
-		len=sprintf(str," \33[%d;%dH",y,x);
-		PutStr(str,len);
-		return;
-}
-
+/*
 int SendPacket1(void * pBuf,int len1)
 {
 		PutStr1((char *)pBuf,len1);
@@ -368,9 +440,18 @@
 		Uart2Stat.SentPacket++;
 	return len1;
 }
-
+*/
 void ToggleRunLed() {	LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_13);}
 void ToggleErrLed() {	LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_14);}
+#if (BOARD_TYPE == 12)
+void ToggleOutStat() {	LL_GPIO_TogglePin(GPIOC,LL_GPIO_PIN_15);}
+
+void SetOutStat(uchar bOn)
+{
+	if (bOn) {LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_15);}
+	else {LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_15);}	
+}
+#else
 void ToggleOutStat() {	LL_GPIO_TogglePin(GPIOA,LL_GPIO_PIN_11);}
 
 void SetOutStat(uchar bOn)
@@ -378,6 +459,7 @@
 	if (bOn) {LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_11);}
 	else {LL_GPIO_ResetOutputPin(GPIOA,LL_GPIO_PIN_11);}	
 }
+#endif
 
 void SetRunLed(uchar bOn)
 {
@@ -529,6 +611,8 @@
 						return Input165_R(8);
 		case 11:
 						return Input165_R(8);
+		case 12:
+					 return 0;	//FP0
 		default:
 			break;
 	}
@@ -615,6 +699,10 @@
 					 return ReadConfig_5();	//New Slave 8 in 8 o
 		case 11:
 					 return ReadConfig_11(); //Mini Board
+		case 12:
+					 return (~(LL_GPIO_ReadInputPort(GPIOA)>>4))&0x0f;	//FP0
+		case 13:
+					 return ReadConfig_5();
 		default:
 			
 					 return 0;
@@ -685,6 +773,7 @@
 	__enable_irq();
 }
 
+/*
 #define STRCLK12_0() LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_7)
 #define STRCLK12_1() LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_7)
 
@@ -715,10 +804,11 @@
 	}		
 	KMem.SDD[30]=i;
 		STRCLK12_0();
-		STRCLK12_1();			
-	__enable_irq();
+		__nop();
+		STRCLK12_1();
+		__enable_irq();
 }
-
+*/
 
 void PutOutputSPI2(unsigned int Y)
 {
@@ -747,12 +837,15 @@
 	}		
 	KMem.SDD[30]=i;
 		STRCLK2_0();
-		STRCLK2_1();			
+		STRCLK2_1();
 	__enable_irq();
 }
 
 void PutOutput(unsigned int Y)		
 {	
+#if (BOARD_TYPE==12)
+	return ;
+#endif
 	PutOutputSPI2(Y);
 	//Output595_16(Y);
 }

--
Gitblit v1.9.1