Browse Source

【V3.0.0.14】 在13的基础上优化了串口控制判断函数,增加了函数注释,以及格式化文档,增加了故障存储,以及加热强制控制转移至bcu

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
feeeb30140

+ 121 - 117
inc/AppConfig.h

@@ -1,159 +1,163 @@
-/****************************************************************************
- *
- * Copy right:   2021-, Copyrigths of RLWL Ltd.Chen J
- * File name:    AppConfig.h
- * Description:  App Config H file 配置文件,可以针对不同参数进行更改
- * History:      Rev3.0   2021-07-06
- *
- ****************************************************************************/
-#ifndef  APPCONFIG_H
-#define  APPCONFIG_H
-#define BMS_MANUFACTURE             (2)                 //BMS制造商表示1-超力源,2-美顺
-#define BMS_INFO                    (3)                 //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺4830,2-2表示美顺6060 2-3表示美顺7250
-#define DATA_MODULE_TYPE            (1)                 //1表示NB模块,2表示4G cat1
-#define EOLSTATE                    (0)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
-#define DEFAULT_SN                  "RRRRRR0000000003" //默认上传的SN编码
-#define	APPSWVERSION		        0x0300000D          //数据模块软件版本号
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 09:27:15
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 15:56:31
+ * @Description  : App Config H file 配置文件,可以针对不同参数进行更改
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppConfig.h
+ */
 
-#define TCP_ADD                     "iotp.fast-fun.cn"  //数据上传的地址
-#define TCP_PORT					8712                //数据上传的端口
+#ifndef APPCONFIG_H
+#define APPCONFIG_H
+#define BMS_MANUFACTURE (2)           //BMS制造商表示1-超力源,2-美顺
+#define BMS_INFO (3)                  //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺4830,2-2表示美顺6060 2-3表示美顺7250
+#define DATA_MODULE_TYPE (1)          //1表示NB模块,2表示4G cat1
+#define EOLSTATE (0)                  //1表示下线检测跳过,使用默认值,0表示使用下线检测
+#define DEFAULT_SN "RRRRRR0000000003" //默认上传的SN编码
+#define APPSWVERSION 0x0300000E       //数据模块软件版本号
 
-#define NB_OTHER_TEMP_NUM           (4)                 //NB采集的温度个数
-#define HWVERSION		            0x0102              //硬件主版本,现为V1.2板
-#define	BLSWVERSION		            0x01020000          //BootLoader版本号V1.2.0.0
-#define	DRVSWVERSION		        0x01050000          //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
+#define TCP_ADD "iotp.fast-fun.cn" //数据上传的地址
+#define TCP_PORT 8712              //数据上传的端口
 
-#define APP_CONFIG_FILE_NAME                "qxappconfig.nvm"
-#define APP_DATAINFO_FILE_NAME              "qxappDataInfo3.nvm"
-#define BCU_DATAINFO_FILE_NAME              "qxBcuDataInfo.nvm"
-#define BATT_SN_LEN                17
-#define BMS_OTHER_TEMP              2
-#define WORK_TIME               5
-#define SLEEP_TIME              60
-#define ErrorNumLength          20
-#define BATT_IDLE_SYM           0x00    //静置
-#define BATT_CHARGE_SYM 		0x02    //充电
-#define BATT_DISCHARGE_SYM      0x01    //放电
-#define BATT_MOVE_SYM	        0x01    //移动
-#define BATT_NO_MOVE_SYM 		0x00    //静止
+#define NB_OTHER_TEMP_NUM (4)   //NB采集的温度个数
+#define HWVERSION 0x0102        //硬件主版本,现为V1.2板
+#define BLSWVERSION 0x01020000  //BootLoader版本号V1.2.0.0
+#define DRVSWVERSION 0x01050000 //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 
-#define TCP_START_SYM1			0x23
-#define TCP_START_SYM2			0x23
-#define TCP_CMD_SYM				0x02	//实时信息上报是0x02
-#define TCP_HEART_SYM           0x07    //心跳包标志
-#define TCP_ANS_SYM 			0xFE
+#define APP_CONFIG_FILE_NAME "qxappconfig.nvm"
+#define APP_DATAINFO_FILE_NAME "qxappDataInfo3.nvm"
+#define BCU_DATAINFO_FILE_NAME "qxBcuDataInfo.nvm"
+#define BATT_SN_LEN 17
+#define BMS_OTHER_TEMP 2
+#define WORK_TIME 5
+#define SLEEP_TIME 60
+#define ErrorNumLength 20
+#define BATT_IDLE_SYM 0x00      //静置
+#define BATT_CHARGE_SYM 0x02    //充电
+#define BATT_DISCHARGE_SYM 0x01 //放电
+#define BATT_MOVE_SYM 0x01      //移动
+#define BATT_NO_MOVE_SYM 0x00   //静止
+
+#define TCP_START_SYM1 0x23
+#define TCP_START_SYM2 0x23
+#define TCP_CMD_SYM 0x02   //实时信息上报是0x02
+#define TCP_HEART_SYM 0x07 //心跳包标志
+#define TCP_ANS_SYM 0xFE
 /*-------以下为下行指令定义区----------*/
-#define TCP_QUERY_SYM				0x80
-#define TCP_SETCMD_SYM				0x81
-#define TCP_CONCMD_SYM				0x82
+#define TCP_QUERY_SYM 0x80
+#define TCP_SETCMD_SYM 0x81
+#define TCP_CONCMD_SYM 0x82
 /*----------------end----------------*/
 
 //encrypt methord
-#define TCP_ENCPT_ENABLE		0x00
-#define TCP_ENCPT_DISABLE		0x01
+#define TCP_ENCPT_ENABLE 0x00
+#define TCP_ENCPT_DISABLE 0x01
 
 //message type mark 0x02上报数据单元定义区
-#define BATTMSG				0x80
-#define GPSMSG				0x82
-#define STATESMSG			0x85
-#define VERSIONMSG			0x86
-#define DEBUGMSG			0x8C
+#define BATTMSG 0x80
+#define GPSMSG 0x82
+#define STATESMSG 0x85
+#define VERSIONMSG 0x86
+#define DEBUGMSG 0x8C
 
 //BMS升级区定义
-#define FLASH_BMS_FOTA_START_ADDR         0x2E6000          //BMS升级文件存储起始地址
-#define FLASH_BMS_FOTA_LEN                0x32000           //BMS升级文件存储长度 = =200k
-#define FLASH_BMS_FOTA_END_ADDR           0x318000          //BMS升级文件存储结束地址
+#define FLASH_BMS_FOTA_START_ADDR 0x2E6000 //BMS升级文件存储起始地址
+#define FLASH_BMS_FOTA_LEN 0x32000         //BMS升级文件存储长度 = =200k
+#define FLASH_BMS_FOTA_END_ADDR 0x318000   //BMS升级文件存储结束地址
 //declear struct vars   结构体变量定义
-typedef struct _AppConfigDataType//该结构体只允许下线检测写入
-{	
-    BOOL   appDataModify;		//数据更改标志位
-	UINT8  battSN[BATT_SN_LEN]; //电池SN号码
-   	BOOL   isBattLocked;		//0:not locked;	1:locked  //暂时取消没有使用
-    UINT8  reserved1;     //
-    UINT8  reserved2;       //电池温度个数
-    UINT8  reserved3;       //电池电压串数
-    UINT8  reserved4;
-    UINT8  reserved5;
+typedef struct _AppConfigDataType //该结构体只允许下线检测写入
+{
+    BOOL appDataModify;        //数据更改标志位
+    UINT8 battSN[BATT_SN_LEN]; //电池SN号码
+    BOOL isBattLocked;         //0:not locked;	1:locked  //暂时取消没有使用
+    UINT8 reserved1;           //
+    UINT8 reserved2;           //电池温度个数
+    UINT8 reserved3;           //电池电压串数
+    UINT8 reserved4;
+    UINT8 reserved5;
     UINT32 reserved6;
     UINT32 reserved7;
-    UINT32 reserved8;        //APP软件版本
-	UINT8  EOLState;
-}AppConfigDataType;
+    UINT32 reserved8; //APP软件版本
+    UINT8 EOLState;
+} AppConfigDataType;
 
 typedef struct _AppConfigDataHeader
 {
     UINT16 fileBodySize; //file body size, not include size of header;
-    UINT8  checkSum;
-}AppConfigDataHeader;
+    UINT8 checkSum;
+} AppConfigDataHeader;
 
 typedef struct _AppDataType
-{	
-    BOOL   appDataModify;		        //数据更改标志位
-    UINT8  BattCellCount;               //电池模组个数
-    UINT8  BattTempCount;               //电池温度个数
-    UINT8  BattInfoSendFreqHigh;        //电池信息发送间隔高频,单位s
-    UINT8  BattInfoSendFreqNomal;       //电池信息发送间隔正常,单位s     
-    UINT8  BattInfoSendFreqLow;         //电池信息发送间隔低频,单位s
-    UINT8  PosInfoSendFreqHigh;         //定位信息发送间隔高频,单位s
-    UINT8  PosInfoSendFreqNormal;       //定位信息发送间隔正常,单位s
-    UINT8  PosInfoSendFreqLow;          //定位信息发送间隔低频,单位s
-    UINT32 AccMileage;                  //累计里程,单位m
-    UINT16 SysReStartCount;             //系统重启次数
-    UINT8  RelayControl;                //继电器控制
-    UINT8  BattForceLock;               //电池强制锁定状态
-    UINT8  BattLock;                    //电池锁定状态
-    UINT8  BattStolenFlag;              //电池被盗状态
-    UINT8  UserLock;                    // 用户锁锁定
-    UINT8  RentalLock;                  //租期锁锁定
-    UINT8  RentalType;                  //租期类型
-    UINT8  ExpiryTimeArray[6];          //超期时间
-    UINT8  ErrorMsg;
-}AppDataBody;
+{
+    BOOL appDataModify;          //数据更改标志位
+    UINT8 BattCellCount;         //电池模组个数
+    UINT8 BattTempCount;         //电池温度个数
+    UINT8 BattInfoSendFreqHigh;  //电池信息发送间隔高频,单位s
+    UINT8 BattInfoSendFreqNomal; //电池信息发送间隔正常,单位s
+    UINT8 BattInfoSendFreqLow;   //电池信息发送间隔低频,单位s
+    UINT8 PosInfoSendFreqHigh;   //定位信息发送间隔高频,单位s
+    UINT8 PosInfoSendFreqNormal; //定位信息发送间隔正常,单位s
+    UINT8 PosInfoSendFreqLow;    //定位信息发送间隔低频,单位s
+    UINT32 AccMileage;           //累计里程,单位m
+    UINT16 SysReStartCount;      //系统重启次数
+    UINT8 RelayControl;          //继电器控制
+    UINT8 BattForceLock;         //电池强制锁定状态
+    UINT8 BattLock;              //电池锁定状态
+    UINT8 BattStolenFlag;        //电池被盗状态
+    UINT8 UserLock;              // 用户锁锁定
+    UINT8 RentalLock;            //租期锁锁定
+    UINT8 RentalType;            //租期类型
+    UINT8 ExpiryTimeArray[6];    //超期时间
+    UINT8 ErrorMsg;
+} AppDataBody;
 typedef struct _AppAlgorithmType
 {
-    BOOL   appDataModify;		        //数据更改标志位
-    UINT32 blcv_Q_totalCpE[28];         //累计均衡容量 读取量 数组最大28
-    UINT16 blcv_Q_reqCpE[28];           //均衡需求容量 读取量 数组最大28
-    UINT16 socd_pct_bcuSocE;            //电池显示SOC 读取量;
-    UINT16 socd_pct_battSocE;           //电池真实SOC 读取量;
-    UINT16 sohd_tm_chrgStartStatE;      //充电前静置时间读取量;
-    BOOL   sohd_flg_chrgEndE;           //充电结束标志位读取量;
-    UINT16 sohv_V_chrgStartStatE[28];   //充电开始时刻的单体电压(数组)读取量;
-    UINT16 sohd_Q_chrgE;                //充入容量读取量;
-    UINT16 sohv_Q_packCapArrE[10];     //10次整包容量(数组)读取量;
-    UINT16 sohv_Q_cellCapArrE[28];     //  
-}AppAlgorithmData;
+    BOOL appDataModify;               //数据更改标志位
+    UINT32 blcv_Q_totalCpE[28];       //累计均衡容量 读取量 数组最大28
+    UINT16 blcv_Q_reqCpE[28];         //均衡需求容量 读取量 数组最大28
+    UINT16 socd_pct_bcuSocE;          //电池显示SOC 读取量;
+    UINT16 socd_pct_battSocE;         //电池真实SOC 读取量;
+    UINT16 sohd_tm_chrgStartStatE;    //充电前静置时间读取量;
+    BOOL sohd_flg_chrgEndE;           //充电结束标志位读取量;
+    UINT16 sohv_V_chrgStartStatE[28]; //充电开始时刻的单体电压(数组)读取量;
+    UINT16 sohd_Q_chrgE;              //充入容量读取量;
+    UINT16 sohv_Q_packCapArrE[10];    //10次整包容量(数组)读取量;
+    UINT16 sohv_Q_cellCapArrE[28];    //
+    BOOL sfmd_flg_mainCirClosFltE;
+    BOOL sfmd_flg_heatCirClosFltE;
+    BOOL sfmd_flg_heatCirOpenFltE;
+} AppAlgorithmData;
 typedef struct _AppDataHeader
 {
     UINT16 fileBodySize; //file body size, not include size of header;
-    UINT8  checkSum;
-}AppDataHeader;
+    UINT8 checkSum;
+} AppDataHeader;
 typedef struct _BCUDataHeader
 {
     UINT16 fileBodySize; //file body size, not include size of header;
-    UINT8  checkSum;
-}BcuDataHeader;
+    UINT8 checkSum;
+} BcuDataHeader;
 typedef struct AppSocketConnectionContext_Tag
 {
     INT32 id;
     INT32 status;
-}AppSocketConnectionContext;
+} AppSocketConnectionContext;
 
 typedef enum
 {
     IDLE = 0,
     WORK,
     LISTEN
-}process_app;
+} process_app;
 typedef struct _GPSInfo
 {
-	UINT8	locateMark;
-	UINT8	satelliteNum;
-	UINT8	direction[2];
-	UINT8	speed[2];
-	UINT8	altitude[2];
-	UINT8	latitude[4];
-	UINT8	longitude[4];
-	UINT8   AccMileage[4];
-}GPSInfo;
+    UINT8 locateMark;
+    UINT8 satelliteNum;
+    UINT8 direction[2];
+    UINT8 speed[2];
+    UINT8 altitude[2];
+    UINT8 latitude[4];
+    UINT8 longitude[4];
+    UINT8 AccMileage[4];
+} GPSInfo;
 #endif

+ 49 - 47
inc/AppSignal.h

@@ -1,11 +1,11 @@
-/****************************************************************************
- *
- * Copy right:   2021-, Copyrigths of RLWL Ltd.
- * File name:    Signal.h
- * Description:  Global variable definition H file
- * History:      Rev3.0   2021-07-06
- *
- ****************************************************************************/
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 09:27:15
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 13:54:12
+ * @Description  : Global variable definition H file
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
+ */
 #include "commontypedef.h"
 #include "cmsis_os2.h"
 #include "AppConfig.h"
@@ -22,25 +22,24 @@ extern UINT32 ErrFlg;
 extern BOOL downloadReady;
 
 //extern declear the UINT8 vars
-extern UINT8    AvgBattTemp;
 extern UINT8	battCellTemp[8];
-extern UINT8	MOSTemp;
-extern UINT8	packTemp;
+extern UINT8	battHeatEnableState;
+extern UINT8	battMOSSwitchState;
+extern UINT8	battSOC;
+extern UINT8	battSOH;
+extern UINT8	battWorkState;
+extern UINT8	bmsHwVersion;
+extern UINT8	bmsSwVersion;
 extern UINT8	fastChargeTemp;
-extern UINT8	normalChargeTemp;
 extern UINT8	heatTemp1;
 extern UINT8	heatTemp2;
-extern UINT8	nbReservedTemp1;
-extern UINT8	nbReservedTemp2;
 extern UINT8	maxCellTemp;
 extern UINT8	minCellTemp;
-extern UINT8	battSOC;
-extern UINT8	battSOH;
-extern UINT8	battWorkState;
-extern UINT8	bmsSwVersion;
-extern UINT8	bmsHwVersion;
-extern UINT8	battMOSSwitchState;
-extern UINT8	battHeatEnableState;
+extern UINT8	MOSTemp;
+extern UINT8	nbReservedTemp1;
+extern UINT8	nbReservedTemp2;
+extern UINT8	normalChargeTemp;
+extern UINT8	packTemp;
 extern UINT8	reservedSignal1;
 extern UINT8	reservedSignal2;
 extern UINT8	reservedSignal3;
@@ -49,56 +48,59 @@ extern UINT8	reservedSignal5;
 extern UINT8	reservedSignal6;
 extern UINT8	reservedSignal7;
 extern UINT8	reservedSignal8;
-extern UINT8    Lockstatus;
-extern UINT8    TcpErrorcount;
-extern UINT8    TCPWorkState;
-extern UINT8    TcpSendLen;
-extern UINT8    CanMsgEnble;
-extern UINT8 	UDSSwitch;
-extern UINT8 	UDSSwitch ;
-extern UINT8 	PosFlag ;     
-extern UINT8    UartRecvFlag ;
-extern UINT8    UartErrorFlag ;
-extern UINT8    UartCmdRecvFlag;
 extern UINT8	UDSService[2];           //uds 服务
 extern UINT8	UDSSubService[2];       // uds 子服务
 extern UINT8	UDSSubServiceActionCode[2];  // uds 子服务状态
-extern UINT8    GpsFlag;
-extern UINT8    BuzzerControl;
+extern UINT8 	PosFlag ;     
+extern UINT8 	UDSSwitch ;
+extern UINT8 	UDSSwitch;
+extern UINT8    AvgBattTemp;
 extern UINT8    BattWorkStateDelay;
+extern UINT8    BMSupdatestatus;
+extern UINT8    BuzzerControl;
+extern UINT8    CanMsgEnble;
+extern UINT8    ChargeForbiddenControl ;
+extern UINT8    chargerConnectState;
+extern UINT8    DisChargeForbiddenControl ;
+extern UINT8    GpsFlag;
 extern UINT8    HeatForceControl;  
+extern UINT8    Lockstatus;
 extern UINT8    PadInterrupt ;
-extern UINT8    chargerConnectState;
-extern UINT8    BMSupdatestatus;
-
+extern UINT8    RelayForbiddenControl ;
+extern UINT8    TcpErrorcount;
+extern UINT8    TcpSendLen;
+extern UINT8    TCPWorkState;
+extern UINT8    UartCmdRecvFlag;
+extern UINT8    UartErrorFlag ;
+extern UINT8    UartRecvFlag ;
 //declear the UINT16 vars
 extern UINT16	battCellU[28];
-extern UINT16	minCellVol;
-extern UINT16	maxCellVol;
-extern UINT16   avrgCellVol;
-extern UINT16	battPackVol;
 extern UINT16	battI;
+extern UINT16	battPackVol;
+extern UINT16	maxCellVol;
+extern UINT16	minCellVol;
 extern UINT16	nbHwVersion;
+extern UINT16   avrgCellVol;
 extern UINT16   ErrorNum[ErrorNumLength];
 extern UINT16   updateDifferDataPackageCounter;
 
 
 //declear the UINT32 vars
-extern UINT32	battWarningState;
+extern UINT32	battBalanceoInfo;
 extern UINT32	battProtectState;
+extern UINT32	battWarningState;
 extern UINT32	nbSwVersion ;
-extern UINT32	battBalanceoInfo;
 extern UINT32   Battdesigncap;
 extern UINT32   PowerVoltage;
 extern volatile UINT32  TimeCounter;
 
 
 //declear other vars
-extern osMutexId_t Error_Mutex;
-extern QueueHandle_t GpsRecvHandle;
-extern QueueHandle_t UartWriteCmdHandle;
+extern AppAlgorithmData   BcuDataInfo;
 extern AppConfigDataType AppNVMData;
 extern AppDataBody AppDataInfo;
-extern AppAlgorithmData   BcuDataInfo;
 extern AppSocketConnectionContext socContext;  //网络连接状态
+extern osMutexId_t Error_Mutex;
 extern process_app 		    gProcess_app;
+extern QueueHandle_t GpsRecvHandle;
+extern QueueHandle_t UartWriteCmdHandle;

+ 5 - 2
inc/EmbeddedCoder_inc/BCUCal.h

@@ -15,7 +15,8 @@ extern const uint16_T cmnm_R_ohm[13];       /* 电池放电参数的Ro数组;
 extern const uint16_T cmnm_R_polar[13];       /* 电池放电参数的Rp数组; */
 extern const uint16_T cmnm_V_ocv[13];       /* 电池放电参数的OCV数组; */
 extern const uint16_T cmnm_pct_soc[13];                         /* 电池放电参数的SOC数组; */
-  
+extern const uint16_T cmnc_V_chrgFulV;                     /* 充满电的截至电压; */
+
 extern const int16_T sfmc_I_chrgCurrOverThr;                 /* 充电电流阈值 */
 extern const int16_T sfmc_I_disChrgCurrOverThr;              /* 放电电流阈值 */
 extern const int16_T sfmc_T_ACPlugTOverThrFlt1;              /* 慢充插头温度过高1级故障诊断阈值 */
@@ -79,8 +80,10 @@ extern const uint16_T sfmc_T_disChrgMosTOverThrRec1;
 extern const uint16_T sfmc_T_disChrgMosTOverThrFlt2;
 extern const uint16_T sfmc_T_disChrgMosTOverThrRec2;
 
+extern const uint16_T sohc_Q_countThr;                       /*                    */
+extern const uint16_T sohc_Q_updateDeltThr;                 /*                    */
+
 
-extern const uint16_T socc_V_chrgFulV;                     /* 充满电的截至电压; */
 extern const uint16_T socc_pct_battSocLow;                    /* SOC下限值; */
 extern const uint16_T socc_pct_battSocUp;                  /* SOC上限值; */
 extern const int16_T socm_I_chrgCor[4];   /* 充电CCV对应的电流数据; */

+ 12 - 5
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -2,15 +2,16 @@
 #include "rtwtypes.h"
 
 extern uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
-extern uint16_T appv_V_cellU[28];
-extern boolean_T ihd_flg_HVILFlt;
+extern uint16_T appv_V_cellU[28];                        /* 静态电压 */
+extern boolean_T ihd_flg_HVILFlt;                        /* 保护板上传的高压互锁故障 */
 extern uint16_T blcv_Q_reqCpEi[28];                      /*均衡需求容量 读取量(数组); */
 extern uint16_T blcv_Q_reqCpEo[28];                      /*均衡需求容量 写入量(数组); */
 extern uint32_T blcv_Q_totalCpEi[28];                    /*累计均衡容量 读取量(数组); */
 extern uint32_T blcv_Q_totalCpEo[28];                    /*累计均衡容量 写入量(数组); */
-extern boolean_T blcv_flg_excute[28];                    /*均衡执行请求标志位 (数组) */
+extern boolean_T blcv_flg_excute[28];                    /*均衡执行请求标志位 (数组) */
 
-extern uint8_T ihd_st_authFaild; 
+extern boolean_T ihd_flg_DTCClear;                       /* 上位机发送的故障清楚指令;*/
+extern uint8_T ihd_st_authFaild;                         /* 底层诊断的认证失败故障;*/
 extern int16_T ihd_I_curr;                               /*电池包电流; */
 extern uint8_T ihd_st_chrgConnect;                       /*充电器连接状态; */
 extern uint16_T ihd_P_gas;                               /*气体浓度 */
@@ -59,7 +60,13 @@ extern uint8_T sfmd_st_fltLevel;                         /*故障等级 */
 extern uint16_T sfmv_T_modT[6];                          /*处理后模组温度 */
 extern uint16_T sfmv_V_cellU[28];                        /*处理后单体电压 */
 extern uint16_T sfmv_idx_fltCode[20];                    /*诊断故障码(数组) */
-extern uint16_T sfmd_V_battU;   
+extern uint16_T sfmd_V_battU;                            /* 处理过后的总电压 */
+extern boolean_T sfmd_flg_mainCirClosFltEi;              /*主回路常闭故障读取量 */  
+extern boolean_T sfmd_flg_mainCirClosFltEo;              /*主回路常闭故障写入量 */  
+extern boolean_T sfmd_flg_heatCirClosFltEi;              /*加热回路常闭故障读取量 */  
+extern boolean_T sfmd_flg_heatCirClosFltEo;              /*加热回路常闭故障写入量 */  
+extern boolean_T sfmd_flg_heatCirOpenFltEi;              /*加热回路常开故障读取量 */  
+extern boolean_T sfmd_flg_heatCirOpenFltEo;              /*加热回路常开故障写入量 */  
 
 extern uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 extern uint16_T socd_pct_estSoc;                         /*估算SOC;*/

+ 30 - 14
inc/EmbeddedCoder_inc/SFM.h

@@ -78,20 +78,36 @@ typedef struct {
 }DiagThrstruct;
 
 typedef struct {
-    uint8_T N151;
-    uint8_T N152;
-    uint8_T N153;
-    uint8_T N154;
-    uint8_T N155;
-    uint8_T N156;
-    uint8_T N157;
-    uint8_T N158;
-    uint8_T N159;
-    uint8_T N160;
-    uint8_T N161;
-    uint8_T N162;
-}DiagMisstruct;
+	uint16_T N22;
+	uint16_T N24;
+	uint16_T N32;
+	uint16_T N33;
+	uint16_T N34;
+	uint16_T N54;
+	uint16_T N56;
+	uint16_T N57;
+	uint16_T N58;
+	uint16_T N59;
+	uint16_T N62;
+	uint16_T N64;
+	uint16_T N65;
+	uint16_T N66;
+	uint16_T N67;
+    uint16_T N151;
+    uint16_T N152;
+    uint16_T N153;
+    uint16_T N154;
+    uint16_T N155;
+    uint16_T N156;
+    uint16_T N157;
+    uint16_T N158;
+    uint16_T N159;
+    uint16_T N160;
+    uint16_T N161;
+    uint16_T N162;
+	uint16_T N179;
+}DiagTimestruct;
 
 extern boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input,uint16_T fltThr,uint16_T recThr,uint16_T fltNumThr,uint16_T recNumThr,uint8_T *fltNum,uint8_T *recNum,boolean_T *fitFlg);
 extern boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input,uint16_T fltThr,uint16_T recThr,uint16_T fltNumThr,uint16_T recNumThr,uint8_T *fltNum,uint8_T *recNum,boolean_T *fitFlg);
-extern boolean_T MisMatich(boolean_T x, boolean_T y, uint8_T *N);
+extern boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr);

+ 1 - 0
inc/EmbeddedCoder_inc/TMS.h

@@ -1,6 +1,7 @@
 #include "rtwtypes.h"
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "AppSignal.h"
 extern boolean_T FirstRun_TMS;
 extern void TMS_Init(void);
 extern void TMS(void);

File diff suppressed because it is too large
+ 452 - 456
src/AppFunc.c


+ 85 - 83
src/AppSignal.c

@@ -1,12 +1,12 @@
-/****************************************************************************
- *
- * Copy right:   2021-, Copyrigths of RLWL Ltd.
- * File name:    AppSignal.c
- * Description:  Global variable definition c file,此文件存放App使用到的全局变量
- * History:      Rev3.0   2021-07-06
- *
- ****************************************************************************/
-
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 09:27:15
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 15:52:41
+ * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
+ */
 #include "AppSignal.h"
 //
 /**declear the bool vars**/
@@ -15,89 +15,91 @@ volatile BOOL BMS_Fota_update_flag = FALSE;
 volatile BOOL CanInterruptFlag = FALSE;
 
 UINT32 ErrFlg = FALSE;
-BOOL downloadReady = FALSE;   
+BOOL downloadReady = FALSE;
 
 /**declear the uint8 vars**/
-UINT8   AvgBattTemp = 0;
-UINT8	battCellTemp[8] = {0};       //Battery temperature 电池温度数值
-UINT8	MOSTemp =0;                 //mos temprature mos温度
-UINT8	packTemp = 0;                //battery pack temprature   电池箱体温度
-UINT8	fastChargeTemp = 0;          // fast charge plug temprature  快充插头温度
-UINT8	normalChargeTemp = 0;        // normal charge plug temprature    慢充插头温度
-UINT8	heatTemp1 = 0;               //Heating plate1 temperature    加热板温度1
-UINT8	heatTemp2 = 0;               //Heating plate2 temperature    加热板温度2
-UINT8	nbReservedTemp1 = 0xFF;         //
-UINT8	nbReservedTemp2 = 0xFF;         //
-UINT8	maxCellTemp = 0xFF;             //最高单体温度
-UINT8	minCellTemp = 0xFF;             //最低单体温度
-UINT8	battSOC = 0xFF;                 //电池SOC
-UINT8	battSOH = 0xFF;                 //电池SOH
-UINT8	battWorkState = 0x00;           //电池工作状态
-UINT8	bmsSwVersion = 0xFF;            //bms软件版本
-UINT8	bmsHwVersion = 0xFF;            //bms硬件版本
-UINT8	battMOSSwitchState = 0x00;      //bms开关状态
-UINT8	battHeatEnableState = 0x00;     //bms加热使能状态
-UINT8	reservedSignal1 = 0xFF;         //can信息保留信号1
-UINT8	reservedSignal2 = 0xFF;         //can信息保留信号2
-UINT8	reservedSignal3 = 0xFF;         //can信息保留信号3
-UINT8	reservedSignal4 = 0xFF;         //can信息保留信号4
-UINT8	reservedSignal5 = 0xFF;         //can信息保留信号5
-UINT8	reservedSignal6 = 0xFF;         //can信息保留信号6
-UINT8	reservedSignal7 = 0xFF;         //can信息保留信号7
-UINT8	reservedSignal8 = 0xFF;         //can信息保留信号8
-UINT8   Lockstatus = 0;             //Interlock status 高压互锁状态
-UINT8   TcpErrorcount=0;            //Error count TCP联网错误计数
-UINT8   TCPWorkState = 0;           //Tcp工作状态,0-表示发送,1-表示应答,2-表示监听以及心跳发送
-UINT8 	TcpSendLen = 0;             //Tcp send status Tcp发送状态
-UINT8   CanMsgEnble = 0;            //Can send status Can中断状态
-UINT8 	UDSSwitch = 0;              //下线检测标志位
-UINT8 	PosFlag = 0;                //定位信息是否有效标志位
-UINT8   UartRecvFlag = 0;           //Uart收到消息标志位0表示未收到,1表示收到
-UINT8   UartErrorFlag = 0;           //Uart故障标志位0表示正常,1表示故障
-UINT8   UartCmdRecvFlag = 0;        //Uart控制应答回复
-UINT8	UDSService[2] = {0};           //uds 服务
-UINT8	UDSSubService[2]  = {0};       // uds 子服务
-UINT8	UDSSubServiceActionCode[2]  = {0};  // uds 子服务状态
-UINT8   GpsFlag = 0;                  //GPS 数据有效标志位
-UINT8   BuzzerControl = 0;          //蜂鸣器控制状态
-UINT8   BattWorkStateDelay = 0;     //电池工作状态(延时处理后的)
-UINT8   HeatForceControl = 0;       //加热强制控制使能
-UINT8   PadInterrupt = 0x00;           //每个bit代表一个中断标志
-UINT8   chargerConnectState = 0x00;
-UINT8   BMSupdatestatus = 0xFF;
+UINT8 AvgBattTemp = 0;
+UINT8 battCellTemp[8] = {0};            //Battery temperature 电池温度数值
+UINT8 battHeatEnableState = 0x00;       //bms加热使能状态
+UINT8 battMOSSwitchState = 0x00;        //bms开关状态
+UINT8 battSOC = 0;                      //电池SOC
+UINT8 battSOH = 0;                      //电池SOH
+UINT8 battWorkState = 0x00;             //电池工作状态
+UINT8 BattWorkStateDelay = 0;           //电池工作状态(延时处理后的)
+UINT8 bmsHwVersion = 0;                 //bms硬件版本
+UINT8 bmsSwVersion = 0;                 //bms软件版本
+UINT8 BMSupdatestatus = 0xFF;           //保护板更新状态 0xFF表示未更新,00表示更新成功,c表示校验不过
+UINT8 BuzzerControl = 0;                //蜂鸣器控制状态
+UINT8 CanMsgEnble = 0;                  //Can send status Can中断状态
+UINT8 ChargeForbiddenControl = 0x00;    //充电禁止控制
+UINT8 chargerConnectState = 0x00;       //充电器连接状态
+UINT8 DisChargeForbiddenControl = 0x00; //放电禁止控制
+UINT8 fastChargeTemp = 0;               // fast charge plug temprature  快充插头温度
+UINT8 GpsFlag = 0;                      //GPS 数据有效标志位
+UINT8 HeatForceControl = 0;             //加热强制控制使能
+UINT8 heatTemp1 = 0;                    //Heating plate1 temperature    加热板温度1
+UINT8 heatTemp2 = 0;                    //Heating plate2 temperature    加热板温度2
+UINT8 Lockstatus = 0;                   //Interlock status 高压互锁状态
+UINT8 maxCellTemp = 0;                  //最高单体温度
+UINT8 minCellTemp = 0;                  //最低单体温度
+UINT8 MOSTemp = 0;                      //mos temprature mos温度
+UINT8 nbReservedTemp1 = 0;              //
+UINT8 nbReservedTemp2 = 0;              //
+UINT8 normalChargeTemp = 0;             // normal charge plug temprature    慢充插头温度
+UINT8 packTemp = 0;                     //battery pack temprature   电池箱体温度
+UINT8 PadInterrupt = 0x00;              //每个bit代表一个中断标志
+UINT8 PosFlag = 0;                      //定位信息是否有效标志位
+UINT8 RelayForbiddenControl = 0x00;     //继电器禁止控制
+UINT8 reservedSignal1 = 0;              //can信息保留信号1
+UINT8 reservedSignal2 = 0;              //can信息保留信号2
+UINT8 reservedSignal3 = 0;              //can信息保留信号3
+UINT8 reservedSignal4 = 0;              //can信息保留信号4
+UINT8 reservedSignal5 = 0;              //can信息保留信号5
+UINT8 reservedSignal6 = 0;              //can信息保留信号6
+UINT8 reservedSignal7 = 0;              //can信息保留信号7
+UINT8 reservedSignal8 = 0;              //can信息保留信号8
+UINT8 TcpErrorcount = 0;                //Error count TCP联网错误计数
+UINT8 TcpSendLen = 0;                   //Tcp send status Tcp发送状态
+UINT8 TCPWorkState = 0;                 //Tcp工作状态,0-表示发送,1-表示应答,2-表示监听以及心跳发送
+UINT8 UartCmdRecvFlag = 0;              //Uart控制应答回复
+UINT8 UartErrorFlag = 0;                //Uart故障标志位0表示正常,1表示故障
+UINT8 UartRecvFlag = 0;                 //Uart收到消息标志位0表示未收到,1表示收到
+UINT8 UDSService[2] = {0};              //uds 服务
+UINT8 UDSSubService[2] = {0};           // uds 子服务
+UINT8 UDSSubServiceActionCode[2] = {0}; // uds 子服务状态
+UINT8 UDSSwitch = 0;                    //下线检测标志位
 
 /**declear the uint16 vars**/
-UINT16	battCellU[28] = {0xFFFF};    //电池包单体电压
-UINT16	minCellVol = 0xFFFF;    //最小单体电压
-UINT16	maxCellVol = 0xFFFF;    //最大单体电压
-UINT16  avrgCellVol = 0xFFFF;   //平均单体电压 
-UINT16	battPackVol = 0xFFFF;   //电池总压
-UINT16	battI = 0xFFFF;         //电池总电流
-UINT16	nbHwVersion = 0xFFFF;   //数据模块硬件状态
-UINT16  ErrorNum[ErrorNumLength]={0};        //Error array,故障数组
-UINT16  updateDifferDataPackageCounter = 0;  //差分包升级计数器
-
+UINT16 avrgCellVol = 0;                    //平均单体电压
+UINT16 battCellU[28] = {0};                //电池包单体电压
+UINT16 battI = 0;                          //电池总电流
+UINT16 battPackVol = 0;                    //电池总压
+UINT16 ErrorNum[ErrorNumLength] = {0};     //Error array,故障数组
+UINT16 maxCellVol = 0;                     //最大单体电压
+UINT16 minCellVol = 0;                     //最小单体电压
+UINT16 nbHwVersion = 0;                    //数据模块硬件状态
+UINT16 updateDifferDataPackageCounter = 0; //差分包升级计数器
 
 /**declear the uint32 vars**/
-UINT32	battWarningState = 0;  //电池告警状态
-UINT32	battProtectState = 0;  //电池保护状态
-UINT32	nbSwVersion = 0;       // 数据模块软件状态
-UINT32	battBalanceoInfo = 0;  //电池均衡状态
-UINT32  Battdesigncap =0xFFFFFFFF;      //battery design cap 电池包设计容量
-volatile UINT32  TimeCounter = 0x00;             //主任务定时器计数
-UINT32  PowerVoltage = 0;
+UINT32 battBalanceoInfo = 0; //电池均衡状态
+UINT32 Battdesigncap = 0;    //battery design cap 电池包设计容量
+UINT32 battProtectState = 0; //电池保护状态
+UINT32 battWarningState = 0; //电池告警状态
+UINT32 nbSwVersion = 0;      // 数据模块软件状态
+UINT32 PowerVoltage = 0;
+volatile UINT32 TimeCounter = 0x00; //主任务定时器计数
 
 /**declear the Handle vars**/
-osMutexId_t Error_Mutex = NULL;         //故障互锁句柄
-QueueHandle_t GpsRecvHandle = NULL;     //定位信息队列句柄
-QueueHandle_t UartWriteCmdHandle = NULL;//Uart写命令队列句柄
+osMutexId_t Error_Mutex = NULL;          //故障互锁句柄
+QueueHandle_t GpsRecvHandle = NULL;      //定位信息队列句柄
+QueueHandle_t UartWriteCmdHandle = NULL; //Uart写命令队列句柄
 
-/**declear other vars**/   
+/**declear other vars**/
 
-AppConfigDataType           AppNVMData;
-AppDataBody                 AppDataInfo;
-AppAlgorithmData            BcuDataInfo;
+AppConfigDataType AppNVMData;
+AppDataBody AppDataInfo;
+AppAlgorithmData BcuDataInfo;
 
-AppSocketConnectionContext  socContext = {-1,0};  //网络连接状态
+AppSocketConnectionContext socContext = {-1, 0}; //网络连接状态
 
-process_app 		        gProcess_app; //全局工作状态
+process_app gProcess_app; //全局工作状态

+ 137 - 143
src/AppTaskCan.c

@@ -10,180 +10,174 @@
 
 static void CanTask(void);
 
-
 static StaticTask_t gProcess_Can_Rx_Task_t;
-static UINT8 		gProcess_Can_Rx_TaskStack[PROC_CAN_RX_TASK_STACK_SIZE];
-static process_CAN	gProcess_CAN_Task = PROCESS_CAN_STATE_IDLE;
-#define 			PROC_CAN_STATE_SWITCH(a)  (gProcess_CAN_Task = a)
+static UINT8 gProcess_Can_Rx_TaskStack[PROC_CAN_RX_TASK_STACK_SIZE];
+static process_CAN gProcess_CAN_Task = PROCESS_CAN_STATE_IDLE;
+#define PROC_CAN_STATE_SWITCH(a) (gProcess_CAN_Task = a)
 
-void AppTaskCanInit(void* arg)
+void AppTaskCanInit(void *arg)
 {
-    osThreadAttr_t task_rx_attr;
-    memset(&task_rx_attr,0,sizeof(task_rx_attr));
-    memset(gProcess_Can_Rx_TaskStack, 0, PROC_CAN_RX_TASK_STACK_SIZE);
-    task_rx_attr.name = "Can_Task";
-    task_rx_attr.stack_mem = gProcess_Can_Rx_TaskStack;
-    task_rx_attr.stack_size = PROC_CAN_RX_TASK_STACK_SIZE;
-    task_rx_attr.priority = osPriorityBelowNormal7;
-    task_rx_attr.cb_mem = &gProcess_Can_Rx_Task_t;
-    task_rx_attr.cb_size = sizeof(StaticTask_t);
-    osDelay(1000);
-    osThreadNew(CanTask, NULL, &task_rx_attr);
+	osThreadAttr_t task_rx_attr;
+	memset(&task_rx_attr, 0, sizeof(task_rx_attr));
+	memset(gProcess_Can_Rx_TaskStack, 0, PROC_CAN_RX_TASK_STACK_SIZE);
+	task_rx_attr.name = "Can_Task";
+	task_rx_attr.stack_mem = gProcess_Can_Rx_TaskStack;
+	task_rx_attr.stack_size = PROC_CAN_RX_TASK_STACK_SIZE;
+	task_rx_attr.priority = osPriorityBelowNormal7;
+	task_rx_attr.cb_mem = &gProcess_Can_Rx_Task_t;
+	task_rx_attr.cb_size = sizeof(StaticTask_t);
+	osDelay(1000);
+	osThreadNew(CanTask, NULL, &task_rx_attr);
 }
 
 static void CanTask()
-{    
+{
 	Can_InitType param;
-    UINT8 udsFlag,msgFlag=0;
+	UINT8 udsFlag, msgFlag = 0;
 	UINT8 i = 0;
 	UINT16 delayconuter = 0;
-	UINT8	UDSService[2];
-	UINT8	UDSSubService[2];
-	UINT8	UDSSubServiceActionCode[2];
+	UINT8 UDSService[2];
+	UINT8 UDSSubService[2];
+	UINT8 UDSSubServiceActionCode[2];
 	CAN_Msg_Type CanRxMsg[2];
-	UINT8  ConvertCounter = 0;
+	UINT8 ConvertCounter = 0;
 
 	PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_INIT);
-	
-    while(TRUE)
-    {	
-    	memset(CanRxMsg, 0, sizeof(CanRxMsg));
-		switch(gProcess_CAN_Task)
+
+	while (TRUE)
+	{
+		memset(CanRxMsg, 0, sizeof(CanRxMsg));
+		switch (gProcess_CAN_Task)
+		{
+		case PROCESS_CAN_STATE_INIT:
+		{
+			param.baudrate = CAN_250Kbps;
+			param.mode = REQOP_NORMAL;
+			param.packType = STD_PACK;
+			HAL_Can_Init(param);
+			osDelay(100);
+			PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
+			break;
+		}
+		case PROCESS_CAN_STATE_IDLE:
 		{
-			case PROCESS_CAN_STATE_INIT:
+			ConvertCounter = 0;
+			while (TRUE)
 			{
-				param.baudrate = CAN_250Kbps;
-				param.mode = REQOP_NORMAL;	
-				param.packType = STD_PACK;
-				HAL_Can_Init(param);
 				osDelay(100);
-				PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-				break;
+				ConvertCounter++;
+				if (gProcess_app != WORK)
+				{
+					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
+					break;
+				}
+				if (getbit(PadInterrupt, 0) == 1 || ConvertCounter >= 10)
+				{
+					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
+					break;
+				}
 			}
-			case PROCESS_CAN_STATE_IDLE:
+			break;
+		}
+		case PROCESS_CAN_STATE_WORK:
+		{
+			if (HAL_Can_Receive(CanRxMsg) > 0)
 			{
-				ConvertCounter = 0;
-				while(TRUE)
+				delayconuter = 0;
+				for (i = 0; i < 2; i++)
 				{
-					osDelay(100);
-					ConvertCounter++;
-					if(gProcess_app!=WORK)
+					if (CanRxMsg[i].Id == 0x7A0)
 					{
-						PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
-						break;
+						udsFlag = 1;
+						UDSService[i] = CanRxMsg[i].Data[0];
+						UDSSubService[i] = CanRxMsg[i].Data[1];
+						UDSSubServiceActionCode[i] = CanRxMsg[i].Data[2];
+						if (UDSService[i] == 0x10)
+						{
+							if (UDSSubService[i] == 0x02)
+							{
+								UDSSwitch = 1;
+							}
+						}
 					}
-					if(getbit(PadInterrupt,0)==1||ConvertCounter>=10)
+					else if (CanRxMsg[i].Id == 0x7A1)
 					{
-						PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-						break;
+						if (CanRxMsg[i].Data[0] != 0x00)
+						{
+							msgFlag = 1;
+						}
+						else
+						{
+							msgFlag = 0;
+						}
 					}
-				}    
-				break;				
-			}
-			case PROCESS_CAN_STATE_WORK:
-			{
-				if(HAL_Can_Receive(CanRxMsg)>0)					
-				{
-					delayconuter=0;						
-					for(i=0; i<2; i++)
-					{								
-						if(CanRxMsg[i].Id == 0x7A0)
-						{	
-							udsFlag = 1;
-							UDSService[i] =  CanRxMsg[i].Data[0];
-							UDSSubService[i] = CanRxMsg[i].Data[1];
-							UDSSubServiceActionCode[i] = CanRxMsg[i].Data[2];
-							if(UDSService[i] == 0x10)
-							{
-								if(UDSSubService[i] == 0x02)
-								{
-									UDSSwitch = 1;
-								}								
-							}
+					else if (CanRxMsg[i].Id == 0x7A2)
+					{
+						if (CanRxMsg[i].Data[0] == 0x01)
+						{
+							AppDataInfo.appDataModify = TRUE;
+							AppDataInfo.RelayControl = TRUE;
 						}
-						else if(CanRxMsg[i].Id == 0x7A1)
+						else
 						{
-							if(CanRxMsg[i].Data[0] != 0x00)
-							{
-								msgFlag = 1;	
-							}
-							else
-							{
-								msgFlag = 0;
-							}
+							AppDataInfo.appDataModify = TRUE;
+							AppDataInfo.RelayControl = FALSE;
 						}
-						else if(CanRxMsg[i].Id == 0x7A2)
+						if (CanRxMsg[i].Data[1] == 0x01)
 						{
-							if(CanRxMsg[i].Data[0] == 0x01)
-							{
-								AppDataInfo.appDataModify = TRUE;	
-								AppDataInfo.RelayControl = TRUE;
-							}
-							else
-							{
-								AppDataInfo.appDataModify = TRUE;	
-								AppDataInfo.RelayControl = FALSE;
-							}
-							if(CanRxMsg[i].Data[1] == 0x01)
-							{
-								HeatForceControl = 0x01;
-							}
-							else if(CanRxMsg[i].Data[1] == 0x02)
-							{
-								HeatForceControl = 0x02;
-							}
-							else
-							{
-								HeatForceControl = 0x00;
-							}
-							if(CanRxMsg[i].Data[2] == 0x01)
-							{
-								BMS_Fota_update_flag = true;
-							}
+							HeatForceControl = 0x01;
+						}
+						else if (CanRxMsg[i].Data[1] == 0x02)
+						{
+							HeatForceControl = 0x02;
+						}
+						else
+						{
+							HeatForceControl = 0x00;
+						}
+						if (CanRxMsg[i].Data[2] == 0x01)
+						{
+							BMS_Fota_update_flag = true;
 						}
-					}	
-					if(udsFlag==1)
-					{	
-						UDS_Service(CanRxMsg);
-						udsFlag = 0;
 					}
-									
 				}
-				else
+				if (udsFlag == 1)
 				{
-					delayconuter++;
-					osDelay(10);					
+					UDS_Service(CanRxMsg);
+					udsFlag = 0;
 				}
-				if(msgFlag == 1)
+			}
+			else
+			{
+				delayconuter++;
+				osDelay(10);
+			}
+			if (msgFlag == 1)
+			{
+				CanMsgTx1000ms();
+			}
+			if (delayconuter >= 100 && msgFlag == 0)
+			{
+				delayconuter = 0;
+				clrbit(PadInterrupt, 0);
+				PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
+			}
+			break;
+		}
+		case PROCESS_CAN_STATE_SLEEP:
+		{
+			HAL_Can_Sleep();
+			while (TRUE)
+			{
+				if (getbit(PadInterrupt, 0) == 1 || (slpManGetWakeupPinValue() & 0x1) == 0x00) //判断是否产生中断,产生中断则退出延时
 				{
-					CanMsgTx1000ms();							
+					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_INIT);
+					break;
 				}
-				if(delayconuter>=100 && msgFlag == 0)
-				{
-					delayconuter=0;
-					clrbit(PadInterrupt,0);
-					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
-				}				
-				break;
-			}	
-	        case PROCESS_CAN_STATE_SLEEP:
-	        {	            
-	            HAL_Can_Sleep();   
-				while (TRUE)
-				{
-					if (getbit(PadInterrupt,0)==1||(slpManGetWakeupPinValue() & 0x1)==0x00)//判断是否产生中断,产生中断则退出延时
-					{
-						PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_INIT);
-						break;
-					}
-					osDelay(2000);
-				}    
-	            break;
-	       	}
-	   }
-	}      
+				osDelay(2000);
+			}
+			break;
+		}
+		}
+	}
 }
-
-
-
-

+ 99 - 99
src/AppTaskControl.c

@@ -8,117 +8,117 @@
  ****************************************************************************/
 #include "AppTaskControl.h"
 
-static StaticTask_t                 gProcess_Control_Task_t;
-static UINT8                        gProcess_Control_TaskStack[PROC_CONTROL_TASK_STACK_SIZE];
-static osThreadId_t                 ControlTaskId = NULL;
-static process_control 		        gProcess_Control_Task = PROCESS_CONTROL_STATE_IDLE;
-#define PROC_CONTROL_STATE_SWITCH(a)    (gProcess_Control_Task = a)
+static StaticTask_t gProcess_Control_Task_t;
+static UINT8 gProcess_Control_TaskStack[PROC_CONTROL_TASK_STACK_SIZE];
+static osThreadId_t ControlTaskId = NULL;
+static process_control gProcess_Control_Task = PROCESS_CONTROL_STATE_IDLE;
+#define PROC_CONTROL_STATE_SWITCH(a) (gProcess_Control_Task = a)
 void GetAdcValue(UINT8 num);
-static void ControlTask(void* arg)
+static void ControlTask(void *arg)
 {
     /*AD采样初始化*/
-    UINT32  param;
-	AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI,&param,1,ADC_GET_RESULT_TIMOUT);						
-	AdcSendReq(ADC_REQ_BITMAP_INRES_CALI,&param,1,ADC_GET_RESULT_TIMOUT);
-    NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-	NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-	NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-	NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
-	FaultDisplay(LED_TURN_OFF);
+    UINT32 param;
+    AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
+    AdcSendReq(ADC_REQ_BITMAP_INRES_CALI, &param, 1, ADC_GET_RESULT_TIMOUT);
+    NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
+    NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
+    NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
+    NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
+    FaultDisplay(LED_TURN_OFF);
     PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_IDLE);
     UINT32 CurrentTime = 0;
     UINT8 AdcOrder = 1;
     UINT8 RingTimes = 0;
     while (true)
     {
-        switch(gProcess_Control_Task)
+        switch (gProcess_Control_Task)
         {
-            case PROCESS_CONTROL_STATE_IDLE:
-            {
-                osDelay(100);
-                PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_WORK);
-                break;
-            }
-            case PROCESS_CONTROL_STATE_WORK:
+        case PROCESS_CONTROL_STATE_IDLE:
+        {
+            osDelay(100);
+            PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_WORK);
+            break;
+        }
+        case PROCESS_CONTROL_STATE_WORK:
+        {
+            osDelay(100);
+            if (CurrentTime != TimeCounter)
             {
-                osDelay(100);
-                if(CurrentTime!=TimeCounter)
+                LEDDisplay();
+                CurrentTime = TimeCounter;
+                if (AppDataInfo.BattLock == FALSE && getbit(UartCmdRecvFlag, 0) == 1)
                 {
-                    LEDDisplay();
-                    CurrentTime = TimeCounter;
-                    if(AppDataInfo.BattLock==FALSE && getbit(UartCmdRecvFlag,0) ==1)
-                    {
-                        relayControlFunc(0.4);
-                        RingTimes++;
-                        if(RingTimes>=3)
-                        {
-                            RingTimes = 0;
-                            clrbit(UartCmdRecvFlag,0);
-                        }
-                    }
-                    else if (AppDataInfo.BattLock==TRUE && getbit(UartCmdRecvFlag,0)==1)
-                    {
-                        relayControlFunc(0.4);
-                        RingTimes++;
-                        if(RingTimes>=2)
-                        {
-                            RingTimes = 0;
-                            clrbit(UartCmdRecvFlag,0);
-                        }
-                    }
-                    else if(BuzzerControl==TRUE||getbit(sfmd_st_fltAct,2)==1)
+                    relayControlFunc(0.4);
+                    RingTimes++;
+                    if (RingTimes >= 3)
                     {
-                        relayControlFunc(0.4);
+                        RingTimes = 0;
+                        clrbit(UartCmdRecvFlag, 0);
                     }
                 }
-                if(TimeCounter%10==0)
+                else if (AppDataInfo.BattLock == TRUE && getbit(UartCmdRecvFlag, 0) == 1)
                 {
-                    GetAdcValue(AdcOrder);
-                    AdcOrder++;
-                    if(AdcOrder>5)
+                    relayControlFunc(0.4);
+                    RingTimes++;
+                    if (RingTimes >= 2)
                     {
-                        AdcOrder = 1;
+                        RingTimes = 0;
+                        clrbit(UartCmdRecvFlag, 0);
                     }
                 }
-                if(gProcess_app!=WORK)
+                else if (BuzzerControl == TRUE || getbit(sfmd_st_fltAct, 2) == 1)
                 {
-                    NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-                    NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-                    NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-                    NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
-                    FaultDisplay(LED_TURN_OFF);
-                    PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_SLEEP);
-                    break;
+                    relayControlFunc(0.4);
                 }
-                //临时故障诊断函数--改为模型诊断
-                ErrorNumHandleFunc();
-                break;
             }
-            case PROCESS_CONTROL_STATE_SLEEP:
+            if (TimeCounter % 10 == 0)
             {
-                osDelay(100);
-                if(TimeCounter%(10*600)==0)
+                GetAdcValue(AdcOrder);
+                AdcOrder++;
+                if (AdcOrder > 5)
                 {
-                    GetAdcValue(AdcOrder);
-                    AdcOrder++;
-                    if(AdcOrder>5)
-                    {
-                        AdcOrder = 1;
-                    }
+                    AdcOrder = 1;
                 }
-                if(gProcess_app==WORK)
+            }
+            if (gProcess_app != WORK)
+            {
+                NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
+                NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
+                NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
+                NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
+                FaultDisplay(LED_TURN_OFF);
+                PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_SLEEP);
+                break;
+            }
+            //临时故障诊断函数--改为模型诊断
+            ErrorNumHandleFunc();
+            break;
+        }
+        case PROCESS_CONTROL_STATE_SLEEP:
+        {
+            osDelay(100);
+            if (TimeCounter % (10 * 600) == 0)
+            {
+                GetAdcValue(AdcOrder);
+                AdcOrder++;
+                if (AdcOrder > 5)
                 {
-                    PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_WORK);
+                    AdcOrder = 1;
                 }
-                break;
             }
+            if (gProcess_app == WORK)
+            {
+                PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_WORK);
+            }
+            break;
+        }
         }
     }
 }
 void AppTaskControlInit(void *arg)
 {
     osThreadAttr_t task_attr;
-    memset(&task_attr,0,sizeof(task_attr));
+    memset(&task_attr, 0, sizeof(task_attr));
     memset(gProcess_Control_TaskStack, 0xA5, PROC_CONTROL_TASK_STACK_SIZE);
     task_attr.name = "Control_Task";
     task_attr.stack_mem = gProcess_Control_TaskStack;
@@ -138,27 +138,27 @@ void GetAdcValue(UINT8 num)
     UINT32 adcValue = 0;
     switch (num)
     {
-        case FAST_CHARGE_TEMP:
-            NB_ADC_Get(&adcValue,FAST_CHARGE_TEMP);
-            fastChargeTemp = LookUpRTtable(adcValue);
-            break;
-        case NORMAL_CHARGE_TEMP:
-            NB_ADC_Get(&adcValue,NORMAL_CHARGE_TEMP);
-            normalChargeTemp = LookUpRTtable(adcValue);
-            break;
-        case OTHER_TEMP_1:
-            NB_ADC_Get(&adcValue,OTHER_TEMP_1);
-            heatTemp1 = LookUpRTtable(adcValue);                      
-            break;
-        case OTHER_TEMP_2:
-            NB_ADC_Get(&adcValue,OTHER_TEMP_2);
-            heatTemp2 = LookUpRTtable(adcValue);                       
-            break;
-        case  VBAT:
-            NB_ADC_Get(&adcValue,VBAT);  
-            PowerVoltage =   adcValue;                    
-            break;
-        default:
-            break;
+    case FAST_CHARGE_TEMP:
+        NB_ADC_Get(&adcValue, FAST_CHARGE_TEMP);
+        fastChargeTemp = LookUpRTtable(adcValue);
+        break;
+    case NORMAL_CHARGE_TEMP:
+        NB_ADC_Get(&adcValue, NORMAL_CHARGE_TEMP);
+        normalChargeTemp = LookUpRTtable(adcValue);
+        break;
+    case OTHER_TEMP_1:
+        NB_ADC_Get(&adcValue, OTHER_TEMP_1);
+        heatTemp1 = LookUpRTtable(adcValue);
+        break;
+    case OTHER_TEMP_2:
+        NB_ADC_Get(&adcValue, OTHER_TEMP_2);
+        heatTemp2 = LookUpRTtable(adcValue);
+        break;
+    case VBAT:
+        NB_ADC_Get(&adcValue, VBAT);
+        PowerVoltage = adcValue;
+        break;
+    default:
+        break;
     }
 }

+ 179 - 179
src/AppTaskGps.c

@@ -15,236 +15,236 @@ extern void GsensorInit(void);
 extern void GsensorI2CHandler(ARM_I2C_SignalEvent_t cb_event);
 extern void GsensorI2CCallback(UINT32 event);
 
-static process_gps             gProcess_Gps_Task = PROCESS_GPS_STATE_IDLE;
-#define PROC_GPS_STATE_SWITCH(a)  (gProcess_Gps_Task = a)
+static process_gps gProcess_Gps_Task = PROCESS_GPS_STATE_IDLE;
+#define PROC_GPS_STATE_SWITCH(a) (gProcess_Gps_Task = a)
 UINT32 location_handle(char *in1);
-void strdel(char * str,char c);
-static void GpsTask(void* arg)
+void strdel(char *str, char c);
+static void GpsTask(void *arg)
 {
 	/*三轴加速度初始化*/
 	GsensorI2CHandler(GsensorI2CCallback);
-    GsensorInit();
-	if(GpsRecvHandle == NULL)
+	GsensorInit();
+	if (GpsRecvHandle == NULL)
 	{
-		GpsRecvHandle = osMessageQueueNew(1,sizeof(GPSInfo), NULL);
+		GpsRecvHandle = osMessageQueueNew(1, sizeof(GPSInfo), NULL);
 	}
 	gpsReqMsg msg;
-	char *p=NULL;
-	CHAR *p2=NULL;
+	char *p = NULL;
+	CHAR *p2 = NULL;
 	const char *delim = "\n";
 	char *databuffer[20];
 	UINT32 speedtemp;
-    UINT32 latitude;
+	UINT32 latitude;
 	UINT32 longitude;
-    UINT16 direction;
+	UINT16 direction;
 	UINT16 GpsNoDataCounter = 0;
-	UINT8  index=0;
-	GPSInfo  GpsInfoData;
+	UINT8 index = 0;
+	GPSInfo GpsInfoData;
 	PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_INIT);
-    while(1)
-    {
-        switch(gProcess_Gps_Task)
+	while (1)
+	{
+		switch (gProcess_Gps_Task)
+		{
+		case PROCESS_GPS_STATE_INIT:
+		{
+
+			osDelay(100);
+			posGGAServiceStart(norGpsHandle);
+			posGGAReset();
+			PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_WORK);
+			break;
+		}
+		case PROCESS_GPS_STATE_IDLE:
 		{
-			case PROCESS_GPS_STATE_INIT:
+
+			osDelay(100);
+			if (gProcess_app == WORK)
 			{
-				
-				osDelay(100);
-				posGGAServiceStart(norGpsHandle);
-				posGGAReset();
 				PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_WORK);
 				break;
 			}
-			case PROCESS_GPS_STATE_IDLE:
+			else
 			{
-
-				osDelay(100);
-				if(gProcess_app==WORK)
-				{
-					PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_WORK);
-					break;
-				}
-				else
-				{
-					PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_SLEEP);
-					break;
-				}
+				PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_SLEEP);
 				break;
 			}
-			case PROCESS_GPS_STATE_WORK:
+			break;
+		}
+		case PROCESS_GPS_STATE_WORK:
+		{
+			if (GpsNoDataCounter >= 60 * 10)
 			{
-				if(GpsNoDataCounter>=60*10)
-				{
-					memset((UINT8 *)&GpsInfoData,0x00,sizeof(GPSInfo));
-					GpsNoDataCounter = 0;
-					osDelay(100);
-					posGGAServiceStart(norGpsHandle);
-					posGGAReset();
-				}
-				osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
-				if(ret==0)
+				memset((UINT8 *)&GpsInfoData, 0x00, sizeof(GPSInfo));
+				GpsNoDataCounter = 0;
+				osDelay(100);
+				posGGAServiceStart(norGpsHandle);
+				posGGAReset();
+			}
+			osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
+			if (ret == 0)
+			{
+				if (msg.dataPtr)
 				{
-					if (msg.dataPtr)
-            		{
-						// char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
-						memset((UINT8 *)&GpsInfoData,0x00,sizeof(GPSInfo));
-						p = strtok(msg.dataPtr,delim);//将信息进行分割
-						p2 = strtok(NULL,delim);
-						#ifdef USING_PRINTF1
-							printf("\nP msgptr data:%s\r\n",p);
-						#endif
-						p = strtok(p,",");//只取第1行的信息RMC
-						// p = strtok(temp,",");//模拟测试
-						if (strcmp(p,"$GNRMC")==0)
+					// char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
+					memset((UINT8 *)&GpsInfoData, 0x00, sizeof(GPSInfo));
+					p = strtok(msg.dataPtr, delim); //将信息进行分割
+					p2 = strtok(NULL, delim);
+#ifdef USING_PRINTF1
+					printf("\nP msgptr data:%s\r\n", p);
+#endif
+					p = strtok(p, ","); //只取第1行的信息RMC
+					// p = strtok(temp,",");//模拟测试
+					if (strcmp(p, "$GNRMC") == 0)
+					{
+						index = 0;
+						while (p)
 						{
-							index = 0;			
-							while (p)
-							{	
-								databuffer[index]=p;
-								p = strtok(NULL,",");
-								index++;
-							}
-							if (index>5&&strcmp(databuffer[2],"A")==0)
-							{
-								GpsNoDataCounter = 0;
-								GpsInfoData.locateMark = 0x01;//有效,东经,北纬写定
-								GpsFlag = 3;
-								strdel(databuffer[3],'.');
-								strdel(databuffer[5],'.');
-								strdel(databuffer[7],'.');
-								speedtemp = atol(databuffer[7])*1852/1e5;//节换算单位,1节=1.852km每小时
-								GpsInfoData.speed[0] = (speedtemp>>8)&0xFF;
-								GpsInfoData.speed[1]= speedtemp&0xFF; 
-								latitude =location_handle(databuffer[3]);
-								GpsInfoData.latitude[0] = latitude>> 24;
-								GpsInfoData.latitude[1] = latitude>> 16;
-								GpsInfoData.latitude[2] = latitude>> 8;
-								GpsInfoData.latitude[3] = latitude;
-								longitude = location_handle(databuffer[5]);
-								GpsInfoData.longitude[0] = longitude>>24;
-								GpsInfoData.longitude[1] = longitude>>16;
-								GpsInfoData.longitude[2] = longitude>>8;
-								GpsInfoData.longitude[3] = longitude;
-								if(speedtemp>=50)//大于5km/h才输出方位
-								{
-									direction = atol(databuffer[8]);
-									GpsInfoData.direction[0] = direction>>8;
-									GpsInfoData.direction[1] = direction;
-								}
-								else
-								{
-									GpsInfoData.direction[0] = 0xff;
-									GpsInfoData.direction[1] = 0xff;
-								}
-								if(speedtemp>=30 && speedtemp<=1500 && BattWorkStateDelay==0x01)
-								{
-									AppDataInfo.appDataModify = true;
-									AppDataInfo.AccMileage = speedtemp/36 + AppDataInfo.AccMileage;
-									if(AppDataInfo.AccMileage>=0xfffffffe)
-									{
-										AppDataInfo.AccMileage = 0;
-									}
-								}
-							}
-							GpsInfoData.AccMileage[0] = AppDataInfo.AccMileage>>24;
-							GpsInfoData.AccMileage[1] = AppDataInfo.AccMileage>>16;
-							GpsInfoData.AccMileage[2] = AppDataInfo.AccMileage>>8;
-							GpsInfoData.AccMileage[3] = AppDataInfo.AccMileage;
+							databuffer[index] = p;
+							p = strtok(NULL, ",");
+							index++;
 						}
-						p2 = strtok(p2,",");//只取第2行的信息GGA
-						memset(databuffer,0x30,20);
-						if(strcmp(p2,"$GNGGA")==0)
+						if (index > 5 && strcmp(databuffer[2], "A") == 0)
 						{
-							index = 0;			
-							while (p2)
-							{	
-								databuffer[index]=p2;
-								p2 = strtok(NULL,",");
-								index++;
-							}
-							if(index>9&&(strcmp(databuffer[6],"1")==0||strcmp(databuffer[6],"2")==0))
+							GpsNoDataCounter = 0;
+							GpsInfoData.locateMark = 0x01; //有效,东经,北纬写定
+							GpsFlag = 3;
+							strdel(databuffer[3], '.');
+							strdel(databuffer[5], '.');
+							strdel(databuffer[7], '.');
+							speedtemp = atol(databuffer[7]) * 1852 / 1e5; //节换算单位,1节=1.852km每小时
+							GpsInfoData.speed[0] = (speedtemp >> 8) & 0xFF;
+							GpsInfoData.speed[1] = speedtemp & 0xFF;
+							latitude = location_handle(databuffer[3]);
+							GpsInfoData.latitude[0] = latitude >> 24;
+							GpsInfoData.latitude[1] = latitude >> 16;
+							GpsInfoData.latitude[2] = latitude >> 8;
+							GpsInfoData.latitude[3] = latitude;
+							longitude = location_handle(databuffer[5]);
+							GpsInfoData.longitude[0] = longitude >> 24;
+							GpsInfoData.longitude[1] = longitude >> 16;
+							GpsInfoData.longitude[2] = longitude >> 8;
+							GpsInfoData.longitude[3] = longitude;
+							if (speedtemp >= 50) //大于5km/h才输出方位
 							{
-								GpsInfoData.satelliteNum = atol(databuffer[7]);//卫星数目写入
-								GpsFlag = GpsInfoData.satelliteNum;
-								strdel(databuffer[9],'.');
-								UINT16 alt = 0;
-								alt = atol(databuffer[9])/10 + 1000;
-								GpsInfoData.altitude[0]  = alt>>8;//海拔
-								GpsInfoData.altitude[1]  = alt;
-								strdel(databuffer[2],'.');
-								strdel(databuffer[4],'.');
-								latitude =location_handle(databuffer[2]);
-								GpsInfoData.latitude[0] = latitude>> 24;
-								GpsInfoData.latitude[1] = latitude>> 16;
-								GpsInfoData.latitude[2] = latitude>> 8;
-								GpsInfoData.latitude[3] = latitude;
-								longitude = location_handle(databuffer[4]);
-								GpsInfoData.longitude[0] = longitude>>24;
-								GpsInfoData.longitude[1] = longitude>>16;
-								GpsInfoData.longitude[2] = longitude>>8;
-								GpsInfoData.longitude[3] = longitude;
+								direction = atol(databuffer[8]);
+								GpsInfoData.direction[0] = direction >> 8;
+								GpsInfoData.direction[1] = direction;
 							}
 							else
 							{
-								GpsFlag = 0;
-								GpsNoDataCounter++;
+								GpsInfoData.direction[0] = 0xff;
+								GpsInfoData.direction[1] = 0xff;
+							}
+							if (speedtemp >= 30 && speedtemp <= 1500 && BattWorkStateDelay == 0x01)
+							{
+								AppDataInfo.appDataModify = true;
+								AppDataInfo.AccMileage = speedtemp / 36 + AppDataInfo.AccMileage;
+								if (AppDataInfo.AccMileage >= 0xfffffffe)
+								{
+									AppDataInfo.AccMileage = 0;
+								}
 							}
 						}
-						osMessageQueueReset(GpsRecvHandle);
-						osMessageQueuePut(GpsRecvHandle,(UINT8 *)&GpsInfoData,0,1000);
+						GpsInfoData.AccMileage[0] = AppDataInfo.AccMileage >> 24;
+						GpsInfoData.AccMileage[1] = AppDataInfo.AccMileage >> 16;
+						GpsInfoData.AccMileage[2] = AppDataInfo.AccMileage >> 8;
+						GpsInfoData.AccMileage[3] = AppDataInfo.AccMileage;
 					}
-					if(msg.dataPtr)
-						free(msg.dataPtr);
-					msg.dataPtr=NULL;
+					p2 = strtok(p2, ","); //只取第2行的信息GGA
+					memset(databuffer, 0x30, 20);
+					if (strcmp(p2, "$GNGGA") == 0)
+					{
+						index = 0;
+						while (p2)
+						{
+							databuffer[index] = p2;
+							p2 = strtok(NULL, ",");
+							index++;
+						}
+						if (index > 9 && (strcmp(databuffer[6], "1") == 0 || strcmp(databuffer[6], "2") == 0))
+						{
+							GpsInfoData.satelliteNum = atol(databuffer[7]); //卫星数目写入
+							GpsFlag = GpsInfoData.satelliteNum;
+							strdel(databuffer[9], '.');
+							UINT16 alt = 0;
+							alt = atol(databuffer[9]) / 10 + 1000;
+							GpsInfoData.altitude[0] = alt >> 8; //海拔
+							GpsInfoData.altitude[1] = alt;
+							strdel(databuffer[2], '.');
+							strdel(databuffer[4], '.');
+							latitude = location_handle(databuffer[2]);
+							GpsInfoData.latitude[0] = latitude >> 24;
+							GpsInfoData.latitude[1] = latitude >> 16;
+							GpsInfoData.latitude[2] = latitude >> 8;
+							GpsInfoData.latitude[3] = latitude;
+							longitude = location_handle(databuffer[4]);
+							GpsInfoData.longitude[0] = longitude >> 24;
+							GpsInfoData.longitude[1] = longitude >> 16;
+							GpsInfoData.longitude[2] = longitude >> 8;
+							GpsInfoData.longitude[3] = longitude;
+						}
+						else
+						{
+							GpsFlag = 0;
+							GpsNoDataCounter++;
+						}
+					}
+					osMessageQueueReset(GpsRecvHandle);
+					osMessageQueuePut(GpsRecvHandle, (UINT8 *)&GpsInfoData, 0, 1000);
 				}
-				PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_IDLE);
-				break;
+				if (msg.dataPtr)
+					free(msg.dataPtr);
+				msg.dataPtr = NULL;
 			}
-			case PROCESS_GPS_STATE_SLEEP:
+			PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_IDLE);
+			break;
+		}
+		case PROCESS_GPS_STATE_SLEEP:
+		{
+			posGGAServiceStop();
+			while (TRUE)
 			{
-				posGGAServiceStop();
-				while(TRUE)
+				osDelay(100);
+				if (gProcess_app == WORK)
 				{
-					osDelay(100);
-					if(gProcess_app==WORK)
-					{
-						PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_INIT);
-						break;
-					}
+					PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_INIT);
+					break;
 				}
-				break;
 			}
+			break;
+		}
 		}
-    }
+	}
 }
 void AppTaskGpsInit(void *arg)
 {
 
-	if(norGpsHandle == NULL)
+	if (norGpsHandle == NULL)
 	{
-		norGpsHandle = osMessageQueueNew(1,sizeof(gpsReqMsg), NULL);
-		if(norGpsHandle == NULL)
+		norGpsHandle = osMessageQueueNew(1, sizeof(gpsReqMsg), NULL);
+		if (norGpsHandle == NULL)
 			return;
 	}
-	if(gpsTaskHandle == NULL)
+	if (gpsTaskHandle == NULL)
 	{
 		osThreadAttr_t task_attr;
-		memset(&task_attr , 0 , sizeof(task_attr));
+		memset(&task_attr, 0, sizeof(task_attr));
 		task_attr.name = "GPSTask";
 		task_attr.priority = osPriorityBelowNormal6;
 		task_attr.cb_mem = &gpsTask;
 		task_attr.cb_size = sizeof(StaticTask_t);
 		task_attr.stack_mem = gpsTaskStack;
-		task_attr.stack_size =GPS_TASK_STACK_SIZE;
-		memset(& gpsTaskStack, 0xa5, GPS_TASK_STACK_SIZE);
-		gpsTaskHandle = osThreadNew(GpsTask , NULL,&task_attr);
-		if(gpsTaskHandle == NULL)
+		task_attr.stack_size = GPS_TASK_STACK_SIZE;
+		memset(&gpsTaskStack, 0xa5, GPS_TASK_STACK_SIZE);
+		gpsTaskHandle = osThreadNew(GpsTask, NULL, &task_attr);
+		if (gpsTaskHandle == NULL)
 			return;
 	}
 }
 void AppTaskGpsDeInit(void *arg)
 {
-    osThreadTerminate(gpsTaskHandle);
-    gpsTaskHandle = NULL;
+	osThreadTerminate(gpsTaskHandle);
+	gpsTaskHandle = NULL;
 }
 UINT32 location_handle(char *in1)
 {
@@ -252,19 +252,19 @@ UINT32 location_handle(char *in1)
 	UINT32 location_degree;
 	UINT32 location_min;
 	location_temp = atol(in1);
-	location_degree = location_temp/(1e7);
-	location_degree = location_degree*(1e6);
-	location_min = location_temp-location_degree*10;
-	location_min = location_min/6;
-	location_temp = location_degree+location_min;
+	location_degree = location_temp / (1e7);
+	location_degree = location_degree * (1e6);
+	location_min = location_temp - location_degree * 10;
+	location_min = location_min / 6;
+	location_temp = location_degree + location_min;
 	return location_temp;
 }
-void strdel(char * str,char c)
+void strdel(char *str, char c)
 {
 	char *p = str;
-	while(*str)
+	while (*str)
 	{
-		if(*str!=c)
+		if (*str != c)
 			*p++ = *str;
 		str++;
 	}

+ 180 - 181
src/AppTaskMain.c

@@ -1,19 +1,20 @@
-/****************************************************************************
- *
- * Copy right:   Qx.CJ
- * File name:    MainTask.c
- * Description:  主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
- * History:      2021-07-05
- * Version:      V3.0
- ****************************************************************************/
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 09:27:15
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 15:38:00
+ * @Description  : 主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskMain.c
+ */
 #include "AppTaskMain.h"
 
-static StaticTask_t           gProcess_Main_Task_t;
-static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
-static osThreadId_t           MainTaskId = NULL;
-static process_Main 		    gProcess_Main_Task;
-#define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
-#define PROC_APP_STATE_SWITCH(a)  (gProcess_app = a)
+static StaticTask_t gProcess_Main_Task_t;
+static UINT8 gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
+static osThreadId_t MainTaskId = NULL;
+static process_Main gProcess_Main_Task;
+#define PROC_MAIN_STATE_SWITCH(a) (gProcess_Main_Task = a)
+#define PROC_APP_STATE_SWITCH(a) (gProcess_app = a)
 static volatile BOOL WorkTimerEnd = FALSE;
 static volatile BOOL SleepTimerEnd = FALSE;
 void monitor_timer_callback(TimerHandle_t xTimer);
@@ -27,217 +28,217 @@ static void appAfterSlp1(void *pdata, slpManLpState state);
 static void appBeforeSlp2(void *pdata, slpManLpState state);
 static void appAfterSlp2(void *pdata, slpManLpState state);
 
-UINT8 MainSlpHandler          = 0xff;//主线程睡眠句柄
-static void MainTask(void* arg)
+UINT8 MainSlpHandler = 0xff; //主线程睡眠句柄
+static void MainTask(void *arg)
 {
     UINT8 PadInterrupt_clrCounter = 0;
     TimerHandle_t monitor_timer = NULL;
     TimerHandle_t work_timer = NULL;
     TimerHandle_t sleep_timer = NULL;
     monitor_timer = xTimerCreate("monitor_timer", 100 / portTICK_RATE_MS, pdTRUE, NULL, monitor_timer_callback);
-    work_timer    = xTimerCreate("work_timer", WORK_TIME*60*1000 / portTICK_RATE_MS, pdTRUE, NULL, work_timer_callback);
-    sleep_timer   = xTimerCreate("sleep_timer", SLEEP_TIME*60*1000 / portTICK_RATE_MS, pdTRUE, NULL, sleep_timer_callback);
+    work_timer = xTimerCreate("work_timer", WORK_TIME * 60 * 1000 / portTICK_RATE_MS, pdTRUE, NULL, work_timer_callback);
+    sleep_timer = xTimerCreate("sleep_timer", SLEEP_TIME * 60 * 1000 / portTICK_RATE_MS, pdTRUE, NULL, sleep_timer_callback);
     PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
-    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP1_STATE);//禁用SLEEP1休眠
+    slpManSetPmuSleepMode(true, SLP_HIB_STATE, false);
+    slpManApplyPlatVoteHandle("MainSlp", &MainSlpHandler);
+    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP1_STATE); //禁用SLEEP1休眠
     UINT32 inParam = 0xAABBCCDD;
-    slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
-    slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
-    slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeHib, &inParam, SLPMAN_HIBERNATE_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterHib, NULL, SLPMAN_HIBERNATE_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeSlp1, NULL, SLPMAN_SLEEP1_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterSlp1, NULL, SLPMAN_SLEEP1_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeSlp2, NULL, SLPMAN_SLEEP2_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterSlp2, NULL, SLPMAN_SLEEP2_STATE);
     slpManWakeSrc_e Wakeup_source;
-    Wakeup_source =  slpManGetWakeupSrc();//获取唤醒源
+    Wakeup_source = slpManGetWakeupSrc(); //获取唤醒源
     //配置文件及运行数据加载
-    if(Error_Mutex == NULL)
+    if (Error_Mutex == NULL)
     {
         Error_Mutex = osMutexNew(NULL);
     }
     LoadAppConfig();
-    
-    if(Wakeup_source ==0)
+
+    if (Wakeup_source == 0)
     {
         AppDataInfo.appDataModify = TRUE;
         AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount + 1;
     }
     xTimerStart(monitor_timer, 0);
     UINT8 Temp = 0;
-    while(true)
+    while (true)
     {
-        switch(gProcess_Main_Task)
+        switch (gProcess_Main_Task)
         {
-            case PROCESS_STATE_IDLE:
-            {
-                LoadAppData();
-                PROC_APP_STATE_SWITCH(IDLE);
-                xTimerStart(work_timer, 0);
-                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
-                break;
-            }
-            case PROCESS_STATE_WORK:
+        case PROCESS_STATE_IDLE:
+        {
+            LoadAppData();
+            PROC_APP_STATE_SWITCH(IDLE);
+            xTimerStart(work_timer, 0);
+            PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
+            break;
+        }
+        case PROCESS_STATE_WORK:
+        {
+            osDelay(100);
+            PROC_APP_STATE_SWITCH(WORK);
+            //状态转换延时
+            if (TimeCounter % 10 == 0)
             {
-                osDelay(100);
-                PROC_APP_STATE_SWITCH(WORK);
-                //状态转换延时
-                if(TimeCounter%10==0)
+                BattWorkDelayFunc(battWorkState);
+#ifdef USING_PRINTF1
+                printf("[%d]-%d-%d,%d,%d \n", __LINE__, TimeCounter, socd_pct_battSoc, fastChargeTemp, normalChargeTemp);
+#endif
+                if (TimeCounter % (10 * 60) == 0)
                 {
-                    BattWorkDelayFunc(battWorkState);
-                    #ifdef USING_PRINTF1
-                        printf("[%d]-%d-%d,%d,%d \n",__LINE__,TimeCounter,socd_pct_battSoc,fastChargeTemp,normalChargeTemp);
-                    #endif
-                    if(TimeCounter%(10*60)==0)
-                    {
-                        BattLockFunc();
-                    }
-                    if(AppDataInfo.appDataModify)
-                    {
-                        SaveAppData();
-                    }
+                    BattLockFunc();
                 }
-                if(WorkTimerEnd==TRUE)//从工作转换为监听的条件,定时器结束
+                if (AppDataInfo.appDataModify)
                 {
-                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
-                    xTimerStop(work_timer,0);
-                    xTimerStart(sleep_timer, 0);
-                    WorkTimerEnd = FALSE;
-                    NVIC_EnableIRQ(PadWakeup1_IRQn);
-                    PadInterrupt = 0x00;
-                    break;
+                    SaveAppData();
                 }
-                if((BMS_Fota_update_flag!=FALSE)||(TCPWorkState!=0x00)||(BattWorkStateDelay!=BATT_IDLE_SYM)||(PadInterrupt!=0x00))
+            }
+            if (WorkTimerEnd == TRUE) //从工作转换为监听的条件,定时器结束
+            {
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
+                xTimerStop(work_timer, 0);
+                xTimerStart(sleep_timer, 0);
+                WorkTimerEnd = FALSE;
+                NVIC_EnableIRQ(PadWakeup1_IRQn);
+                PadInterrupt = 0x00;
+                break;
+            }
+            if ((BMS_Fota_update_flag != FALSE) || (TCPWorkState != 0x00) || (BattWorkStateDelay != BATT_IDLE_SYM) || (PadInterrupt != 0x00))
+            {
+                xTimerReset(work_timer, 0);
+            }
+            if (TcpErrorcount >= 10 && PadInterrupt == 0x00)
+            {
+                AppDataInfo.appDataModify = true;
+                AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount + 1;
+                if (AppDataInfo.SysReStartCount >= 0xfffe)
                 {
-                    xTimerReset(work_timer,0);
+                    AppDataInfo.SysReStartCount = 0;
                 }
-                if(TcpErrorcount>=10 &&PadInterrupt==0x00)
+                if (AppDataInfo.appDataModify)
                 {
-                    AppDataInfo.appDataModify = true;
-                    AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount +1;
-                    if(AppDataInfo.SysReStartCount>=0xfffe)
-                    {
-                        AppDataInfo.SysReStartCount = 0;
-                    }
-                    if(AppDataInfo.appDataModify)
-                    {
-                        SaveAppData();
-                    }
-                    if(BcuDataInfo.appDataModify)
-                    {
-                        SaveBcuData();
-                    }
-                    appSetCFUN(0);
-                    osDelay(1000);
-                    EC_SystemReset();
+                    SaveAppData();
                 }
-				if(BcuDataInfo.appDataModify)//BCU数据实时保存
+                if (BcuDataInfo.appDataModify)
                 {
                     SaveBcuData();
                 }
+                appSetCFUN(0);
+                osDelay(1000);
+                EC_SystemReset();
+            }
+            if (BcuDataInfo.appDataModify) //BCU数据实时保存
+            {
+                SaveBcuData();
+            }
+            break;
+        }
+        case PROCESS_STATE_LISTEN:
+        {
+            PROC_APP_STATE_SWITCH(LISTEN);
+            if (getbit(PadInterrupt, 1) == 0x01)
+            {
+                clrbit(PadInterrupt, 1);
+                osDelay(10);
+                PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
+                Temp = PadInterrupt;
+            }
+            else if (getbit(PadInterrupt, 1) == 0x00 && PadInterrupt != 0x00)
+            {
+                PadInterrupt_clrCounter = PadInterrupt_clrCounter + 3;
+            }
+            else
+            {
+                osDelay(100);
+            }
+            if (AppDataInfo.appDataModify)
+            {
+                SaveAppData();
+            }
+            if (BcuDataInfo.appDataModify)
+            {
+                SaveBcuData();
+            }
+#ifdef USING_PRINTF1
+            printf("[%d]%x - %x - %x - %x\n", __LINE__, SleepTimerEnd, BMS_Fota_update_flag, TCPWorkState, PadInterrupt);
+#endif
+            if ((SleepTimerEnd) || (TCPWorkState == 1) || (PadInterrupt_clrCounter >= 3)) //从监听转换为工作的条件
+            {
+#ifdef USING_PRINTF1
+                printf("[%d]-%x", __LINE__, battWorkState);
+                printf("[%d]%x - %x - %x - %x - %x-%d\n", __LINE__, WorkTimerEnd, BMS_Fota_update_flag, TCPWorkState, BattWorkStateDelay, Temp, PadInterrupt_clrCounter);
+#endif
+#ifdef DEBUGLOG
+                Debug_printf("WORK:%d,%d\n", PadInterrupt_clrCounter, PadInterrupt);
+#endif
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+                xTimerStop(sleep_timer, 0);
+                SleepTimerEnd = FALSE;
+                PadInterrupt = 0x00;
+                PadInterrupt_clrCounter = 0;
+                NVIC_DisableIRQ(PadWakeup1_IRQn);
                 break;
             }
-            case PROCESS_STATE_LISTEN:
+            if (NB_Fota_update_flag)
             {
-                PROC_APP_STATE_SWITCH(LISTEN);
-                if(getbit(PadInterrupt,1)==0x01)
-                {
-                    clrbit(PadInterrupt,1);
-                    osDelay(10);
-                    PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
-                    Temp = PadInterrupt;
-                }
-                else if(getbit(PadInterrupt,1)==0x00 && PadInterrupt!=0x00)
-                {
-                    PadInterrupt_clrCounter = PadInterrupt_clrCounter + 3;
-                }
-                else
-                {
-                    osDelay(100);
-                }
-                if(AppDataInfo.appDataModify)
+                if (AppDataInfo.appDataModify)
                 {
                     SaveAppData();
                 }
-                if(BcuDataInfo.appDataModify)
+                if (BcuDataInfo.appDataModify)
                 {
                     SaveBcuData();
                 }
-                #ifdef USING_PRINTF1
-                    printf("[%d]%x - %x - %x - %x\n",__LINE__,SleepTimerEnd,BMS_Fota_update_flag,TCPWorkState,PadInterrupt);
-                #endif
-                if((SleepTimerEnd)||(TCPWorkState==1)||(PadInterrupt_clrCounter>=3))//从监听转换为工作的条件
-                {
-                    #ifdef USING_PRINTF1
-                        printf("[%d]-%x",__LINE__,battWorkState);
-                        printf("[%d]%x - %x - %x - %x - %x-%d\n",__LINE__,WorkTimerEnd,BMS_Fota_update_flag,TCPWorkState,BattWorkStateDelay,Temp,PadInterrupt_clrCounter);
-                    #endif
-                    #ifdef DEBUGLOG
-                        Debug_printf("WORK:%d,%d\n",PadInterrupt_clrCounter,PadInterrupt);
-                    #endif
-                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
-                    xTimerStop(sleep_timer,0);
-                    SleepTimerEnd = FALSE;
-                    PadInterrupt = 0x00;
-                    PadInterrupt_clrCounter = 0;
-                    NVIC_DisableIRQ(PadWakeup1_IRQn);
-                    break;
-                }
-                if(NB_Fota_update_flag)
-                {
-                    if(AppDataInfo.appDataModify)
-                    {
-                        SaveAppData();
-                    }
-                    if(BcuDataInfo.appDataModify)
-                    {
-                        SaveBcuData();
-                    }
-                    appSetCFUN(0);
-                    osDelay(1000);
-                    EC_SystemReset();
-                }
-                break;
-            }
-            default:
-            {
-                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
-                break;
+                appSetCFUN(0);
+                osDelay(1000);
+                EC_SystemReset();
             }
+            break;
+        }
+        default:
+        {
+            PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+            break;
+        }
         }
     }
 }
 void monitor_timer_callback(TimerHandle_t xTimer)
 {
     TimeCounter++;
-    if(TimeCounter>0xFFFFFFF0)
+    if (TimeCounter > 0xFFFFFFF0)
     {
-        TimeCounter=0;
+        TimeCounter = 0;
     }
 }
 void work_timer_callback(TimerHandle_t xTimer)
 {
-    #ifdef USING_PRINTF
-        printf("work_timer_callback\n");
-    #endif
+#ifdef USING_PRINTF
+    printf("work_timer_callback\n");
+#endif
     WorkTimerEnd = true;
 }
 void sleep_timer_callback(TimerHandle_t xTimer)
 {
-    #ifdef USING_PRINTF
-        printf("sleep_timer_callback\n");
-    #endif
+#ifdef USING_PRINTF
+    printf("sleep_timer_callback\n");
+#endif
     SleepTimerEnd = true;
 }
 void AppTaskMainInit(void *arg)
 {
-    #ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
+#ifndef USING_PRINTF
+    if (BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
     {
         HAL_UART_RecvFlowControl(false);
     }
-    #endif
+#endif
     osThreadAttr_t task_attr;
-    memset(&task_attr,0,sizeof(task_attr));
+    memset(&task_attr, 0, sizeof(task_attr));
     memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
     task_attr.name = "Main_Task";
     task_attr.stack_mem = gProcess_Main_TaskStack;
@@ -246,7 +247,6 @@ void AppTaskMainInit(void *arg)
     task_attr.cb_mem = &gProcess_Main_Task_t;
     task_attr.cb_size = sizeof(StaticTask_t);
     MainTaskId = osThreadNew(MainTask, NULL, &task_attr);
-
 }
 void AppTaskMainDeInit(void *arg)
 {
@@ -258,41 +258,40 @@ static void appBeforeHib(void *pdata, slpManLpState state)
 {
     uint32_t *p_param = (uint32_t *)pdata;
 
-    #ifdef USING_PRINTF
-        printf("Before Hibernate:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
-
+#ifdef USING_PRINTF
+    printf("Before Hibernate:%d \n", state);
+#endif
+    slpManAONIOLatchEn(AonIOLatch_Enable);
 }
 static void appAfterHib(void *pdata, slpManLpState state)
 {
-    #ifdef USING_PRINTF
-        printf("Try Hibernate Failed:%d \n",state);
-    #endif
+#ifdef USING_PRINTF
+    printf("Try Hibernate Failed:%d \n", state);
+#endif
 }
 static void appBeforeSlp1(void *pdata, slpManLpState state)
 {
-    #ifdef USING_PRINTF
-        printf("Before Sleep1:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
+#ifdef USING_PRINTF
+    printf("Before Sleep1:%d \n", state);
+#endif
+    slpManAONIOLatchEn(AonIOLatch_Enable);
 }
 static void appAfterSlp1(void *pdata, slpManLpState state)
 {
-    #ifdef USING_PRINTF
-        printf("After Sleep1:%d \n",state);
-    #endif
+#ifdef USING_PRINTF
+    printf("After Sleep1:%d \n", state);
+#endif
 }
 static void appBeforeSlp2(void *pdata, slpManLpState state)
 {
-    #ifdef USING_PRINTF
-        printf("before sleep2:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
+#ifdef USING_PRINTF
+    printf("before sleep2:%d \n", state);
+#endif
+    slpManAONIOLatchEn(AonIOLatch_Enable);
 }
 static void appAfterSlp2(void *pdata, slpManLpState state)
 {
-    #ifdef USING_PRINTF
-        printf("sleep2 failed:%d \n",state);
-    #endif
+#ifdef USING_PRINTF
+    printf("sleep2 failed:%d \n", state);
+#endif
 }

File diff suppressed because it is too large
+ 233 - 265
src/AppTaskTcp.c


File diff suppressed because it is too large
+ 502 - 431
src/AppTaskUart.c


+ 158 - 158
src/BCU.c

@@ -1,177 +1,177 @@
 
 #include "BCU.h"
 
-static StaticTask_t         gProcess_Bcu_Task_t;
-static UINT8                gProcess_Bcu_TaskStack[PROC_BCU_TASK_STACK_SIZE];
-static osThreadId_t         BcuTaskId = NULL;
-static process_Bcu 		    gProcess_Bcu_Task;
-#define PROC_BCU_STATE_SWITCH(a)  (gProcess_Bcu_Task = a)
+static StaticTask_t gProcess_Bcu_Task_t;
+static UINT8 gProcess_Bcu_TaskStack[PROC_BCU_TASK_STACK_SIZE];
+static osThreadId_t BcuTaskId = NULL;
+static process_Bcu gProcess_Bcu_Task;
+#define PROC_BCU_STATE_SWITCH(a) (gProcess_Bcu_Task = a)
 
 //======================================================
 void BCU(void)
-{     
-      uint16_T i;
-	  UINT32 locateTimeCounter = 0;
-	  osDelay(5000);
-	  PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-	  
-	  while (TRUE)
-	  {
-		switch(gProcess_Bcu_Task)
-		{
-		  case PROCESS_STATE_INIT:	
-		  {
-		    BCU_Init();  
-			memcpy(blcv_Q_totalCpEi,BcuDataInfo.blcv_Q_totalCpE, sizeof(blcv_Q_totalCpEi));		 
-			memcpy(blcv_Q_reqCpEi,BcuDataInfo.blcv_Q_reqCpE, sizeof(blcv_Q_reqCpEi));	 
-			socd_pct_bcuSocEi = BcuDataInfo.socd_pct_bcuSocE;			
-			socd_pct_battSocEi = BcuDataInfo.socd_pct_battSocE; 		
-			sohd_tm_chrgStartStatEi = BcuDataInfo.sohd_tm_chrgStartStatE;	  
-			sohd_flg_chrgEndEi = BcuDataInfo.sohd_flg_chrgEndE; 		   
-			memcpy(sohv_V_chrgStartStatEi,BcuDataInfo.sohv_V_chrgStartStatE, sizeof(sohv_V_chrgStartStatEi));
-			sohd_Q_chrgEi = BcuDataInfo.sohd_Q_chrgE;				  
-			memcpy(sohv_Q_packCapArrEi,BcuDataInfo.sohv_Q_packCapArrE, sizeof(sohv_Q_packCapArrEi));
-			memcpy(sohv_Q_cellCapArrEi,BcuDataInfo.sohv_Q_cellCapArrE, sizeof(sohv_Q_cellCapArrEi));
-			PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
-			break;
-		  }
-		  //------------------------------------------------------------------------------------	  
-		  case PROCESS_STATE_WORK:
-		  { 
-			while (TRUE)
-			{
-			  	//osDelay(100);
-			  	if(locateTimeCounter != TimeCounter)
-			  	{
-					locateTimeCounter = TimeCounter;
-					if(gProcess_app==LISTEN)
-					{
-						  PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
-						  break;
-					}
-					//  printf("sleep_time:%d,BattWorkStateDelay:%d,battI:%d\n",sleep_time,BattWorkStateDelay,battI);
-					  
-					  //=============================================================================
-					  if(BattWorkStateDelay==0&&battI==10000)
-					  {    
-						  memcpy(appv_V_cellU,battCellU,sizeof(appv_V_cellU));
-					  }
-					  ihd_I_curr = (int16_T)(-(battI - 10000));
-					  memcpy(ihv_V_cellU,battCellU,sizeof(battCellU));
-			
-					  for(i=0 ;i < cmnc_num_modTNum;i++)
-					  {
-						  ihv_T_modT[i] = battCellTemp[i];
-					  }
-					  
-					  ihd_T_mosT       =    MOSTemp; 
-					  ihd_T_DCPlugT    =   fastChargeTemp;
-					  ihd_T_ACPlugT    =   normalChargeTemp;
-					  ihd_T_heatPanT1  = heatTemp1;
-					  ihd_T_heatPanT2  = heatTemp2;
-                      ihd_pct_soc      =    battSOC * 10;
-					  ihd_pct_soh      =    battSOH * 10;
-                      ihd_flg_HVILFlt  =    Lockstatus;
-					  ihd_st_workStat  =    BattWorkStateDelay;
-					  ihd_flg_urtRecFlt   =    UartErrorFlag;
-					  ihd_st_chrgConnect = chargerConnectState;
-					  ihd_flg_cellULowFlt        =  ((battWarningState      ) & 0x01) == 1;
-					  ihd_flg_battULowFlt        =  ((battWarningState >> 1 ) & 0x01) == 1;
-					  ihd_flg_cellUOverFlt       =  ((battWarningState >> 2 ) & 0x01) == 1;
-					  ihd_flg_battUOverFlt       =  ((battWarningState >> 3 ) & 0x01) == 1;
-					  ihd_flg_disChrgCurrOverFlt =  ((battWarningState >> 4 ) & 0x01) == 1;
-					  ihd_flg_chrgCurrOverFlt    =  ((battWarningState >> 5 ) & 0x01) == 1;
-					  ihd_flg_disChrgModTOverFlt =  ((battWarningState >> 6 ) & 0x01) == 1;
-					  ihd_flg_chrgModTOverFlt    =  ((battWarningState >> 7 ) & 0x01) == 1;
-					  ihd_flg_chrgMosTOverFlt    =  ((battWarningState >> 11) & 0x01) == 1;
-					  ihd_flg_disChrgMosClosFlt  =  ((battWarningState >> 18) & 0x01) == 1;
-					  ihd_flg_chrgMosClosFlt     =  ((battWarningState >> 19) & 0x01) == 1;
-					  ihd_flg_disChrgModTLowFlt  =  ((battWarningState >> 22) & 0x01) == 1;
-					  ihd_flg_chrgModTLowFlt     =  ((battWarningState >> 23) & 0x01) == 1;
-		              ihd_flg_currOpenFlt      =  0;
+{
+    uint16_T i;
+    UINT32 locateTimeCounter = 0;
+    osDelay(5000);
+    PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+
+    while (TRUE)
+    {
+        switch (gProcess_Bcu_Task)
+        {
+        case PROCESS_STATE_INIT:
+        {
+            BCU_Init();
+            memcpy(blcv_Q_totalCpEi, BcuDataInfo.blcv_Q_totalCpE, sizeof(blcv_Q_totalCpEi));
+            memcpy(blcv_Q_reqCpEi, BcuDataInfo.blcv_Q_reqCpE, sizeof(blcv_Q_reqCpEi));
+            socd_pct_bcuSocEi = BcuDataInfo.socd_pct_bcuSocE;
+            socd_pct_battSocEi = BcuDataInfo.socd_pct_battSocE;
+            sohd_tm_chrgStartStatEi = BcuDataInfo.sohd_tm_chrgStartStatE;
+            sohd_flg_chrgEndEi = BcuDataInfo.sohd_flg_chrgEndE;
+            memcpy(sohv_V_chrgStartStatEi, BcuDataInfo.sohv_V_chrgStartStatE, sizeof(sohv_V_chrgStartStatEi));
+            sohd_Q_chrgEi = BcuDataInfo.sohd_Q_chrgE;
+            memcpy(sohv_Q_packCapArrEi, BcuDataInfo.sohv_Q_packCapArrE, sizeof(sohv_Q_packCapArrEi));
+            memcpy(sohv_Q_cellCapArrEi, BcuDataInfo.sohv_Q_cellCapArrE, sizeof(sohv_Q_cellCapArrEi));
+
+            sfmd_flg_mainCirClosFltEi = BcuDataInfo.sfmd_flg_mainCirClosFltE;
+            sfmd_flg_heatCirClosFltEi = BcuDataInfo.sfmd_flg_heatCirClosFltE;
+            sfmd_flg_heatCirOpenFltEi = BcuDataInfo.sfmd_flg_heatCirOpenFltE;
+            PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
+            break;
+        }
+        //------------------------------------------------------------------------------------
+        case PROCESS_STATE_WORK:
+        {
+            while (TRUE)
+            {
+                //osDelay(100);
+                if (locateTimeCounter != TimeCounter)
+                {
+                    locateTimeCounter = TimeCounter;
+                    if (gProcess_app == LISTEN)
+                    {
+                        PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
+                        break;
+                    }
+
+                    //=============================================================================
+                    if (BattWorkStateDelay == 0 && battI == 10000)
+                    {
+                        memcpy(appv_V_cellU, battCellU, sizeof(appv_V_cellU));
+                    }
+
+                    ihd_I_curr = (int16_T)(-(battI - 10000));
+                    memcpy(ihv_V_cellU, battCellU, sizeof(battCellU));
+                    for (i = 0; i < cmnc_num_modTNum; i++)
+                    {
+                        ihv_T_modT[i] = battCellTemp[i];
+                    }
+
+                    ihd_T_mosT = MOSTemp;
+                    ihd_T_DCPlugT = fastChargeTemp;
+                    ihd_T_ACPlugT = normalChargeTemp;
+                    ihd_T_heatPanT1 = heatTemp1;
+                    ihd_T_heatPanT2 = heatTemp2;
+                    ihd_pct_soc = battSOC * 10;
+                    ihd_pct_soh = battSOH * 10;
+                    ihd_flg_HVILFlt = Lockstatus;
+                    ihd_st_workStat = BattWorkStateDelay;
+                    ihd_flg_urtRecFlt = UartErrorFlag;
+                    ihd_st_chrgConnect = chargerConnectState;
+                    ihd_flg_cellULowFlt = ((battWarningState)&0x01) == 1;
+                    ihd_flg_battULowFlt = ((battWarningState >> 1) & 0x01) == 1;
+                    ihd_flg_cellUOverFlt = ((battWarningState >> 2) & 0x01) == 1;
+                    ihd_flg_battUOverFlt = ((battWarningState >> 3) & 0x01) == 1;
+                    ihd_flg_disChrgCurrOverFlt = ((battWarningState >> 4) & 0x01) == 1;
+                    ihd_flg_chrgCurrOverFlt = ((battWarningState >> 5) & 0x01) == 1;
+                    ihd_flg_disChrgModTOverFlt = ((battWarningState >> 6) & 0x01) == 1;
+                    ihd_flg_chrgModTOverFlt = ((battWarningState >> 7) & 0x01) == 1;
+                    ihd_flg_chrgMosTOverFlt = ((battWarningState >> 11) & 0x01) == 1;
+                    ihd_flg_disChrgMosClosFlt = ((battWarningState >> 18) & 0x01) == 1;
+                    ihd_flg_chrgMosClosFlt = ((battWarningState >> 19) & 0x01) == 1;
+                    ihd_flg_disChrgModTLowFlt = ((battWarningState >> 22) & 0x01) == 1;
+                    ihd_flg_chrgModTLowFlt = ((battWarningState >> 23) & 0x01) == 1;
+                    ihd_flg_currOpenFlt = 0;
 
-					  //=============================================================================
-					  SFM();
-					  TMS();
-					  SPM();
-	
-					 //==============================shi shi cun chu=======
-					  if(socd_flg_EEsave==1)
-					  {
-						 BCUEEDataSave();
-					  }
-			  	}
-				osDelay(5);
-			}
-			break;
-		  }
-		  //----------------------------------------------------------------------------------------------------
-		  case PROCESS_STATE_SLEEP:
-		  { 
-			BCUEEDataSave();
-			//
-			ihd_tm_parkTime=0;
-			while (TRUE)
-			{
-			  osDelay(1000);
-			  ihd_tm_parkTime++;
-			  //printf("ihd_tm_parkTime:%d\n",ihd_tm_parkTime);
-			  if(gProcess_app==WORK)
-			  {
-				PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-				break;
-			  }
-			}
-			break;
-		  }
-		  default:
-		  {
-			PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-			break;
-		  }
-		}
-	  }
+                    //=============================================================================
+                    SFM();
+                    TMS();
+                    SPM();
+
+                    //==============================shi shi cun chu=======
+                    if (socd_flg_EEsave == 1)
+                    {
+                        BCUEEDataSave();
+                    }
+                }
+                osDelay(5);
+            }
+            break;
+        }
+        //----------------------------------------------------------------------------------------------------
+        case PROCESS_STATE_SLEEP:
+        {
+            BCUEEDataSave();
+            //
+            ihd_tm_parkTime = 0;
+            while (TRUE)
+            {
+                osDelay(1000);
+                ihd_tm_parkTime++;
+                if (gProcess_app == WORK)
+                {
+                    PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+                    break;
+                }
+            }
+            break;
+        }
+        default:
+        {
+            PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+            break;
+        }
+        }
+    }
 }
 
-/* Model initialize function */
+//=================================================================================
 void BCU_Init(void)
 {
-
-  SFM_Init();
-  TMS_Init();
-  SPM_Init();
-  
+    SFM_Init();
+    TMS_Init();
+    SPM_Init();
 }
 
-
 //================================================================================
 void AppTaskBcuInit(void *arg)
 {
-		osThreadAttr_t task_attr;
-		memset(&task_attr,0,sizeof(task_attr));
-		memset(gProcess_Bcu_TaskStack, 0xA5, PROC_BCU_TASK_STACK_SIZE);
-		task_attr.name = "Bcu_Task";
-		task_attr.stack_mem = gProcess_Bcu_TaskStack;
-		task_attr.stack_size = PROC_BCU_TASK_STACK_SIZE;
-		task_attr.priority = osPriorityBelowNormal7;
-		task_attr.cb_mem = &gProcess_Bcu_Task_t;
-		task_attr.cb_size = sizeof(StaticTask_t);
-		BcuTaskId = osThreadNew(BCU, NULL, &task_attr);
+    osThreadAttr_t task_attr;
+    memset(&task_attr, 0, sizeof(task_attr));
+    memset(gProcess_Bcu_TaskStack, 0xA5, PROC_BCU_TASK_STACK_SIZE);
+    task_attr.name = "Bcu_Task";
+    task_attr.stack_mem = gProcess_Bcu_TaskStack;
+    task_attr.stack_size = PROC_BCU_TASK_STACK_SIZE;
+    task_attr.priority = osPriorityBelowNormal7;
+    task_attr.cb_mem = &gProcess_Bcu_Task_t;
+    task_attr.cb_size = sizeof(StaticTask_t);
+    BcuTaskId = osThreadNew(BCU, NULL, &task_attr);
 }
-//=========================================================================================
+//=================================================================================
 void BCUEEDataSave(void)
 {
-	  memcpy(BcuDataInfo.blcv_Q_totalCpE,blcv_Q_totalCpEo, sizeof(blcv_Q_totalCpEo));	   
-	  memcpy(BcuDataInfo.blcv_Q_reqCpE,blcv_Q_reqCpEo, sizeof(blcv_Q_reqCpEo));	
-	  BcuDataInfo.socd_pct_bcuSocE =  socd_pct_bcuSocEo;  
-	  BcuDataInfo.socd_pct_battSocE = socd_pct_battSocEo;
-	  BcuDataInfo.sohd_tm_chrgStartStatE = sohd_tm_chrgStartStatEo;
-	  BcuDataInfo.sohd_flg_chrgEndE = sohd_flg_chrgEndEo;	  
-	  memcpy(BcuDataInfo.sohv_V_chrgStartStatE,sohv_V_chrgStartStatEo, sizeof(sohv_V_chrgStartStatEo));
-	  BcuDataInfo.sohd_Q_chrgE = sohd_Q_chrgEo;		   
-	  memcpy(BcuDataInfo.sohv_Q_packCapArrE,sohv_Q_packCapArrEo, sizeof(sohv_Q_packCapArrEo));
-	  memcpy(BcuDataInfo.sohv_Q_cellCapArrE,sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
-	  BcuDataInfo.appDataModify = TRUE;
-
- }
- 
+    memcpy(BcuDataInfo.blcv_Q_totalCpE, blcv_Q_totalCpEo, sizeof(blcv_Q_totalCpEo));
+    memcpy(BcuDataInfo.blcv_Q_reqCpE, blcv_Q_reqCpEo, sizeof(blcv_Q_reqCpEo));
+    BcuDataInfo.socd_pct_bcuSocE = socd_pct_bcuSocEo;
+    BcuDataInfo.socd_pct_battSocE = socd_pct_battSocEo;
+    BcuDataInfo.sohd_tm_chrgStartStatE = sohd_tm_chrgStartStatEo;
+    BcuDataInfo.sohd_flg_chrgEndE = sohd_flg_chrgEndEo;
+    memcpy(BcuDataInfo.sohv_V_chrgStartStatE, sohv_V_chrgStartStatEo, sizeof(sohv_V_chrgStartStatEo));
+    BcuDataInfo.sohd_Q_chrgE = sohd_Q_chrgEo;
+    memcpy(BcuDataInfo.sohv_Q_packCapArrE, sohv_Q_packCapArrEo, sizeof(sohv_Q_packCapArrEo));
+    memcpy(BcuDataInfo.sohv_Q_cellCapArrE, sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
+    BcuDataInfo.sfmd_flg_mainCirClosFltE = sfmd_flg_mainCirClosFltEo;
+    BcuDataInfo.sfmd_flg_heatCirClosFltE = sfmd_flg_heatCirClosFltEo;
+    BcuDataInfo.sfmd_flg_heatCirOpenFltE = sfmd_flg_heatCirOpenFltEo;
+    BcuDataInfo.appDataModify = TRUE;
+}

+ 89 - 90
src/EmbeddedCoder_src/BCUCal.c

@@ -1,103 +1,102 @@
 
 #include "rtwtypes.h"
 
-const uint16_T blcc_R_esr = 1000U;                          /* 均衡电阻 */
-const uint16_T blcc_T_close = 125U;                         /* 均衡暂停温度; */
-const uint16_T blcc_T_open = 100U;                          /* 均衡暂停恢复温度; */
-const uint16_T blcc_V_low = 10U;                            /* 均衡开启电压阈值 */
+const uint16_T blcc_R_esr = 1000U;  /* 均衡电阻 */
+const uint16_T blcc_T_close = 125U; /* 均衡暂停温度; */
+const uint16_T blcc_T_open = 100U;  /* 均衡暂停恢复温度; */
+const uint16_T blcc_V_low = 10U;    /* 均衡开启电压阈值 */
 
-const uint16_T cmnc_Q_ratedCp = 600U;                       /* 电池容量; */
-const uint16_T cmnc_num_cellUNum = 17U;                     /* 电压采样点实际个数; */
-const uint16_T cmnc_num_modTNum = 4U;                       /* 温度采样点实际个数; */
-const uint16_T cmnc_tm_parkTime = 1800U;                    /* 静置时间阈值; */
-const uint16_T cmnm_F_polar[13] = { 3880U, 5062U, 4454U, 10798U, 12885U, 12990U,
-  14331U, 10754U, 9378U, 10340U, 10592U, 11946U, 11515U } ; /* 电池放电参数的C数组; */
-const uint16_T cmnm_R_ohm[13] = { 2181U, 2043U, 2040U, 1927U, 1850U, 1802U,
-  1771U, 1743U, 1733U, 1728U, 1748U, 1762U, 1789U } ;       /* 电池放电参数的Ro数组; */
-const uint16_T cmnm_R_polar[13] = { 1837U, 1055U, 7352U, 1453U, 1181U, 1125U,
-  1205U, 1283U, 1228U, 1187U, 1104U, 1170U, 1049U } ;       /* 电池放电参数的Rp数组; */
-const uint16_T cmnm_V_ocv[13] = { 3311U, 3411U, 3476U, 3553U, 3610U, 3638U,
-  3674U, 3758U, 3845U, 3942U, 4051U, 4106U, 4175U } ;       /* 电池放电参数的OCV数组; */
-const uint16_T cmnm_pct_soc[13] = { 0U, 50U, 100U, 200U, 300U, 400U, 500U, 600U,
-  700U, 800U, 900U, 950U, 1000U } ;                         /* 电池放电参数的SOC数组; */
-  
-const uint16_T sfmc_I_chrgCurrOverThr = 600;                 /* 充电电流阈值 */
-const uint16_T sfmc_I_disChrgCurrOverThr = 600;              /* 放电电流阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt1 = 120;              /* 慢充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 125;              /* 慢充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec1 = 110;              /* 慢充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec2 = 110;              /* 慢充插头温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 120;              /* 快充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 125;              /* 快充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec1 = 110;              /* 快充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec2 = 110;              /* 快充插头温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTLowThrFlt1 = 42U;             /* 充电模组温度过低1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTLowThrFlt2 = 40U;             /* 充电模组温度过低2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTLowThrRec1 = 45U;             /* 充电模组温度过低1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTLowThrRec2 = 45U;             /* 充电模组温度过低2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTOverThrFlt1 = 97U;            /* 充电模组温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTOverThrFlt2 = 100U;           /* 充电模组温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTOverThrRec1 = 90U;            /* 充电模组温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTOverThrRec2 = 90U;            /* 充电模组温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrFlt1 = 120;             /* 充电Mos温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrFlt2 = 125;             /* 充电Mos温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrRec1 = 110;             /* 充电Mos温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrRec2 = 110;             /* 充电Mos温度过高2级故障恢复阈值 */
+const uint16_T cmnc_Q_ratedCp = 600U;    /* 电池容量; */
+const uint16_T cmnc_num_cellUNum = 17U;  /* 电压采样点实际个数; */
+const uint16_T cmnc_num_modTNum = 4U;    /* 温度采样点实际个数; */
+const uint16_T cmnc_tm_parkTime = 1800U; /* 静置时间阈值; */
+const uint16_T cmnm_F_polar[13] = {3880U, 5062U, 4454U, 10798U, 12885U, 12990U,
+                                   14331U, 10754U, 9378U, 10340U, 10592U, 11946U, 11515U}; /* 电池放电参数的C数组; */
+const uint16_T cmnm_R_ohm[13] = {2181U, 2043U, 2040U, 1927U, 1850U, 1802U,
+                                 1771U, 1743U, 1733U, 1728U, 1748U, 1762U, 1789U}; /* 电池放电参数的Ro数组; */
+const uint16_T cmnm_R_polar[13] = {1837U, 1055U, 7352U, 1453U, 1181U, 1125U,
+                                   1205U, 1283U, 1228U, 1187U, 1104U, 1170U, 1049U}; /* 电池放电参数的Rp数组; */
+const uint16_T cmnm_V_ocv[13] = {3311U, 3411U, 3476U, 3553U, 3610U, 3638U,
+                                 3674U, 3758U, 3845U, 3942U, 4051U, 4106U, 4175U}; /* 电池放电参数的OCV数组; */
+const uint16_T cmnm_pct_soc[13] = {0U, 50U, 100U, 200U, 300U, 400U, 500U, 600U,
+                                   700U, 800U, 900U, 950U, 1000U}; /* 电池放电参数的SOC数组; */
+const uint16_T cmnc_V_chrgFulV = 4200U;                            /* 充满电的截至电压; */
 
-const uint16_T sfmc_T_disChrgModTLowThrFlt1 = 25U;          /* 放电模组温度过低1级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrFlt2 = 20U;          /* 放电模组温度过低2级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrRec1 = 30U;          /* 放电模组温度过低1级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrRec2 = 30U;          /* 放电模组温度过低2级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrFlt1 = 97U;         /* 放电模组温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrFlt2 = 100U;        /* 放电模组温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrRec1 = 90U;         /* 放电模组温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrRec2 = 90U;         /* 放电模组温度过高2级故障恢复阈值 */
+const uint16_T sfmc_I_chrgCurrOverThr = 600;      /* 充电电流阈值 */
+const uint16_T sfmc_I_disChrgCurrOverThr = 600;   /* 放电电流阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrFlt1 = 120;   /* 慢充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 125;   /* 慢充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec1 = 110;   /* 慢充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec2 = 110;   /* 慢充插头温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 120;   /* 快充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 125;   /* 快充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec1 = 110;   /* 快充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec2 = 110;   /* 快充插头温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTLowThrFlt1 = 42U;   /* 充电模组温度过低1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTLowThrFlt2 = 40U;   /* 充电模组温度过低2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTLowThrRec1 = 45U;   /* 充电模组温度过低1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTLowThrRec2 = 45U;   /* 充电模组温度过低2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTOverThrFlt1 = 97U;  /* 充电模组温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTOverThrFlt2 = 100U; /* 充电模组温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTOverThrRec1 = 90U;  /* 充电模组温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTOverThrRec2 = 90U;  /* 充电模组温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrFlt1 = 120;  /* 充电Mos温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrFlt2 = 125;  /* 充电Mos温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrRec1 = 110;  /* 充电Mos温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrRec2 = 110;  /* 充电Mos温度过高2级故障恢复阈值 */
+
+const uint16_T sfmc_T_disChrgModTLowThrFlt1 = 25U;   /* 放电模组温度过低1级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrFlt2 = 20U;   /* 放电模组温度过低2级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrRec1 = 30U;   /* 放电模组温度过低1级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrRec2 = 30U;   /* 放电模组温度过低2级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrFlt1 = 97U;  /* 放电模组温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrFlt2 = 100U; /* 放电模组温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrRec1 = 90U;  /* 放电模组温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrRec2 = 90U;  /* 放电模组温度过高2级故障恢复阈值 */
 const uint16_T sfmc_T_disChrgMosTOverThrFlt1 = 120U;
 const uint16_T sfmc_T_disChrgMosTOverThrRec1 = 110U;
 const uint16_T sfmc_T_disChrgMosTOverThrFlt2 = 125U;
 const uint16_T sfmc_T_disChrgMosTOverThrRec2 = 110U;
 
-const uint16_T sfmc_T_heatPanTOverThrFlt1 = 125;             /* 加热板温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_heatPanTOverThrFlt2 = 130;             /* 加热板温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_heatPanTOverThrRec1 = 120;             /* 加热板温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_heatPanTOverThrRec2 = 120;             /* 加热板温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_modTDiffThrFlt1 = 20;                  /* 模组温差过大1级故障诊断阈值 */
-const uint16_T sfmc_T_modTDiffThrFlt2 = 25;                  /* 模组温差过大2级故障诊断阈值 */
-const uint16_T sfmc_T_modTDiffThrRec1 = 15;                  /* 模组温差过大1级故障恢复阈值 */
-const uint16_T sfmc_T_modTDiffThrRec2 = 15;                  /* 模组温差过大2级故障恢复阈值 */
-
-const uint16_T sfmc_V_battULowThrFlt1 = 590U;               /* 总压欠压1级故障诊断阈值 */
-const uint16_T sfmc_V_battULowThrFlt2 = 580U;               /* 总压欠压2级故障诊断阈值 */
-const uint16_T sfmc_V_battULowThrRec1 = 600U;               /* 总压欠压1级故障恢复阈值 */
-const uint16_T sfmc_V_battULowThrRec2 = 600U;               /* 总压欠压2级故障恢复阈值 */
-const uint16_T sfmc_V_battUOverThrFlt1 = 850U;              /* 总压过压1级故障诊断阈值 */
-const uint16_T sfmc_V_battUOverThrFlt2 = 860U;              /* 总压过压2级故障诊断阈值 */
-const uint16_T sfmc_V_battUOverThrRec1 = 840U;              /* 总压过压1级故障恢复阈值 */
-const uint16_T sfmc_V_battUOverThrRec2 = 840U;              /* 总压过压2级故障恢复阈值 */
-const uint16_T sfmc_V_cellULowThrFlt1 = 2950U;              /* 单体电压欠压1级故障诊断阈值 */
-const uint16_T sfmc_V_cellULowThrFlt2 = 2900U;              /* 单体电压欠压2级故障诊断阈值 */
-const uint16_T sfmc_V_cellULowThrRec1 = 3000U;              /* 单体电压欠压1级故障恢复阈值 */
-const uint16_T sfmc_V_cellULowThrRec2 = 3000U;              /* 单体电压欠压2级故障恢复阈值 */
-const uint16_T sfmc_V_cellUOverThrFlt1 = 4250U;             /* 单体电压过压1级故障诊断阈值 */
-const uint16_T sfmc_V_cellUOverThrFlt2 = 4300U;             /* 单体电压过压2级故障诊断阈值 */
-const uint16_T sfmc_V_cellUOverThrRec1 = 4200U;             /* 单体电压过压1级故障恢复阈值 */
-const uint16_T sfmc_V_cellUOverThrRec2 = 4200U;             /* 单体电压过压2级故障恢复阈值 */
-const uint16_T sfmc_flg_cellUDiffThrFlt1 = 250U;            /* 压差过大1级故障诊断阈值 */
-const uint16_T sfmc_flg_cellUDiffThrFlt2 = 300U;            /* 压差过大2级故障诊断阈值 */
-const uint16_T sfmc_flg_cellUDiffThrRec1 = 250U;            /* 压差过大1级故障恢复阈值 */
-const uint16_T sfmc_flg_cellUDiffThrRec2 = 250U;            /* 压差过大2级故障恢复阈值 */
-
-
-const uint16_T socc_V_chrgFulV = 4200U;                     /* 充满电的截至电压; */
-const uint16_T socc_pct_battSocLow = 0U;                    /* SOC下限值; */
-const uint16_T socc_pct_battSocUp = 1000U;                  /* SOC上限值; */
-const int16_T socm_I_chrgCor[4] = { 50, 100, 200, 400 } ;   /* 充电CCV对应的电流数据; */
-const int16_T socm_I_disChrgCor[3] = { -400, -200, -100 } ; /* 放电CCV对应的电流数据; */
-const uint16_T socm_V_chrgCor[4] = { 4125U, 4128U, 4132U, 4137U } ;/* 充电CCV对应的电压; */
-const uint16_T socm_V_disChrgCor[3] = { 3100U, 3270U, 3380U } ; /* 放电CCV对应的电压; */
+const uint16_T sfmc_T_heatPanTOverThrFlt1 = 125; /* 加热板温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_heatPanTOverThrFlt2 = 130; /* 加热板温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_heatPanTOverThrRec1 = 120; /* 加热板温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_heatPanTOverThrRec2 = 120; /* 加热板温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_modTDiffThrFlt1 = 20;      /* 模组温差过大1级故障诊断阈值 */
+const uint16_T sfmc_T_modTDiffThrFlt2 = 25;      /* 模组温差过大2级故障诊断阈值 */
+const uint16_T sfmc_T_modTDiffThrRec1 = 15;      /* 模组温差过大1级故障恢复阈值 */
+const uint16_T sfmc_T_modTDiffThrRec2 = 15;      /* 模组温差过大2级故障恢复阈值 */
 
-const uint16_T tmsc_T_openThr = 45U;                         /* 热管理开启温度; */
-const uint16_T tmsc_T_closeMinThr = 50U;                     /* 热管理关闭温度(最低模组); */
-const uint16_T tmsc_T_closeMaxThr = 70U;                     /* 热管理开启温度(最高模组); */
+const uint16_T sfmc_V_battULowThrFlt1 = 590U;    /* 总压欠压1级故障诊断阈值 */
+const uint16_T sfmc_V_battULowThrFlt2 = 580U;    /* 总压欠压2级故障诊断阈值 */
+const uint16_T sfmc_V_battULowThrRec1 = 600U;    /* 总压欠压1级故障恢复阈值 */
+const uint16_T sfmc_V_battULowThrRec2 = 600U;    /* 总压欠压2级故障恢复阈值 */
+const uint16_T sfmc_V_battUOverThrFlt1 = 850U;   /* 总压过压1级故障诊断阈值 */
+const uint16_T sfmc_V_battUOverThrFlt2 = 860U;   /* 总压过压2级故障诊断阈值 */
+const uint16_T sfmc_V_battUOverThrRec1 = 840U;   /* 总压过压1级故障恢复阈值 */
+const uint16_T sfmc_V_battUOverThrRec2 = 840U;   /* 总压过压2级故障恢复阈值 */
+const uint16_T sfmc_V_cellULowThrFlt1 = 2950U;   /* 单体电压欠压1级故障诊断阈值 */
+const uint16_T sfmc_V_cellULowThrFlt2 = 2900U;   /* 单体电压欠压2级故障诊断阈值 */
+const uint16_T sfmc_V_cellULowThrRec1 = 3000U;   /* 单体电压欠压1级故障恢复阈值 */
+const uint16_T sfmc_V_cellULowThrRec2 = 3000U;   /* 单体电压欠压2级故障恢复阈值 */
+const uint16_T sfmc_V_cellUOverThrFlt1 = 4250U;  /* 单体电压过压1级故障诊断阈值 */
+const uint16_T sfmc_V_cellUOverThrFlt2 = 4300U;  /* 单体电压过压2级故障诊断阈值 */
+const uint16_T sfmc_V_cellUOverThrRec1 = 4200U;  /* 单体电压过压1级故障恢复阈值 */
+const uint16_T sfmc_V_cellUOverThrRec2 = 4200U;  /* 单体电压过压2级故障恢复阈值 */
+const uint16_T sfmc_flg_cellUDiffThrFlt1 = 250U; /* 压差过大1级故障诊断阈值 */
+const uint16_T sfmc_flg_cellUDiffThrFlt2 = 300U; /* 压差过大2级故障诊断阈值 */
+const uint16_T sfmc_flg_cellUDiffThrRec1 = 250U; /* 压差过大1级故障恢复阈值 */
+const uint16_T sfmc_flg_cellUDiffThrRec2 = 250U; /* 压差过大2级故障恢复阈值 */
 
+const uint16_T sohc_Q_countThr = 60U;                            /*                    */
+const uint16_T sohc_Q_updateDeltThr = 200U;                      /*                    */
+const uint16_T socc_pct_battSocLow = 0U;                         /* SOC下限值; */
+const uint16_T socc_pct_battSocUp = 1000U;                       /* SOC上限值; */
+const int16_T socm_I_chrgCor[4] = {50, 100, 200, 400};           /* 充电CCV对应的电流数据; */
+const int16_T socm_I_disChrgCor[3] = {-400, -200, -100};         /* 放电CCV对应的电流数据; */
+const uint16_T socm_V_chrgCor[4] = {4125U, 4128U, 4132U, 4137U}; /* 充电CCV对应的电压; */
+const uint16_T socm_V_disChrgCor[3] = {3100U, 3270U, 3380U};     /* 放电CCV对应的电压; */
 
+const uint16_T tmsc_T_openThr = 45U;     /* 热管理开启温度; */
+const uint16_T tmsc_T_closeMinThr = 50U; /* 热管理关闭温度(最低模组); */
+const uint16_T tmsc_T_closeMaxThr = 70U; /* 热管理开启温度(最高模组); */

+ 7 - 1
src/EmbeddedCoder_src/BCUDisp.c

@@ -4,13 +4,13 @@
 uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
 uint16_T appv_V_cellU[28];
 boolean_T ihd_flg_HVILFlt;
-
 uint16_T blcv_Q_reqCpEi[28];                      /*均衡需求容量 读取量(数组); */
 uint16_T blcv_Q_reqCpEo[28];                      /*均衡需求容量 写入量(数组); */
 uint32_T blcv_Q_totalCpEi[28];                    /*累计均衡容量 读取量(数组); */
 uint32_T blcv_Q_totalCpEo[28];                    /*累计均衡容量 写入量(数组); */
 boolean_T blcv_flg_excute[28];                    /*均衡执行请求标志位 (数组) */
 
+boolean_T ihd_flg_DTCClear;
 uint8_T ihd_st_authFaild;                         
 int16_T ihd_I_curr;                               /*电池包电流; */
 uint8_T ihd_st_chrgConnect;                       /*充电器连接状态; */
@@ -61,6 +61,12 @@ uint16_T sfmv_T_modT[6];                          /*处理后模组温度 */
 uint16_T sfmv_V_cellU[28];                        /*处理后单体电压 */
 uint16_T sfmv_idx_fltCode[20];                    /*诊断故障码(数组) */
 uint16_T sfmd_V_battU;  
+boolean_T sfmd_flg_mainCirClosFltEi;              /*主回路常闭故障读取量 */  
+boolean_T sfmd_flg_mainCirClosFltEo;              /*主回路常闭故障写入量 */  
+boolean_T sfmd_flg_heatCirClosFltEi;              /*加热回路常闭故障读取量 */  
+boolean_T sfmd_flg_heatCirClosFltEo;              /*加热回路常闭故障写入量 */  
+boolean_T sfmd_flg_heatCirOpenFltEi;              /*加热回路常开故障读取量 */  
+boolean_T sfmd_flg_heatCirOpenFltEo;              /*加热回路常开故障写入量 */  
 
 uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 uint16_T socd_pct_estSoc;                         /*估算SOC;*/

File diff suppressed because it is too large
+ 362 - 250
src/EmbeddedCoder_src/SFM.c


+ 7 - 9
src/EmbeddedCoder_src/SOC.c

@@ -384,7 +384,7 @@ void SOC(void)
             overFlg = 1;
         }
         //
-        if(sfmd_V_cellUMax >= socc_V_chrgFulV)
+        if(sfmd_V_cellUMax >= cmnc_V_chrgFulV)
         {
             fulCntl = ( (fulCntl + 1) > 60000 ? 60000 : (fulCntl + 1));
         }
@@ -652,13 +652,11 @@ void SOC_LookUp(uint16_T battsoc, uint16_T x[], uint16_T y[],uint16_T *bcusoc)
     {
 
 	   *bcusoc =   (uint16_T) ((real_T)((battsoc - x[0]) * 0.1) * (real_T)((y[1] - y[0]) * 0.1) /(real_T)((x[1] - x[0]) * 0.1) * 10)+ y[0];
-	//*bcusoc = (uint16_T)(((((uint16_T)(((uint16_T)div_repeat_u32((uint32_T)(uint16_T)(battsoc - x[0]) * (y[1] - y[0]),(uint16_T)(x[1] - x[0]), 3U) * 5U)>> 2) * 52429U) >> 4) + ((uint32_T)y[0] << 15)) >>15);
-    }
+	}
 	//
     if (battsoc >= x[1] && battsoc < x[2]) //(x-x1)*(y2-y1)/(x2-x1)+y1
     {
        *bcusoc =   (uint16_T) ((real_T)((battsoc - x[1]) * 0.1) * (real_T)((y[2] - y[1]) * 0.1) /(real_T)((x[2] - x[1]) * 0.1) * 10)+ y[1];
-	//*bcusoc = (uint16_T)(((((uint16_T)(((uint16_T)div_repeat_u32((uint32_T)(uint16_T)(battsoc - x[1]) * (y[2] - y[1]),(uint16_T)(x[2] - x[1]), 3U) * 5U)>> 2) * 52429U) >> 4) + ((uint32_T)y[1] << 15)) >>15);
     }
 }
 //-------------------------------------------------------------------------
@@ -667,22 +665,22 @@ void SOCfit_IfActionSubsystem1(uint16_T SOC, uint16_T SOCfit_Delay, uint16_T *SO
 {
     if ((int16_T)(SOC - SOCfit_Delay) > m)
     {
-        *SOCfit=SOCfit_Delay+m;
+        *SOCfit = SOCfit_Delay + m;
     }
     else
     {
-        *SOCfit=SOC;
+        *SOCfit = SOC;
     }
 }
 //-------------------------------------------------------------------------
-void SOCfit_IfActionSubsystem2(uint16_T SOC, uint16_T SOCfit_Delay, uint16_T *SOCfit, uint16_T m)
+  void SOCfit_IfActionSubsystem2(uint16_T SOC, uint16_T SOCfit_Delay, uint16_T *SOCfit, uint16_T m)
 {
     if ((int16_T)(SOC - SOCfit_Delay) < -m)
     {
-        *SOCfit=SOCfit_Delay-m;
+        *SOCfit = SOCfit_Delay - m;
     }
     else
     {
-        *SOCfit=SOC;
+        *SOCfit = SOC;
     }
 }

+ 2 - 3
src/EmbeddedCoder_src/SOH.c

@@ -90,11 +90,10 @@ void SOH(void)
             sohn_tm_chrgStartStatEE = sohd_tm_chrgStartStatEi;
             sohn_flg_chrgEndEE = sohd_flg_chrgEndEi;
         }
-
  		//=======================================================================================
         //--------------------------计算使能-------------------------------------------------------
         //=======================================================================================
-        if(ihd_tm_parkTime > cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > 15 && !sfmd_flg_cellUDisable && sfmd_I_curr < 10 && sfmd_I_curr > -10)
+        if(ihd_tm_parkTime > cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > sohc_Q_countThr && !sfmd_flg_cellUDisable && sfmd_I_curr < 10 && sfmd_I_curr > -10)
         {
             sohn_flg_countEn = true;
         }
@@ -116,7 +115,7 @@ void SOH(void)
                 deltSoc[i] = soc2[i] - soc1[i];
                 sohv_Q_cellCapArrEo[i] = (uint16_T)( (real_T)(sohn_Q_chrgEE * 0.1) / (real_T)(deltSoc[i]  * 0.1/100)  * 10);
 				
-                if( (int16_T)(sohv_Q_cellCapArrEo[i]) -sohn_Q_cellCapArrEE[i] > 50  ||  (int16_T)(sohv_Q_cellCapArrEo[i]) -sohn_Q_cellCapArrEE[i] < -50  )
+                if( (int16_T)(sohv_Q_cellCapArrEo[i]) -sohn_Q_cellCapArrEE[i] > sohc_Q_updateDeltThr  ||  (int16_T)(sohv_Q_cellCapArrEo[i]) -sohn_Q_cellCapArrEE[i] < -sohc_Q_updateDeltThr  )
                 {
                     sohn_flg_update = false;
                     break;

+ 7 - 14
src/EmbeddedCoder_src/SPM.c

@@ -17,25 +17,18 @@ void SPM(void)
 
   static uint16_T spmd_Nr_cellNr;
 
-  uint8_T Feq = 15;
+  
   if (FirstRun_SPM)
   {
       spmd_Nr_cellNr =0;
-      cand_Nr_cellNr = 1;
   }
   spmd_Nr_cellNr = spmd_Nr_cellNr + 1;
-  if(spmd_Nr_cellNr>=60000U)
-  {
-    spmd_Nr_cellNr = 0;
-  }
-  if(spmd_Nr_cellNr%(Feq*10)==0)
+  if (spmd_Nr_cellNr >= cmnc_num_cellUNum * 10)
   {
-    cand_Nr_cellNr++;
-  }
-  if (cand_Nr_cellNr > cmnc_num_cellUNum)
-  {
-     cand_Nr_cellNr = 1;
+     spmd_Nr_cellNr = 0;
   }
+  cand_Nr_cellNr = (uint16_T)(spmd_Nr_cellNr * 0.1) + 1;
+  
   SOH();
   BLC();
   if (!ihd_flg_urtRecFlt)
@@ -45,10 +38,10 @@ void SPM(void)
 
   
   cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_Nr_cellNr-1];
-  cand_V_chrgStartStat=sohv_V_chrgStartStatEo[cand_Nr_cellNr-1];
+  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_Nr_cellNr-1];
   cand_Q_reqCp   = blcv_Q_reqCpEo[cand_Nr_cellNr-1];
   cand_Q_totalCp = blcv_Q_totalCpEo[cand_Nr_cellNr-1];
-  FirstRun_SPM =false;
+  FirstRun_SPM = false;
 }
 
 

+ 33 - 13
src/EmbeddedCoder_src/TMS.c

@@ -1,10 +1,18 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 11:29:45
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 15:53:09
+ * @Description  : file content
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\EmbeddedCoder_src\TMS.c
+ */
 #include "TMS.h"
 
-
 boolean_T FirstRun_TMS;
 void TMS_Init(void)
 {
-    FirstRun_TMS =true;
+    FirstRun_TMS = true;
 }
 
 void TMS(void)
@@ -12,7 +20,7 @@ void TMS(void)
     static uint8_T TminLowNr;
     static uint8_T TminOverNr;
     static uint8_T TmaxOverNr;
-    
+
     //初始值
     if (FirstRun_TMS)
     {
@@ -21,7 +29,7 @@ void TMS(void)
         TminOverNr = 0;
         TmaxOverNr = 0;
     }
-    
+
     //
     if (sfmd_T_modTMin < tmsc_T_openThr)
     {
@@ -49,26 +57,38 @@ void TMS(void)
     {
         TmaxOverNr = 0;
     }
-    
-    //=====================================================================
+
+    //================================温度判定 开关热管理状态===============================
     if (tmsd_st_heatAct == 0)
     {
-        if((TminLowNr >= 20 && ihd_st_chrgConnect == 1)||(TminLowNr >= 20 && ihd_st_chrgConnect == 0 && socd_pct_battSoc > 100))
+        if (TminLowNr >= 20 && ((ihd_st_chrgConnect == 0 && socd_pct_battSoc > 100) || ihd_st_chrgConnect == 1))
         {
             tmsd_st_heatAct = 1;
         }
     }
     else
     {
-        if(TmaxOverNr >= 20 || TminOverNr >= 20 || (ihd_st_chrgConnect == 0 && socd_pct_battSoc < 50))
+        if (TmaxOverNr >= 20 || TminOverNr >= 20 || (ihd_st_chrgConnect == 0 && socd_pct_battSoc < 50))
         {
             tmsd_st_heatAct = 0;
         }
     }
-	if (((sfmd_st_fltAct >> 4) & 0x01) == 1)
-	{
-	    tmsd_st_heatAct = 0;
-	}
-    FirstRun_TMS = false;
 
+    //因故障关闭热管理
+    if (((sfmd_st_fltAct >> 4) & 0x01) == 1)
+    {
+        tmsd_st_heatAct = 0;
+    }
+
+    //强制控制加热回路
+    if (HeatForceControl == 1)
+    {
+        tmsd_st_heatAct = 1;
+    }
+    if (HeatForceControl == 2)
+    {
+        tmsd_st_heatAct = 0;
+    }
+
+    FirstRun_TMS = false;
 }

+ 80 - 79
src/bsp_custom.c

@@ -14,9 +14,9 @@
 #include "plat_config.h"
 #include "debug_log.h"
 #include "os_exception.h"
-#if (WDT_FEATURE_ENABLE==1)
+#if (WDT_FEATURE_ENABLE == 1)
 #include "wdt_ec616.h"
-#define WDT_TIMEOUT_VALUE     (20)            // in unit of second, shall be less than 256s
+#define WDT_TIMEOUT_VALUE (20) // in unit of second, shall be less than 256s
 #endif
 #include "AppSignal.h"
 #ifdef BL_FILE_LOG
@@ -51,7 +51,7 @@ extern ARM_DRIVER_USART Driver_USART1;
  */
 static void SetPrintUart(usart_port_t port)
 {
-    if(port == PORT_USART_0)
+    if (port == PORT_USART_0)
     {
 #if (RTE_UART0)
         UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 0);
@@ -61,7 +61,7 @@ static void SetPrintUart(usart_port_t port)
         GPR_SWReset(GPR_ResetUART0Func);
 #endif
     }
-    else if(port == PORT_USART_1)
+    else if (port == PORT_USART_1)
     {
 #if (RTE_UART1)
         UsartPrintHandle = &CREATE_SYMBOL(Driver_USART, 1);
@@ -72,22 +72,22 @@ static void SetPrintUart(usart_port_t port)
 #endif
     }
 
-    if(UsartPrintHandle == NULL)
+    if (UsartPrintHandle == NULL)
         return;
 
     UsartPrintHandle->Initialize(NULL);
     UsartPrintHandle->PowerControl(ARM_POWER_FULL);
     UsartPrintHandle->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
-                        ARM_USART_PARITY_NONE       | ARM_USART_STOP_BITS_1 |
-                        ARM_USART_FLOW_CONTROL_NONE, 115200ul);
+                                  ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
+                                  ARM_USART_FLOW_CONTROL_NONE,
+                              115200ul);
 }
 
-
 #if LOW_POWER_AT_TEST
 slpManSlpState_t CheckUsrdefSlpStatus(void)
 {
     slpManSlpState_t status = SLP_HIB_STATE;
-    if((slpManGetWakeupPinValue() & (0x1<<1)) == 0)         // pad2 value is low
+    if ((slpManGetWakeupPinValue() & (0x1 << 1)) == 0) // pad2 value is low
         status = SLP_IDLE_STATE;
     else
         status = SLP_HIB_STATE;
@@ -101,38 +101,38 @@ slpManSlpState_t CheckUsrdefSlpStatus(void)
   \brief      CheckLockOutState
   \param     void
  */
-void CheckLockOutState(void){
-	if((slpManGetWakeupPinValue() & (0x1<<2)) == 0)
+void CheckLockOutState(void)
+{
+    if ((slpManGetWakeupPinValue() & (0x1 << 2)) == 0)
     {
-		#ifdef USING_PRINTF
-			printf("LOCK_OUT DOWN\r\n");
-		#endif	
+#ifdef USING_PRINTF
+        printf("LOCK_OUT DOWN\r\n");
+#endif
         Lockstatus = true;
-		 #ifdef BL_FILE_LOG
-			 lockoutState=1;
-		#endif
-	}
+#ifdef BL_FILE_LOG
+        lockoutState = 1;
+#endif
+    }
     else
     {
         Lockstatus = false;
-		#ifdef USING_PRINTF
-			printf("LOCK_OUT UP\r\n");
-		#endif	
-		 #ifdef BL_FILE_LOG
-			 lockoutState=0;
-		#endif
-	}
+#ifdef USING_PRINTF
+        printf("LOCK_OUT UP\r\n");
+#endif
+#ifdef BL_FILE_LOG
+        lockoutState = 0;
+#endif
+    }
 }
 
-
 static void PMU_WakeupPadInit(void)
 {
     const padWakeupSettings_t cfg =
-    {
-        false, true,             // group0 posedge, negedge
-        true, true,             // group1 posedge, negedge
-        true, true,             // group2 posedge, negedge
-    };
+        {
+            false, true, // group0 posedge, negedge
+            true, true,  // group1 posedge, negedge
+            true, true,  // group2 posedge, negedge
+        };
 
     slpManSetWakeupPad(cfg);
 }
@@ -157,17 +157,18 @@ void NMI_Handler()
 {
     ECOMM_TRACE(UNILOG_PLA_APP, enter_NMI_handler, P_ERROR, 0, "WDT timeout!!! Enter NMI Handler!!!");
     // If we have been in exception handler excecution, we shall resume it.
-    if(is_in_excep_handler())
+    if (is_in_excep_handler())
     {
         WDT_Stop();
     }
     else
     {
-        if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION) == EXCEP_OPTION_SILENT_RESET)
+        if (BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION) == EXCEP_OPTION_SILENT_RESET)
         {
             ResetReasonWrite(RESET_REASON_WDT);
             EC_SystemReset();
-            while(1);
+            while (1)
+                ;
         }
         else
         {
@@ -186,7 +187,7 @@ void BSP_CustomInit(void)
 {
     extern void mpu_init(void);
     mpu_init();
-	
+
     GPR_SetUartClk();
     relayConfigInit();
 
@@ -194,15 +195,15 @@ void BSP_CustomInit(void)
     //slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);  //暂时屏蔽Rx拉低不允许睡眠的操作
 #endif
 
-    plat_config_raw_flash_t* rawFlashPlatConfig;
+    plat_config_raw_flash_t *rawFlashPlatConfig;
 
     BSP_LoadPlatConfigFromRawFlash();
     rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
 #if 1
 #ifdef USING_PRINTF
-	SetPrintUart(PORT_USART_0);
+    SetPrintUart(PORT_USART_0);
 #else
-    if(rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0 ))
+    if (rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0))
     {
         SetUnilogUart(PORT_USART_0, rawFlashPlatConfig->uartBaudRate, true);
         uniLogInitStart(UART_0_FOR_UNILOG);
@@ -211,36 +212,36 @@ void BSP_CustomInit(void)
 #endif
 #endif
 #if (WDT_FEATURE_ENABLE == 1)
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_START_WDT))
+    if (BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_START_WDT))
     {
         BSP_WdtInit();
         WDT_Start();
     }
 #endif
-	slpManGetPMUSettings();				
+    slpManGetPMUSettings();
     ResetReasonInit();
-	PMU_WakeupPadInit();
-	NVIC_EnableIRQ(PadWakeup0_IRQn);//can
-	NVIC_DisableIRQ(PadWakeup1_IRQn);//rx
-	NVIC_EnableIRQ(PadWakeup2_IRQn);//lock
-	NVIC_DisableIRQ(PadWakeup3_IRQn);//gsensor
-	NVIC_DisableIRQ(PadWakeup4_IRQn);//gsensor
-	NVIC_EnableIRQ(PadWakeup5_IRQn);//wakeup2
-	CheckLockOutState();
-	slpManStartWaitATTimer();
+    PMU_WakeupPadInit();
+    NVIC_EnableIRQ(PadWakeup0_IRQn);  //can
+    NVIC_DisableIRQ(PadWakeup1_IRQn); //rx
+    NVIC_EnableIRQ(PadWakeup2_IRQn);  //lock
+    NVIC_DisableIRQ(PadWakeup3_IRQn); //gsensor
+    NVIC_DisableIRQ(PadWakeup4_IRQn); //gsensor
+    NVIC_EnableIRQ(PadWakeup5_IRQn);  //wakeup2
+    CheckLockOutState();
+    slpManStartWaitATTimer();
 
-	CanSPIHandler(NULL,ARM_SPI_CPOL0_CPHA0,8,200000U);
+    CanSPIHandler(NULL, ARM_SPI_CPOL0_CPHA0, 8, 200000U);
 
-	slpManAONIOPowerOn();
-	PowerPinConfig(AON_IO);
-	PowerPinConfig(NORMAL_IO);
-	posGGAReset();
-	GPSUsartHandler(9600);
-	NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-	NetSocDisplay(LED_SOC_3,LED_TURN_ON);
-	FaultDisplay(LED_TURN_ON);
+    slpManAONIOPowerOn();
+    PowerPinConfig(AON_IO);
+    PowerPinConfig(NORMAL_IO);
+    posGGAReset();
+    GPSUsartHandler(9600);
+    NetSocDisplay(LED_SOC_0, LED_TURN_ON);
+    NetSocDisplay(LED_SOC_1, LED_TURN_ON);
+    NetSocDisplay(LED_SOC_2, LED_TURN_ON);
+    NetSocDisplay(LED_SOC_3, LED_TURN_ON);
+    FaultDisplay(LED_TURN_ON);
 }
 
 /**
@@ -250,79 +251,79 @@ void BSP_CustomInit(void)
  */
 void Pad0_WakeupIntHandler(void)
 {
-    if(slpManExtIntPreProcess(PadWakeup0_IRQn)==false)
+    if (slpManExtIntPreProcess(PadWakeup0_IRQn) == false)
     {
         return;
     }
     else
     {
-        setbit(PadInterrupt,0);
+        setbit(PadInterrupt, 0);
     }
-    #ifdef USING_PRINTF1
-        printf("-[%d]-[%s]\n",__LINE__, __FUNCTION__);
-    #endif
+#ifdef USING_PRINTF1
+    printf("-[%d]-[%s]\n", __LINE__, __FUNCTION__);
+#endif
 }
 
 void Pad1_WakeupIntHandler(void)
 {
-    if(slpManExtIntPreProcess(PadWakeup1_IRQn)==false)
+    if (slpManExtIntPreProcess(PadWakeup1_IRQn) == false)
     {
         return;
     }
     else
     {
-        #ifdef USING_PRINTF
-        printf("Pad1-[%d]\n",__LINE__);
-        #endif
-        setbit(PadInterrupt,1);
+#ifdef USING_PRINTF
+        printf("Pad1-[%d]\n", __LINE__);
+#endif
+        setbit(PadInterrupt, 1);
     }
 }
 
 void Pad2_WakeupIntHandler(void)
 {
-     CheckLockOutState();
-    if(slpManExtIntPreProcess(PadWakeup2_IRQn)==false)
+    CheckLockOutState();
+    if (slpManExtIntPreProcess(PadWakeup2_IRQn) == false)
     {
         return;
     }
     else
     {
-        setbit(PadInterrupt,2);
+        setbit(PadInterrupt, 2);
     }
 }
 
 void Pad3_WakeupIntHandler(void)
 {
-    if(slpManExtIntPreProcess(PadWakeup3_IRQn)==false)
+    if (slpManExtIntPreProcess(PadWakeup3_IRQn) == false)
     {
         return;
     }
     else
     {
-        setbit(PadInterrupt,3);
+        setbit(PadInterrupt, 3);
     }
 }
 
 void Pad4_WakeupIntHandler(void)
 {
-    if(slpManExtIntPreProcess(PadWakeup4_IRQn)==false)
+    if (slpManExtIntPreProcess(PadWakeup4_IRQn) == false)
     {
         return;
     }
     else
     {
-        setbit(PadInterrupt,4);
+        setbit(PadInterrupt, 4);
     }
 }
 
 void Pad5_WakeupIntHandler(void)
 {
-    if(slpManExtIntPreProcess(PadWakeup5_IRQn)==false)
+    if (slpManExtIntPreProcess(PadWakeup5_IRQn) == false)
     {
         return;
     }
     else
     {
-        setbit(PadInterrupt,5);
+        setbit(PadInterrupt, 5);
     }
 }

File diff suppressed because it is too large
+ 330 - 323
src/hal_module_adapter.c


+ 345 - 355
src/sensor.c

@@ -1,329 +1,326 @@
 #include "sensor.h"
 
-#if 1//def _SC7A20_
+#if 1 //def _SC7A20_
 /***************���߲���**********************/
 INT8 SL_SC7A20_Online_Test(void)
 {
-    UINT8 SL_Read_Reg=0xff;
-    GSENSOR_ReadReg(SC7A20_CHIP_ID_ADDRESS,1, &SL_Read_Reg); 
-    printf("SL_Read_Reg = %#x\r\n",SL_Read_Reg);	
-    if(SL_Read_Reg==SC7A20_CHIP_ID_VALUE){
-	return  1;
-   } else { 
-   	return -1;
-   }
+    UINT8 SL_Read_Reg = 0xff;
+    GSENSOR_ReadReg(SC7A20_CHIP_ID_ADDRESS, 1, &SL_Read_Reg);
+    printf("SL_Read_Reg = %#x\r\n", SL_Read_Reg);
+    if (SL_Read_Reg == SC7A20_CHIP_ID_VALUE)
+    {
+        return 1;
+    }
+    else
+    {
+        return -1;
+    }
 }
 
 /***************BOOT �����ڲ��Ĵ���ֵ*********************/
-INT8  SL_SC7A20_BOOT(void)
+INT8 SL_SC7A20_BOOT(void)
 {
-    UINT8 SL_Read_Reg=0xff;
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_SC7A20_BOOT_ENABLE;//|SL_Read_Reg;
+    UINT8 SL_Read_Reg = 0xff;
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_SC7A20_BOOT_ENABLE; //|SL_Read_Reg;
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
-    return  1;
+    return 1;
 }
 
-
 /***************��������������**********************/
-INT8  SL_SC7A20_FS_Config(UINT8 Sc7a20_FS_Reg)
+INT8 SL_SC7A20_FS_Config(UINT8 Sc7a20_FS_Reg)
 {
-    UINT8 SL_Read_Reg=0xff,SL_Write_Reg;
+    UINT8 SL_Read_Reg = 0xff, SL_Write_Reg;
 
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG4,1, &SL_Read_Reg); 
-    SL_Write_Reg=0x80|Sc7a20_FS_Reg|SL_SC7A20_HR_ENABLE;
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG4, 1, &SL_Read_Reg);
+    SL_Write_Reg = 0x80 | Sc7a20_FS_Reg | SL_SC7A20_HR_ENABLE;
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG4, SL_Write_Reg);
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG4,1, &SL_Read_Reg); 
-    if(SL_Read_Reg==SL_Write_Reg) {
-	return  1;
-    }else{
-    	return -1;
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG4, 1, &SL_Read_Reg);
+    if (SL_Read_Reg == SL_Write_Reg)
+    {
+        return 1;
+    }
+    else
+    {
+        return -1;
     }
 }
 
-#if SL_6D4D2D1D_SEL==1  //1D
+#if SL_6D4D2D1D_SEL == 1 //1D
 //AOI1_INT1  �˶���⣬�˶������ж�        6D�˶����
 //AOI2_INT2  λ�ü�⣬����Ƿ��뿪X+λ��  1Dλ��ʶ��
 /***************�����*************/
-INT8  SL_SC7A20_INT_Config(void)
+INT8 SL_SC7A20_INT_Config(void)
 {
     UINT8 SL_Read_Reg;
 
     /*******************AOI1  IN  INT1********************/
-    SL_Read_Reg=0x08;//AOI1 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg); 
-    
-    SL_Read_Reg=SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
+    SL_Read_Reg = 0x08; //AOI1 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
+
+    SL_Read_Reg = SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
     //interrupt happen,int pin output lower level
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
-    
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
+
     //AOI1 CONFIG
-    SL_Read_Reg=0x00;            //0x7F
-    SL_Read_Reg=SL_Read_Reg|0x40;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x02;//X ����¼� X�����ݵľ���ֵ������ֵ
-    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0x7F
+    SL_Read_Reg = SL_Read_Reg | 0x40; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x02; //X ����¼� X�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);
 
     //HPF SET
-  //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    SL_Read_Reg=0xcf;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
+    //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    SL_Read_Reg = 0xcf; //SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
-    
+
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-        
+
     //AOI1 TO INT1
-   // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
-    SL_Read_Reg=0x40;//SL_Read_Reg|0x40; //AOI1 TO INT1
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);  
+    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
+    SL_Read_Reg = 0x40; //SL_Read_Reg|0x40; //AOI1 TO INT1
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);
     /*******************AOI1  IN  INT1********************/
 
-
     /*******************AOI2  IN  INT2********************/
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x02;//AOI2 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);	
-    
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x02; //AOI2 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
 
     //AOI2 CONFIG
-    SL_Read_Reg=0x00;            //0xFF
-    SL_Read_Reg=SL_Read_Reg|0xC0;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x02;//X ����¼� X�����ݵľ���ֵ������ֵ
-    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0xFF
+    SL_Read_Reg = SL_Read_Reg | 0xC0; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x02; //X ����¼� X�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);
 
     //HPF SET
-   // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    //SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2 
-   // GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
+    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    //SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2
+    // GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-    
+
     //AOI2 TO INT2
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x20; //AOI2 TO INT2
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x20; //AOI2 TO INT2
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
     /*******************AOI2  IN  INT2********************/
 
-    return  1;
+    return 1;
 }
-#elif  SL_6D4D2D1D_SEL==2  //2D
-//AOI1_INT1  �˶���⣬�˶������ж� ���¼�   3D�˶���� 
+#elif SL_6D4D2D1D_SEL == 2 //2D
+//AOI1_INT1  �˶���⣬�˶������ж� ���¼�   3D�˶����
 //AOI2_INT2  λ�ü�⣬���X+ �� X-          2Dλ��ʶ��
 /***************�����*************/
-INT8  SL_SC7A20_INT_Config(void)
+INT8 SL_SC7A20_INT_Config(void)
 {
     UINT8 SL_Read_Reg;
 
     /*******************AOI1  IN  INT1********************/
-    SL_Read_Reg=0x08;//AOI1 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg); 
-    
-    SL_Read_Reg=SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
+    SL_Read_Reg = 0x08; //AOI1 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
+
+    SL_Read_Reg = SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
     //interrupt happen,int pin output lower level
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
-    
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
+
     //AOI1 CONFIG
-    SL_Read_Reg=0x00;            //0x7F
-    SL_Read_Reg=SL_Read_Reg|0x40;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x02;//X ����¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x04;//Y ����¼� Y�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0x7F
+    SL_Read_Reg = SL_Read_Reg | 0x40; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x02; //X ����¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x04; //Y ����¼� Y�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);
 
     //HPF SET
-  //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    SL_Read_Reg=0xcf;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
+    //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    SL_Read_Reg = 0xcf; //SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
-    
+
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-        
+
     //AOI1 TO INT1
-   // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
-    SL_Read_Reg=0x40;//SL_Read_Reg|0x40; //AOI1 TO INT1
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);  
+    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
+    SL_Read_Reg = 0x40; //SL_Read_Reg|0x40; //AOI1 TO INT1
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);
     /*******************AOI1  IN  INT1********************/
 
-
     /*******************AOI2  IN  INT2********************/
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x02;//AOI2 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);	
-    
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x02; //AOI2 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
 
     //AOI2 CONFIG
-    SL_Read_Reg=0x00;            //0xFF
-    SL_Read_Reg=SL_Read_Reg|0xC0;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x02;//X ����¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x04;//Y ����¼� Y�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0xFF
+    SL_Read_Reg = SL_Read_Reg | 0xC0; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x02; //X ����¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x04; //Y ����¼� Y�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);
 
     //HPF SET
-    //GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    //SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2 
+    //GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    //SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2
     //GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-    
+
     //AOI2 TO INT2
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x20; //AOI2 TO INT2
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x20; //AOI2 TO INT2
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
     /*******************AOI2  IN  INT2********************/
 
-    return  1;
+    return 1;
 }
-#elif  SL_6D4D2D1D_SEL==4  //4D
-//AOI1_INT1  �˶���⣬�˶������ж� ���¼�     3D�˶���� 
+#elif SL_6D4D2D1D_SEL == 4 //4D
+//AOI1_INT1  �˶���⣬�˶������ж� ���¼�     3D�˶����
 //AOI2_INT2  λ�ü�⣬���X+ �� X-  Y+ �� Y-  4Dλ��ʶ��
 /***************�����*************/
-INT8  SL_SC7A20_INT_Config(void)
+INT8 SL_SC7A20_INT_Config(void)
 {
     UINT8 SL_Read_Reg;
 
     /*******************AOI1  IN  INT1********************/
-    SL_Read_Reg=0x08;//AOI1 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg); 
-    
-    SL_Read_Reg=SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
+    SL_Read_Reg = 0x08; //AOI1 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
+
+    SL_Read_Reg = SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
     //interrupt happen,int pin output lower level
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
-    
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
+
     //AOI1 CONFIG
-    SL_Read_Reg=0x00;            //0x7F
-    SL_Read_Reg=SL_Read_Reg|0x40;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x03;//X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x0C;//Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0x7F
+    SL_Read_Reg = SL_Read_Reg | 0x40; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x03; //X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x0C; //Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);
 
     //HPF SET
-  //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    SL_Read_Reg=0xcf;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
+    //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    SL_Read_Reg = 0xcf; //SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
-    
+
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-        
+
     //AOI1 TO INT1
-   // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
-    SL_Read_Reg=0x40;//SL_Read_Reg|0x40; //AOI1 TO INT1
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);  
+    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
+    SL_Read_Reg = 0x40; //SL_Read_Reg|0x40; //AOI1 TO INT1
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);
     /*******************AOI1  IN  INT1********************/
 
-
     /*******************AOI2  IN  INT2********************/
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x02;//AOI2 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);	
-    
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x02; //AOI2 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
 
     //AOI2 CONFIG
-    SL_Read_Reg=0x00;            //0xFF
-    SL_Read_Reg=SL_Read_Reg|0xC0;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x03;//X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x0C;//Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0xFF
+    SL_Read_Reg = SL_Read_Reg | 0xC0; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x03; //X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x0C; //Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);
 
     //HPF SET
-    //GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-   // SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2 
-   // GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
+    //GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    // SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2
+    // GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_10PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-    
+
     //AOI2 TO INT2
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x20; //AOI2 TO INT2
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x20; //AOI2 TO INT2
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
     /*******************AOI2  IN  INT2********************/
 
-    return  1;
+    return 1;
 }
-#elif  SL_6D4D2D1D_SEL==6  //6D
+#elif SL_6D4D2D1D_SEL == 6 //6D
 //AOI1_INT1  �˶���⣬�˶������ж�                    6D�˶����
 //AOI2_INT2  λ�ü�⣬���X+ �� X-  Y+ �� Y- Z+ �� Z- 6Dλ��ʶ��
 /***************�����*************/
-INT8  SL_SC7A20_INT_Config(void)
+INT8 SL_SC7A20_INT_Config(void)
 {
     UINT8 SL_Read_Reg;
 
     /*******************AOI1  IN  INT1********************/
-    SL_Read_Reg=0x08;//AOI1 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg); 
-    
-    SL_Read_Reg=SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
+    SL_Read_Reg = 0x08; //AOI1 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
+
+    SL_Read_Reg = SL_SC7A20_INT_ACTIVE_HIGH_LEVEL;
     //interrupt happen,int pin output lower level
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
-    
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
+
     //AOI1 CONFIG
-    SL_Read_Reg=0x00;            //0x7F
-    SL_Read_Reg=SL_Read_Reg|0x40;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x03;//X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x0C;//Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ	
-    SL_Read_Reg=SL_Read_Reg|0x30;//Z ��ߵ��¼� Z�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0x7F
+    SL_Read_Reg = SL_Read_Reg | 0x40; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x03; //X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x0C; //Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x30; //Z ��ߵ��¼� Z�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, SL_Read_Reg);
 
     //HPF SET
-  //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    SL_Read_Reg=0xcf;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
+    //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg);
+    SL_Read_Reg = 0xcf; //SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
-    
+
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_20PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_20PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_30CLK);
-        
+
     //AOI1 TO INT1
-   // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
-    SL_Read_Reg=0x40;//SL_Read_Reg|0x40; //AOI1 TO INT1
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);  
+    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
+    SL_Read_Reg = 0x40; //SL_Read_Reg|0x40; //AOI1 TO INT1
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG3, SL_Read_Reg);
     /*******************AOI1  IN  INT1********************/
 
-
     /*******************AOI2  IN  INT2********************/
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x02;//AOI2 LATCH
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);	
-    
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG5, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x02; //AOI2 LATCH
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG5, SL_Read_Reg);
 
     //AOI2 CONFIG
-    SL_Read_Reg=0x00;            //0xFF
-    SL_Read_Reg=SL_Read_Reg|0xc0;//�����˶�ʶ��ģʽ
-    SL_Read_Reg=SL_Read_Reg|0x03;//X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
-    SL_Read_Reg=SL_Read_Reg|0x0C;//Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ	
-    SL_Read_Reg=SL_Read_Reg|0x30;//Z ��ߵ��¼� Z�����ݵľ���ֵ������ֵ	
-    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);    
+    SL_Read_Reg = 0x00;               //0xFF
+    SL_Read_Reg = SL_Read_Reg | 0xc0; //�����˶�ʶ��ģʽ
+    SL_Read_Reg = SL_Read_Reg | 0x03; //X ��ߵ��¼� X�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x0C; //Y ��ߵ��¼� Y�����ݵľ���ֵ������ֵ
+    SL_Read_Reg = SL_Read_Reg | 0x30; //Z ��ߵ��¼� Z�����ݵľ���ֵ������ֵ
+    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, SL_Read_Reg);
 
     //HPF SET
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
- //   SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2 
-//    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2, 1, &SL_Read_Reg);
+    //   SL_Read_Reg=SL_Read_Reg&0xFD;//NO HPF TO AOI2
+    //    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_5PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_5PERCENT);
     //������ֵ����ʱ�䴥���ж�
     GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_2CLK);
-    
+
     //AOI2 TO INT2
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
-    SL_Read_Reg=SL_Read_Reg|0x20; //AOI2 TO INT2
-    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);  
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | 0x20; //AOI2 TO INT2
+    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG6, SL_Read_Reg);
     /*******************AOI2  IN  INT2********************/
 
-    return  1;
+    return 1;
 }
 #endif
 
@@ -334,50 +331,50 @@ INT8  SL_SC7A20_INT_Config(void)
 //retrun_value&0x20=0x04  YL  Y����¼�
 //retrun_value&0x20=0x02  XH  X����¼�
 //retrun_value&0x20=0x01  XL  X����¼�
-INT8  SL_SC7A20_INT_RESET(void)
+INT8 SL_SC7A20_INT_RESET(void)
 {
 
     UINT8 SL_Read_Reg1;
     UINT8 SL_Read_Reg2;
-    
-    /*****Ϊ�˱����ȡ���ݹ������ֲ����жϣ�������ʱ�ر��ж�*****/	
- 
+
+    /*****Ϊ�˱����ȡ���ݹ������ֲ����жϣ�������ʱ�ر��ж�*****/
+
     //SL_Read_Reg1 display the int1 type
-    GSENSOR_ReadReg(SL_SC7A20_INT1_SRC,1, &SL_Read_Reg1);
+    GSENSOR_ReadReg(SL_SC7A20_INT1_SRC, 1, &SL_Read_Reg1);
     //SL_Read_Reg2 display the int2 type
-    GSENSOR_ReadReg(SL_SC7A20_INT2_SRC,1, &SL_Read_Reg2);
-    
+    GSENSOR_ReadReg(SL_SC7A20_INT2_SRC, 1, &SL_Read_Reg2);
+
     //close INT1
     GSENSOR_WriteReg(SL_SC7A20_INT1_CFG, 0x00);
     //close INT2
-    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, 0x00);     
-    
-    if((SL_Read_Reg2&0x02)==0x02)
+    GSENSOR_WriteReg(SL_SC7A20_INT2_CFG, 0x00);
+
+    if ((SL_Read_Reg2 & 0x02) == 0x02)
     {
         //X+
     }
-    if((SL_Read_Reg2&0x01)==0x01)
+    if ((SL_Read_Reg2 & 0x01) == 0x01)
     {
         //X-
     }
-    if((SL_Read_Reg2&0x08)==0x08)
+    if ((SL_Read_Reg2 & 0x08) == 0x08)
     {
         //Y+
     }
-    if((SL_Read_Reg2&0x04)==0x04)
+    if ((SL_Read_Reg2 & 0x04) == 0x04)
     {
         //Y-
     }
-    if((SL_Read_Reg2&0x20)==0x20)
+    if ((SL_Read_Reg2 & 0x20) == 0x20)
     {
         //Z+
     }
-    if((SL_Read_Reg2&0x10)==0x10)
+    if ((SL_Read_Reg2 & 0x10) == 0x10)
     {
         //Z-
     }
-    
-    if(SL_Read_Reg1!=0||SL_Read_Reg2!=0)
+
+    if (SL_Read_Reg1 != 0 || SL_Read_Reg2 != 0)
     {
         return 1;
     }
@@ -385,198 +382,190 @@ INT8  SL_SC7A20_INT_RESET(void)
     {
         return 0;
     }
-
 }
 
-
-void  SL_SC7A20_AOI1_event(void)
+void SL_SC7A20_AOI1_event(void)
 {
 
     UINT8 SL_SRC_Reg1;
     UINT8 SL_THS_Reg1;
     UINT8 SL_DURATION_Reg1;
- 
- 
+
     //SL_Read_Reg1 display the int1 type
-    GSENSOR_ReadReg(SL_SC7A20_INT1_SRC,1, &SL_SRC_Reg1);
-    GSENSOR_ReadReg(SL_SC7A20_INT1_THS,1, &SL_THS_Reg1);
-    GSENSOR_ReadReg(SL_SC7A20_INT1_DURATION,1, &SL_DURATION_Reg1);
-	
-    printf("SL_SC7A20_INT1_SRC=%#x\r\n",SL_SRC_Reg1);	
- //   if((SL_SRC_Reg1&0x40)==0x40){
-
-	    if((SL_SRC_Reg1&0x01)==0x01)
-	    {
-	        //X-
-		    printf("X1-\r\n");	
-	    }
-	    if((SL_SRC_Reg1&0x02)==0x02)
-	    {
-	        //X+
-		    printf("X1+\r\n");	
-	    }
-	    if((SL_SRC_Reg1&0x04)==0x04)
-	    {
-	        //Y-
-		    printf("Y1-\r\n");	
-	    }
-	    if((SL_SRC_Reg1&0x08)==0x08)
-	    {
-	        //Y+
-		    printf("Y1+\r\n");	
-	    }
-	    if((SL_SRC_Reg1&0x10)==0x10)
-	    {
-	        //Z-
-		    printf("Z1-\r\n");	
-	    }
-	    if((SL_SRC_Reg1&0x20)==0x20)
-	    {
-	        //Z+
-		    printf("Z1+\r\n");	
-	    }
-//    }
-    
-}
+    GSENSOR_ReadReg(SL_SC7A20_INT1_SRC, 1, &SL_SRC_Reg1);
+    GSENSOR_ReadReg(SL_SC7A20_INT1_THS, 1, &SL_THS_Reg1);
+    GSENSOR_ReadReg(SL_SC7A20_INT1_DURATION, 1, &SL_DURATION_Reg1);
 
+    printf("SL_SC7A20_INT1_SRC=%#x\r\n", SL_SRC_Reg1);
+    //   if((SL_SRC_Reg1&0x40)==0x40){
 
-INT8  SL_SC7A20_AOI2_event(void)
+    if ((SL_SRC_Reg1 & 0x01) == 0x01)
+    {
+        //X-
+        printf("X1-\r\n");
+    }
+    if ((SL_SRC_Reg1 & 0x02) == 0x02)
+    {
+        //X+
+        printf("X1+\r\n");
+    }
+    if ((SL_SRC_Reg1 & 0x04) == 0x04)
+    {
+        //Y-
+        printf("Y1-\r\n");
+    }
+    if ((SL_SRC_Reg1 & 0x08) == 0x08)
+    {
+        //Y+
+        printf("Y1+\r\n");
+    }
+    if ((SL_SRC_Reg1 & 0x10) == 0x10)
+    {
+        //Z-
+        printf("Z1-\r\n");
+    }
+    if ((SL_SRC_Reg1 & 0x20) == 0x20)
+    {
+        //Z+
+        printf("Z1+\r\n");
+    }
+    //    }
+}
+
+INT8 SL_SC7A20_AOI2_event(void)
 {
 
     UINT8 SL_SRC_Reg2;
     UINT8 SL_THS_Reg2;
     UINT8 SL_DURATION_Reg2;
- 
- 
+
     //SL_Read_Reg1 display the int1 type
-    GSENSOR_ReadReg(SL_SC7A20_INT2_SRC,1, &SL_SRC_Reg2);
-    GSENSOR_ReadReg(SL_SC7A20_INT2_THS,1, &SL_THS_Reg2);
-    GSENSOR_ReadReg(SL_SC7A20_INT2_DURATION,1, &SL_DURATION_Reg2);
-	
-    printf("SL_SC7A20_INT2_SRC=%#x\r\n",SL_SRC_Reg2);	
-  //  if((SL_SRC_Reg2&0x40)==0x40){
-
-	    if((SL_SRC_Reg2&0x01)==0x01)
-	    {
-	        //X-
-		    printf("X2-\r\n");	
-	    }
-	    if((SL_SRC_Reg2&0x02)==0x02)
-	    {
-	        //X+
-		    printf("X2+\r\n");	
-	    }
-	    if((SL_SRC_Reg2&0x04)==0x04)
-	    {
-	        //Y-
-		    printf("Y2-\r\n");	
-	    }
-	    if((SL_SRC_Reg2&0x08)==0x08)
-	    {
-	        //Y+
-		    printf("Y2+\r\n");	
-	    }
-	    if((SL_SRC_Reg2&0x10)==0x10)
-	    {
-	        //Z-
-		    printf("Z2-\r\n");	
-	    }
-	    if((SL_SRC_Reg2&0x20)==0x20)
-	    {
-	        //Z+
-		    printf("Z2+\r\n");	
-	    }
- //   }
-    
-}
+    GSENSOR_ReadReg(SL_SC7A20_INT2_SRC, 1, &SL_SRC_Reg2);
+    GSENSOR_ReadReg(SL_SC7A20_INT2_THS, 1, &SL_THS_Reg2);
+    GSENSOR_ReadReg(SL_SC7A20_INT2_DURATION, 1, &SL_DURATION_Reg2);
 
+    printf("SL_SC7A20_INT2_SRC=%#x\r\n", SL_SRC_Reg2);
+    //  if((SL_SRC_Reg2&0x40)==0x40){
 
-void  SL_SC7A20_Reg_read_all(void)
+    if ((SL_SRC_Reg2 & 0x01) == 0x01)
+    {
+        //X-
+        printf("X2-\r\n");
+    }
+    if ((SL_SRC_Reg2 & 0x02) == 0x02)
+    {
+        //X+
+        printf("X2+\r\n");
+    }
+    if ((SL_SRC_Reg2 & 0x04) == 0x04)
+    {
+        //Y-
+        printf("Y2-\r\n");
+    }
+    if ((SL_SRC_Reg2 & 0x08) == 0x08)
+    {
+        //Y+
+        printf("Y2+\r\n");
+    }
+    if ((SL_SRC_Reg2 & 0x10) == 0x10)
+    {
+        //Z-
+        printf("Z2-\r\n");
+    }
+    if ((SL_SRC_Reg2 & 0x20) == 0x20)
+    {
+        //Z+
+        printf("Z2+\r\n");
+    }
+    //   }
+}
+
+void SL_SC7A20_Reg_read_all(void)
 {
     UINT8 SL_Read_Reg;
-    printf("SL_SC7A20_Reg_readall ++++++++\r\n");	
+    printf("SL_SC7A20_Reg_readall ++++++++\r\n");
     /*******************AOI1  IN  INT1********************/
-	UINT8 adr;
-	for(adr=0x20;adr<=0x3F;adr++){
-		GSENSOR_ReadReg(adr,1, &SL_Read_Reg);
-		printf("%#x = %#x\r\n",adr,SL_Read_Reg);	
-	}
-	
-    printf("SL_SC7A20_Reg_readall --------\r\n");	
-}
-
-
+    UINT8 adr;
+    for (adr = 0x20; adr <= 0x3F; adr++)
+    {
+        GSENSOR_ReadReg(adr, 1, &SL_Read_Reg);
+        printf("%#x = %#x\r\n", adr, SL_Read_Reg);
+    }
 
+    printf("SL_SC7A20_Reg_readall --------\r\n");
+}
 
 /***************���ݸ�������**���ٶȼ�ʹ��**********/
-INT8  SL_SC7A20_Power_Config(UINT8 Power_Config_Reg)
+INT8 SL_SC7A20_Power_Config(UINT8 Power_Config_Reg)
 {
     UINT8 SL_Read_Reg;
 
-#if  SL_SC7A20_MTP_ENABLE==1
-    SL_Read_Reg  = 0x00;
+#if SL_SC7A20_MTP_ENABLE == 1
+    SL_Read_Reg = 0x00;
     GSENSOR_WriteReg(SL_SC7A20_MTP_CFG, SL_SC7A20_MTP_VALUE);
-    GSENSOR_ReadReg(SL_SC7A20_SDOI2C_PU_CFG,1, &SL_Read_Reg); 
-    SL_Read_Reg=SL_Read_Reg|SL_SC7A20_SDO_PU_MSK|SL_SC7A20_I2C_PU_MSK;
+    GSENSOR_ReadReg(SL_SC7A20_SDOI2C_PU_CFG, 1, &SL_Read_Reg);
+    SL_Read_Reg = SL_Read_Reg | SL_SC7A20_SDO_PU_MSK | SL_SC7A20_I2C_PU_MSK;
     GSENSOR_WriteReg(SL_SC7A20_SDOI2C_PU_CFG, SL_Read_Reg);
     GSENSOR_WriteReg(SL_SC7A20_MTP_CFG, 0);
 #endif
-    SL_Read_Reg  = 0xff;
+    SL_Read_Reg = 0xff;
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG1, Power_Config_Reg);
-    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG1,1, &SL_Read_Reg); 
+    GSENSOR_ReadReg(SL_SC7A20_CTRL_REG1, 1, &SL_Read_Reg);
 
-    if(SL_Read_Reg==Power_Config_Reg){
-	return  1;
-    }else{
-    	return -1;
+    if (SL_Read_Reg == Power_Config_Reg)
+    {
+        return 1;
+    }
+    else
+    {
+        return -1;
     }
 }
 
-
-#if   SL_SC7A20_16BIT_8BIT==0
+#if SL_SC7A20_16BIT_8BIT == 0
 /***************���ٶȼ����ݶ�ȡ*8bits*********/
-INT8  SL_SC7A20_Read_XYZ_Data(INT8 *SL_SC7A20_Data_XYZ_Buf)
+INT8 SL_SC7A20_Read_XYZ_Data(INT8 *SL_SC7A20_Data_XYZ_Buf)
 {
     UINT8 SL_Read_Buf[7];
-    
-    GSENSOR_ReadReg(SL_SC7A20_STATUS_REG,1, &SL_Read_Buf[0]);
-    
-    if((SL_Read_Buf[0]&0x0f)==0x0f)
+
+    GSENSOR_ReadReg(SL_SC7A20_STATUS_REG, 1, &SL_Read_Buf[0]);
+
+    if ((SL_Read_Buf[0] & 0x0f) == 0x0f)
     {
-        GSENSOR_ReadReg(SL_SC7A20_DATA_OUT,6, &SL_Read_Buf[1]);
-        SL_SC7A20_Data_XYZ_Buf[0]=(INT8)SL_Read_Buf[2];
-        SL_SC7A20_Data_XYZ_Buf[1]=(INT8)SL_Read_Buf[4];
-        SL_SC7A20_Data_XYZ_Buf[2]=(INT8)SL_Read_Buf[6];
-        return  1;   
+        GSENSOR_ReadReg(SL_SC7A20_DATA_OUT, 6, &SL_Read_Buf[1]);
+        SL_SC7A20_Data_XYZ_Buf[0] = (INT8)SL_Read_Buf[2];
+        SL_SC7A20_Data_XYZ_Buf[1] = (INT8)SL_Read_Buf[4];
+        SL_SC7A20_Data_XYZ_Buf[2] = (INT8)SL_Read_Buf[6];
+        return 1;
     }
     else
     {
         return 0;
     }
 }
-#elif SL_SC7A20_16BIT_8BIT==1
+#elif SL_SC7A20_16BIT_8BIT == 1
 /***************���ٶȼ����ݶ�ȡ*16bits*********/
-INT8  SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf)
+INT8 SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf)
 {
     UINT8 SL_Read_Buf[7];
-    
-    GSENSOR_ReadReg(SL_SC7A20_STATUS_REG,1, &SL_Read_Buf[0]);
-    #ifdef USING_PRINTF	
-		printf("SL_SC7A20_STATUS_REG = %#x\r\n",SL_Read_Buf[0]);
-	#endif
-    if((SL_Read_Buf[0]&0x0f)==0x0f)
-    {
-        GSENSOR_ReadReg(SL_SC7A20_DATA_OUT,6, &SL_Read_Buf[1]);
-        #ifdef USING_PRINTF	
-			printf("SL_SC7A20_DATA_OUT22 = %#x\r\n",SL_Read_Buf[1]);
-		#endif
-        SL_SC7A20_Data_XYZ_Buf[0]=(INT16)((SL_Read_Buf[2]<<8) + SL_Read_Buf[1]);
-        SL_SC7A20_Data_XYZ_Buf[1]=(INT16)((SL_Read_Buf[4]<<8) + SL_Read_Buf[3]);
-        SL_SC7A20_Data_XYZ_Buf[2]=(INT16)((SL_Read_Buf[6]<<8) + SL_Read_Buf[5]);
-        #ifdef USING_PRINTF	
-			printf("SL_SC7A20_DATA_OUT BUF:X = %d,Y = %d,Z = %d\r\n",SL_SC7A20_Data_XYZ_Buf[0],SL_SC7A20_Data_XYZ_Buf[1],SL_SC7A20_Data_XYZ_Buf[2]);
-		#endif
-        return  1;
+
+    GSENSOR_ReadReg(SL_SC7A20_STATUS_REG, 1, &SL_Read_Buf[0]);
+#ifdef USING_PRINTF
+    printf("SL_SC7A20_STATUS_REG = %#x\r\n", SL_Read_Buf[0]);
+#endif
+    if ((SL_Read_Buf[0] & 0x0f) == 0x0f)
+    {
+        GSENSOR_ReadReg(SL_SC7A20_DATA_OUT, 6, &SL_Read_Buf[1]);
+#ifdef USING_PRINTF
+        printf("SL_SC7A20_DATA_OUT22 = %#x\r\n", SL_Read_Buf[1]);
+#endif
+        SL_SC7A20_Data_XYZ_Buf[0] = (INT16)((SL_Read_Buf[2] << 8) + SL_Read_Buf[1]);
+        SL_SC7A20_Data_XYZ_Buf[1] = (INT16)((SL_Read_Buf[4] << 8) + SL_Read_Buf[3]);
+        SL_SC7A20_Data_XYZ_Buf[2] = (INT16)((SL_Read_Buf[6] << 8) + SL_Read_Buf[5]);
+#ifdef USING_PRINTF
+        printf("SL_SC7A20_DATA_OUT BUF:X = %d,Y = %d,Z = %d\r\n", SL_SC7A20_Data_XYZ_Buf[0], SL_SC7A20_Data_XYZ_Buf[1], SL_SC7A20_Data_XYZ_Buf[2]);
+#endif
+        return 1;
     }
     else
     {
@@ -586,15 +575,16 @@ INT8  SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf)
 #endif
 void GsensorInit(void)
 {
-	INT8 res = 0;
-	res = SL_SC7A20_Online_Test();
-	if(res==1){
-		
-		SL_SC7A20_BOOT();
-		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);
-	}
+    INT8 res = 0;
+    res = SL_SC7A20_Online_Test();
+    if (res == 1)
+    {
+
+        SL_SC7A20_BOOT();
+        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);
+    }
 }
 #endif

Some files were not shown because too many files changed in this diff