ソースを参照

对WLMCP.ewp添加新增的.c/h文件;恢复静态测试注释;AD测温采用NTC插值方式;当前功耗增加最大最小值限制;默认gearsensor模式;

Ye Jin 1 年間 前
コミット
f8074996e4

+ 1 - 1
User project/1.FrameLayer/Source/FSM_2nd.c

@@ -188,7 +188,7 @@ void Switch_Second_FSM(const FSM_RUN_HOOK *in)
  All rights reserved.
 ************************************************************************/
 #ifdef _CTRLMDFSM1_C_
-#undef _CTRLMDFSM1_C_
+#undef _CTRLMDFSM1_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/1.FrameLayer/Source/TimeTask_Event.c

@@ -57,7 +57,7 @@ static BOOL Event_pvt_blBikeThroFlg = FALSE, Event_pvt_blBikeThroFlgZ1 = FALSE;
  *  Function
  *
  ******************************/
-void  Event_1ms(void)
+void  Event_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     /* Timing of time slices */
     TimingTaskTimerServer();

+ 2 - 2
User project/1.FrameLayer/Source/main.c

@@ -52,7 +52,7 @@
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-int main(void)
+int main(void) /* parasoft-suppress GJB5369-4_2_1_10 "mismatch" */
 {
 #ifndef RUN_ARCH_SIM
     SCB->VTOR = 0x08003000;
@@ -732,7 +732,7 @@ void mn_voMcParInit(void)
  All rights reserved.
 *************************************************************************/
 #ifdef _MAIN_C_
-#undef _MAIN_C_
+#undef _MAIN_C_ /* parasoft-suppress MISRA2004-19_6 "本项目无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/1.FrameLayer/Source/tbc.c

@@ -173,7 +173,7 @@ void tbc_voDownIsr(void)
  All rights reserved.
 *************************************************************************/
 #ifdef _TBC_C_
-#undef _TBC_C_
+#undef _TBC_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/1.FrameLayer/Source/tbs.c

@@ -54,7 +54,7 @@ void tbs_voIsr(void)
  All rights reserved.
 *************************************************************************/
 #ifdef _TBS_C_
-#undef _TBS_C_
+#undef _TBS_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/1.FrameLayer/Source/tbt.c

@@ -53,7 +53,7 @@ void tbt_voIsr(void)
  All rights reserved.
 ************************************************************************/
 #ifdef _TBT_C_
-#undef _TBT_C_
+#undef _TBT_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /************************************************************************
  End of this File (EOF)!

+ 11 - 10
User project/2.MotorDrive/Source/adc.c

@@ -160,7 +160,7 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
  Subroutine Call:
  Reference: N/A
 ****************************************************************/
-void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out)
+void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     UWORD uwIpeakPu;
 
@@ -361,12 +361,13 @@ void adc_voSampleUp_High(const ADC_COF *cof, ADC_UP_OUT *out)
     }
 
     ////////////////// PCB TEMP//////////////////////////////////////////////////////
-//    if(out->PCBTempReg != 0)
-//    {
-//        out->PCBTempR = (UWORD)((ULONG)4096 * PCB_TEMP_SAMPLER / out->PCBTempReg - PCB_TEMP_SAMPLER); // Q14=Q24-Q10;
-//    }
-//    PcbTempCal((SWORD)out->PCBTempR);
-//    out->PCBTemp = tmp_PcbTemp;
+    out->PCBTempReg = iAdc_GetResultPointer(0)[HW_ADC_PCBTEMP_CH]; 
+    if(out->PCBTempReg != 0)
+    {
+        out->PCBTempR = (UWORD)((ULONG)4096 * PCB_TEMP_SAMPLER / out->PCBTempReg - PCB_TEMP_SAMPLER); // Q14=Q24-Q10;
+    }
+    PcbTempCal((SWORD)out->PCBTempR);
+    out->PCBTemp = tmp_PcbTemp;
     
 }
 
@@ -378,8 +379,8 @@ void adc_voSampleUp_Low(const ADC_COF *cof, ADC_UP_OUT *out)
     out->uwU5VReg = iAdc_GetResultPointer(0)[HW_ADC_U5V_CH]; 
     out->uwU5VPu = (UWORD)((ULONG)out->uwU5VReg * cof->uwU5VReg2Pu >> 10);    // Q14=Q24-Q10;
     
-    out->PCBTempReg = iAdc_GetResultPointer(0)[HW_ADC_PCBTEMP_CH]; 
-    out->PCBTemp = GetPCBTemp(out->PCBTempReg);
+//    out->PCBTempReg = iAdc_GetResultPointer(0)[HW_ADC_PCBTEMP_CH]; 
+//    out->PCBTemp = GetPCBTemp(out->PCBTempReg);
     
     out->uwFU6VReg = iAdc_GetResultPointer(0)[HW_ADC_MOTTEMP_CH]; 
     out->uwFU6VPu = (UWORD)((ULONG)out->uwFU6VReg * cof->uwU6VReg2Pu >> 10); // Q14=Q24-Q10;
@@ -620,7 +621,7 @@ void adc_voSampleInit(void)
  All rights reserved.
 *************************************************************************/
 #ifdef _ADCDRV_C_
-#undef _ADCDRV_C_
+#undef _ADCDRV_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 3 - 3
User project/2.MotorDrive/Source/alarm.c

@@ -282,7 +282,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voDetecTBC(const ALM_IN *in, const ALM_DETECTBC_COF *coef)
+void alm_voDetecTBC(const ALM_IN *in, const ALM_DETECTBC_COF *coef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     SWORD swTmp1, swTmp2;
     
@@ -956,7 +956,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voReset(const ALM_IN *in, const ALM_RESET_COF *coef)
+void alm_voReset(const ALM_IN *in, const ALM_RESET_COF *coef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
 
     /*=======================================================================
@@ -1606,7 +1606,7 @@ Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
 All rights reserved.
 *************************************************************************/
 #ifdef _ALARM_C_
-#undef _ALARM_C_
+#undef _ALARM_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
 End of this File (EOF):

+ 3 - 3
User project/2.MotorDrive/Source/pwm.c

@@ -165,8 +165,8 @@ void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef)
  Subroutine Call: N/A;
  Reference: N/A;
 ************************************************************************/
-void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out)
-{
+void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
+{ /* parasoft-suppress GJB5369-4_2_2_2 "本项目函数行数无法更改,后续应避免" */
     SLONG slL1, slL2, slL3;
     SLONG slKsvpwm;
     SLONG slX, slY, slZ;
@@ -883,7 +883,7 @@ void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out)
  All rights reserved.
 ************************************************************************/
 #ifdef _PWM_C_
-#undef _PWM_C_
+#undef _PWM_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /************************************************************************
  End of this File (EOF)!

+ 2 - 2
User project/2.MotorDrive/Source/spdctrFSM.c

@@ -381,7 +381,7 @@ void ClzLoop_TbsHook(void)
 void Stop_TbsHook(void)
 {}
 
-void scm_voSpdCtrMdFSM(void)
+void scm_voSpdCtrMdFSM(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     switch (curSpeed_state.state)
     {
@@ -579,7 +579,7 @@ void Switch_speed_FSMInit(void)
  All rights reserved.
 ************************************************************************/
 #ifdef _STARTFSM_C_
-#undef _STARTFSM_C_
+#undef _STARTFSM_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/2.MotorDrive/Source/spdctrmode.c

@@ -864,7 +864,7 @@ void  scm_voSpdCtrMdDownTbc(void)
  All rights reserved.
 *************************************************************************/
 #ifdef _SPDCTRMODE_C_
-#undef _SPDCTRMODE_C_
+#undef _SPDCTRMODE_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 30 - 33
User project/3.BasicFunction/Include/Temp.h

@@ -24,53 +24,50 @@ WLBDM_M0_SR_20170814-new FSM1.1, by cyf, create this file;
 /************************************************************************
  Definitions & Macros
 *************************************************************************/
-#define PCB_TEMP_SAMPLER 1000 // 0.01kOhm
-#define PCB_TEMP_NUM       13
-#define TORQ_TEMP_NUM      7
-#define CURCALIBNUM      8
-#define CURCALIBUNIT     10 // centidegree
+#define PCB_TEMP_SAMPLER 	1000 // 0.01kOhm
+
+#define MOTOR_TEMP_DETECT	1		//
+
+#define MOTOR_TEMP_R1	 	150	//0.01K
+#define MOTOR_TEMP_R2	 	82		//0.01k
+#define MOTOR_TEMP_VCC		51		//0.1V  PCB霍尔板供电电压大约5.1V
+#define MOTOR_TEMP_AD_VCC 	33		//0.1V
+
+#define TEMPNUM          	7
+#define CURCALIBNUM      	7
+#define CURCALIBUNIT     	10 // centidegree
 /************************************************************************
  TypeDefs & Structure defines (N/A)
 *************************************************************************/
 #define temp_0   0
-#define temp_10  1
-#define temp_20  2
-#define temp_30  3
-#define temp_40  4
-#define temp_50  5
-#define temp_60  6
-#define temp_70  7
-#define temp_80  8
-#define temp_90  9
-#define temp_100 10
-#define temp_110  11
-#define temp_120 12
+#define temp_20  1
+#define temp_40  2
+#define temp_60  3
+#define temp_80  4
+#define temp_100 5
+#define temp_120 6
 
+#define temp_motor_150 	32
+#define temp_pcb_140 	25
 
-#define temp_coef_0_10     0
-#define temp_coef_10_20    1
-#define temp_coef_20_30    2
-#define temp_coef_30_40    3
-#define temp_coef_40_50    4
-#define temp_coef_50_60    5
-#define temp_coef_60_70    6
-#define temp_coef_70_80    7
-#define temp_coef_80_90    8
-#define temp_coef_90_100   9
-#define temp_coef_100_110  10
-#define temp_coef_110_120  11
+#define temp_coef_0_20   0
+#define temp_coef_20_40  1
+#define temp_coef_40_60  2
+#define temp_coef_60_80  3
+#define temp_coef_80_100 4
 
 /************************************************************************
  Exported Variables
 *************************************************************************/
 extern SWORD tmp_PcbTemp;
-extern SWORD tmp_CurCalibCoef[];
-extern SWORD tmp_CurCalibLimitDeta[];
+extern SWORD tmp_MotTemp;
+//extern SWORD tmp_CurCalibCoef[];
+//extern SWORD tmp_CurCalibLimitDeta[];
 
 extern void TempInit(void);
 extern void PcbTempCal(SWORD PcbR);
-extern void MotorTempCal(void);
-SWORD temp_swTorqTempCal(UWORD Reg);
+extern void MotorTempCal(SWORD PcbR);
+
 /************************************************************************
  Flag Define (N/A)
 *************************************************************************/

+ 130 - 209
User project/3.BasicFunction/Source/Temp.c

@@ -13,7 +13,10 @@
  Beginning of File, do not put anything above here except notes
  Compiler Directives:
 *************************************************************************/
+#include "syspar.h"
 #include "typedefine.h"
+#include "mathtool.h"
+#include "gd32f30x.h"
 #include "Temp.h"
 
 /******************************
@@ -21,88 +24,68 @@
  *  Parameter
  *
  ******************************/
-SWORD tmp_CurCalibCoef[CURCALIBNUM] = {
-    1024, // 0-20
-    1024, // 20-30
-    1024, // 30-40
-    1024, // 40-50
-    1000, // 50-60
-    980,  // 60-70
-    960,  // 70-80
-    940,  // 80-90
+SLONG tmp_CurCalibCoef[CURCALIBNUM] = {
+    30224, // 0-19		Q10
+    53743, // 20-39
+    77427, // 40-59    
+    101477, // 60-79
+    125143, // 80-99
+    149524,  // 100-119
+    174172,  // 120-139
 };
 
-static SWORD PCB_swRTempTab[PCB_TEMP_NUM] = {
-0, // 0.01kOnm IPM voltage at 0 C      initial
-0, // 0.01kOnm IPM voltage at 10 C
-0, // 0.01kOnm IPM voltage at 20 C
-0, // 0.01kOnm IPM voltage at 30 C
-0,   // 0.01kOnm IPM voltage at 40 C
-0,  //0.01kOnm IPM voltage at 50 C
-0,  // 0.01kOnm IPM voltage at 60 C
-0, // 0.01kOnm IPM voltage at 70 C
-0,   // 0.01kOnm IPM voltage at 80 C
-0,  // 0.01kOnm IPM voltage at 90 C
-0,   // 0.01kOnm IPM voltage at 100 C
-0, // 0.01kOnm IPM voltage at 110 C
-0// 40 // 0.01kOnm IPM voltage at 120 C
-};
-static SWORD PCB_swRTempTab_CITY[PCB_TEMP_NUM] = {
- 3000,  // 0.01kOnm IPM voltage at 0 C        CITY
- 1900,  // 0.01kOnm IPM voltage at 10 C
- 1200,  // 0.01kOnm IPM voltage at 20 C
- 718,   // 0.01kOnm IPM voltage at 30 C
- 436,   // 0.01kOnm IPM voltage at 40 C
- 302,   // 0.01kOnm IPM voltage at 50 C
- 211,   // 0.01kOnm IPM voltage at 60 C
- 149,   // 0.01kOnm IPM voltage at 70 C
- 107,    // 0.01kOnm IPM voltage at 80 C
- 79,    // 0.01kOnm IPM voltage at 90 C
- 59,    // 0.01kOnm IPM voltage at 100 C
- 43,    // 0.01kOnm IPM voltage at 110 C
- 33     // 0.01kOnm IPM voltage at 120 C
-};
-static SWORD PCB_swRTempTab_MTB[PCB_TEMP_NUM] = {
- 3000, // 0.01kOnm IPM voltage at 0 C       MTB
- 1800, // 0.01kOnm IPM voltage at 10 C
- 1100, // 0.01kOnm IPM voltage at 20 C
- 661, // 0.01kOnm IPM voltage at 30 C
- 386,   // 0.01kOnm IPM voltage at 40 C
- 280,  //0.01kOnm IPM voltage at 50 C
- 190,  // 0.01kOnm IPM voltage at 60 C
- 136, // 0.01kOnm IPM voltage at 70 C
- 95,   // 0.01kOnm IPM voltage at 80 C
- 68,  // 0.01kOnm IPM voltage at 90 C
- 51,   // 0.01kOnm IPM voltage at 100 C
- 37, // 0.01kOnm IPM voltage at 110 C
- 27  //  0.01kOnm IPM voltage at 120 C
+static SWORD PCB_swRTempTab[TEMPNUM] = {
+    3362, // 0.01kOnm IPM voltage at 0 C
+    1253, // 0.01kOnm IPM voltage at 20 C
+    530,  // 0.01kOnm IPM voltage at 40 C
+    248,  // 0.01kOnm IPM voltage at 60 C
+    127,  // 0.01kOnm IPM voltage at 80 C
+    69,   // 0.01kOnm IPM voltage at 100 C
+    40,		//120C
 };
 
-static SWORD PCB_swRTempCofTab[PCB_TEMP_NUM-1] = {
-  0,0,0,0,0,0,0,0,0,0,0,0
+static SWORD PCB_swRTempCofTab[TEMPNUM] = {
+    -10,  // Q10  0-19 Coef of R
+    -28,  // Q10  20-39 Coef of R
+    -72,  // Q10  40-59 Coef of R
+    -167, // Q10  60-79 Coef of R
+    -349, // Q10  80-99 Coef of R
+    -696, // Q10  100-119
+    -1301,// Q10  120-139
 };
-
-static volatile SWORD TorqTempReg[TORQ_TEMP_NUM]= {
-3301,    //-11 C
-2690,    //8 C
-1802,    //28 C
-1368,    //40 C
-899,     //55 C
-580,     //69 C
-376      //85 C
+/* motor NTC intercept array */
+SLONG q10_motor_tmp_CurCalibCoef[CURCALIBNUM] = {
+    112056, // 70-81		Q10
+    125480, // 81-91
+    139284, // 92-102
+    152248, // 103-113
+    166113, // 114-124
+    178913,  // 125-135
+    198400,  // 136-146
 };
-static volatile SWORD TorqTemp[TORQ_TEMP_NUM]= {
--1083,    //unit: 0.01C
-843,    
-2830,    
-3997,    
-5460,     
-6930,     
-8453      
+/* motor NTC resistance */
+static SWORD motor_swRTempTab[TEMPNUM] = {
+    223, // 0.01kOnm IPM voltage at 70 C
+    163, // 0.01kOnm IPM voltage at 81 C
+    120,  // 0.01kOnm IPM voltage at 92 C
+    91,  // 0.01kOnm IPM voltage at 103 C
+    69,  // 0.01kOnm IPM voltage at 114 C
+    54,   // 0.01kOnm IPM voltage at 125 C
+    43,   //0.01kOnm IPM voltage at 136 C
 };
-static volatile SWORD TorqTempCof[TORQ_TEMP_NUM-1]= {
-  0,0,0,0,0,0
+/* motor NTC fitting slope array */
+static SWORD q10_motor_swRTempCofTab[TEMPNUM] = {
+    -182,  // Q10  70-81 Coef of R
+    -263,  // Q10  81-91 Coef of R
+    -378,  // Q10  92-102 Coef of R
+    -519, // Q10  103-113 Coef of R
+    -715, // Q10  114-124 Coef of R
+    -947,	//Q10 125-135
+    -1393,	//Q10 136-146
 };
+
+SWORD tmp_PcbTemp = 0;
+SWORD tmp_MotTemp = 0;
 /***************************************************************
  Function: TempInit;
  Description: cadence frequency get initialization
@@ -114,31 +97,13 @@ static volatile SWORD TorqTempCof[TORQ_TEMP_NUM-1]= {
 ****************************************************************/
 void TempInit(void)
 {
-    UWORD i = 0;
-
-#if((MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
-	for(i = 0 ; i < PCB_TEMP_NUM ;i ++)
-	{
-	PCB_swRTempTab[i] =   PCB_swRTempTab_MTB[i] ;
-	}
-#elif((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V))
-	for(i = 0 ; i < PCB_TEMP_NUM ;i ++)
-	{
-	PCB_swRTempTab[i] =   PCB_swRTempTab_CITY[i] ;
-	}
-#endif
-    
-    for (i = 0; i < (PCB_TEMP_NUM - 1); i++)
+#if 0	
+    UWORD CNT = 0;
+    for (CNT = 0; CNT < (TEMPNUM - 1); CNT++)
     {
-        PCB_swRTempCofTab[i] =  (SWORD)(((SLONG)10 << 10) / (PCB_swRTempTab[i] - PCB_swRTempTab[i+ 1])); //Q10
-    }  
-    
-           
-//    for (i = 0; i < (TORQ_TEMP_NUM - 1); i++)
-//    {
-//        TorqTempCof[i] = (((SLONG)TorqTemp[i+1] - (SLONG)TorqTemp[i]) << 10) / (TorqTempReg[i] - TorqTempReg[i+1]) ; //Q10
-//    }
-
+        PCB_swRTempCofTab[CNT] = ((SLONG)20 << 10) / (PCB_swRTempTab[CNT + 1] - PCB_swRTempTab[CNT]);
+    }
+#endif	
 }
 
 /***************************************************************
@@ -150,151 +115,107 @@ void TempInit(void)
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-SWORD tmp_PcbTemp = 0;
-//void PcbTempCal(SWORD PcbR)
-//{
-//    if (PcbR >= PCB_swRTempTab[temp_0])
-//    {
-//        tmp_PcbTemp = 0;
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_0] && PcbR >= PCB_swRTempTab[temp_20])
-//    {
-//        tmp_PcbTemp = 0 + (((PcbR - PCB_swRTempTab[temp_0]) * PCB_swRTempCofTab[temp_coef_0_20]) >> 10);
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_20] && PcbR >= PCB_swRTempTab[temp_40])
-//    {
-//        tmp_PcbTemp = 20 + (((PcbR - PCB_swRTempTab[temp_20]) * PCB_swRTempCofTab[temp_coef_20_40]) >> 10);
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_40] && PcbR >= PCB_swRTempTab[temp_60])
-//    {
-//        tmp_PcbTemp = 40 + (((PcbR - PCB_swRTempTab[temp_40]) * PCB_swRTempCofTab[temp_coef_40_60]) >> 10);
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_60] && PcbR >= PCB_swRTempTab[temp_80])
-//    {
-//        tmp_PcbTemp = 60 + (((PcbR - PCB_swRTempTab[temp_60]) * PCB_swRTempCofTab[temp_coef_60_80]) >> 10);
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_80] && PcbR >= PCB_swRTempTab[temp_100])
-//    {
-//        tmp_PcbTemp = 80 + (((PcbR - PCB_swRTempTab[temp_80]) * PCB_swRTempCofTab[temp_coef_80_100]) >> 10);
-//    }
-//    else if (PcbR < PCB_swRTempTab[temp_100])
-//    {
-//        tmp_PcbTemp = 100 +(((PcbR - PCB_swRTempTab[temp_100]) * PCB_swRTempCofTab[temp_coef_100_120]) >> 10);
-//    }
-//    else
-//    {}
-//}
-static SWORD coeftest = 0 ;
+#if 0
 void PcbTempCal(SWORD PcbR)
 {
     if (PcbR >= PCB_swRTempTab[temp_0])
     {
         tmp_PcbTemp = 0;
-        coeftest = 2 ;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_10])
+    else if (PcbR < PCB_swRTempTab[temp_0] && PcbR >= PCB_swRTempTab[temp_20])
     {
-        tmp_PcbTemp = 10 - (((PcbR - PCB_swRTempTab[temp_10]) * PCB_swRTempCofTab[temp_coef_0_10]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_0_10] ;
-          
+        tmp_PcbTemp = 0 + (((PcbR - PCB_swRTempTab[temp_0]) * PCB_swRTempCofTab[temp_coef_0_20]) >> 10);
     }
-    else if (PcbR >= PCB_swRTempTab[temp_20])
+    else if (PcbR < PCB_swRTempTab[temp_20] && PcbR >= PCB_swRTempTab[temp_40])
     {
-        tmp_PcbTemp = 20 - (((PcbR - PCB_swRTempTab[temp_20]) * PCB_swRTempCofTab[temp_coef_10_20]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_10_20] ;
+        tmp_PcbTemp = 20 + (((PcbR - PCB_swRTempTab[temp_20]) * PCB_swRTempCofTab[temp_coef_20_40]) >> 10);
     }
-    else if (PcbR >= PCB_swRTempTab[temp_30])
+    else if (PcbR < PCB_swRTempTab[temp_40] && PcbR >= PCB_swRTempTab[temp_60])
     {
-        tmp_PcbTemp = 30 - (((PcbR - PCB_swRTempTab[temp_30]) * PCB_swRTempCofTab[temp_coef_20_30]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_20_30] ;
+        tmp_PcbTemp = 40 + (((PcbR - PCB_swRTempTab[temp_40]) * PCB_swRTempCofTab[temp_coef_40_60]) >> 10);
     }
-    else if (PcbR >= PCB_swRTempTab[temp_40])
+    else if (PcbR < PCB_swRTempTab[temp_60] && PcbR >= PCB_swRTempTab[temp_80])
     {
-        tmp_PcbTemp = 40 - (((PcbR - PCB_swRTempTab[temp_40]) * PCB_swRTempCofTab[temp_coef_30_40]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_30_40] ;
+        tmp_PcbTemp = 60 + (((PcbR - PCB_swRTempTab[temp_60]) * PCB_swRTempCofTab[temp_coef_60_80]) >> 10);
     }
-    else if (PcbR >= PCB_swRTempTab[temp_50])
+    else if (PcbR < PCB_swRTempTab[temp_80] && PcbR >= PCB_swRTempTab[temp_100])
     {
-        tmp_PcbTemp = 50 - (((PcbR - PCB_swRTempTab[temp_50]) * PCB_swRTempCofTab[temp_coef_40_50]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_40_50] ;
+        tmp_PcbTemp = 80 + (((PcbR - PCB_swRTempTab[temp_80]) * PCB_swRTempCofTab[temp_coef_80_100]) >> 10);
     }
-    else if (PcbR >= PCB_swRTempTab[temp_60])
+    else if (PcbR < PCB_swRTempTab[temp_100])
     {
-        tmp_PcbTemp = 60 - (((PcbR - PCB_swRTempTab[temp_60]) * PCB_swRTempCofTab[temp_coef_50_60]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_50_60] ;
+        tmp_PcbTemp = 100;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_70])
+    else
+    {}
+}
+#endif
+
+/*!
+ * @brief Fault state called in fast state machine
+ *
+ * @param  1)current NTC resistance 2) NTC resistance array
+ *         3)fitting slope array  4)intercept array 5)140C correspond resistance   
+ *
+ * @return current temperature
+ */
+
+#if 1
+SWORD TempCal(SWORD PcbR, SWORD *ptemp_tab, SWORD *p_temp_coef, SLONG *p_cali_coef, SWORD temp_140)
+{
+    SWORD per_temp;
+    if (PcbR >= *(ptemp_tab+temp_0))
     {
-        tmp_PcbTemp = 70 - (((PcbR - PCB_swRTempTab[temp_70]) * PCB_swRTempCofTab[temp_coef_60_70]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_60_70] ;
+        per_temp = 0;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_80])
+    else if (PcbR < *(ptemp_tab+temp_0) && PcbR >= *(ptemp_tab+temp_20))
     {
-        tmp_PcbTemp = 80 - (((PcbR - PCB_swRTempTab[temp_80]) * PCB_swRTempCofTab[temp_coef_70_80]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_70_80] ;
+	per_temp = (PcbR * (*(p_temp_coef+temp_0)) + (*(p_cali_coef+temp_0))) >> 10;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_90])
+    else if (PcbR < *(ptemp_tab+temp_20) && PcbR >= *(ptemp_tab+temp_40))
     {
-        tmp_PcbTemp = 90 - (((PcbR - PCB_swRTempTab[temp_90]) * PCB_swRTempCofTab[temp_coef_80_90]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_80_90] ;
+	per_temp = (PcbR * (*(p_temp_coef+temp_20)) + (*(p_cali_coef+temp_20))) >> 10;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_100])
+    else if (PcbR < *(ptemp_tab+temp_40) && PcbR >= *(ptemp_tab+temp_60))
     {
-        tmp_PcbTemp = 100 - (((PcbR - PCB_swRTempTab[temp_100]) * PCB_swRTempCofTab[temp_coef_90_100]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_90_100] ;
+	per_temp = (PcbR * (*(p_temp_coef+temp_40)) + (*(p_cali_coef+temp_40))) >> 10;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_110])
+    else if (PcbR < *(ptemp_tab+temp_60) && PcbR >= *(ptemp_tab+temp_80))
     {
-        tmp_PcbTemp = 110 - (((PcbR - PCB_swRTempTab[temp_110]) * PCB_swRTempCofTab[temp_coef_100_110]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_100_110] ;
+	per_temp = (PcbR * (*(p_temp_coef+temp_60)) + (*(p_cali_coef+temp_60))) >> 10;
     }
-    else if (PcbR >= PCB_swRTempTab[temp_120])
+    else if (PcbR < *(ptemp_tab+temp_80) && PcbR >= *(ptemp_tab+temp_100))
     {
-        tmp_PcbTemp = 120 - (((PcbR - PCB_swRTempTab[temp_120]) * PCB_swRTempCofTab[temp_coef_110_120]) >> 10);
-        coeftest = PCB_swRTempCofTab[temp_coef_110_120] ;
+	per_temp = (PcbR * (*(p_temp_coef+temp_80)) + (*(p_cali_coef+temp_80))) >> 10;
+    }
+    else if (PcbR < *(ptemp_tab+temp_100) && PcbR >= *(ptemp_tab+temp_120))
+    {
+	per_temp = (PcbR * (*(p_temp_coef+temp_100)) + (*(p_cali_coef+temp_100))) >> 10;
+    }
+    else if(PcbR < *(ptemp_tab+temp_120))
+    {
+	per_temp = (PcbR * (*(p_temp_coef+temp_120)) + (*(p_cali_coef+temp_120))) >> 10;
+    }
+    else if(PcbR < temp_140)
+    {
+	per_temp = 150;	
     }
     else
     {
-        tmp_PcbTemp = 130 ;
-        coeftest = 1;
     }
+    return per_temp;
 }
-/***************************************************************
- Function: 
- Description:
- Call by: 
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: N/A
- Reference: N/A
-****************************************************************/    
-//SWORD temp_swTorqTempCal(UWORD Reg)  
-//{
-//    SWORD Temp = 0,i = 0;
-//    
-//    if(Reg >= TorqTempReg[0])
-//    {
-//       Temp = TorqTemp[0];
-//    }
-//    else if(Reg < TorqTempReg[TORQ_TEMP_NUM - 1])
-//    {
-//       Temp = TorqTemp[TORQ_TEMP_NUM - 1];
-//    }
-//    else
-//    {
-//        for (i = 0; i < (TORQ_TEMP_NUM - 1); i++)
-//        {
-//            if(Reg >= TorqTempReg[i+1] && Reg < TorqTempReg[i])
-//            {
-//               Temp = TorqTemp[i] + ((SLONG)TorqTempCof[i] * (TorqTempReg[i] - Reg) >> 10);  //Q10
-//               break;
-//            }        
-//        }    
-//    }
-//    
-//    return  Temp;
-//}
-    
+
+void PcbTempCal(SWORD PcbR)
+{
+    tmp_PcbTemp = TempCal(PcbR, PCB_swRTempTab, PCB_swRTempCofTab, tmp_CurCalibCoef, temp_pcb_140);		
+}
+
+void MotorTempCal(SWORD PcbR)
+{
+    tmp_MotTemp = TempCal(PcbR, motor_swRTempTab, q10_motor_swRTempCofTab, q10_motor_tmp_CurCalibCoef, temp_motor_150);	
+}
+#endif
 /*************************************************************************
  End of this File (EOF)!
  Do not put anything after this part!

+ 17 - 2
User project/3.BasicFunction/Source/canAppl.c

@@ -263,7 +263,7 @@ void Can_voInitMC_Run(void)
     MC_RunInfo.RemainDistance = 0xffff;                           // init invalid value
 }
 
-void Can_voMC_Run_1ms(void) 
+void Can_voMC_Run_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     if (cp_stBikeRunInfoPara.BikeSpeedKmH > 30)
     {
@@ -671,7 +671,7 @@ void Can_voMC_Run_200ms(void)
         if((cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stBikeRunInfoPara.uwBikeGear <= 5))
         {
             MC_RunInfo.PowerPerKm =
-                    (UBYTE)(*(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10); //平均功耗 0.01Ah/km
+                    (UBYTE)(*(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10); //平均功耗 0.01Ah/km  /* parasoft-suppress MISRA2004-17_4 "本项目无法更改,后续避免非数组索引指针运算" */
             MC_RunInfo.RemainDistance = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
         }
         else
@@ -760,6 +760,20 @@ void Can_RemainTrip_Cal(void)
             {
                 cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
             }
+            
+            /*限制功耗防止续航里程过大或过小*/
+            if(cp_stBikeRunInfoPara.uwAvePowerPerKm < 50)
+            {
+                cp_stBikeRunInfoPara.uwAvePowerPerKm = 50;        /*limit min*/
+            }
+            else if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 500)
+            {
+                cp_stBikeRunInfoPara.uwAvePowerPerKm = 500;     /*limit max*/
+            }
+            else
+            {
+                /* no deal with */
+            }
 
             if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 0)
             {
@@ -817,6 +831,7 @@ void Can_RemainTrip_Cal(void)
                 {
                     uwCruisCoef = 4096;
                 }
+                
                 MC_RunInfo.RemainDistance = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
             }
         }

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/user.h

@@ -48,7 +48,7 @@ Update Time
 #define MOTOR_WELLING_MTB_48V     0x31
 
 #define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V  
-#define GEARSENSOR_ENABLE         0 //0-Uart,1-GearSensor
+#define GEARSENSOR_ENABLE         1 //0-Uart,1-GearSensor
 
 //#define TEST  //only use for testing
 

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/crdnt.c

@@ -244,7 +244,7 @@ void crd_voIClark(const CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out)
  All rights reserved.
 *************************************************************************/
 #ifdef _CRDNT_C_
-#undef _CRDNT_C_
+#undef _CRDNT_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF)!

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/macroequ.c

@@ -44,7 +44,7 @@ Include File
  All rights reserved.
 ************************************************************************/
 #ifdef _MACROEQU_C_
-#undef _MACROEQU_C_
+#undef _MACROEQU_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /************************************************************************
  End of this File (EOF)!

+ 2 - 2
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/mathtool.c

@@ -480,7 +480,7 @@ SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit)
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-UWORD mth_voArctan(const ARCTAN_IN *in)
+UWORD mth_voArctan(const ARCTAN_IN *in) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     UWORD uwQuadrant, uwStep;
     SLONG slX, slY, slCurAngle, slNewX;
@@ -615,7 +615,7 @@ UWORD mth_voArctan(const ARCTAN_IN *in)
  All rights reserved.
 *************************************************************************/
 #ifdef _MATHTOOL_C_
-#undef _MATHTOOL_C_
+#undef _MATHTOOL_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
 #endif
 /*************************************************************************
  End of this File (EOF):

+ 1 - 1
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/queue.c

@@ -108,7 +108,7 @@ UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, const ERROR_LOG *rxdata, UBYTE length)
     for (UBYTE i = 0; i < length; i++)
     {
         que_voEnter(Q, *rxdata);
-        rxdata++;
+        rxdata++; /* parasoft-suppress MISRA2004-17_1 "本项目无法更改,后续避免未指向数组的指针运算" */ /* parasoft-suppress MISRA2004-17_4 "本项目无法更改,后续避免非数组索引指针运算" */
     }
 
     return (UBYTE)1;

+ 48 - 0
WLMCP.ewp

@@ -2456,6 +2456,9 @@
             <name>1.FrameLayer</name>
             <group>
                 <name>Include</name>
+                <file>
+                    <name>$PROJ_DIR$\User project\1.FrameLayer\Include\app.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\1.FrameLayer\Include\FSM_1st.h</name>
                 </file>
@@ -2663,6 +2666,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikebrake.h</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikegearsensor.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\bikelight.h</name>
                 </file>
@@ -2687,6 +2693,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\display.h</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\enviolo_can.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\flash_master.h</name>
                 </file>
@@ -2696,9 +2705,18 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\InputCapture.h</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\LoadObsTheta.h</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\ntc_sensor.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\power.h</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\rtwtypes2.h</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\spi_master.h</name>
                 </file>
@@ -2720,6 +2738,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikebrake.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikegearsensor.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\bikelight.c</name>
                 </file>
@@ -2744,6 +2765,9 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\display.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Source\enviolo_can.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\flash_master.c</name>
                 </file>
@@ -2753,6 +2777,12 @@
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\InputCapture.c</name>
                 </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Source\LoadObsTheta.c</name>
+                </file>
+                <file>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Source\ntc_sensor.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Source\power.c</name>
                 </file>
@@ -2821,6 +2851,9 @@
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Include\mathtool.h</name>
                     </file>
+                    <file>
+                        <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Include\notchfilter.h</name>
+                    </file>
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Include\queue.h</name>
                     </file>
@@ -2851,6 +2884,9 @@
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Source\mathtool.c</name>
                     </file>
+                    <file>
+                        <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Source\notchfilter.c</name>
+                    </file>
                     <file>
                         <name>$PROJ_DIR$\User project\4.BasicHardwSoftwLayer\2.BasicSoftwLayer\Source\queue.c</name>
                     </file>
@@ -2913,6 +2949,18 @@
             <file>
                 <name>$PROJ_DIR$\User project\5.Api_rt\api_rt_uart.h</name>
             </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler.h</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler_port.c</name>
+            </file>
+            <file>
+                <name>$PROJ_DIR$\User project\5.Api_rt\profiler_port.h</name>
+            </file>
         </group>
     </group>
 </project>