瀏覽代碼

增加eeprom 增加uds

CHENJIE-PC\QiXiang_CHENJIE 2 年之前
父節點
當前提交
240d6dcb6f

+ 7 - 0
Project_Settings/Linker_Files/linker_flash_s32k146.ld.bak2

@@ -34,6 +34,9 @@ MEMORY
     int_flash_interrupts    : ORIGIN = 0x00014200, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
    /* int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
     int_flash               : ORIGIN = 0x00014600, LENGTH = 0x000EBA00    /* ~1.0MB */ 
+    
+    m_flexram        		: ORIGIN = 0x10000000, LENGTH = 0x00001000
+    
     int_sram_results        : ORIGIN = 0x1FFF0000, LENGTH = 0x00000100    /* 256bytes */
     int_sram                : ORIGIN = 0x1FFF0100, LENGTH = 0x0001DF00    /* ~120K */
     int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000 - 0x10    /* 4K  */
@@ -48,6 +51,10 @@ ENTRY(Reset_Handler)
 
 SECTIONS
 {
+	.eeeprom (NOLOAD):  
+    {      
+     	*(.eeprom)   
+    } >m_flexram 
     
 	.flash_interrupts :
 	{

+ 5 - 17
src/AppGlobalVar.c

@@ -21,6 +21,9 @@
 uint8 TcpbattSN[17] = {0x31}; //上传的SN编号
 uint8 VIN[17] = {0};
 volatile uint32 TimerCounter = 0; // ms单位
+uint32 BattTempR = 0;//ADC查询的温度R值
+uint16 ErrorArray[10]={0};
+
 /*GPS*/
 QueueHandle_t GpsDataQueueHandle;
 sint16 xyzData[3] = {0};
@@ -36,29 +39,14 @@ char ImeiNum[15] = {0};
 char IccidNum[20] = {0};
 uint8 CSQValue = 0;
 sint8 SocketId = -1;
+sint8 RegChkRet = 0;
 char WebSiteIp[15] = {0};
 const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
 const uint16 WebSitePort = 8712;
 
 #define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
-VAR_ALIGN(uint8 dataWrTestPatt[EEP_WRTESTPATT_SIZE],4)
-VAR_ALIGN(uint8 BufferRead[EEP_WRTESTPATT_SIZE],4)
-/* Data write to eeprom device */
-uint8 dataWrTestPatt[EEP_WRTESTPATT_SIZE]=
-{
-    0x01, 0x02, 0x03, 0x04,
-    0x11, 0x12, 0x13, 0x14,
-    0x21, 0x22, 0x23, 0x24,
-    0x31, 0x32, 0x33, 0x34,
-    0x41, 0x42, 0x43, 0x44,
-    0x51, 0x52, 0x53, 0x54,
-    0x61, 0x62, 0x63, 0x64,
-    0x71, 0x72, 0x73, 0x74,0x23
-};
-
-uint8 BufferRead[EEP_WRTESTPATT_SIZE] = {0};
-
+AppConfigBody AppConfigInfo={false,false,{defaultSn},{0}};
 #define EEP_STOP_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
 

+ 12 - 2
src/AppGlobalVar.h

@@ -39,6 +39,9 @@
 extern uint8 TcpbattSN[17];
 extern uint8 VIN[17];
 extern volatile uint32 TimerCounter;
+extern uint32 BattTempR;
+extern uint16 ErrorArray[10];
+
 typedef struct
 {
     uint8 RealLen;
@@ -57,14 +60,21 @@ extern QueueHandle_t CanRecvQueueHandle;
 /*以下变量均为TCP相关变量*/
 extern uint8 CSQValue;
 extern sint8 SocketId;
+extern sint8 RegChkRet;
 extern char WebSiteIp[15];
 extern const char WebSiteName[];
 extern const uint16 WebSitePort;
 extern char ImeiNum[15];
 extern char IccidNum[20];
 
-VAR_ALIGN(extern uint8 dataWrTestPatt[EEP_WRTESTPATT_SIZE],4)
-VAR_ALIGN(extern uint8 BufferRead[EEP_WRTESTPATT_SIZE],4)
+typedef struct _AppConfigType
+{
+	bool appSaveFlg;
+	bool eolFlg;
+	uint8 deviceSn[17];
+	uint8 re[20];
+} AppConfigBody;
+extern AppConfigBody AppConfigInfo;
 
 /*以下变量均为App_CAN相关变量*/
 #ifdef APP_CAN_ENABLE

+ 359 - 2
src/AppTaskCan.c

@@ -7,6 +7,10 @@
 #include "AppTaskCan.h"
 #ifdef APP_CAN_ENABLE
 uint32 timerCounterNow = 0;
+static uint8 BattSendFlg = 0;
+static void UDSAnsFunc(uint8 *rawData);
+static void UdsAns(bool PosFlg,uint8 UdsService,uint8 UdsSubService,uint8 Idx,uint8 *AnsData,uint8 AnsDataLen);
+static void BattSendFunc(void);
 static void vCanRxCallback(TimerHandle_t pxTimer)
 {
 	uint32 ulTimerID;
@@ -26,9 +30,9 @@ void CanTask(void *pvParameters)
 	monitorTimer1ms = xTimerCreate("monitor1ms",1,pdTRUE,(void *)0,vCanRxCallback);
 	xTimerStart(monitorTimer1ms,0);
 	BaseType_t ret = pdFALSE;
+	GsensorInit();
 	while(1)
 	{
-
 		do
 		{
 			memset(&CanRxMsg, 0, sizeof(CanRxMsg));
@@ -48,10 +52,16 @@ void CanTask(void *pvParameters)
 				}
 			}
 		}while(ret == pdPASS);
-		if(TimerCounter%100==0&&timerCounterNow!=TimerCounter)
+		SL_SC7A20_Read_XYZ_Data(xyzData);
+		if(BattSendFlg)
+		{
+			BattSendFunc();
+		}
+		if((TimerCounter - timerCounterNow)>100)
 		{
 			BcuRxDiagnose();
 			timerCounterNow = TimerCounter;
+			ADC_ReadValue();
 		}
 	}
 }
@@ -60,6 +70,9 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 {
 	switch (ID)
 	{
+	case 0x1C00EDEA:
+		UDSAnsFunc(rawData);
+		break;
 	case 0x1801EFF4:
 		BMS13_ReqVIN = (uint8)(((*(uint8 *)(rawData + 0))) & 0xFF);
 		BcuRxFlag[0] = 0x01;
@@ -1088,6 +1101,350 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		break;
 	}
 }
+static void UDSAnsFunc(uint8 *rawData)
+{
+	static uint8 UdsStates = 1;
+	uint8 Data[8] = {0};
+	memcpy(Data,rawData,8);
+	uint8 UdsService = 0;
+	uint8 UdsSubService = 0;
+	UdsService = Data[0];
+	UdsSubService = Data[1];
+	uint8 AnsData[24]={0};
+	static uint8 deviceSnRecvFlg = 0;
+	switch(UdsService)
+	{
+	case 0x10://模式切换
+	{
+		if(UdsSubService==0x01)
+		{
+			UdsStates = 0x01;//关闭UDS诊断
+			UdsAns(true,UdsService,UdsSubService,0x00,NULL,0);
+		}
+		else if(UdsSubService==0x02)
+		{
+			if(UdsStates==0x01||UdsStates==0x02)
+			{
+				UdsStates = 0x02;//打开UDS诊断
+				UdsAns(true,UdsService,UdsSubService,0x00,NULL,0);
+			}
+			else
+			{
+				UdsAns(false,UdsService,UdsSubService,0x00,NULL,0);
+			}
+		}
+		break;
+	}
+	case 0x22://查询
+	{
+		if(UdsStates==0x02)
+		{
+			switch(UdsSubService)
+			{
+			case 0x01://版本号查询
+			{
+				AnsData[0] = APPSWVERSION>>24;
+				AnsData[1] = APPSWVERSION>>16;
+				AnsData[2] = APPSWVERSION>>8;
+				AnsData[3] = APPSWVERSION>>0;
+				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,4);
+				break;
+			}
+			case 0x02://SN号码查询
+			{
+				memcpy(AnsData,AppConfigInfo.deviceSn,17);
+				for(uint8 i=0;i<5;i++)
+				{
+					UdsAns(true,UdsService,UdsSubService,i,&AnsData[i*4],4);
+				}
+				break;
+			}
+			case 0x03://ICCID查询
+			{
+				memcpy(AnsData,IccidNum,20);
+				for(uint8 i=0;i<5;i++)
+				{
+					UdsAns(true,UdsService,UdsSubService,i,&AnsData[i*4],4);
+				}
+				break;
+			}
+			case 0x04://IMEI查询
+			{
+				memcpy(AnsData,ImeiNum,15);
+				for(uint8 i=0;i<4;i++)
+				{
+					UdsAns(true,UdsService,UdsSubService,i,&AnsData[i*4],4);
+				}
+				break;
+			}
+			case 0x05://驻网状态查询
+			{
+				AnsData[0]= RegChkRet;
+				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
+				break;
+			}
+			case 0x06://联网状态查询
+			{
+				AnsData[0]= SocketId;
+				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
+				break;
+			}
+			case 0x07://定位信息查询
+			{
+				GPSInfo GpsRecvData;
+				if (xQueuePeek(GpsDataQueueHandle, &GpsRecvData, 0) == pdPASS)
+				{
+					AnsData[0] = GpsRecvData.locateMark;
+					AnsData[4] = GpsRecvData.longitude[0];
+					AnsData[5] = GpsRecvData.longitude[1];
+					AnsData[6] = GpsRecvData.longitude[2];
+					AnsData[7] = GpsRecvData.longitude[3];
+					AnsData[8] = GpsRecvData.latitude[0];
+					AnsData[9] = GpsRecvData.latitude[1];
+					AnsData[10] = GpsRecvData.latitude[2];
+					AnsData[11] = GpsRecvData.latitude[3];
+					AnsData[12] = GpsRecvData.altitude[0];
+					AnsData[13] = GpsRecvData.altitude[1];
+					AnsData[14] = GpsRecvData.satelliteNum;
+					for(uint8 i=0;i<4;i++)
+					{
+						UdsAns(true,UdsService,UdsSubService,i,&AnsData[i*4],4);
+					}
+					break;
+				}
+				else
+				{
+					AnsData[0]=0xFF;
+					UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
+				}
+				break;
+			}
+			case 0x08://温度检测查询
+			{
+				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
+				break;
+			}
+			case 0x09://电池信息查询
+			{
+				UdsAns(true,UdsService,UdsSubService,0x00,AnsData,1);
+				BattSendFlg = 1;
+				break;
+			}
+			case 0x0A://三轴数据查询
+			{
+				AnsData[0] = xyzData[0]>>8;
+				AnsData[1] = xyzData[0]>>0;
+				AnsData[2] = xyzData[1]>>8;
+				AnsData[3] = xyzData[1]>>0;
+				AnsData[4] = xyzData[2]>>8;
+				AnsData[5] = xyzData[2]>>0;
+				for(uint8 i=0;i<2;i++)
+				{
+					UdsAns(true,UdsService,UdsSubService,i,&AnsData[i*4],4);
+				}
+				break;
+			}
+			}//switch
+		}//if
+		else
+		{
+			UdsAns(false,UdsService,UdsSubService,0x00,NULL,0);
+		}
+		break;
+	}
+	case 0x27://控制
+	{
+		if(UdsStates==0x02)
+		{
+
+		}
+		else
+		{
+			UdsAns(false,UdsService,UdsSubService,0x00,NULL,0);
+		}
+		break;
+	}
+	case 0x2E://写入
+	{
+		if(UdsStates==0x02)
+		{
+			switch(UdsSubService)
+			{
+			case 0x01:
+			{
+				setbit(deviceSnRecvFlg,Data[3]);
+				if(Data[3]<0x04)
+				{
+					memcpy(&AppConfigInfo.deviceSn[Data[3]*4],&Data[4],4);
+					UdsAns(true,UdsService,UdsSubService,0x00,&Data[3],1);
+				}
+				else if(Data[3]==0x04)
+				{
+					memcpy(&AppConfigInfo.deviceSn[Data[3]*4],&Data[4],1);
+					UdsAns(true,UdsService,UdsSubService,0x00,&Data[3],1);
+				}
+				if(deviceSnRecvFlg==0x1F)
+				{
+					deviceSnRecvFlg = 0;
+					AppConfigInfo.appSaveFlg = true;
+				}
+				break;
+			}
+			}
+		}
+		else
+		{
+			UdsAns(false,UdsService,UdsSubService,0x00,NULL,0);
+		}
+		break;
+	}
+	default:
+		break;
+	}
+	return;
+}
+static void UdsAns(bool PosFlg,uint8 UdsService,uint8 UdsSubService,uint8 Idx,uint8 *AnsData,uint8 AnsDataLen)
+{
+	Can_Msg_Type CanTxMsg;
+	uint32 CanAnsId = 0x1C00EAED;
+	uint8 SendData[8] = {0};
+	if(PosFlg)
+	{
+		SendData[0] = 0x78;
+		SendData[1] = UdsService;
+		SendData[2] = UdsSubService;
+		SendData[3] = Idx;
+		if(AnsData!=NULL&&AnsDataLen!=0x00)
+		{
+			memcpy(&SendData[4],AnsData,AnsDataLen);
+		}
+	}
+	else
+	{
+		SendData[0] = 0x7F;
+		SendData[1] = UdsService;
+		SendData[2] = UdsSubService;
+		SendData[3] = 0x00;
+	}
+	CanTxMsg.id = CanAnsId;
+	CanTxMsg.idFrame = CAN_EXTENDED_ID_TYPE;
+	CanTxMsg.sdu = SendData;
+	CanTxMsg.length = 8;
+	CanIf_SendMessage(CAN1, CanTxMsg);
+}
+static void BattSendFunc(void)
+{
+	Can_Msg_Type CanTxMsg;
+	uint32 CanAnsId = 0;
+	uint8 SendData[8] = {0};
+	static uint8 SendStep = 0;
+	static uint8 SendCounter = 0;
+	switch(SendStep)
+	{
+	case 0x00:
+	{
+		SendStep++;
+		return;
+		break;
+	}
+	case 0x01:
+	{
+		CanAnsId = 0x1C01EAED;
+		SendData[0] =  0;
+		SendData[1] =  0;
+		SendData[2] =  0;
+		SendData[3] =  0;
+		SendStep++;
+		break;
+	}
+	case 0x02:
+	{
+		uint16 ErrorTemp ;
+		ErrorTemp = GetErrorNum(ErrorArray,sizeof(ErrorArray)/2);
+		CanAnsId = 0x1C09EAED;
+		SendData[0] =  0;
+		SendData[1] =  ErrorTemp>>8;
+		SendData[2] =  ErrorTemp;
+		SendData[3] =  0;
+		SendData[4] =  0;
+		SendData[5] =  0;
+		SendData[6] =  0;
+		SendData[7] =  0;
+		SendStep++;
+		break;
+	}
+	case 0x03:
+	{
+		CanAnsId = 0x1C0AEAED;
+		uint16 SocTemp = BMS2_SOC*10;
+		SendData[0] =  BMS2_PackCurrent>>8;
+		SendData[1] =  BMS2_PackCurrent;
+		SendData[2] =  BMS2_PackInsideVolt>>8;
+		SendData[3] =  BMS2_PackInsideVolt;
+		SendData[4] =  SocTemp>>8;
+		SendData[5] =  SocTemp;
+		SendData[6] =  BMS2_SOH;
+		SendData[7] =  0;
+		SendStep++;
+		break;
+	}
+	case 0x04:
+	{
+		CanAnsId = 0x1C10EAED + (SendCounter<<16);
+		if((SendCounter*8 + 7)>BMS_TEMP_MAX_NUM)
+		{
+			SendCounter = 0;
+			SendStep++;
+			return;
+			break;
+		}
+		SendData[0] =  BMS_Cell_TempN[SendCounter*8 + 0];
+		SendData[1] =  BMS_Cell_TempN[SendCounter*8 + 1];
+		SendData[2] =  BMS_Cell_TempN[SendCounter*8 + 2];
+		SendData[3] =  BMS_Cell_TempN[SendCounter*8 + 3];
+		SendData[4] =  BMS_Cell_TempN[SendCounter*8 + 4];
+		SendData[5] =  BMS_Cell_TempN[SendCounter*8 + 5];
+		SendData[6] =  BMS_Cell_TempN[SendCounter*8 + 6];
+		SendData[7] =  BMS_Cell_TempN[SendCounter*8 + 7];
+		SendCounter++;
+		break;
+	}
+	case 0x05:
+	{
+		CanAnsId = 0x1CA0EAED + (SendCounter<<16);
+		if((SendCounter*4 + 3)>BMS_CELL_MAX_NUM)
+		{
+			SendCounter = 0;
+			SendStep++;
+			return;
+			break;
+		}
+		SendData[0] =  BMS_Cell_Volt[SendCounter*4 + 0]>>8;
+		SendData[1] =  BMS_Cell_Volt[SendCounter*4 + 0];
+		SendData[2] =  BMS_Cell_Volt[SendCounter*4 + 1]>>8;
+		SendData[3] =  BMS_Cell_Volt[SendCounter*4 + 1];
+		SendData[4] =  BMS_Cell_Volt[SendCounter*4 + 2]>>8;
+		SendData[5] =  BMS_Cell_Volt[SendCounter*4 + 2];
+		SendData[6] =  BMS_Cell_Volt[SendCounter*4 + 3]>>8;
+		SendData[7] =  BMS_Cell_Volt[SendCounter*4 + 3];
+		SendCounter++;
+		break;
+	}
+	default:
+	{
+		SendStep = 0;
+		BattSendFlg = 0;
+		return;
+		break;
+	}
+	}
+	CanTxMsg.id = CanAnsId;
+	CanTxMsg.idFrame = CAN_EXTENDED_ID_TYPE;
+	CanTxMsg.sdu = SendData;
+	CanTxMsg.length = 8;
+	CanIf_SendMessage(CAN1, CanTxMsg);
+}
+
 void BcuRxDiagnose(void)//100ms调用一次
 {
 	static uint32 TimeCounter = 0;//ms

+ 1 - 0
src/AppTaskCan.h

@@ -12,6 +12,7 @@
 #include "AppFuncLib.h"
 #include "UDSTask.h"
 #include "Hal_Wdg.h"
+#include "AppTaskGps.h"
 void BcuDecodeFunction(uint32 ID, uint8 *rawData);
 void BcuRxDiagnose(void);
 void BcuRxMsgSetInvalidValue(uint32 ID);

+ 1 - 4
src/AppTaskGps.c

@@ -14,17 +14,14 @@ void GpsTask(void *pvParameters)
 	GpsDataQueueHandle = xQueueCreate(1, sizeof(GPSInfo));//长度为1才可以允许覆写
 	Dio_WriteChannel(DioConf_DioChannel_PTD1_GPIO_OUT_MCU_GPS_POW_EN, STD_ON);//GPS开机
 	uint16 pReadLen = 0;
-	GsensorInit();
-	sint16 SL_SC7A20_Data_XYZ_Buf[3];
 	while(1)
 	{
-		vTaskDelay(pdMS_TO_TICKS(100));
+		vTaskDelay(pdMS_TO_TICKS(10));
 		memset(RX_Buffer[UART_LPUART2],0x00,sizeof(RX_Buffer[UART_LPUART2]));
 		UART_Receive_Data(UART_LPUART2,RX_Buffer[UART_LPUART2],&pReadLen,1000);
 		if(pReadLen>0)
 		{
 			GpsDataDecode(RX_Buffer[UART_LPUART2]);
-			SL_SC7A20_Read_XYZ_Data(SL_SC7A20_Data_XYZ_Buf);
 		}
 	}
 }

+ 11 - 0
src/AppTaskMain.c

@@ -16,6 +16,12 @@ void MainTask(void *pvParameters)
 	TimerHandle_t monitorTimer1ms;
 	monitorTimer1ms = xTimerCreate("monitor1ms",1,pdTRUE,(void *)0,vTimer1msCallback);
 	xTimerStart(monitorTimer1ms,0);
+	uint32 *eppromAddStart = 0x14000000;
+	if(*(uint8 *)(eppromAddStart)==0xff)
+	{
+		HAL_EEP_Write(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
+	}
+	HAL_EEP_Read(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
 	while(1)
 	{
 		vTaskDelay(pdMS_TO_TICKS(10));
@@ -26,6 +32,11 @@ void MainTask(void *pvParameters)
 				WATCHDOG_HAL_Feed();
 			}
 		}
+		if(AppConfigInfo.appSaveFlg)
+		{
+			AppConfigInfo.appSaveFlg = false;
+			HAL_EEP_Write(0,(uint8 *)&AppConfigInfo,sizeof(AppConfigInfo));
+		}
 	}
 }
 static void vTimerCallback(TimerHandle_t pxTimer)

+ 5 - 5
src/AppTaskUart1.c

@@ -65,7 +65,7 @@ void Uart_4G_Task(void *pvParameters)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
 			}
-			else if ((TimerCounter -SendTimerCounter)>1000)
+			else if ((TimerCounter -SendTimerCounter)>1000 && AppConfigInfo.eolFlg==1)
 			{
 				SendTimerCounter = TimerCounter;
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
@@ -93,7 +93,6 @@ void Uart_4G_Task(void *pvParameters)
 		}
 		case PROCESS_TCP_REGCHK: //驻网检查,包括SIM,CPIN检查,ICCID获取
 		{
-			sint8 RegChkRet = 0;
 			RegChkRet = TcpRegisterChkFunc();
 			if (RegChkRet > 0) //检查通过,SIM卡已就绪,已进行驻网
 			{
@@ -172,7 +171,7 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 	sint8 outValue = -1;
 	uint32 pSendDataAddr = 0;
 	uint16 DataSendLen = 0;
-	memcpy(TcpbattSN, defaultSn, 17);
+	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
 	TcpDataEncode(&pSendDataAddr, &DataSendLen); //数据组包,malloc申请在里面,pSendData指向申请的地址
 	if (DataSendLen == 0)
 	{
@@ -248,7 +247,6 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			else
 			{
 				ConnectStep++;
-				*ConnectId = 0;
 			}
 			break;
 		}
@@ -276,6 +274,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 		{
 			char AtCmdSend[20] = {0};
 			uint8 AtCmdSendTotalLen = 0;
+			*ConnectId = 0;
 			sprintf(AtCmdSend, "%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //此处需要优化
 			AtCmdSendTotalLen = mstrlen(AtCmdSend);
 			AtcmdTransmit(AT_CONNECT, AtCmdSend, AtCmdSendTotalLen, &ATRet);
@@ -286,6 +285,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			else
 			{
 				ChkState = -ConnectStep;
+				*ConnectId = -1;
 				return ChkState;
 			}
 			break;
@@ -493,7 +493,7 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	}
 	memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
 
-	UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
+	UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
 
 	*retFunc = Atcmdfunc[CmdIdx].cb(PtrATCmdSend, RX_Buffer[UART_LPUART1], CmdIdx, ReadLen);
 	if (PtrATCmdSend != NULL)

+ 1 - 0
src/AppTaskUart1.h

@@ -133,6 +133,7 @@ typedef enum
     AT_SEND,
     AT_DISCON,
     AT_NETCLOSE,
+	AT_CGNSSPWR
 } ATCmd;
 typedef sint8 (*pFunc)(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen);
 sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pReadLen);

+ 17 - 15
src/SL_Sc7a20_Driver.c

@@ -104,7 +104,7 @@ Std_ReturnType  SL_SC7A20_INT_Config(void)
     //interrupt happen,int pin output lower level
     Gsensor_SPI_Write(SL_SC7A20_CTRL_REG6, SL_Write_Reg,1);
 
-    //AOI1 CONFIG
+    //AOI1 CONFIG  只开高中断
     SL_Write_Reg[0]=0x00;            //0x7F
 #if  SL_6D4D2D1D_SEL== 1
     SL_Write_Reg[0]=SL_Write_Reg[0]|0x02;//X
@@ -115,23 +115,23 @@ Std_ReturnType  SL_SC7A20_INT_Config(void)
     SL_Write_Reg[0]=SL_Write_Reg[0]|0x03;//X
     SL_Write_Reg[0]=SL_Write_Reg[0]|0x0C;//Y
 #elif  SL_6D4D2D1D_SEL== 6
-    SL_Write_Reg[0]=SL_Write_Reg[0]|0x03;//Xֵ
-    SL_Write_Reg[0]=SL_Write_Reg[0]|0x0C;//Yֵ
-    SL_Write_Reg[0]=SL_Write_Reg[0]|0x30;//Z
+    SL_Write_Reg[0]=SL_Write_Reg[0]|0x02;//Xֵ
+    SL_Write_Reg[0]=SL_Write_Reg[0]|0x08;//Yֵ
+    SL_Write_Reg[0]=SL_Write_Reg[0]|0x20;//Z
 #endif
 
     Gsensor_SPI_Write(SL_SC7A20_INT1_CFG, SL_Write_Reg,1);
 
     //HPF SET
   //  Gsensor_SPI_Read(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
-    SL_Write_Reg[0]=0xCF;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1
+    SL_Write_Reg[0]=0x81;//SL_Read_Reg|0xCF;//Normal HP , HPF TO AOI1
     Gsensor_SPI_Write(SL_SC7A20_CTRL_REG2, SL_Write_Reg,1);
 
 #if SL_6D4D2D1D_SEL== 6
     SL_Write_Reg[0] = SL_SC7A20_INT_THS_20PERCENT;
 	Gsensor_SPI_Write(SL_SC7A20_INT1_THS, SL_Write_Reg,1);
 
-	SL_Write_Reg[0] = SL_SC7A20_INT_DURATION_30CLK;
+	SL_Write_Reg[0] = SL_SC7A20_INT_DURATION_10CLK;
 	Gsensor_SPI_Write(SL_SC7A20_INT1_DURATION, SL_Write_Reg, 1);
 #else
     SL_Write_Reg[0] = SL_SC7A20_INT_THS_10PERCENT;
@@ -156,7 +156,7 @@ Std_ReturnType  SL_SC7A20_INT_Config(void)
 
 
     //AOI2 CONFIG
-    SL_Write_Reg[0]=0x00;            //0xFF
+    SL_Write_Reg[0]=0x00|0x0C;            //0xFF
 
 #if  SL_6D4D2D1D_SEL== 1
     SL_Write_Reg[0]=SL_Write_Reg[0]|0x02;//X
@@ -184,13 +184,13 @@ Std_ReturnType  SL_SC7A20_INT_Config(void)
 
 
 #if SL_6D4D2D1D_SEL== 6
-    SL_Write_Reg[0] = SL_SC7A20_INT_THS_5PERCENT;
+    SL_Write_Reg[0] = SL_SC7A20_INT_THS_20PERCENT;
 #else
     SL_Write_Reg[0] = SL_SC7A20_INT_THS_10PERCENT;
 #endif
     Gsensor_SPI_Write(SL_SC7A20_INT2_THS,SL_Write_Reg,1 );
 
-    SL_Write_Reg[0] = SL_SC7A20_INT_DURATION_2CLK;
+    SL_Write_Reg[0] = SL_SC7A20_INT_DURATION_10CLK;
     Gsensor_SPI_Write(SL_SC7A20_INT2_DURATION, SL_Write_Reg,1);
 
     //AOI2 TO INT2
@@ -374,16 +374,12 @@ void  SL_SC7A20_Reg_read_all(void)
 {
     uint8 SL_Read_Reg[32];
     memset(SL_Read_Reg,0xFF,32);
-//    printf("SL_SC7A20_Reg_readall ++++++++\r\n");
-    /*******************AOI1  IN  INT1********************/
 	uint8 adr = 0x20;
 	for(adr=0x20;adr<=0x3F;adr++)
 	{
 		Gsensor_SPI_Read(adr,&SL_Read_Reg[adr-0x20],1);
-//		printf("%#x = %#x\r\n",adr,SL_Read_Reg[adr-0x20]);
 	}
-
-//    printf("SL_SC7A20_Reg_readall --------\r\n");
+	return;
 }
 
 
@@ -446,6 +442,12 @@ Std_ReturnType  SL_SC7A20_Read_XYZ_Data(sint16 *SL_SC7A20_Data_XYZ_Buf)
         SL_SC7A20_Data_XYZ_Buf[0]=(sint16)((SL_Read_Buf[2]<<8) + SL_Read_Buf[1]);
         SL_SC7A20_Data_XYZ_Buf[1]=(sint16)((SL_Read_Buf[4]<<8) + SL_Read_Buf[3]);
         SL_SC7A20_Data_XYZ_Buf[2]=(sint16)((SL_Read_Buf[6]<<8) + SL_Read_Buf[5]);
+        SL_SC7A20_Data_XYZ_Buf[0] = SL_SC7A20_Data_XYZ_Buf[0] >>4;
+        SL_SC7A20_Data_XYZ_Buf[1] = SL_SC7A20_Data_XYZ_Buf[1] >>4;
+        SL_SC7A20_Data_XYZ_Buf[2] = SL_SC7A20_Data_XYZ_Buf[2] >>4;
+        SL_SC7A20_Data_XYZ_Buf[0] = SL_SC7A20_Data_XYZ_Buf[0] * 2;
+		SL_SC7A20_Data_XYZ_Buf[1] = SL_SC7A20_Data_XYZ_Buf[1] * 2;
+		SL_SC7A20_Data_XYZ_Buf[2] = SL_SC7A20_Data_XYZ_Buf[2] * 2;
         return  E_OK;
 
     }
@@ -466,7 +468,7 @@ Std_ReturnType GsensorInit(void)
 		SL_SC7A20_FS_Config(SL_SC7A20_FS_4G);
 		SL_SC7A20_INT_Config();
 		//SL_SC7A20_INT_RESET();
-		SL_SC7A20_Power_Config(SL_SC7A20_LOWER_POWER_ODR_400HZ);
+		SL_SC7A20_Power_Config(SL_SC7A20_ODR_400HZ);
 	}
 	return Status;
 }

+ 1 - 1
src/SL_Sc7a20_Driver.h

@@ -90,7 +90,7 @@
 #define  SL_SC7A20_ACT_DURATION   (uint8)0x3F
 	
 /*连续读取数据时的数据寄存器地址*/
-#define  SL_SC7A20_DATA_OUT       (uint8)(SL_SC7A20_OUT_X_L|0x80)
+#define  SL_SC7A20_DATA_OUT       (uint8)(SL_SC7A20_OUT_X_L)
 
 /**********特殊功能寄存器**********/
 /*非原厂技术人员请勿修改*/

+ 33 - 72
src/hal_adapter.c

@@ -6,11 +6,13 @@
  */
 #include "hal_adapter.h"
 #include "AppGlobalVar.h"
-
  uint8_t __attribute__((section(".non_cacheable_data"))) RX_Buffer[3][BUFFER_SIZE];
  uint32_t bufferIdx[3] = {0};
  volatile uint32 VarNotification_0 = 0;
  volatile uint32 VarNotification_1 = 0;
+ TP_Value_Type    ConvertedBuffer[NUM_RESULTS];
+ Adc_ValueGroupType    ResultBuffer[NUM_RESULTS];
+ Std_ReturnType  ADC_Converter(Adc_ValueGroupType* Buffer, TP_Value_Type* ConvertedValueR);
  Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout)
  {
      volatile Std_ReturnType R_Uart_Status;
@@ -21,10 +23,6 @@
      uint32 R_bytesRemaining;
      uint32 timeout = T_timeout;
      uint32 retVal = E_NOT_OK;
-     //    uint8 Rx_Buffer[MSG_LEN];
-
-     /* Uart_AsyncReceive transmit data */
- //    IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(0);
      bufferIdx[recvChannel]=0;
 	 switch(recvChannel)
 	 {
@@ -61,10 +59,8 @@
 		 return E_NOT_OK;
 	 }
 	 /* Check for no on-going transmission */
-//	 Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_ON);
 	 do
 	 {
-//		 Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_ON);
 		 if(Uart_TransmitStatus != UART_STATUS_NO_ERROR)
 		 {
 			 Uart_TransmitStatus = Uart_GetStatus(transChannel, &T_bytesRemaining, UART_SEND);
@@ -73,14 +69,8 @@
 		 {
 			 Uart_ReceiveStatus = Uart_GetStatus(recvChannel, &R_bytesRemaining, UART_RECEIVE);
 		 }
-
 		 vTaskDelay(pdMS_TO_TICKS(1));
-//		 Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
-
 	 } while (((UART_STATUS_NO_ERROR != Uart_TransmitStatus || UART_STATUS_NO_ERROR != Uart_ReceiveStatus) && 0 < --timeout));
-//	 Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_OFF);
-
-
 	 if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
 	 {
 		 Uart_Abort(transChannel, UART_SEND);
@@ -94,7 +84,6 @@
 	 {
 		 Uart_Abort(recvChannel, UART_RECEIVE);
 		 *rxlen = bufferIdx[recvChannel];
-		 //IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
 		 retVal = E_NOT_OK;
 	 }
 	 else
@@ -113,22 +102,18 @@
      uint32 T_bytesRemaining;
      uint32 timeout = T_timeout;
      uint32 retVal = E_NOT_OK;
-     //    uint8 Rx_Buffer[MSG_LEN];
-
      if (txBuffer == NULL)
      {
          return retVal;
      }
 
      /* Uart_AsyncSend transmit data */
-//     Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
      T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
      if (E_OK != T_Uart_Status)
      {
          Uart_Abort(transChannel, UART_SEND);
          return E_NOT_OK;
      }
-
      /* Check for no on-going transmission */
      do
      {
@@ -138,7 +123,6 @@
 
      if ((UART_STATUS_NO_ERROR != Uart_TransmitStatus))
      {
-         //Uart_Abort(transChannel, UART_SEND);
          retVal = E_NOT_OK;
      }
      else
@@ -226,7 +210,7 @@
 //     	temp = DMA_SIZE - (uint32_t)IP_DMA->TCD->CITER.ELINKNO;
 //     	/*Add the remaining data size to the sum of the received size*/
 //     	bufferIdx[hwInstance] += temp;
-         /*Abort the receiving after detecting IDLE receiving*/
+        /*Abort the receiving after detecting IDLE receiving*/
      	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
      	Lpuart_Uart_Ip_AbortSendingData(hwInstance);
  //    	bufferIdx = 0;
@@ -274,7 +258,6 @@
      PduInfo.swPduHandle = swPduHandle;
      PduInfo.length = length;
      PduInfo.sdu = sdu;
-
      return PduInfo;
  }
  Std_ReturnType CanIf_SendMessage(uint8 ControllerId, Can_Msg_Type CanMsg)
@@ -367,7 +350,8 @@
 
  void Notification_0(void)
  {
-     VarNotification_0++;
+	 ADC_Converter(ResultBuffer,ConvertedBuffer);
+	 memcpy(BattTempR,&ConvertedBuffer[3],4*sizeof(uint32));
  }
 
  void Notification_1(void)
@@ -375,8 +359,6 @@
      VarNotification_1++;
  }
 
-
-
  Std_ReturnType  ADC_Converter(Adc_ValueGroupType* Buffer, TP_Value_Type* ConvertedValueR)
  {
 	 Adc_ValueGroupType REFH,REFL;
@@ -384,64 +366,50 @@
 	 REFL = Buffer[2];
 	 for(int i = 3; i < NUM_RESULTS; i++)
 	 {
-		 ConvertedValueR[i] = (TP_Value_Type)((float)(10000 * Buffer[i]/(float)(REFH - REFL))/(1-(float)(Buffer[i]/(float)(REFH - REFL))));
+		if(Buffer[i] >= REFH)
+		{
+		 ConvertedValueR[i] = 40930000;
+		}
+		else if(Buffer[i] <=REFL)
+		{
+			ConvertedValueR[i] = 0x00;
+		}
+		else
+		{
+		 ConvertedValueR[i] = (TP_Value_Type)((float)(10000 * (Buffer[i] - REFL)/(float)(REFH - REFL))/(1-(float)((Buffer[i]- REFL)/(float)(REFH - REFL))));
+		}
 	 }
  }
 
- Std_ReturnType  ADC_ReadValue(ADC_TP_Channel_Type channel, TP_Value_Type* value)
+ Std_ReturnType  ADC_ReadValue()
  {
 	 Std_ReturnType ret = E_NOT_OK;
-
-	 Adc_ValueGroupType    ResultBuffer[NUM_RESULTS];
 	 Adc_ValueGroupType    AdcReadGroupBuffer[NUM_RESULTS];
-
-	 TP_Value_Type    ConvertedBuffer[NUM_RESULTS];
 	 volatile Std_ReturnType Status = TRUE;
-
 	 for(int i = 0; i<NUM_RESULTS; i++)
 	 {
 		 ResultBuffer[i] = 0xFFFF;
 		 AdcReadGroupBuffer[i] = 0xFFFE;
 		 ConvertedBuffer[i] = 0x00;
 	 }
-
 	 Adc_SetupResultBuffer(AdcGroupSoftwareOneShot, ResultBuffer);
 	 Adc_EnableGroupNotification(AdcGroupSoftwareOneShot);
 	 VarNotification_0 = 0;
 	 Adc_StartGroupConversion(AdcGroupSoftwareOneShot);
-
-	 while(VarNotification_0 == 0)
-	 {}
-	 Status = Adc_ReadGroup(AdcGroupSoftwareOneShot, AdcReadGroupBuffer);
-	 if(Status == E_NOT_OK)
-	 {
-		 return Status;
-	 }
-	 else
-	 {
-		 ret = E_OK;
-	 }
-
-	 ADC_Converter(ResultBuffer,ConvertedBuffer);
-	 switch(channel)
-	 {
-		 case SystemTPChannel:
-			 *value = ConvertedBuffer[3];
-			 break;
-		 case SlowChargeTPChannel:
-			 *value = ConvertedBuffer[4];
-			 break;
-		 case QuickChargeTPChannel:
-			 *value = ConvertedBuffer[5];
-			 break;
-		 case CC1TPChannel:
-			 *value = ConvertedBuffer[6];
-			 break;
-		 default:
-			 *value = 0xFFF;
-			 Status = E_NOT_OK;
-			 break;
-	 }
+//	 uint32 TimeOut = 0;
+//	 while(VarNotification_0 == 0 && VarNotification_1==0 && TimeOut<0xFFFF)
+//	 {
+//		 TimeOut++;
+//	 }
+//	 AdcStates = Adc_ReadGroup(AdcGroupSoftwareOneShot, AdcReadGroupBuffer);
+//	 if(AdcStates == E_NOT_OK)
+//	 {
+//		 return AdcStates;
+//	 }
+//	 else
+//	 {
+//		 ret = E_OK;
+//	 }
 	 return ret;
  }
 
@@ -531,15 +499,11 @@
      u32FlexNvmPartSize = (uint32)( (u32RegSimFcfg1 & SIM_FCFG1_DEPART_MASK) >> SIM_FCFG1_DEPART_SHIFT );
      if (u32FlexNvmPartSize == 0xF) /* We just partition again if curent size different with expected */
      {
-
          /* partition for EERAM 64K with NOT loading EERAM at reset in hardware */
          TestEep_FlexNvmProgramPartCmd(EEP_FTFC_KEY_SIZE_0_BYTES, EEP_FTFC_VERIFY_ONLY_DISABLED, \
                                                 EEP_FTFC_LOAD_AT_RESET_ENABLED, EEP_FTFC_EERAM_SIZE_4K, T_EEP_SIZE);
      }
-
  }
-
-
  /* Erase memory by writing erase value */
  Std_ReturnType HAL_EEP_Erase(uint32 eepEraseStartAddr,uint32 eepEraseSize)
  {
@@ -615,9 +579,6 @@
      return E_OK;
  }
 
-
-
-
  /* Compares a eeprom memory area with an application data buffer */
  Std_ReturnType HAL_EEP_Compare(uint32 eepCompareStartAddr,uint8* pDataNeedtoCompare,uint32 dataSize)
  {

+ 4 - 1
src/hal_adapter.h

@@ -39,6 +39,9 @@
  #include "Adc.h"
  #include "Eep.h"
  #include "SL_Sc7a20_Driver.h"
+#define CAN0 0
+#define CAN1 1
+
 #ifndef min
 #define min(A,B) ((A) <= (B) ? (A) : (B))
 #endif
@@ -73,7 +76,7 @@
  }ADC_TP_Channel_Type;
 
  typedef uint32 TP_Value_Type;
- Std_ReturnType  ADC_ReadValue(ADC_TP_Channel_Type channel, TP_Value_Type* value);
+ Std_ReturnType  ADC_ReadValue(void);
 // extern uint8 GpsBufferGet[GPSBUFFER_SIZE];
  Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, const uint8 *txBuffer, uint32 sendLength, uint8 *rxBuffer, uint16 *rxlen,uint32 T_timeout);
  Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout);

+ 2 - 7
src/main.c

@@ -117,7 +117,7 @@ int main(void)
 #endif /* ADC_PRECOMPILE_SUPPORT == STD_ON */
 
     /* Partition only if it was not partitioned before for EERAM with code 0x4 */
-    Eep_DepartParitition(T_EEEPROM_SIZE);
+//    Eep_DepartParitition(T_EEEPROM_SIZE);
     /* Initialize Eep driver */
 #if defined (EEP_PRECOMPILE_SUPPORT)
     Eep_Init(NULL_PTR);
@@ -131,12 +131,7 @@ int main(void)
 	{
 		// if so, the adc is failed to Calibrate;
 	}
-	TP_Value_Type value = 0;
-	for (ADC_TP_Channel_Type channel = 0; channel < ChannelCounter; channel++)
-	{
-		ADC_ReadValue(channel, &value);
-	}
-
+	ADC_ReadValue();
 	Boot_CheckDownlaodAPPStatus();
 
 	Spi_Init(NULL_PTR);