Browse Source

版本号为:2.2.0.0, 卫蓝电池生成软件,更改了CAN驱动和CAN任务

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
b9bf4b7b00
6 changed files with 197 additions and 96 deletions
  1. 3 3
      inc/app.h
  2. 1 1
      inc/hal_module_adapter.h
  3. 13 9
      src/CANTask.c
  4. 2 2
      src/UartTask.c
  5. 1 1
      src/bsp_custom.c
  6. 177 80
      src/hal_module_adapter.c

+ 3 - 3
inc/app.h

@@ -13,7 +13,7 @@
 extern "C" {
 #endif
 //全局定义声明区
-#define BMS_MANUFACTURE (1) //BMS制造商表示1-超力源,2-美顺
+#define BMS_MANUFACTURE (2) //BMS制造商表示1-超力源,2-美顺
 #define DATA_MODULE_TYPE (1) //1表示NB模块,2表示4G cat1
 #define BMS_INFO  (2)       //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
 #define EOLSTATE (0) //1标识下线检测跳过,使用默认值
@@ -45,8 +45,8 @@ extern "C" {
 #define	BLSWVERSION		0x01020000    //BootLoader版本号V1.2.0.0
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 //#define	APPSWVERSION		0x01020209     
-#define	APPSWVERSION		0x02000105
-//#define	APPSWVERSION		0x02010003
+//#define	APPSWVERSION		0x02000105
+#define	APPSWVERSION		0x02020000
 //--------------------------------------------------------------------------------
 
 #define APP_CONFIG_FILE_LATEST_VERSION 0

+ 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 - 9
src/CANTask.c

@@ -28,6 +28,7 @@ extern UINT32 Timer_count;
 extern volatile BOOL Sleep_flag;
 
 CAN_Msg_Type CanRxMsg[2];
+
 /*线程声明*/
 #define 			PROC_CAN_RX_TASK_STACK_SIZE			(1024)
 static StaticTask_t gProcess_Can_Rx_Task_t;
@@ -39,6 +40,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 +84,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 +127,11 @@ static void Can_Receive()
 					}
 					else if(msgFlag == 1)
 					{
-						CanMsgTx1000ms();
-						
-					}
-					break;
+						CanMsgTx1000ms();							
+					}				
 				}
+				break;
+				
 	        case PROCESS_CAN_STATE_SLEEP:
 	        {	            
 	            HAL_Can_Sleep();	 

+ 2 - 2
src/UartTask.c

@@ -136,12 +136,12 @@ static void UartTask(void* arg)
                 }
                 else if(Timer_count%10==0)
                 {
-                    #ifdef USING_PRINTF
+                    #ifdef USING_PRINTF1
                         printf("[%d]Uart Timer 5s:%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);

+ 1 - 1
src/bsp_custom.c

@@ -126,7 +126,7 @@ static void PMU_WakeupPadInit(void)
 {
     const padWakeupSettings_t cfg =
     {
-        true, false,             // group0 posedge, negedge
+        false, true,             // group0 posedge, negedge
         true, true,             // group1 posedge, negedge
         true, true,             // group2 posedge, negedge
     };

+ 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);