Bladeren bron

Merge branch 'V2版本-蓝精灵1000' into V2版本-LS电池

# Conflicts:
#	inc/app.h
更改了CAN驱动,和2.3.0.0保持一致
CHENJIE-PC\QiXiang_CHENJIE 3 jaren geleden
bovenliggende
commit
ac6f98db01
9 gewijzigde bestanden met toevoegingen van 231 en 110 verwijderingen
  1. 1 1
      inc/Fota.h
  2. 4 0
      inc/app.h
  3. 1 1
      inc/hal_module_adapter.h
  4. 13 10
      src/CANTask.c
  5. 9 3
      src/MainTask.c
  6. 6 1
      src/TcpTask.c
  7. 3 3
      src/UartTask.c
  8. 17 11
      src/bsp_custom.c
  9. 177 80
      src/hal_module_adapter.c

+ 1 - 1
inc/Fota.h

@@ -8,7 +8,7 @@
  ****************************************************************************/
 #include "bsp_custom.h"
 #define FLASH_BMS_FOTA_START_ADDR         0x2E6000
-#define FLASH_BMS_FOTA_LEN               0x204800  //200k
+#define FLASH_BMS_FOTA_LEN               0x32000  //200k
 #define FLASH_BMS_FOTA_END_ADDR         0x318000
 typedef struct _Fota_Type
 {

+ 4 - 0
inc/app.h

@@ -37,6 +37,10 @@ extern "C" {
         #define BATT_CELL_VOL_NUM  (17)
         #define BATT_TEMP_NUM  (4)
         #define BATT_OTHER_TEMP_NUM  (2)
+    #elif BMS_INFO==3
+        #define BATT_CELL_VOL_NUM  (20)
+        #define BATT_TEMP_NUM  (4)
+        #define BATT_OTHER_TEMP_NUM  (2)
     #endif
 #endif
 #define BATT_CELL_VOL_NUM_2 (BATT_CELL_VOL_NUM*2)

+ 1 - 1
inc/hal_module_adapter.h

@@ -184,7 +184,7 @@ void HAL_Can_Init(Can_InitType param);
 void HAL_Can_Sleep(void);
 INT32 HAL_Can_Reset(void);
 INT8 HAL_Can_Transmit(CAN_Msg_Type Can_TxMsg);
-void  HAL_Can_Receive(CAN_Msg_Type* CanRxMsgBuffer);
+UINT8  HAL_Can_Receive(CAN_Msg_Type* CanRxMsgBuffer);
 void UTCToBeijing(UTC8TimeType* UTC8Time,unsigned int UTCyear,unsigned char UTCmonth,unsigned char UTCday,unsigned int UTChour,unsigned char UTCminute,unsigned char UTCsecond);
 BOOL NB_ADC_Get(UINT32* adcValue, ADC_CHANNEL_TYPE adcChannel);
 

+ 13 - 10
src/CANTask.c

@@ -39,6 +39,7 @@ static process_CAN	gProcess_CAN_Task = PROCESS_CAN_STATE_IDLE;
 volatile bool 		CAN_Sleep_State = false;
 UINT8 				CanSendSlpHandler	= 0xfd;
 
+extern updateBMSStatus MS_BMS_Update_Service();
 
 
 void CANTaskInit(void* arg)
@@ -82,12 +83,14 @@ static void Can_Receive()
 				break;				
 			
 			case PROCESS_CAN_STATE_WORK:
+				
+				if(Sleep_flag)
 				{
-					if(Sleep_flag)
-					{
-						PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
-					}
-					HAL_Can_Receive(CanRxMsg);
+					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
+				}
+				
+				if(HAL_Can_Receive(CanRxMsg)>0)					
+				{						
 					for(i=0; i<2; i++)
 					{								
 						if(CanRxMsg[i].Id == 0x7A0)
@@ -123,11 +126,11 @@ static void Can_Receive()
 					}
 					else if(msgFlag == 1)
 					{
-						CanMsgTx1000ms();
-						
-					}
-					break;
+						CanMsgTx1000ms();							
+					}				
 				}
+				break;
+				
 	        case PROCESS_CAN_STATE_SLEEP:
 	        {	            
 	            HAL_Can_Sleep();	 
@@ -141,7 +144,7 @@ static void Can_Receive()
 	            break;
 	       }
 	   }
-	   osDelay(50);
+	   //osDelay(50);
 	}      
 }
 

+ 9 - 3
src/MainTask.c

@@ -36,7 +36,7 @@
 extern UINT8 	UDSSwitch;
 extern volatile bool NB_Fota_update_flag;
 extern volatile bool BMS_Fota_update_flag;
-CHAR defaultBattSN[BATT_SN_LEN] = "MGYGYN660N214E009";//未进行下线检测的默认SN
+CHAR defaultBattSN[BATT_SN_LEN] = "00000000000000000";//未进行下线检测的默认SN
 //全局变量
 UINT32 Timer_count;//每100ms加1
 volatile BOOL Sleep_flag = false;//睡眠标志位
@@ -44,9 +44,11 @@ extern UINT32 TcpService;
 extern UINT8 BattChrgEndFlag;
 AppConfigHeader   AppConfigHr;   //4 bytes
 AppNVMDataType AppNVMData;
-
 AppDataHeader AppDataHr;
 AppDataBody AppDataInfo;
+
+BOOL Can_Msg_Enble = false;
+
 //主线程堆栈声明区
 static StaticTask_t           gProcess_Main_Task_t;
 static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
@@ -221,9 +223,13 @@ static void MainTask(void* arg)
                     }
                     i++;   
                 }
-                if(TcpService!=0x00||UDSSwitch==1||BMS_Fota_update_flag||battWorkState!=0)
+                #ifdef USING_PRINTF1
+                    printf("TcpService:%d,UDSSwitch:%d,BMS_Fota_update_flag:%d,battWorkState:%d,Can_Msg_Enble:%d\r\n",TcpService,UDSSwitch,BMS_Fota_update_flag,battWorkState,Can_Msg_Enble);
+                #endif	
+                if(TcpService!=0x00||UDSSwitch==1||BMS_Fota_update_flag||battWorkState!=0||Can_Msg_Enble==true)
                 {
                     xTimerReset(work_timer,0);
+                    Can_Msg_Enble = false;
                 }
                 if(BattChrgEndFlag)
                 {

+ 6 - 1
src/TcpTask.c

@@ -138,7 +138,7 @@ static void TcpTask(void* arg)
                     {
                         Error_count = 0;
                         #ifdef DEBUGLOG
-                            Debug_printf("Tcp Connect failed , systerm restart !\n");
+                            Debug_printf("404\n");
                         #endif
                         appSetCFUN(0);
                         osDelay(1000);
@@ -529,6 +529,11 @@ static void TcpDataInfoAssembleSend()
         UINT8 *SendBuffer = PNULL;
         UINT16 BufferLen = 0;
         BufferLen = Debug_GetSize();
+        if(BufferLen>200)
+        {
+            Debug_Del_Logfile();
+            return;
+        }
         UINT8 rbuf[BufferLen];
         #ifdef USING_PRINTF
             printf("BufferLen:%d!\n",BufferLen);

+ 3 - 3
src/UartTask.c

@@ -136,12 +136,12 @@ static void UartTask(void* arg)
                 }
                 else if(Timer_count%10==0)
                 {
-                    #ifdef USING_PRINTF
-                        printf("[%d]Uart Timer 5s:%d,uartReadSuccessFlag:%d\n",__LINE__,Timer_count,uartReadSuccessFlag);
+                    #ifdef USING_PRINTF1
+                        printf("[%d]Uart Timer 1s:%d,uartReadSuccessFlag:%d\n",__LINE__,Timer_count,uartReadSuccessFlag);
                     #endif
                     if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
                     {
-                        #ifdef USING_PRINTF
+                        #ifdef USING_PRINTF1
                             printf("[%d]UartWriteCmdHandle :%x\n",__LINE__,UartWriteData.WriteCmd);
                         #endif
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);

+ 17 - 11
src/bsp_custom.c

@@ -18,7 +18,7 @@
 extern uint8_t lockoutState;
 #endif
 extern UINT8 Lockstatus;
-
+extern BOOL Can_Msg_Enble;
 void GPR_SetUartClk(void)
 {
     GPR_ClockDisable(GPR_UART0FuncClk);
@@ -203,13 +203,19 @@ void BSP_CustomInit(void)
 void Pad0_WakeupIntHandler(void)
 {
     if(slpManExtIntPreProcess(PadWakeup0_IRQn)==false)
+    {
         return;
-#ifdef USING_PRINTF
+    }
+    else
+    {
+        Can_Msg_Enble = true;
+    }
+#ifdef USING_PRINTF1
 	printf("[%d]PadWakeup0_IRQn\r\n",__LINE__);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn");
+// #else	
+//     ECOMM_TRACE(UNILOG_PLA_APP, pad0_Wk, P_SIG, 0, "PadWakeup0_IRQn");
 #endif
-	CanTiggerEvt(1);
+	// CanTiggerEvt(1);
 }
 
 void Pad1_WakeupIntHandler(void)
@@ -232,10 +238,10 @@ void Pad3_WakeupIntHandler(void)
         return;
 
     // add custom code below //
-#ifdef USING_PRINTF
+#ifdef USING_PRINTF1
 	printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
-#else	
-    ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn");
+// #else	
+//     ECOMM_TRACE(UNILOG_PLA_APP, pad3_Wk, P_SIG, 0, "PadWakeup3_IRQn");
 #endif
 
  	
@@ -249,11 +255,11 @@ void Pad4_WakeupIntHandler(void)
     if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false)
         return;
     // add custom code below //
-#ifdef USING_PRINTF
+#ifdef USING_PRINTF1
 	printf("[%d]PadWakeup3_IRQn\r\n",__LINE__);
-#else	
+// #else	
 
-    ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn");
+//     ECOMM_TRACE(UNILOG_PLA_APP, pad4_Wk, P_SIG, 0, "PadWakeup4_IRQn");
 #endif
 
 }

+ 177 - 80
src/hal_module_adapter.c

@@ -799,12 +799,13 @@ void HAL_Can_Init(Can_InitType param)
 	HAL_Can_Reset();	//¡¤¡é?¨ª?¡ä????¨¢?¨¨¨ª?t?¡ä??MCP2515
 	osDelay(100/portTICK_PERIOD_MS);		
       CAN_WriteReg(CANCTRL,OPMODE_CONFIG |CLKOUT_ENABLED);
-      CAN_ReadReg(CANCTRL,1,&temp);//?¨¢¨¨?CAN¡Á¡ä¨¬???¡ä??¡Â¦Ì??¦Ì
+    //  CAN_ReadReg(CANCTRL,1,&temp);//?¨¢¨¨?CAN¡Á¡ä¨¬???¡ä??¡Â¦Ì??¦Ì
    #ifdef USING_PRINTF   
 	//printf("[%d] CANCTRL = %#x \r\n",__LINE__,temp);
    #endif  
+
 	CAN_WriteReg(CNF1,param.baudrate);
-	CAN_WriteReg(CNF2,0x80|PHSEG1_3TQ|PRSEG_1TQ);
+	CAN_WriteReg(CNF2,BTLMODE_CNF3|PHSEG1_3TQ|PRSEG_1TQ);
 	CAN_WriteReg(CNF3,PHSEG2_3TQ);
 	
 	if(param.packType == STD_PACK){
@@ -843,7 +844,7 @@ void HAL_Can_Init(Can_InitType param)
 		CAN_WriteReg(RXF5SIDL,0xE0&(param.RxStdIDL[5]));
 #endif
 	
-		CAN_WriteReg(RXB0CTRL,RXM_RCV_ALL);
+		CAN_WriteReg(RXB0CTRL,RXM_RCV_ALL|BUKT_ROLLOVER);
 		CAN_WriteReg(RXB0DLC,DLC_8);
 		
 		CAN_WriteReg(RXB1CTRL,RXM_RCV_ALL);
@@ -904,8 +905,8 @@ void HAL_Can_Init(Can_InitType param)
 	
 	}
 
-	//CAN_WriteReg(BFPCTRL,0x0F);//zhengchao20210304  add
-	CAN_WriteReg(CANINTE,0x43); //zhengchao20210304  0x43 -> 0x03
+	CAN_WriteReg(BFPCTRL,0x3F);//zhengchao20210304  add
+	CAN_WriteReg(CANINTE,RX0IF|RX1IF); //zhengchao20210304  0x43 -> 0x03
 	CAN_WriteReg(CANINTF,0x00);
 	
 	CAN_WriteReg(CANCTRL,param.mode |CLKOUT_ENABLED);//??MCP2515¨¦¨¨???a?y3¡ê?¡ê¨º?,¨ª?3??????¡ê¨º? REQOP_NORMAL|CLKOUT_ENABLED
@@ -972,6 +973,11 @@ INT8  HAL_Can_Transmit(CAN_Msg_Type Can_TxMsg)
 		TXBufferCase =1;
 	else if((TXB2CTRLvalue&TXREQ)==0)
 		TXBufferCase =2;
+	else
+	{
+		CAN_WriteReg(TXB0CTRL, TXB0CTRLvalue&(~TXREQ));
+		TXBufferCase = 0;
+	}
 	
 	switch(TXBufferCase)
 	{
@@ -1083,94 +1089,185 @@ INT8  HAL_Can_Transmit(CAN_Msg_Type Can_TxMsg)
 * ����???��  : len(?����?��?��y?Y��?3��?��,0~8��??��)
 * ?��?��    : ?T
 *******************************************************************************/
-void  HAL_Can_Receive(CAN_Msg_Type* CanRxMsgBuffer)
+UINT8  HAL_Can_Receive(CAN_Msg_Type* CanRxMsgBuffer)
 {
 	
-	UINT8 i=0,len=0,temp=0;
+	UINT8 j=0,len=0,temp=0;
 	UINT8 SIdH,SIdL,EId8,EId0;
 	//static UINT16 counterBuff0,counterBuff1 = 0;
+	UINT8 ret = 0;
 	
 	CAN_ReadReg(CANINTF,1,&temp);
-#ifdef USING_PRINTF
-	//printf("CANINTF = 0x%x\n",temp);
-	//USARTdrv->Send(&temp,1);
-#endif
-	if(temp & 0x01)  //Rx Buffer 0
-	{	
-		/*get the id information*/
-		CAN_ReadReg(RXB0SIDH,1,&SIdH);
-		CAN_ReadReg(RXB0SIDL,1,&SIdL);
-		CAN_ReadReg(RXB0EID8,1,&EId8);
-		CAN_ReadReg(RXB0EID0,1,&EId0);
 		
-		CAN_ReadReg(RXB0DLC,1,&len);		
-		len = len&0x0F;
-		CanRxMsgBuffer[0].DLC = len;
+		ret = temp&0x03;
 
-		if(SIdL & 0x8)  // if SIdL.3 = 1, the id belongs to ExtID
-		{
-			(CanRxMsgBuffer[0]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
-		}
-		else
-		{
-			(CanRxMsgBuffer[0]).Id = SIdH<<3 | SIdL>>5;
-		}
-		
-		i = 0;
-		while(i<len)
-		{	
-			CAN_ReadReg(RXB0D0+i,1,&((CanRxMsgBuffer[0]).Data[i]));
-			i++;
-		}	
-	#ifdef USING_PRINTF1		
-		printf("buffer0 ID = %x\n",CanRxMsgBuffer[0].Id);
-		for(i=0;i<8;i++)
-		{
-			printf("%x ",CanRxMsgBuffer[0].Data[i]);
-		}
-		printf("\n");
-	#endif
-		
-	}
-	if(temp & 0x02)  //RX Buffer 1
-	{
-		/*get the id information*/
-		CAN_ReadReg(RXB1SIDH,1,&SIdH);
-		CAN_ReadReg(RXB1SIDL,1,&SIdL);
-		CAN_ReadReg(RXB1EID8,1,&EId8);
-		CAN_ReadReg(RXB1EID0,1,&EId0);
-		
-		CAN_ReadReg(RXB1DLC,1,&len);		
-		len = len & 0x0F;
-		CanRxMsgBuffer[1].DLC = len;
-	
-		if(SIdL & 0x8)  // SIdL.3 = 1, ExtID
-		{
-			(CanRxMsgBuffer[1]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
-		}
-		else
+		switch(ret)
 		{
-			(CanRxMsgBuffer[1]).Id = SIdH<<3 | SIdL>>5;
-		}
+			case 0x00:
+				return ret;
+				break;
+			case 0x01:
+				/*get the id information*/
+				CAN_ReadReg(RXB0SIDH,1,&SIdH);
+				CAN_ReadReg(RXB0SIDL,1,&SIdL);
+				CAN_ReadReg(RXB0EID8,1,&EId8);
+				CAN_ReadReg(RXB0EID0,1,&EId0);
+				
+				CAN_ReadReg(RXB0DLC,1,&len);		
+				len = len&0x0F;
+				CanRxMsgBuffer[0].DLC = len;
 
-		i = 0 ;
-		while(i<len)
-		{	
-			CAN_ReadReg(RXB1D0+i,1,&((CanRxMsgBuffer[1]).Data[i]));
-			i++;			
-		}
+				if(SIdL & 0x8)  // if SIdL.3 = 1, the id belongs to ExtID
+				{
+					(CanRxMsgBuffer[0]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
+				}
+				else
+				{
+					(CanRxMsgBuffer[0]).Id = SIdH<<3 | SIdL>>5;
+				}
+				
+				j = 0;
+				while(j<len)
+				{	
+					CAN_ReadReg(RXB0D0+j,1,&((CanRxMsgBuffer[0]).Data[j]));
+					j++;
+				}	
+			#ifdef USING_PRINTF1	
+				printf("buffer0 ID = %x\n",CanRxMsgBuffer[0].Id);
+				for(j=0;j<8;j++)
+				{
+					printf("%x ",CanRxMsgBuffer[0].Data[j]);
+				}
+				printf("\n");
+			#endif
+				CAN_WriteReg(CANINTF,temp&0xFE);
+				return ret;
+				break;
+
+			case 0x02:
+				/*get the id information*/
+				CAN_ReadReg(RXB1SIDH,1,&SIdH);
+				CAN_ReadReg(RXB1SIDL,1,&SIdL);
+				CAN_ReadReg(RXB1EID8,1,&EId8);
+				CAN_ReadReg(RXB1EID0,1,&EId0);
+				
+				CAN_ReadReg(RXB1DLC,1,&len);		
+				len = len & 0x0F;
+				CanRxMsgBuffer[1].DLC = len;
+			
+				if(SIdL & 0x8)  // SIdL.3 = 1, ExtID
+				{
+					(CanRxMsgBuffer[1]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
+				}
+				else
+				{
+					(CanRxMsgBuffer[1]).Id = SIdH<<3 | SIdL>>5;
+				}
+
+				j = 0 ;
+				while(j<len)
+				{	
+					CAN_ReadReg(RXB1D0+j,1,&((CanRxMsgBuffer[1]).Data[j]));
+					j++;			
+				}
+
+			#ifdef USING_PRINTF1		
+				printf("buffer1 ID = %x\n",CanRxMsgBuffer[1].Id);
+				for(j=0;j<8;j++)
+				{
+					printf("%x ",CanRxMsgBuffer[1].Data[j]);
+				}
+				printf("\n");
+			#endif
+				CAN_WriteReg(CANINTF,temp&0xFD);
+				return ret;
+				break;
+			case 0x03:
+				/*get the id information*/
+				CAN_ReadReg(RXB0SIDH,1,&SIdH);
+				CAN_ReadReg(RXB0SIDL,1,&SIdL);
+				CAN_ReadReg(RXB0EID8,1,&EId8);
+				CAN_ReadReg(RXB0EID0,1,&EId0);
+				
+				CAN_ReadReg(RXB0DLC,1,&len);		
+				len = len&0x0F;
+				CanRxMsgBuffer[0].DLC = len;
 
-	#ifdef USING_PRINTF1		
-		printf("buffer1 ID = %x\n",CanRxMsgBuffer[1].Id);
-		for(i=0;i<8;i++)
+				if(SIdL & 0x8)  // if SIdL.3 = 1, the id belongs to ExtID
+				{
+					(CanRxMsgBuffer[0]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
+				}
+				else
+				{
+					(CanRxMsgBuffer[0]).Id = SIdH<<3 | SIdL>>5;
+				}
+				
+				j = 0;
+				while(j<len)
+				{	
+					CAN_ReadReg(RXB0D0+j,1,&((CanRxMsgBuffer[0]).Data[j]));
+					j++;
+				}	
+			#ifdef USING_PRINTF1	
+				printf("buffer0 ID = %x\n",CanRxMsgBuffer[0].Id);
+				for(j=0;j<8;j++)
+				{
+					printf("%x ",CanRxMsgBuffer[0].Data[j]);
+				}
+				printf("\n");
+			#endif
+
+				/*get the id information*/
+				CAN_ReadReg(RXB1SIDH,1,&SIdH);
+				CAN_ReadReg(RXB1SIDL,1,&SIdL);
+				CAN_ReadReg(RXB1EID8,1,&EId8);
+				CAN_ReadReg(RXB1EID0,1,&EId0);
+				
+				CAN_ReadReg(RXB1DLC,1,&len);		
+				len = len & 0x0F;
+				CanRxMsgBuffer[1].DLC = len;
+			
+				if(SIdL & 0x8)  // SIdL.3 = 1, ExtID
+				{
+					(CanRxMsgBuffer[1]).Id = ((SIdH<<5 | (SIdL>>5)<<2 | SIdL&0x3 )<<16 | (EId8<<8) | EId0);
+				}
+				else
+				{
+					(CanRxMsgBuffer[1]).Id = SIdH<<3 | SIdL>>5;
+				}
+
+				j = 0 ;
+				while(j<len)
+				{	
+					CAN_ReadReg(RXB1D0+j,1,&((CanRxMsgBuffer[1]).Data[j]));
+					j++;			
+				}
+
+			#ifdef USING_PRINTF1		
+				printf("buffer1 ID = %x\n",CanRxMsgBuffer[1].Id);
+				for(j=0;j<8;j++)
+				{
+					printf("%x ",CanRxMsgBuffer[1].Data[j]);
+				}
+				printf("\n");
+			#endif
+				CAN_WriteReg(CANINTF,temp&0xFC);
+				return ret;
+				break;
+
+			default:
+				break;
+
+		}
+/*
+		CAN_ReadReg(CANINTF,1, &temp1);
+		if((temp1&0x03) == (temp&0x03))
 		{
-			printf("%x ",CanRxMsgBuffer[1].Data[i]);
+			CAN_WriteReg(CANINTF,temp&0xFC);
+			break;
 		}
-		printf("\n");
-	#endif
-		
-	}
-	CAN_WriteReg(CANINTF,0);
+*/
+	return ret;
 //	CAN_ReadReg(CANINTF,1,&temp);
 //	printf("CANINTF_1 = 0x%x\n",temp);