Sfoglia il codice sorgente

静态问题合并

Ye Jin 1 anno fa
parent
commit
80253b2d29
39 ha cambiato i file con 525 aggiunte e 486 eliminazioni
  1. 3 7
      User project/1.FrameLayer/Include/FSM_1st.h
  2. 2 2
      User project/1.FrameLayer/Include/FSM_2nd.h
  3. 1 1
      User project/1.FrameLayer/Include/TimeTask_Event.h
  4. 1 1
      User project/1.FrameLayer/Include/app.h
  5. 2 2
      User project/1.FrameLayer/Source/FSM_1st.c
  6. 16 16
      User project/1.FrameLayer/Source/FSM_2nd.c
  7. 23 22
      User project/1.FrameLayer/Source/TimeTask_Event.c
  8. 1 1
      User project/1.FrameLayer/Source/gd32f30x_it.c
  9. 105 107
      User project/1.FrameLayer/Source/main.c
  10. 2 2
      User project/1.FrameLayer/Source/tbc.c
  11. 2 3
      User project/1.FrameLayer/Source/tbs.c
  12. 6 6
      User project/2.MotorDrive/Include/adc.h
  13. 21 21
      User project/2.MotorDrive/Include/alarm.h
  14. 4 4
      User project/2.MotorDrive/Include/pwm.h
  15. 1 1
      User project/2.MotorDrive/Include/spdctrFSM.h
  16. 14 14
      User project/2.MotorDrive/Source/adc.c
  17. 75 67
      User project/2.MotorDrive/Source/alarm.c
  18. 87 73
      User project/2.MotorDrive/Source/pwm.c
  19. 37 13
      User project/2.MotorDrive/Source/spdctrFSM.c
  20. 22 8
      User project/2.MotorDrive/Source/spdctrmode.c
  21. 2 2
      User project/3.BasicFunction/Source/Cadence.c
  22. 0 1
      User project/3.BasicFunction/Source/InputCapture.c
  23. 1 1
      User project/3.BasicFunction/Source/bikelight.c
  24. 6 5
      User project/3.BasicFunction/Source/bikespeed.c
  25. 1 1
      User project/3.BasicFunction/Source/can.c
  26. 18 18
      User project/3.BasicFunction/Source/canAppl.c
  27. 1 1
      User project/3.BasicFunction/Source/spi_master.c
  28. 16 16
      User project/3.BasicFunction/Source/switchhall.c
  29. 8 8
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/crdnt.h
  30. 0 28
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/glbcof.h
  31. 2 2
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/mathtool.h
  32. 3 2
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/queue.h
  33. 9 5
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/user.h
  34. 4 4
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/crdnt.c
  35. 0 11
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/glbcof.c
  36. 6 2
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/mathtool.c
  37. 4 4
      User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/queue.c
  38. 17 2
      User project/5.Api_rt/api_rt_pwm.c
  39. 2 2
      WLMCP_PACKED.ewp

+ 3 - 7
User project/1.FrameLayer/Include/FSM_1st.h

@@ -20,7 +20,6 @@ extern "C" {
  *          Definitions & Macros
  *
  ****************************************/
-
 #define SYS_RDY_FLG_DEFAULT               \
     {                                     \
         FALSE, FALSE, FALSE, FALSE, FALSE \
@@ -36,7 +35,6 @@ extern "C" {
  *          Type  Definations
  *
  ***************************************/
-
 /**
  * @brief Type of signal
  *
@@ -59,7 +57,6 @@ typedef enum
     SysInit = 0,
     SysRdy = 1,
     SysFault = 2,
-
 } SYS_FSM_STATUS;
 
 /**
@@ -68,7 +65,7 @@ typedef enum
  */
 typedef struct
 {
-    BOOL HMI_Flag; ///<
+    BOOL HMI_Flag; 
     BOOL SysCoef_Flag;
     BOOL SysRdy_Flag;
     BOOL SysRun_Flag;
@@ -107,13 +104,11 @@ typedef struct
  *           Exported variable
  *
  ****************************************/
-
 extern FSM_SYS_HOOK   FSM1st_Sys_state;
 extern FSM_SYS_HOOK   SysFault_state;
 extern SYS_RDY_FLG    sysfsm_stFlg;
 extern SIGNAL_STATE   signal_state;
 extern SYS_FMS_FLAG   switch_flg;
-
 /***************************************
  *
  *          Function  Definations
@@ -203,7 +198,7 @@ void SysFault_Tbshook(void);
  *
  * @param in pointer to target state
  */
-void Switch_sys_FSM(FSM_SYS_HOOK *in);
+void Switch_sys_FSM(const FSM_SYS_HOOK *in);
 
 /**
  * @brief System FSM running function
@@ -223,6 +218,7 @@ void RlyOnInit(void);
  */
 void FSM_voInit(void);
 
+
 #ifdef __cplusplus
 }
 #endif // __cplusplus

+ 2 - 2
User project/1.FrameLayer/Include/FSM_2nd.h

@@ -51,7 +51,7 @@ typedef struct
     RUN_FSM_STATUS state;
     void (*Event_hook)(void);
     void (*Tbcup_hook)(void);
-    void (*Tbcdown_hook)(void); ///<
+    void (*Tbcdown_hook)(void); 
     void (*Tbs_hook)(void);
 } FSM_RUN_HOOK;
 
@@ -166,7 +166,7 @@ void Exit_tbshook(void);
  *
  * @param in pointer to target state
  */
-void Switch_Second_FSM(FSM_RUN_HOOK *in);
+void Switch_Second_FSM(const FSM_RUN_HOOK *in);
 
 /**
  *

+ 1 - 1
User project/1.FrameLayer/Include/TimeTask_Event.h

@@ -31,7 +31,7 @@
  */
 typedef struct
 {
-    void (*proc)(void); // process program
+    void (*const proc)(void); // process program
     SLONG timespan;     // process period
     SLONG tick;         // process tick
 } _op_;

+ 1 - 1
User project/1.FrameLayer/Include/app.h

@@ -1,5 +1,5 @@
 /**
- * @file sys_task.h
+ * @file app.h
  * @author Ye Jin (yejin4@midea.com)
  * @brief 
  * @version 0.1

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

@@ -251,9 +251,9 @@ void SysFault_TbcDownhook(void)
 void SysFault_Tbshook(void)
 {}
 
-void Switch_sys_FSM(FSM_SYS_HOOK *in)
+void Switch_sys_FSM(const FSM_SYS_HOOK *in)
 {
-    void (*function)(void) = switchfuction[FSM1st_Sys_state.state][in->state];
+    void (*const function)(void) = switchfuction[FSM1st_Sys_state.state][in->state];
     function();
     FSM1st_Sys_state = *in;
 }

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

@@ -50,16 +50,16 @@ void FSM_2nd_Main(void)
             {
 
                 /* PWM on */
-                pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[0] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[1] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[2] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[3] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[4] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[5] = HW_INIT_HHPWM_PERIOD;
 
                 sysctrl_voPwmOn();
 
-                /* Init */
+                /* 3rd FSM Init */
                 Switch_speed_FSMInit();
 
                 /* switch to Boost FSM */
@@ -69,15 +69,15 @@ void FSM_2nd_Main(void)
             {
 
                 /* PWM on */
-                pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
-                pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[0] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[1] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[2] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[3] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[4] = HW_INIT_HHPWM_PERIOD;
+                pwm_stGenOut.uwNewTIM1COMPR[5] = HW_INIT_HHPWM_PERIOD;
                 sysctrl_voPwmOn();
 
-                /* Init */
+                /* 3rd FSM Init */
                 Switch_speed_FSMInit();
 
                 /* switch to Boost FSM */
@@ -115,7 +115,7 @@ void FSM_2nd_Main(void)
 //        if(signal_state.Sensor && (!signal_state.Assist))
 //        {
 //            /* Initial Value of Assit Output */
-//            Assist_torqueper = scm_swIqFdbLpfPu;    // scm_swIqFdbLpfPu need filter? In case of big ripple?
+//            ass_stCalOut.swAssitCurRef = scm_swIqFdbLpfPu;    // scm_swIqFdbLpfPu need filter? In case of big ripple?
 //            ass_pvt_stCurLpf.slY.sw.hi = scm_swIqFdbLpfPu;
 //            /* SpdRef Clear */
 //            scm_swSpdRefPu = 0;
@@ -173,7 +173,7 @@ void Exit_tbcdownhook(void)
 void Exit_tbshook(void)
 {}
 
-void Switch_Second_FSM(FSM_RUN_HOOK *in)
+void Switch_Second_FSM(const FSM_RUN_HOOK *in)
 {
     FSM2nd_Run_state = *in;
 }

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

@@ -82,21 +82,21 @@ void  Event_1ms(void)
             ass_voMoveAverageFilter(&ass_stTorqMafValue);
             
             /* Iqref maf test, dont add torq obs */
-//            if(ass_stCalOut.blTorqPIFlg)
-//            {
-//                ass_stUqLimMafValue.swValue = ass_stTorqPIOut.swIRefPu;
-//                ass_voMoveAverageFilter(&ass_stUqLimMafValue);
-//                Event_pvt_blMafClrFlg = FALSE;
-//            }
-//            else if((!ass_stCalOut.blTorqPIFlg) && (Event_pvt_blMafClrFlg == FALSE))
-//            {
-//                ass_voMoveAverageFilterClear(&ass_stUqLimMafValue);
-//                Event_pvt_blMafClrFlg = TRUE;
-//            }
-//            else
-//            {
-//            	//do noting
-//            }
+            if(ass_stCalOut.blTorqPIFlg)
+            {
+                ass_stUqLimMafValue.swValue = ass_stTorqPIOut.swIRefPu;
+                ass_voMoveAverageFilter(&ass_stUqLimMafValue);
+                Event_pvt_blMafClrFlg = FALSE;
+            }
+            else if((!ass_stCalOut.blTorqPIFlg) && (Event_pvt_blMafClrFlg == FALSE))
+            {
+                ass_voMoveAverageFilterClear(&ass_stUqLimMafValue);
+                Event_pvt_blMafClrFlg = TRUE;
+            }
+            else
+            {
+            	//do nothing
+            }
         }
         
         // Torque info update
@@ -229,6 +229,7 @@ void  Event_1ms(void)
                 }
                 else
                 {
+                    //do nothing
                 }
 
             }
@@ -279,8 +280,8 @@ void Event_10ms(void)
             {
             	//do nothing
             }
-//            
-             if(ABS(uart_slSpdRefRpm) < 300)
+            
+             if(ABS((int32_t)uart_slSpdRefRpm) < 300)
              {
                  uart_slSpdRefRpm = 0;
              }
@@ -387,11 +388,6 @@ void Event_100ms(void)
 void  Event_200ms(void)
 {
     Can_voMC_Run_200ms();
-
-    if (switch_flg.SysFault_Flag == TRUE)
-    {
-        SendData(ID_MC_BC, MODE_REPORT, 0x1104, (uint8_t *)&MC_ErrorCode.Code);
-    }
     
     if(switch_flg.SysCoef_Flag == TRUE)
     {
@@ -416,6 +412,11 @@ void  Event_200ms(void)
             alm_stBikeIn.blMotorNTCExistFlg = FALSE;
 //            alm_voDetec200MS(&alm_stBikeIn, &alm_stDetect200MSCoef);   
         }
+        
+        if (switch_flg.SysFault_Flag == TRUE)
+        {
+            SendData(ID_MC_BC, MODE_REPORT, 0x1104, (uint8_t *)&MC_ErrorCode.Code);
+        }
     }
 }
 

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

@@ -226,7 +226,7 @@ void TIMER1_IRQHandler(void)
 //    }
 //    else
 //    {
-//    	//do noting
+//    	//do nothing
 //    }
 }
 /*!

+ 105 - 107
User project/1.FrameLayer/Source/main.c

@@ -52,12 +52,9 @@
 ****************************************************************/
 int main(void)
 {
+#ifndef RUN_ARCH_SIM
     SCB->VTOR = 0x08003000;
-    /*Bootloader configuration*/
-    //    #ifdef BOOTLOADER
-    //        boot_voBootloader();
-    //    #endif
-    /* Disable all interrupts */
+
     DISABLE_IRQ; 
     /* MCU Core and GPIO configuration */
     hw_voHardwareSetup1();
@@ -92,6 +89,8 @@ int main(void)
     }
     
     return 0;
+    
+#endif
 }
 /***************************************************************
  Function: mn_voSoftwareInit;
@@ -154,19 +153,19 @@ void mn_voParaSet(void)
         {
             if (i2c_stRXCRCOut.blMotorParaFltFlg == FALSE)
             {
-                cp_stMotorPara.swMotrPolePairs = I2C_uwMotorParaRead[0];
-                cp_stMotorPara.swRsOhm = I2C_uwMotorParaRead[1];
-                cp_stMotorPara.swLdmH = I2C_uwMotorParaRead[2];
-                cp_stMotorPara.swLqmH = I2C_uwMotorParaRead[3];
-                cp_stMotorPara.swFluxWb = I2C_uwMotorParaRead[4];
-                cp_stMotorPara.swIdMaxA = I2C_uwMotorParaRead[5];
-                cp_stMotorPara.swIdMinA = I2C_uwMotorParaRead[6];
-                cp_stMotorPara.swRSpeedRpm = I2C_uwMotorParaRead[7];
-                cp_stMotorPara.swRPwrWt = I2C_uwMotorParaRead[8];
-                cp_stMotorPara.swRIarmsA = I2C_uwMotorParaRead[9];
-                cp_stMotorPara.swRUdcV = I2C_uwMotorParaRead[10];
-                cp_stMotorPara.swJD = I2C_uwMotorParaRead[11];
-                cp_stMotorPara.swTorMax = I2C_uwMotorParaRead[12];
+                cp_stMotorPara.swMotrPolePairs = (SWORD)I2C_uwMotorParaRead[0];
+                cp_stMotorPara.swRsOhm = (SWORD)I2C_uwMotorParaRead[1];
+                cp_stMotorPara.swLdmH = (SWORD)I2C_uwMotorParaRead[2];
+                cp_stMotorPara.swLqmH = (SWORD)I2C_uwMotorParaRead[3];
+                cp_stMotorPara.swFluxWb = (SWORD)I2C_uwMotorParaRead[4];
+                cp_stMotorPara.swIdMaxA = (SWORD)I2C_uwMotorParaRead[5];
+                cp_stMotorPara.swIdMinA = (SWORD)I2C_uwMotorParaRead[6];
+                cp_stMotorPara.swRSpeedRpm = (SWORD)I2C_uwMotorParaRead[7];
+                cp_stMotorPara.swRPwrWt = (SWORD)I2C_uwMotorParaRead[8];
+                cp_stMotorPara.swRIarmsA = (SWORD)I2C_uwMotorParaRead[9];
+                cp_stMotorPara.swRUdcV = (SWORD)I2C_uwMotorParaRead[10];
+                cp_stMotorPara.swJD = (SWORD)I2C_uwMotorParaRead[11];
+                cp_stMotorPara.swTorMax = (SWORD)I2C_uwMotorParaRead[12];
             }
             else
             {}
@@ -181,7 +180,7 @@ void mn_voParaSet(void)
                 ass_stParaCong.uwAssistSelect1 = I2C_uwBikeParaRead[6];
                 ass_stParaCong.uwAssistSelect2 = I2C_uwBikeParaRead[7];
                 ass_stParaCong.uwLightVoltage = I2C_uwBikeParaRead[8];
-                ass_stParaCong.swDeltPerimeter = I2C_uwBikeParaRead[9];
+                ass_stParaCong.swDeltPerimeter = (SWORD)I2C_uwBikeParaRead[9];
                 ass_stParaCong.uwStartMode = I2C_uwBikeParaRead[10];
                 ass_stParaCong.uwAutoPowerOffTime = I2C_uwBikeParaRead[11];
             }
@@ -191,16 +190,16 @@ void mn_voParaSet(void)
             {
                 cp_stFlg.ParaFirstSetFlg = I2C_uwMControlRead[0];
                 cp_stFlg.SpiOffsetFirstSetFlg = I2C_uwMControlRead[1];
-                spi_stResolverOut.swSpiThetaOffsetOrignPu = I2C_uwMControlRead[2];
-                spi_stResolverOut.swSpiThetaOffsetPu = I2C_uwMControlRead[3];
-                cp_stMotorPara.swIpeakMaxA = I2C_uwMControlRead[4];
-                cp_stControlPara.swAlmOverCurrentVal = I2C_uwMControlRead[5];
-                cp_stControlPara.swAlmOverVolVal3 = I2C_uwMControlRead[6];
-                cp_stControlPara.swAlmUnderVolVal2 = I2C_uwMControlRead[7];
-                cp_stControlPara.swAlmOverSpdVal = I2C_uwMControlRead[8];
-                cp_stControlPara.swAlmOverHeatCeVal = I2C_uwMControlRead[9];
-                cp_stControlPara.swAlmRecOHeatVal = I2C_uwMControlRead[10];
-                cp_stControlPara.swAlmPwrLimitStartTempVal = I2C_uwMControlRead[11];
+                spi_stResolverOut.swSpiThetaOffsetOrignPu = (SWORD)I2C_uwMControlRead[2];
+                spi_stResolverOut.swSpiThetaOffsetPu = (SWORD)I2C_uwMControlRead[3];
+                cp_stMotorPara.swIpeakMaxA = (SWORD)I2C_uwMControlRead[4];
+                cp_stControlPara.swAlmOverCurrentVal = (SWORD)I2C_uwMControlRead[5];
+                cp_stControlPara.swAlmOverVolVal3 = (SWORD)I2C_uwMControlRead[6];
+                cp_stControlPara.swAlmUnderVolVal2 = (SWORD)I2C_uwMControlRead[7];
+                cp_stControlPara.swAlmOverSpdVal = (SWORD)I2C_uwMControlRead[8];
+                cp_stControlPara.swAlmOverHeatCeVal = (SWORD)I2C_uwMControlRead[9];
+                cp_stControlPara.swAlmRecOHeatVal = (SWORD)I2C_uwMControlRead[10];
+                cp_stControlPara.swAlmPwrLimitStartTempVal = (SWORD)I2C_uwMControlRead[11];
             }
             else
             {
@@ -267,19 +266,19 @@ void mn_voParaUpdate(void)
 {
         if (cp_stFlg.ParaMInfoUpdateFlg == TRUE)
         {
-            cp_stMotorPara.swMotrPolePairs = MC_UpcInfo.stMotorInfo.uwPolePairs;
-            cp_stMotorPara.swRsOhm = MC_UpcInfo.stMotorInfo.uwRsmOhm;
-            cp_stMotorPara.swLdmH = MC_UpcInfo.stMotorInfo.uwLduH;
-            cp_stMotorPara.swLqmH = MC_UpcInfo.stMotorInfo.uwLquH;
-            cp_stMotorPara.swFluxWb = MC_UpcInfo.stMotorInfo.uwFluxmWb;
-            cp_stMotorPara.swIdMaxA = MC_UpcInfo.stMotorInfo.uwIdMaxA;
-            cp_stMotorPara.swIdMinA = MC_UpcInfo.stMotorInfo.uwIdMinA;
-            cp_stMotorPara.swRSpeedRpm = MC_UpcInfo.stMotorInfo.uwRSpdRpm;
-            cp_stMotorPara.swRPwrWt = MC_UpcInfo.stMotorInfo.uwRPwrWt;
-            cp_stMotorPara.swRIarmsA = MC_UpcInfo.stMotorInfo.uwRCurA;
-            cp_stMotorPara.swRUdcV = MC_UpcInfo.stMotorInfo.uwRVolV;
-            cp_stMotorPara.swJD = MC_UpcInfo.stMotorInfo.uwJD;
-            cp_stMotorPara.swTorMax = MC_UpcInfo.stMotorInfo.uwTorMaxNm;
+            cp_stMotorPara.swMotrPolePairs = (SWORD)MC_UpcInfo.stMotorInfo.uwPolePairs;
+            cp_stMotorPara.swRsOhm = (SWORD)MC_UpcInfo.stMotorInfo.uwRsmOhm;
+            cp_stMotorPara.swLdmH = (SWORD)MC_UpcInfo.stMotorInfo.uwLduH;
+            cp_stMotorPara.swLqmH = (SWORD)MC_UpcInfo.stMotorInfo.uwLquH;
+            cp_stMotorPara.swFluxWb = (SWORD)MC_UpcInfo.stMotorInfo.uwFluxmWb;
+            cp_stMotorPara.swIdMaxA = (SWORD)MC_UpcInfo.stMotorInfo.uwIdMaxA;
+            cp_stMotorPara.swIdMinA = (SWORD)MC_UpcInfo.stMotorInfo.uwIdMinA;
+            cp_stMotorPara.swRSpeedRpm = (SWORD)MC_UpcInfo.stMotorInfo.uwRSpdRpm;
+            cp_stMotorPara.swRPwrWt = (SWORD)MC_UpcInfo.stMotorInfo.uwRPwrWt;
+            cp_stMotorPara.swRIarmsA = (SWORD)MC_UpcInfo.stMotorInfo.uwRCurA;
+            cp_stMotorPara.swRUdcV = (SWORD)MC_UpcInfo.stMotorInfo.uwRVolV;
+            cp_stMotorPara.swJD = (SWORD)MC_UpcInfo.stMotorInfo.uwJD;
+            cp_stMotorPara.swTorMax = (SWORD)MC_UpcInfo.stMotorInfo.uwTorMaxNm;
 
             cp_stFlg.ParaMotorDriveUpdateFinishFlg = TRUE;
             cp_stFlg.ParaMInfoUpdateFlg = FALSE;
@@ -310,14 +309,14 @@ void mn_voParaUpdate(void)
             cp_stFlg.SpiOffsetFirstSetFlg = MC_UpcInfo.stTestParaInfo.uwSPIOffsetFirstSetFlg;
             spi_stResolverOut.swSpiThetaOffsetOrignPu = MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetOrigin;
             spi_stResolverOut.swSpiThetaOffsetPu = MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetNow;
-            cp_stMotorPara.swIpeakMaxA = MC_UpcInfo.stMContorlInfo.uwIPeakMaxA;
-            cp_stControlPara.swAlmOverCurrentVal = MC_UpcInfo.stMContorlInfo.uwAlamOCurA;
-            cp_stControlPara.swAlmOverVolVal3 = MC_UpcInfo.stMContorlInfo.uwAlamOVolV;
-            cp_stControlPara.swAlmUnderVolVal2 = MC_UpcInfo.stMContorlInfo.uwAlamUVolV;
-            cp_stControlPara.swAlmOverSpdVal = MC_UpcInfo.stMContorlInfo.uwAlamOverSpdRpm;
-            cp_stControlPara.swAlmOverHeatCeVal = MC_UpcInfo.stMContorlInfo.uwAlamOverHeatCe;
-            cp_stControlPara.swAlmRecOHeatVal = MC_UpcInfo.stMContorlInfo.uwAlamRecHeatCe;
-            cp_stControlPara.swAlmPwrLimitStartTempVal = MC_UpcInfo.stMContorlInfo.uwPwrLimitStartCe;
+            cp_stMotorPara.swIpeakMaxA = (SWORD)MC_UpcInfo.stMContorlInfo.uwIPeakMaxA;
+            cp_stControlPara.swAlmOverCurrentVal = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamOCurA;
+            cp_stControlPara.swAlmOverVolVal3 = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamOVolV;
+            cp_stControlPara.swAlmUnderVolVal2 = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamUVolV;
+            cp_stControlPara.swAlmOverSpdVal = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamOverSpdRpm;
+            cp_stControlPara.swAlmOverHeatCeVal = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamOverHeatCe;
+            cp_stControlPara.swAlmRecOHeatVal = (SWORD)MC_UpcInfo.stMContorlInfo.uwAlamRecHeatCe;
+            cp_stControlPara.swAlmPwrLimitStartTempVal = (SWORD)MC_UpcInfo.stMContorlInfo.uwPwrLimitStartCe;
 
             cp_stFlg.ParaMotorDriveUpdateFinishFlg = TRUE;
             cp_stFlg.ParaMCInfoUpdateFlg = FALSE;
@@ -364,31 +363,31 @@ void mn_voParaUpdate(void)
 
         if(cp_stFlg.TestParaInfoUpdateFlg == TRUE)
         {
-            cp_stControlPara.swAlignCurAp = MC_UpcInfo.stTestParaInfo.uwInitPosCurAmp;
-            cp_stControlPara.swDragVolAp = MC_UpcInfo.stTestParaInfo.uwVFControlVolAmp;
-            cp_stControlPara.swDragCurAp = MC_UpcInfo.stTestParaInfo.uwIFControlCurAmp;
-            cp_stControlPara.swDragSpdHz = MC_UpcInfo.stTestParaInfo.uwVFIFTargetFreHz;
-
-            cp_stControlPara.swSpeedAccRate = MC_UpcInfo.stTestParaInfo.uwSpeedLoopAccRate;
-            cp_stControlPara.swSpeedDccRate = MC_UpcInfo.stTestParaInfo.uwSpeedLoopDecRate;
-            cp_stControlPara.swAsrPIBandwidth = MC_UpcInfo.stTestParaInfo.uwSpeedLoopBandWidthHz;
-            cp_stControlPara.swAsrPIM = MC_UpcInfo.stTestParaInfo.uwSpeedLoopCoefM;
-
-            cp_stControlPara.swAcrPIBandwidth = MC_UpcInfo.stTestParaInfo.uwCuerrentLoopBandWidthHz;
-            cp_stControlPara.swAcrRaCoef = MC_UpcInfo.stTestParaInfo.uwCurrentLoopCoefM;
-
-            cp_stControlPara.swObsFluxPICrossfreHz = MC_UpcInfo.stTestParaInfo.uwFluxObsBandWidthHz;
-            cp_stControlPara.swObsFluxPIDampratio = MC_UpcInfo.stTestParaInfo.uwFluxObsCoefM;
-            cp_stControlPara.swObsSpdPLLBandWidthHz = MC_UpcInfo.stTestParaInfo.uwThetaObsPLLBandWidthHz;
-            cp_stControlPara.swObsSpdPLLM = MC_UpcInfo.stTestParaInfo.uwThetaObsPLLCoefM;
-
-            cp_stMotorPara.swJD = MC_UpcInfo.stTestParaInfo.uwJm;
-            cp_stControlPara.swPWMMaxDuty = MC_UpcInfo.stTestParaInfo.uwPWMMaxDuty;
-            cp_stControlPara.swPWM7to5Duty = MC_UpcInfo.stTestParaInfo.uwPWM7to5Duty;
-            cp_stControlPara.swPwrLimitValWt = MC_UpcInfo.stTestParaInfo.uwPwrLimit;
-            cp_stControlPara.swPwrLimitErrWt = MC_UpcInfo.stTestParaInfo.uwPwrLimitError;
-            cp_stControlPara.swPwrLimitKpPu = MC_UpcInfo.stTestParaInfo.uwPwrLimitKp;
-            cp_stControlPara.swPwrLimitKiPu = MC_UpcInfo.stTestParaInfo.uwPwrLimitKi;
+            cp_stControlPara.swAlignCurAp = (SWORD)MC_UpcInfo.stTestParaInfo.uwInitPosCurAmp;
+            cp_stControlPara.swDragVolAp = (SWORD)MC_UpcInfo.stTestParaInfo.uwVFControlVolAmp;
+            cp_stControlPara.swDragCurAp = (SWORD)MC_UpcInfo.stTestParaInfo.uwIFControlCurAmp;
+            cp_stControlPara.swDragSpdHz = (SWORD)MC_UpcInfo.stTestParaInfo.uwVFIFTargetFreHz;
+
+            cp_stControlPara.swSpeedAccRate = (SWORD)MC_UpcInfo.stTestParaInfo.uwSpeedLoopAccRate;
+            cp_stControlPara.swSpeedDccRate = (SWORD)MC_UpcInfo.stTestParaInfo.uwSpeedLoopDecRate;
+            cp_stControlPara.swAsrPIBandwidth = (SWORD)MC_UpcInfo.stTestParaInfo.uwSpeedLoopBandWidthHz;
+            cp_stControlPara.swAsrPIM = (SWORD)MC_UpcInfo.stTestParaInfo.uwSpeedLoopCoefM;
+
+            cp_stControlPara.swAcrPIBandwidth = (SWORD)MC_UpcInfo.stTestParaInfo.uwCuerrentLoopBandWidthHz;
+            cp_stControlPara.swAcrRaCoef = (SWORD)MC_UpcInfo.stTestParaInfo.uwCurrentLoopCoefM;
+
+            cp_stControlPara.swObsFluxPICrossfreHz = (SWORD)MC_UpcInfo.stTestParaInfo.uwFluxObsBandWidthHz;
+            cp_stControlPara.swObsFluxPIDampratio = (SWORD)MC_UpcInfo.stTestParaInfo.uwFluxObsCoefM;
+            cp_stControlPara.swObsSpdPLLBandWidthHz = (SWORD)MC_UpcInfo.stTestParaInfo.uwThetaObsPLLBandWidthHz;
+            cp_stControlPara.swObsSpdPLLM = (SWORD)MC_UpcInfo.stTestParaInfo.uwThetaObsPLLCoefM;
+
+            cp_stMotorPara.swJD = (SWORD)MC_UpcInfo.stTestParaInfo.uwJm;
+            cp_stControlPara.swPWMMaxDuty = (SWORD)MC_UpcInfo.stTestParaInfo.uwPWMMaxDuty;
+            cp_stControlPara.swPWM7to5Duty = (SWORD)MC_UpcInfo.stTestParaInfo.uwPWM7to5Duty;
+            cp_stControlPara.swPwrLimitValWt = (SWORD)MC_UpcInfo.stTestParaInfo.uwPwrLimit;
+            cp_stControlPara.swPwrLimitErrWt = (SWORD)MC_UpcInfo.stTestParaInfo.uwPwrLimitError;
+            cp_stControlPara.swPwrLimitKpPu = (SWORD)MC_UpcInfo.stTestParaInfo.uwPwrLimitKp;
+            cp_stControlPara.swPwrLimitKiPu = (SWORD)MC_UpcInfo.stTestParaInfo.uwPwrLimitKi;
 
             cp_stFlg.ParaMotorDriveUpdateFinishFlg = TRUE;
             // cp_stFlg.TestParaInfoUpdateFlg = FALSE;
@@ -407,19 +406,19 @@ void mn_voEEUperParaUpdate(void)
 {
     if (MC_UpcInfo.stMotorInfo.uwSaveFlg == TRUE)
     {
-        Syspara2.stMotorPara.uwPolePairs.uwReal = cp_stMotorPara.swMotrPolePairs;
-        Syspara2.stMotorPara.uwRsmOhm.uwReal = cp_stMotorPara.swRsOhm;
-        Syspara2.stMotorPara.uwLduH.uwReal = cp_stMotorPara.swLdmH;
-        Syspara2.stMotorPara.uwLquH.uwReal = cp_stMotorPara.swLqmH;
-        Syspara2.stMotorPara.uwFluxmWb.uwReal = cp_stMotorPara.swFluxWb;
-        Syspara2.stMotorPara.uwIdMaxA.uwReal = cp_stMotorPara.swIdMaxA;
-        Syspara2.stMotorPara.uwIdMinA.uwReal = cp_stMotorPara.swIdMinA;
-        Syspara2.stMotorPara.uwRSpdRpm.uwReal = cp_stMotorPara.swRSpeedRpm;
-        Syspara2.stMotorPara.uwRPwrWt.uwReal = cp_stMotorPara.swRPwrWt;
-        Syspara2.stMotorPara.uwRCurA.uwReal = cp_stMotorPara.swRIarmsA;
-        Syspara2.stMotorPara.uwRVolV.uwReal = cp_stMotorPara.swRUdcV;
-        Syspara2.stMotorPara.uwJD.uwReal = cp_stMotorPara.swJD;
-        Syspara2.stMotorPara.uwTorMaxNm.uwReal = cp_stMotorPara.swTorMax;
+        Syspara2.stMotorPara.uwPolePairs.uwReal = (UWORD)cp_stMotorPara.swMotrPolePairs;
+        Syspara2.stMotorPara.uwRsmOhm.uwReal = (UWORD)cp_stMotorPara.swRsOhm;
+        Syspara2.stMotorPara.uwLduH.uwReal = (UWORD)cp_stMotorPara.swLdmH;
+        Syspara2.stMotorPara.uwLquH.uwReal = (UWORD)cp_stMotorPara.swLqmH;
+        Syspara2.stMotorPara.uwFluxmWb.uwReal = (UWORD)cp_stMotorPara.swFluxWb;
+        Syspara2.stMotorPara.uwIdMaxA.uwReal = (UWORD)cp_stMotorPara.swIdMaxA;
+        Syspara2.stMotorPara.uwIdMinA.uwReal = (UWORD)cp_stMotorPara.swIdMinA;
+        Syspara2.stMotorPara.uwRSpdRpm.uwReal = (UWORD)cp_stMotorPara.swRSpeedRpm;
+        Syspara2.stMotorPara.uwRPwrWt.uwReal = (UWORD)cp_stMotorPara.swRPwrWt;
+        Syspara2.stMotorPara.uwRCurA.uwReal = (UWORD)cp_stMotorPara.swRIarmsA;
+        Syspara2.stMotorPara.uwRVolV.uwReal = (UWORD)cp_stMotorPara.swRUdcV;
+        Syspara2.stMotorPara.uwJD.uwReal = (UWORD)cp_stMotorPara.swJD;
+        Syspara2.stMotorPara.uwTorMaxNm.uwReal = (UWORD)cp_stMotorPara.swTorMax;
     }
     Syspara2.stBikePara.swDeltPerimeter.swReal = ass_stParaCong.swDeltPerimeter;
     if (MC_UpcInfo.stBikeInfo.uwSaveFlg == TRUE)
@@ -443,14 +442,14 @@ void mn_voEEUperParaUpdate(void)
         Syspara2.stMControlPara.SpiOffsetFirstSetFlg.uwReal = cp_stFlg.SpiOffsetFirstSetFlg;
         Syspara2.stMControlPara.uwSPIPosOffsetOrigin.uwReal = spi_stResolverOut.swSpiThetaOffsetOrignPu;
         Syspara2.stMControlPara.uwSPIPosOffsetNow.uwReal = spi_stResolverOut.swSpiThetaOffsetPu;
-        Syspara2.stMControlPara.uwIPeakMaxA.uwReal = cp_stMotorPara.swIpeakMaxA;
-        Syspara2.stMControlPara.uwAlamOCurA.uwReal = cp_stControlPara.swAlmOverCurrentVal;
-        Syspara2.stMControlPara.uwAlamOVolV.uwReal = cp_stControlPara.swAlmOverVolVal3;
-        Syspara2.stMControlPara.uwAlamUVolV.uwReal = cp_stControlPara.swAlmUnderVolVal2;
-        Syspara2.stMControlPara.uwAlamOverSpdRpm.uwReal = cp_stControlPara.swAlmOverSpdVal;
-        Syspara2.stMControlPara.uwAlamOverHeatCe.uwReal = cp_stControlPara.swAlmOverHeatCeVal;
-        Syspara2.stMControlPara.uwAlamRecHeatCe.uwReal = cp_stControlPara.swAlmRecOHeatVal;
-        Syspara2.stMControlPara.uwPwrLimitStartCe.uwReal = cp_stControlPara.swAlmPwrLimitStartTempVal;
+        Syspara2.stMControlPara.uwIPeakMaxA.uwReal = (UWORD)cp_stMotorPara.swIpeakMaxA;
+        Syspara2.stMControlPara.uwAlamOCurA.uwReal = (UWORD)cp_stControlPara.swAlmOverCurrentVal;
+        Syspara2.stMControlPara.uwAlamOVolV.uwReal = (UWORD)cp_stControlPara.swAlmOverVolVal3;
+        Syspara2.stMControlPara.uwAlamUVolV.uwReal = (UWORD)cp_stControlPara.swAlmUnderVolVal2;
+        Syspara2.stMControlPara.uwAlamOverSpdRpm.uwReal = (UWORD)cp_stControlPara.swAlmOverSpdVal;
+        Syspara2.stMControlPara.uwAlamOverHeatCe.uwReal = (UWORD)cp_stControlPara.swAlmOverHeatCeVal;
+        Syspara2.stMControlPara.uwAlamRecHeatCe.uwReal = (UWORD)cp_stControlPara.swAlmRecOHeatVal;
+        Syspara2.stMControlPara.uwPwrLimitStartCe.uwReal = (UWORD)cp_stControlPara.swAlmPwrLimitStartTempVal;
     }
     if (MC_UpcInfo.stSensorInfo.uwSaveFlg == TRUE)
     {
@@ -573,7 +572,6 @@ void mn_voSoftwareInit(void)
     adc_voSampleInit();
     adc_voSampleCoef(&adc_stCof);
     /* UART init */
-    //uart_voApplInit();
     uart_voMonitorInit();
 }
 
@@ -588,9 +586,9 @@ void mn_voSoftwareInit(void)
 ************************************************************************/
 void mn_voMtParInit(void)
 {
-    mn_swIdTurn1Pu = ((SLONG)M_LD_TURN1_ID_AP << 14) / cof_uwIbAp; // Q14, saturation current of Ld
+    mn_swIdTurn1Pu = (SWORD)(((SLONG)M_LD_TURN1_ID_AP << 14) / (SWORD)cof_uwIbAp); // Q14, saturation current of Ld
     mn_slLdTurn1Pu = ((SLONG)M_LD_TURN1_LD_MH << 10) / cof_uwLbHm; // Q10, saturation inductance of Ld
-    mn_swIdTurn2Pu = ((SLONG)M_LD_TURN2_ID_AP << 14) / cof_uwIbAp; // Q14, saturation current of Ld
+    mn_swIdTurn2Pu = (SWORD)(((SLONG)M_LD_TURN2_ID_AP << 14) / (SWORD)cof_uwIbAp); // Q14, saturation current of Ld
     mn_slLdTurn2Pu = ((SLONG)M_LD_TURN2_LD_MH << 10) / cof_uwLbHm; // Q10, saturation inductance of Ld
     if (mn_swIdTurn1Pu == mn_swIdTurn2Pu)
     {
@@ -598,12 +596,12 @@ void mn_voMtParInit(void)
     }
     else
     {
-        mn_swKLdSat = ((mn_slLdTurn2Pu - mn_slLdTurn1Pu) << 10) / (mn_swIdTurn2Pu - mn_swIdTurn1Pu); // Q10
+        mn_swKLdSat = (SWORD)(((mn_slLdTurn2Pu - mn_slLdTurn1Pu) << 10) / (mn_swIdTurn2Pu - mn_swIdTurn1Pu)); // Q10
     }
 
-    mn_swIqTurn1Pu = ((SLONG)M_LQ_TURN1_IQ_AP << 14) / cof_uwIbAp; // Q14, saturation current of Lq
+    mn_swIqTurn1Pu = (SWORD)(((SLONG)M_LQ_TURN1_IQ_AP << 14) / (SWORD)cof_uwIbAp); // Q14, saturation current of Lq
     mn_slLqTurn1Pu = ((SLONG)M_LQ_TURN1_LQ_MH << 10) / cof_uwLbHm; // Q10, saturation inductance of Lq
-    mn_swIqTurn2Pu = ((SLONG)M_LQ_TURN2_IQ_AP << 14) / cof_uwIbAp; // Q14, saturation current of Lq
+    mn_swIqTurn2Pu = (SWORD)(((SLONG)M_LQ_TURN2_IQ_AP << 14) / (SWORD)cof_uwIbAp); // Q14, saturation current of Lq
     mn_slLqTurn2Pu = ((SLONG)M_LQ_TURN2_LQ_MH << 10) / cof_uwLbHm; // Q10, saturation inductance of Lq
     if (mn_swIqTurn1Pu == mn_swIqTurn2Pu)
     {
@@ -611,7 +609,7 @@ void mn_voMtParInit(void)
     }
     else
     {
-        mn_swKLqSat = ((mn_slLqTurn2Pu - mn_slLqTurn1Pu) << 10) / (mn_swIqTurn2Pu - mn_swIqTurn1Pu); // Q10
+        mn_swKLqSat = (SWORD)(((mn_slLqTurn2Pu - mn_slLqTurn1Pu) << 10) / (mn_swIqTurn2Pu - mn_swIqTurn1Pu)); // Q10
     }
 }
 
@@ -629,7 +627,7 @@ void mn_voMcParInit(void)
     align_voInit();
 
     // Align Parameters
-    mn_uwAlignCurPu = CUR_AP2PU(cp_stControlPara.swAlignCurAp); // Q14
+    mn_uwAlignCurPu = (UWORD)CUR_AP2PU(cp_stControlPara.swAlignCurAp); // Q14
     mn_ulAlignRampTbcCt = TBC_MS2CT(cp_stControlPara.swAlignRampTMms);
     mn_ulAlignHoldTbcCt = TBC_MS2CT(cp_stControlPara.swAlignHoldTMms);
     if (mn_ulAlignRampTbcCt == 0)
@@ -647,8 +645,8 @@ void mn_voMcParInit(void)
     mn_slAlignAngInit = ANG_DEG2PU(cp_stControlPara.swAlignAngInitDeg);
 
     // Open Drag Parameters
-    mn_uwDragCurPu = CUR_AP2PU(cp_stControlPara.swDragCurAp); // Q14
-    mn_swDragSpdPu = SPD_HZ2PU(cp_stControlPara.swDragSpdHz); // Q15
+    mn_uwDragCurPu = (UWORD)CUR_AP2PU(cp_stControlPara.swDragCurAp); // Q14
+    mn_swDragSpdPu = (SWORD)SPD_HZ2PU(cp_stControlPara.swDragSpdHz); // Q15
     mn_ulDragSpdRampTbcCt = TBC_MS2CT(cp_stControlPara.swDragSpdRampTMms);
     if (mn_ulDragSpdRampTbcCt == 0)
     {
@@ -677,7 +675,7 @@ void mn_voMcParInit(void)
         }
     }
     // Stop Parameters
-    mn_swStopSpdRefPu = SPD_RPM2PU(cp_stControlPara.swStopSpdRefRpm);
+    mn_swStopSpdRefPu = (SWORD)SPD_RPM2PU(cp_stControlPara.swStopSpdRefRpm);
 }
 
 /***************************************************************

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

@@ -64,7 +64,7 @@ void tbc_voUpIsr(void)
     }
     else
     {
-
+        //do nothing
     }
 
     FSM1st_Sys_state.Tbcup_hook();
@@ -157,7 +157,7 @@ void tbc_voDownIsr(void)
         que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
         que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
 
-        que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1 );//54
+        que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);//54
     }
     else if(switch_flg.SysFault_Flag == FALSE)
     {

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

@@ -42,11 +42,10 @@ Revising History (ECL of this file):
 void tbs_voIsr(void)
 {
     /* Alarm detect */
-//    alm_voDetecTBS(&alm_stIn, &alm_stDetectTbsCoef);
+    alm_voDetecTBS(&alm_stIn, &alm_stDetectTbsCoef);
 
+  /* 1st FSM */
     FSM1st_Sys_state.Tbs_hook();
-
-    /* System FSM */
 }
 
 /*************************************************************************

+ 6 - 6
User project/2.MotorDrive/Include/adc.h

@@ -188,18 +188,18 @@ _ADCDRV_EXT UWORD adc_RdsonADCGainSum;
 *************************************************************************/
 #ifdef _ADCDRV_C_
 _ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
+_ADCDRV_EXT void adc_voSampleUp(const ADC_COF *cof, ADC_UP_OUT *out);
+_ADCDRV_EXT void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out);
 _ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
 _ADCDRV_EXT void adc_voSampleInit(void);
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof, ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out);
+_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof, const ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out);
 #else
 _ADCDRV_EXT void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2); // Phase A and B current zero point, other A/D sample value
-_ADCDRV_EXT void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out);
-_ADCDRV_EXT void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out);
+_ADCDRV_EXT void adc_voSampleUp(const ADC_COF *cof, ADC_UP_OUT *out);
+_ADCDRV_EXT void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out);
 _ADCDRV_EXT void adc_voSampleCoef(ADC_COF *cof);
 _ADCDRV_EXT void adc_voSampleInit(void);
-_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof, ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out);
+_ADCDRV_EXT void adc_voSRCalibration(ADC_COF *cof, const ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out);
 #endif
 
 /************************************************************************

+ 21 - 21
User project/2.MotorDrive/Include/alarm.h

@@ -41,7 +41,7 @@ Revising History (ECL of this file):
     } // Default value of ALM_ACTION
 #define ALM_IN_DEFAULT                                              \
     {                                                               \
-        FALSE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,FALSE \
+        FALSE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0 ,FALSE \
     } // Default value of ALM_IN_DEFAULT
 #define ALM_DETECT_COUNT_DEFAULT           \
     {                                      \
@@ -514,43 +514,43 @@ _ALARM_EXT ALM_DETEC200MS_COF alm_stDetect200MSCoef;
 #ifdef _ALARM_C_
 _ALARM_EXT void alm_voInit(void);
 _ALARM_EXT void alm_voCoef(void);
-_ALARM_EXT void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef);
+_ALARM_EXT void alm_voDetecTBC(const ALM_IN *in, const ALM_DETECTBC_COF *coef);
 _ALARM_EXT void alm_voDetecTBCCoef(ALM_DETECTBC_COFIN *in, ALM_DETECTBC_COF *out);
-_ALARM_EXT void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef);
+_ALARM_EXT void alm_voDetecTBS(const ALM_IN *in, const ALM_DETECTBS_COF *coef);
 _ALARM_EXT void alm_voDetecTBSCoef(ALM_DETECTBS_COFIN *in, ALM_DETECTBS_COF *out);
-_ALARM_EXT void alm_voHandleTBC(ALM_IN *in);
-_ALARM_EXT void alm_voHandleTBS(ALM_IN *in);
+_ALARM_EXT void alm_voHandleTBC(const ALM_IN *in);
+_ALARM_EXT void alm_voHandleTBS(const ALM_IN *in);
 _ALARM_EXT void alm_voStopTBCCoef(ALM_STOPTBC_COFIN *in, ALM_STOPTBC_COF *out);
-_ALARM_EXT void alm_voStopTBC(ALM_IN *in, ALM_STOPTBC_COF *coef);
+_ALARM_EXT void alm_voStopTBC(const ALM_IN *in, const ALM_STOPTBC_COF *coef);
 _ALARM_EXT void alm_voStopTBS(void);
 _ALARM_EXT void alm_voResetCoef(ALM_RESET_COFIN *in, ALM_RESET_COF *out);
-_ALARM_EXT void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef);
+_ALARM_EXT void alm_voReset(const ALM_IN *in, const ALM_RESET_COF *coef);
 _ALARM_EXT void alm_voHandleRst(void);
 _ALARM_EXT void alm_voDetec200MSCoef(ALM_DETEC200MS_COFIN *in, ALM_DETEC200MS_COF *out);
-_ALARM_EXT void alm_voDetec200MS(ALM_BIKE_IN *in, ALM_DETEC200MS_COF *coef);
-_ALARM_EXT void alm_voHandle1MS(ALM_BIKE_IN *in);
-_ALARM_EXT void alm_voReset1MSCoef(ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out);
-_ALARM_EXT void alm_voReset1MS(ALM_BIKE_IN *in, ALM_RESET1MS_COF *coef, ALM_DETEC200MS_COF *detctcoef);
+_ALARM_EXT void alm_voDetec200MS(const ALM_BIKE_IN *in, const ALM_DETEC200MS_COF *coef);
+_ALARM_EXT void alm_voHandle1MS(const ALM_BIKE_IN *in);
+_ALARM_EXT void alm_voReset1MSCoef(const ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out);
+_ALARM_EXT void alm_voReset1MS(const ALM_BIKE_IN *in, const ALM_RESET1MS_COF *coef, const ALM_DETEC200MS_COF *detctcoef);
 #else
 _ALARM_EXT void alm_voInit(void);
 _ALARM_EXT void alm_voCoef(void);
-_ALARM_EXT void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef);
+_ALARM_EXT void alm_voDetecTBC(const ALM_IN *in, const ALM_DETECTBC_COF *coef);
 _ALARM_EXT void alm_voDetecTBCCoef(ALM_DETECTBC_COFIN *in, ALM_DETECTBC_COF *out);
-_ALARM_EXT void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef);
+_ALARM_EXT void alm_voDetecTBS(const ALM_IN *in, const ALM_DETECTBS_COF *coef);
 _ALARM_EXT void alm_voDetecTBSCoef(ALM_DETECTBS_COFIN *in, ALM_DETECTBS_COF *out);
-_ALARM_EXT void alm_voHandleTBC(ALM_IN *in);
-_ALARM_EXT void alm_voHandleTBS(ALM_IN *in);
+_ALARM_EXT void alm_voHandleTBC(const ALM_IN *in);
+_ALARM_EXT void alm_voHandleTBS(const ALM_IN *in);
 _ALARM_EXT void alm_voStopTBCCoef(ALM_STOPTBC_COFIN *in, ALM_STOPTBC_COF *out);
-_ALARM_EXT void alm_voStopTBC(ALM_IN *in, ALM_STOPTBC_COF *coef);
+_ALARM_EXT void alm_voStopTBC(const ALM_IN *in, const ALM_STOPTBC_COF *coef);
 _ALARM_EXT void alm_voStopTBS(void);
 _ALARM_EXT void alm_voResetCoef(ALM_RESET_COFIN *in, ALM_RESET_COF *out);
-_ALARM_EXT void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef);
+_ALARM_EXT void alm_voReset(const ALM_IN *in, const ALM_RESET_COF *coef);
 _ALARM_EXT void alm_voHandleRst(void);
 _ALARM_EXT void alm_voDetec200MSCoef(ALM_DETEC200MS_COFIN *in, ALM_DETEC200MS_COF *out);
-_ALARM_EXT void alm_voDetec200MS(ALM_BIKE_IN *in, ALM_DETEC200MS_COF *coef);
-_ALARM_EXT void alm_voHandle1MS(ALM_BIKE_IN *in);
-_ALARM_EXT void alm_voReset1MSCoef(ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out);
-_ALARM_EXT void alm_voReset1MS(ALM_BIKE_IN *in, ALM_RESET1MS_COF *coef, ALM_DETEC200MS_COF *detctcoef);
+_ALARM_EXT void alm_voDetec200MS(const ALM_BIKE_IN *in, const ALM_DETEC200MS_COF *coef);
+_ALARM_EXT void alm_voHandle1MS(const ALM_BIKE_IN *in);
+_ALARM_EXT void alm_voReset1MSCoef(const ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out);
+_ALARM_EXT void alm_voReset1MS(const ALM_BIKE_IN *in, const ALM_RESET1MS_COF *coef, const ALM_DETEC200MS_COF *detctcoef);
 #endif
 
 /************************************************************************

+ 4 - 4
User project/2.MotorDrive/Include/pwm.h

@@ -123,7 +123,7 @@ typedef struct
     RDSON_SAMPLE_AREA   uwSampleArea;
     SINGELR_SAMPLE_AREA uwSingelRSampleAreaLast;
     SINGELR_SAMPLE_AREA uwSingelRSampleArea;
-    UWORD               uwRDSONTrig;
+    UWORD               uwRdsonTrig;
     UWORD               uwSigRTrig;
     BOOL                blOvmFlag;
     BOOL                blSampleCalibFlag;
@@ -137,7 +137,7 @@ PWM_EXT PWM_GEN_OUT  pwm_stGenOut = PWM_GEN_OUT_DEFAULT;
 
 PWM_EXT SWORD pwm_sw1stCurSmplCt = PWM_1ST_SAMPLE_CTS_IPM;                 // min time for ADC one channel of Current
 PWM_EXT SWORD pwm_sw2ndCurSmplCt = PWM_2ND_SAMPLE_CTS_IPM;                 // the time of second current sample trig lag the second comparator
-PWM_EXT SWORD pwm_swMinDoubleCurSmplPu = (PWM_MIN_EFF_VECTOR_PU_IPM << 1); // min time of Two valid voltage vector
+PWM_EXT SWORD pwm_swMinDoubleCurSmplPu = PWM_MIN_EFF_VECTOR_PU_IPM << 1; // min time of Two valid voltage vector
 PWM_EXT SWORD pwm_swMinCurSmplCt = PWM_MIN_EFF_VECTOR_CTS_IPM;             // min counts of one valid voltage vector
 PWM_EXT SWORD pwm_swMinCurSmplPu = PWM_MIN_EFF_VECTOR_CTS_IPM;             // min time of one valid voltage vector
 #else
@@ -161,11 +161,11 @@ PWM_EXT SWORD pwm_swMinCurSmplPu;
  Exported Function Call Prototypes (N/A)
 ************************************************************************/
 #ifdef _PWM_C_
-PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out);
+PWM_EXT void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out);
 PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef);
 PWM_EXT void pwm_voInit(void);
 #else
-PWM_EXT void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out);
+PWM_EXT void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out);
 PWM_EXT void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef);
 PWM_EXT void pwm_voInit(void);
 #endif

+ 1 - 1
User project/2.MotorDrive/Include/spdctrFSM.h

@@ -85,7 +85,7 @@ _STARTFSM_EXT void ClzLoop_TbsHook(void);
 _STARTFSM_EXT void Stop_TbsHook(void);
 
 _STARTFSM_EXT void scm_voSpdCtrMdFSM(void);
-_STARTFSM_EXT void Switch_speed_FSM(SPD_STATE_HOOK *in);
+_STARTFSM_EXT void Switch_speed_FSM(const SPD_STATE_HOOK *in);
 _STARTFSM_EXT void Switch_speed_FSMInit(void);
 
 /************************************************************************

+ 14 - 14
User project/2.MotorDrive/Source/adc.c

@@ -58,13 +58,9 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
         else
         {
             if(cp_stFlg.CurrentSampleModelSelect == COMBINATION)
-            {
-//                pwm_stGenOut.uwRDSONTrig = 129 ;  
-//                pwm_stGenOut.uwSigRTrig = HW_HHHPWM_PERIOD;
-//                pwm_stGenOut.blSampleCalibFlag = TRUE;
-                
+            {              
                 ULONG samplingTick[2];
-                samplingTick[0] = HW_HHHPWM_PERIOD;
+                samplingTick[0] = HW_INIT_HHHPWM_PERIOD;
                 samplingTick[1] = 129;
                 iPwm_SyncMultiSamplingCountUp(0, &samplingTick[0], 2);
                 pwm_stGenOut.blSampleCalibFlag = TRUE;
@@ -148,7 +144,9 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
 //                }
 //            }
             else
-            {}
+            {
+            	//do nothing
+            }
         }
     }
 }
@@ -161,7 +159,7 @@ void adc_voCalibration(ADC_COF *cof, ADC_DOWN_OUT *out1, ADC_UP_OUT *out2)
  Subroutine Call:
  Reference: N/A
 ****************************************************************/
-void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out)
+void adc_voSampleDown(const ADC_COF *cof, ADC_DOWN_OUT *out)
 {
     UWORD uwIpeakPu;
 
@@ -241,9 +239,9 @@ void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out)
     else if(cp_stFlg.CurrentSampleModelSelect == RDSON)
     {
        SWORD tmp_swIphase1, tmp_swIphase2, tmp_swIphase3;
-        out->uwIaReg = adc_uwRdsonUReg;
-        out->uwIbReg = adc_uwRdsonVReg;
-        out->uwIcReg = adc_uwRdsonWReg;
+        out->uwIaReg = iAdc_GetResultPointer(1)[HW_ADC_IA_CH];
+        out->uwIbReg = iAdc_GetResultPointer(1)[HW_ADC_IB_CH];
+        out->uwIcReg = iAdc_GetResultPointer(1)[HW_ADC_IC_CH];
 
         tmp_swIphase1 = -(((SWORD)out->uwIaReg - cof->uwIaOffset) * cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
         tmp_swIphase2 = -(((SWORD)out->uwIbReg - cof->uwIbOffset) * cof->uwCurReg2Pu >> 10); // Q14=Q24-Q10
@@ -292,7 +290,9 @@ void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out)
         } 
     }*/
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Current absolute value & max value */
     if ((out->swIaPu) >= 0)
@@ -325,7 +325,7 @@ void adc_voSampleDown(ADC_COF *cof, ADC_DOWN_OUT *out)
     out->uwIpeakPu = uwIpeakPu;
 }
 
-void adc_voSampleUp(ADC_COF *cof, ADC_UP_OUT *out)
+void adc_voSampleUp(const ADC_COF *cof, ADC_UP_OUT *out)
 {
     /* Register value */
     out->uwVdcReg = iAdc_GetResultPointer(0)[HW_ADC_UDC_CH]; 
@@ -386,7 +386,7 @@ static LPF_OUT adc_pvt_stRdsonCoefLpf = {.slY.sw.hi = 1024, .slY.sw.low = 0};
 static BOOL adc_pvt_blCalGainFlg = FALSE;
 static ULONG adc_pvt_ulGainTemp1 = 0;
 static ULONG adc_pvt_ulIaAbsPu, adc_pvt_ulIbAbsPu, adc_pvt_ulIcAbsPu, adc_pvt_ulIPeakPu;
-void adc_voSRCalibration(ADC_COF *cof, ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out)
+void adc_voSRCalibration(ADC_COF *cof, const ADC_UP_OUT *up_out, ADC_DOWN_OUT *down_out)
 { 
     if (pwm_stGenOut.blSampleCalibFlag == TRUE)
     {             

+ 75 - 67
User project/2.MotorDrive/Source/alarm.c

@@ -32,7 +32,10 @@ Included File:
 #include "spdctrFSM.h"
 #include "api.h"
 #include "sys_ctrl.h"
+
+#ifndef RUN_ARCH_SIM
 #include "gd32f30x.h"
+#endif
 /************************************************************************
 Private Variables:
 ************************************************************************/
@@ -279,7 +282,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
+void alm_voDetecTBC(const ALM_IN *in, const ALM_DETECTBC_COF *coef)
 {
     SWORD swTmp1, swTmp2;
     
@@ -294,8 +297,8 @@ void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
     =======================================================================*/
     if (iPwm_GetBreakState(0) != 0)
     {
-        alm_unAction.bit.ThrPhsShrtFrc = TRUE;
-        alm_unCode.bit.IPMFlt = TRUE;
+        alm_unAction.bit.ThrPhsShrtFrc = 1;
+        alm_unCode.bit.IPMFlt = 1;
     }
 
     if (alm_pvt_blTbcFirstFlg == TRUE)
@@ -313,8 +316,8 @@ void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
                     if (alm_stDecCt.ulOvrCur >= coef->ulOvrCurValCt) // 500us
                     {
                         alm_stDecCt.ulOvrCur = coef->ulOvrCurValCt;
-                        alm_unAction.bit.PWMOff = TRUE;
-                        alm_unCode.bit.OvrCur = TRUE;
+                        alm_unAction.bit.PWMOff = 1;
+                        alm_unCode.bit.OvrCur = 1;
                     }
                 }
                 else
@@ -334,8 +337,8 @@ void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
         //    {
         //      if((in->uwIdcOffset >= coef->slAdcDetHigValPu)||(in->uwIdcOffset <= coef->slAdcDetLowValPu))
         //      {
-        //        alm_unAction.bit.ThrPhsShrt = TRUE;
-        //        alm_unCode.bit.ADCOffsetFlt = TRUE;
+        //        alm_unAction.bit.ThrPhsShrt = 1;
+        //        alm_unCode.bit.ADCOffsetFlt = 1;
         //      }
         //    }
         /*=======================================================================
@@ -382,9 +385,9 @@ void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
                 alm_stDecCt.ulPhsALoss = coef->ulPhsLossValCt;
                 alm_stDecCt.ulPhsBLoss = coef->ulPhsLossValCt;
                 alm_stDecCt.ulPhsCLoss = coef->ulPhsLossValCt;
-                alm_unAction.bit.PWMOff = TRUE;
-                // alm_unAction.bit.ThrPhsShrt = TRUE;
-//                alm_unCode.bit.PhsLoss = TRUE;
+                alm_unAction.bit.PWMOff = 1;
+                // alm_unAction.bit.ThrPhsShrt = 1;
+//                alm_unCode.bit.PhsLoss = 1;
             }
         }
         else
@@ -429,9 +432,9 @@ void alm_voDetecTBC(ALM_IN *in, ALM_DETECTBC_COF *coef)
                     if (alm_stDecCt.slRotorLock >= coef->slRotorLockValCt) // 4s
                     {
                         alm_stDecCt.slRotorLock = coef->slRotorLockValCt;
-                        // alm_unAction.bit.ThrPhsShrt = TRUE;
-                        alm_unAction.bit.PWMOff = TRUE;
-                        alm_unCode.bit.RotorLock = TRUE;
+                        // alm_unAction.bit.ThrPhsShrt = 1;
+                        alm_unAction.bit.PWMOff = 1;
+                        alm_unCode.bit.RotorLock = 1;
                     }
                 }
                 else
@@ -523,7 +526,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
+void alm_voDetecTBS(const ALM_IN *in, const ALM_DETECTBS_COF *coef)
 {
     if (alm_pvt_blTbsFirstFlg == FALSE)
     {
@@ -539,9 +542,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulOvrVltLvl3 >= coef->ulOvrVltLvl3ValCt) // 1ms
             {
                 alm_stDecCt.ulOvrVltLvl3 = coef->ulOvrVltLvl3ValCt;
-                // alm_unAction.bit.ThrPhsShrt = TRUE;
-                alm_unCode.bit.OvrVlt = TRUE;
-                alm_unAction.bit.PWMOff = TRUE;
+                // alm_unAction.bit.ThrPhsShrt = 1;
+                alm_unCode.bit.OvrVlt = 1;
+                alm_unAction.bit.PWMOff = 1;
             }
         }
         else
@@ -556,9 +559,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulOvrVltLvl2 >= coef->ulOvrVltLvl2ValCt) // 10ms
             {
                 alm_stDecCt.ulOvrVltLvl2 = coef->ulOvrVltLvl2ValCt;
-                // alm_unAction.bit.ThrPhsShrt = TRUE;
-                alm_unCode.bit.OvrVlt = TRUE;
-                alm_unAction.bit.PWMOff = TRUE;
+                // alm_unAction.bit.ThrPhsShrt = 1;
+                alm_unCode.bit.OvrVlt = 1;
+                alm_unAction.bit.PWMOff = 1;
             }
         }
         else
@@ -573,9 +576,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulOvrVltLvl1 >= coef->ulOvrVltLvl1ValCt) // 2s
             {
                 alm_stDecCt.ulOvrVltLvl1 = coef->ulOvrVltLvl1ValCt;
-                // alm_unAction.bit.ThrPhsShrt = TRUE;
-                alm_unCode.bit.OvrVlt = TRUE;
-                alm_unAction.bit.PWMOff = TRUE;
+                // alm_unAction.bit.ThrPhsShrt = 1;
+                alm_unCode.bit.OvrVlt = 1;
+                alm_unAction.bit.PWMOff = 1;
             }
         }
         else
@@ -592,8 +595,8 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulUndrVltLvl2 >= coef->ulUndrVltLvl2ValCt) // 1ms
             {
                 alm_stDecCt.ulUndrVltLvl2 = coef->ulUndrVltLvl2ValCt;
-                alm_unAction.bit.PWMOff = TRUE;
-                alm_unCode.bit.UndrVlt = TRUE;
+                alm_unAction.bit.PWMOff = 1;
+                alm_unCode.bit.UndrVlt = 1;
             }
         }
         else
@@ -608,8 +611,8 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulUndrVltLvl1 >= coef->ulUndrVltLvl1ValCt) // 2s
             {
                 alm_stDecCt.ulUndrVltLvl1 = coef->ulUndrVltLvl1ValCt;
-                alm_unAction.bit.PWMOff = TRUE;
-                alm_unCode.bit.UndrVlt = TRUE;
+                alm_unAction.bit.PWMOff = 1;
+                alm_unCode.bit.UndrVlt = 1;
             }
         }
         else
@@ -629,8 +632,8 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
             if (alm_stDecCt.ulOvrSpd >= coef->ulOvrSpdValCt) // 100ms
             {
                 alm_stDecCt.ulOvrSpd = coef->ulOvrSpdValCt;
-                alm_unAction.bit.ThrPhsShrt = TRUE;
-                alm_unCode.bit.OvrSpd = TRUE;
+                alm_unAction.bit.ThrPhsShrt = 1;
+                alm_unCode.bit.OvrSpd = 1;
             }
         }
         else
@@ -649,9 +652,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
                 if (alm_stDecCt.ulIPMOvrHeat1 >= coef->ulIPMOvrHeatValCt) // 2s
                 {
                     alm_stDecCt.ulIPMOvrHeat1 = coef->ulIPMOvrHeatValCt;
-//                    // alm_unAction.bit.ThrPhsShrt = TRUE;
-                    alm_unAction.bit.PWMOff = TRUE;
-                    alm_unCode.bit.IPMOvrHeat = TRUE;
+                    // alm_unAction.bit.ThrPhsShrt = 1;
+                    alm_unAction.bit.PWMOff = 1;
+                    alm_unCode.bit.IPMOvrHeat = 1;
                 }
             }
             else
@@ -667,9 +670,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
                 if (alm_stDecCt.ulIPMOvrHeat >= coef->ulIPMOvrHeatValCt) // 2s
                 {
                     alm_stDecCt.ulIPMOvrHeat = coef->ulIPMOvrHeatValCt;
-                    // alm_unAction.bit.ThrPhsShrt = TRUE;
-                    alm_unAction.bit.PWMOff = TRUE;
-                    alm_unCode.bit.IPMOvrHeat = TRUE;
+                    // alm_unAction.bit.ThrPhsShrt = 1;
+                    alm_unAction.bit.PWMOff = 1;
+                    alm_unCode.bit.IPMOvrHeat = 1;
                     alm_pvt_blIPMOTReCheckFlg = TRUE;
                 }
             }
@@ -689,9 +692,9 @@ void alm_voDetecTBS(ALM_IN *in, ALM_DETECTBS_COF *coef)
         =======================================================================*/
 //        if (uart_bCommOvrTmFlg)
 //        {
-//            alm_unAction.bit.PWMOff = TRUE;
-//            // alm_unAction.bit.ThrPhsShrt = TRUE;
-//            alm_unCode.bit.CommOvrTm = TRUE;
+//            alm_unAction.bit.PWMOff = 1;
+//            // alm_unAction.bit.ThrPhsShrt = 1;
+//            alm_unCode.bit.CommOvrTm = 1;
 //        }
         alm_pvt_blTbsFirstFlg = FALSE;
     }
@@ -705,11 +708,12 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voHandleTBC(ALM_IN *in)
+void alm_voHandleTBC(const ALM_IN *in)
 {
     /* Alarm occur */
     if (alm_blAlmOccrFlg)
     {
+        /* micro fault */
         if(clasB_unFaultCode.all != 0)
         {
             if(scm_stSpdFbkLpf.slY.sw.hi < SPD_RPM2PU(10))//pu? ?10rpm
@@ -753,7 +757,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voHandleTBS(ALM_IN *in)
+void alm_voHandleTBS(const ALM_IN *in)
 {
     /* Alarm occur */
     if (alm_blAlmOccrFlg)
@@ -812,7 +816,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voStopTBC(ALM_IN *in, ALM_STOPTBC_COF *coef)
+void alm_voStopTBC(const ALM_IN *in, const ALM_STOPTBC_COF *coef)
 {
     if (alm_unAction.bit.ThrPhsShrtFrc != 0)
     {
@@ -952,7 +956,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef)
+void alm_voReset(const ALM_IN *in, const ALM_RESET_COF *coef)
 {
 
     /*=======================================================================
@@ -1028,67 +1032,71 @@ void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef)
     if (alm_stRecCt.ulGlbl >= coef->ulRecAllValCt) // 200ms
     {
         /* IPM fault */
-        if ((alm_unCode.bit.IPMFlt == TRUE) && (alm_stRecCt.ulIPMOC >= coef->ulIPMOcRecValCt))
+        if ((alm_unCode.bit.IPMFlt == 1) && (alm_stRecCt.ulIPMOC >= coef->ulIPMOcRecValCt))
         {
             iPwm_ClearBreak(0); /* Clear TIME0 break flag */
             iPwm_EnableOutput(0);   /* Enable TIME0 Channel outputs */
 
-            alm_unCode.bit.IPMFlt = FALSE;
+            alm_unCode.bit.IPMFlt = 0;
         }
 
         /* Over current */
-        if (alm_unCode.bit.OvrCur)
+        if (alm_unCode.bit.OvrCur != 0)
         {
             alm_stDecCt.ulOvrCur = 0;
-            alm_unCode.bit.OvrCur = FALSE;
+            alm_unCode.bit.OvrCur = 0;
         }
 
         /* Over voltage */
-        if (alm_unCode.bit.OvrVlt)
+        if (alm_unCode.bit.OvrVlt != 0)
         {
             if ((alm_stRecCt.ulOvrVlt >= coef->ulOvrVltRecValCt) || (alm_stRecCt.ulUndrVlt1 >= coef->ulOvrVltRec1ValCt)) // 4s 20s
             {
                 alm_stDecCt.ulOvrVltLvl1 = 0;
                 alm_stDecCt.ulOvrVltLvl2 = 0;
                 alm_stDecCt.ulOvrVltLvl3 = 0;
-                alm_unCode.bit.OvrVlt = FALSE;
+                alm_unCode.bit.OvrVlt = 0;
             }
         }
 
         /* Under voltage */
-        if (alm_unCode.bit.UndrVlt)
+        if (alm_unCode.bit.UndrVlt != 0)
         {
             if ((alm_stRecCt.ulUndrVlt >= coef->ulUndrVltRecValCt) || (alm_stRecCt.ulUndrVlt1 >= coef->ulUndrVltRec1ValCt)) // 4s 20s
             {
                 alm_stDecCt.ulUndrVltLvl1 = 0;
                 alm_stDecCt.ulUndrVltLvl2 = 0;
-                alm_unCode.bit.UndrVlt = FALSE;
+                alm_unCode.bit.UndrVlt = 0;
             }
         }
 
         /* IPM over heat */
-        if (alm_unCode.bit.IPMOvrHeat)
+        if (alm_unCode.bit.IPMOvrHeat != 0)
         {
             if (alm_stRecCt.ulIPMOvrHeat >= coef->ulIPMOvrHeatRecValCt)
             {
                 alm_stDecCt.ulIPMOvrHeat = 0;
                 alm_stDecCt.ulIPMOvrHeat1 = 0;
-                alm_unCode.bit.IPMOvrHeat = FALSE;
+                alm_unCode.bit.IPMOvrHeat = 0;
                 alm_pvt_blIPMOTReCheckFlg = FALSE;
             }
             else if (alm_stRecCt.ulIPMOvrHeat1 >= coef->ulIPMOvrHeatRec1ValCt)
             {
                 alm_stDecCt.ulIPMOvrHeat = 0;
                 alm_stDecCt.ulIPMOvrHeat1 = 0;
-                alm_unCode.bit.IPMOvrHeat = FALSE;
+                alm_unCode.bit.IPMOvrHeat = 0;
                 alm_pvt_blIPMOTReCheckFlg = TRUE;
             }
+            else
+            {
+            	//do nothing
+            }
         }
 
         /* Hall loss */
-        if (alm_unCode.bit.HallLoss)
+        if (alm_unCode.bit.HallLoss != 0)
         {
-            alm_unCode.bit.HallLoss = FALSE;
+            alm_unCode.bit.HallLoss = 0;
         }
         
         /* Spi Thete Fault */
@@ -1098,28 +1106,28 @@ void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef)
         }
 
         /* Phase loss */
-        if (alm_unCode.bit.PhsLoss)
+        if (alm_unCode.bit.PhsLoss != 0)
         {
             alm_stDecCt.ulPhsALoss = 0;
             alm_stDecCt.ulPhsBLoss = 0;
             alm_stDecCt.ulPhsCLoss = 0;
-            alm_unCode.bit.PhsLoss = FALSE;
+            alm_unCode.bit.PhsLoss = 0;
         }
 
         /* Rotor lock */
-        if (alm_unCode.bit.RotorLock)
+        if (alm_unCode.bit.RotorLock != 0)
         {
             alm_stDecCt.slRotorLock = 0;
-            alm_unCode.bit.RotorLock = FALSE;
+            alm_unCode.bit.RotorLock = 0;
         }
 
         /* Communication over time */
-        if (alm_unCode.bit.CommOvrTm)
+        if (alm_unCode.bit.CommOvrTm != 0)
         {
-            alm_unCode.bit.CommOvrTm = FALSE;
+            alm_unCode.bit.CommOvrTm = 0;
         }
 
-        if (alm_unCode.bit.ADCOffsetFlt)
+        if (alm_unCode.bit.ADCOffsetFlt != 0)
         {
             /* ADC init */
             adc_stDownOut.ulIdcRegSum = 0;
@@ -1132,7 +1140,7 @@ void alm_voReset(ALM_IN *in, ALM_RESET_COF *coef)
             adc_stUpOut.uwADCCalibCt = 0;
             adc_stUpOut.blADCCalibFlg = FALSE;
             sysfsm_stFlg.blADCInitOvrFlg = FALSE;
-            alm_unCode.bit.ADCOffsetFlt = FALSE;
+            alm_unCode.bit.ADCOffsetFlt = 0;
         }
     }
     /*=======================================================================
@@ -1224,7 +1232,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voDetec200MS(ALM_BIKE_IN *in, ALM_DETEC200MS_COF *coef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
+void alm_voDetec200MS(const ALM_BIKE_IN *in, const ALM_DETEC200MS_COF *coef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 { 
     /** Bike sensors judge each other **/
     /* Bike speed sensor fault */
@@ -1371,7 +1379,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voHandle1MS(ALM_BIKE_IN *in)
+void alm_voHandle1MS(const ALM_BIKE_IN *in)
 {
    if(alm_unBikeCode.all != 0)
    {
@@ -1421,7 +1429,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voReset1MSCoef(ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out)
+void alm_voReset1MSCoef(const ALM_RESET1MS_COFIN *in, ALM_RESET1MS_COF *out)
 {
     out->ulRecAllValCt = (ULONG)in->uwBikeGlblTm * in->uwFT1MSHz / 1000;
     out->ulRecBikeSpdCt = (ULONG)in->uwBikeSpdFltTm * in->uwFT1MSHz / 1000;
@@ -1440,7 +1448,7 @@ Output/Return Variables:
 Subroutine Call:
 Reference:
 ****************************************************************/
-void alm_voReset1MS(ALM_BIKE_IN *in, ALM_RESET1MS_COF *coef, ALM_DETEC200MS_COF *detctcoef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
+void alm_voReset1MS(const ALM_BIKE_IN *in, const ALM_RESET1MS_COF *coef, const ALM_DETEC200MS_COF *detctcoef) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     /*=======================================================================
     Recover condition

+ 87 - 73
User project/2.MotorDrive/Source/pwm.c

@@ -69,19 +69,19 @@ void pwm_voInit(void)
     pwm_stGenOut.swUalphaPu = 0; // Q14
     pwm_stGenOut.swUbetaPu = 0;  // Q14
     pwm_stGenOut.uwNewSectorNum = 0;
-    pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwNewTIM1COMPR[3] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwNewTIM1COMPR[4] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
-    pwm_stGenOut.uwFirstTrigCOMPR = HW_HHHPWM_PERIOD;
-    pwm_stGenOut.uwSecondTrigCOMPR = HW_HHPWM_PERIOD + HW_HHHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[0] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[1] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[2] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[3] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[4] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwNewTIM1COMPR[5] = HW_INIT_HHPWM_PERIOD;
+    pwm_stGenOut.uwFirstTrigCOMPR = HW_INIT_HHHPWM_PERIOD;
+    pwm_stGenOut.uwSecondTrigCOMPR = HW_INIT_HHPWM_PERIOD + HW_INIT_HHHPWM_PERIOD;
     pwm_stGenOut.uwOldTrig = 0;
     pwm_stGenOut.uwNewTrig = 0;
     pwm_stGenOut.uwSampleArea = IgnoreNone;
-    pwm_stGenOut.uwRDSONTrig = 129;
-    pwm_stGenOut.uwSigRTrig = HW_HHHPWM_PERIOD;
+    pwm_stGenOut.uwRdsonTrig = 129;
+    pwm_stGenOut.uwSigRTrig = HW_INIT_HHHPWM_PERIOD;
     pwm_stGenOut.blSampleCalibFlag = FALSE;
 }
 
@@ -104,6 +104,10 @@ void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef)
     {
         in->uwPWMDutyMax = 1;
     }
+    else
+    {
+    	//do nothing
+    }
 
     if (in->uwPWM7To5Duty > 1000)
     {
@@ -113,6 +117,10 @@ void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef)
     {
         in->uwPWM7To5Duty = 1;
     }
+    else
+    {
+    	//do nothing
+    }
 
     if (in->uwOvmNo > 2)
     {
@@ -127,6 +135,10 @@ void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef)
     {
         in->uwPWMPd = 4;
     }
+    else
+    {
+    	//do nothing
+    }
 
     coef->uwPWMDutyMaxPu = (UWORD)((((ULONG)in->uwPWMDutyMax - 3) << 14) / 1000);   // Q14
     coef->uwPWM7To5DutyPu = (UWORD)(((ULONG)in->uwPWM7To5Duty << 14) / 1000);       // Q14
@@ -138,7 +150,7 @@ void pwm_voGenCoef(PWM_COF_IN *in, PWM_CALC_COF *coef)
     coef->uwPWMPd = in->uwPWMPd;
     coef->uwHPWMPd = in->uwPWMPd >> 1;
     coef->uwHHPWMPd = in->uwPWMPd >> 2;
-    coef->ulPWMPerInv = (((ULONG)1 << 21) / in->uwPWMPd); // Q21, 1/PWM period
+    coef->ulPWMPerInv = ((ULONG)1 << 21) / in->uwPWMPd; // Q21, 1/PWM period
 
     coef->uwMaxCmpCt = (UWORD)(((ULONG)in->uwPWMDutyMax * coef->uwHPWMPd) / 1000); // Q14
     coef->uwSampleSteadyCt = (UWORD)(((ULONG)in->uwSampleSteadyPu * coef->uwHPWMPd) / 1000);
@@ -153,7 +165,7 @@ 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, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
+void pwm_voGen(PWM_GEN_IN *in, const PWM_CALC_COF *coef, PWM_GEN_OUT *out)
 {
     SLONG slL1, slL2, slL3;
     SLONG slKsvpwm;
@@ -244,7 +256,7 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         if ((swT1 + swT2) > coef->uwPWMDutyMaxPu)
         {
             swOvmT1 = (SWORD)(swT1 * (SLONG)coef->uwPWMDutyMaxPu / (swT1 + swT2)); // Q14=Q14+Q14-Q14
-            swOvmT2 = (SWORD)(coef->uwPWMDutyMaxPu - swOvmT1);
+            swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu - swOvmT1;
             out->blOvmFlag = TRUE;
         }
         else
@@ -258,17 +270,17 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         /* SVPWM over modulation: min amplitude error */
         if ((swT1 + swT2) > coef->uwPWMDutyMaxPu)
         {
-            swOvmT1 = swT1 - ((swT1 + swT2 - coef->uwPWMDutyMaxPu) >> 1);
-            swOvmT2 = swT2 - ((swT1 + swT2 - coef->uwPWMDutyMaxPu) >> 1);
+            swOvmT1 = swT1 - ((swT1 + swT2 - (SWORD)coef->uwPWMDutyMaxPu) >> 1);
+            swOvmT2 = swT2 - ((swT1 + swT2 - (SWORD)coef->uwPWMDutyMaxPu) >> 1);
             if (swOvmT1 < 0)
             {
                 swOvmT1 = 0;
-                swOvmT2 = coef->uwPWMDutyMaxPu;
+                swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu;
             }
             if (swOvmT2 < 0)
             {
                 swOvmT2 = 0;
-                swOvmT1 = coef->uwPWMDutyMaxPu;
+                swOvmT1 = (SWORD)coef->uwPWMDutyMaxPu;
             }
             out->blOvmFlag = TRUE;
         }
@@ -287,25 +299,25 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
             {
                 if (swT1 > coef->uwPWMDutyMaxPu)
                 {
-                    swOvmT1 = coef->uwPWMDutyMaxPu;
+                    swOvmT1 = (SWORD)coef->uwPWMDutyMaxPu;
                 }
                 else
                 {
                     swOvmT1 = swT1;
                 }
-                swOvmT2 = coef->uwPWMDutyMaxPu - swOvmT1;
+                swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu - swOvmT1;
             }
             else
             {
-                if (swT2 > coef->uwPWMDutyMaxPu)
+                if (swT2 > (SWORD)coef->uwPWMDutyMaxPu)
                 {
-                    swOvmT2 = coef->uwPWMDutyMaxPu;
+                    swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu;
                 }
                 else
                 {
                     swOvmT2 = swT2;
                 }
-                swOvmT1 = coef->uwPWMDutyMaxPu - swOvmT2;
+                swOvmT1 = (SWORD)coef->uwPWMDutyMaxPu - swOvmT2;
             }
             out->blOvmFlag = TRUE;
         }
@@ -324,25 +336,25 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
             {
                 if (swT1 > coef->uwPWMDutyMaxPu)
                 {
-                    swOvmT1 = coef->uwPWMDutyMaxPu;
+                    swOvmT1 = (SWORD)coef->uwPWMDutyMaxPu;
                 }
                 else
                 {
                     swOvmT1 = swT1;
                 }
-                swOvmT2 = coef->uwPWMDutyMaxPu - swOvmT1;
+                swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu - swOvmT1;
             }
             else
             {
                 if (swT2 > coef->uwPWMDutyMaxPu)
                 {
-                    swOvmT2 = coef->uwPWMDutyMaxPu;
+                    swOvmT2 = (SWORD)coef->uwPWMDutyMaxPu;
                 }
                 else
                 {
                     swOvmT2 = swT2;
                 }
-                swOvmT1 = coef->uwPWMDutyMaxPu - swOvmT2;
+                swOvmT1 = (SWORD)coef->uwPWMDutyMaxPu - swOvmT2;
             }
             out->blOvmFlag = TRUE;
         }
@@ -360,17 +372,17 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
          /*================================================================
                             Calculate compare value
         ================================================================*/
-        if ((swOvmT1 + swOvmT2) > coef->uwPWM7To5DutyPu) /* Five SVPWM */
+        if ((swOvmT1 + swOvmT2) > (SWORD)coef->uwPWM7To5DutyPu) /* Five SVPWM */
         {
-            swPWMPRD1 = coef->uwHPWMPd;
-            swPWMPRD2 = ((ULONG)(16384 - swOvmT2) * coef->uwHPWMPd) >> 14;
-            swPWMPRD3 = ((ULONG)(16384 - swOvmT1 - swOvmT2) * coef->uwHPWMPd) >> 14;
+            swPWMPRD1 = (SWORD)coef->uwHPWMPd;
+            swPWMPRD2 = (SWORD)(((SLONG)16384 - swOvmT2) * (SWORD)coef->uwHPWMPd >> 14);
+            swPWMPRD3 = (SWORD)(((SLONG)16384 - swOvmT1 - swOvmT2) * (SWORD)coef->uwHPWMPd >> 14);
         }
         else /* Seven SVPWM */
         {
-            swPWMPRD1 = ((ULONG)(16384 + swOvmT1 + swOvmT2) * coef->uwHHPWMPd) >> 14;
-            swPWMPRD2 = ((ULONG)(16384 + swOvmT1 - swOvmT2) * coef->uwHHPWMPd) >> 14;
-            swPWMPRD3 = ((ULONG)(16384 - swOvmT1 - swOvmT2) * coef->uwHHPWMPd) >> 14;
+            swPWMPRD1 = (SWORD)(((SLONG)16384 + swOvmT1 + swOvmT2) * (SWORD)coef->uwHHPWMPd >> 14);
+            swPWMPRD2 = (SWORD)(((SLONG)16384 + swOvmT1 - swOvmT2) * (SWORD)coef->uwHHPWMPd >> 14);
+            swPWMPRD3 = (SWORD)(((SLONG)16384 - swOvmT1 - swOvmT2) * (SWORD)coef->uwHHPWMPd >> 14);
         }
 
         if (swOvmT2 > coef->uwPWMMinSample3Pu)
@@ -501,18 +513,18 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         out->uwNewSectorNum = uwSector;
         out->uwPWMNewSectorNum = out->uwNewSectorNum;
 
-        tmp_swPeriodA = coef->uwPWMPd - out->uwNewTIM1COMPR[0] - out->uwNewTIM1COMPR[3];
-        tmp_swPeriodB = coef->uwPWMPd - out->uwNewTIM1COMPR[1] - out->uwNewTIM1COMPR[4];
-        tmp_swPeriodC = coef->uwPWMPd - out->uwNewTIM1COMPR[2] - out->uwNewTIM1COMPR[5];
+        tmp_swPeriodA = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[0] - (SWORD)out->uwNewTIM1COMPR[3];
+        tmp_swPeriodB = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[1] - (SWORD)out->uwNewTIM1COMPR[4];
+        tmp_swPeriodC = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[2] - (SWORD)out->uwNewTIM1COMPR[5];
 
-        swUaPu = ((((SLONG)tmp_swPeriodA * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUbPu = ((((SLONG)tmp_swPeriodB * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUcPu = ((((SLONG)tmp_swPeriodC * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
+        swUaPu = (SWORD)(((((SLONG)tmp_swPeriodA * (SLONG)coef->ulPWMPerInv) >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUbPu = (SWORD)(((((SLONG)tmp_swPeriodB * (SLONG)coef->ulPWMPerInv) >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUcPu = (SWORD)(((((SLONG)tmp_swPeriodC * (SLONG)coef->ulPWMPerInv) >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
 
         out->swUalphaPu = (swUaPu + swUaPu - swUbPu - swUcPu) * PWM_1DIV3 >> 14; // Q14=Q14+Q14-Q14
         out->swUbetaPu = (swUbPu - swUcPu) * PWM_SQRT3_INV >> 14;                // Q14=Q14+Q14-Q14
 
-        out->uwRDSONTrig = 129 ;
+        out->uwRdsonTrig = 129 ;
     }
     else if(cp_stFlg.CurrentSampleModelSelect == SINGLERESISITANCE)
     {
@@ -524,9 +536,9 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         SWORD swPWMPRD32=0;
                                     
         /*1/4 of zero vector in the middle,and others apart in the beginning and ending*/
-        swPWMPRD1 = (((SLONG)16384 * 3 + swOvmT1 + swOvmT2) * coef->uwPWMPd) >> 17; // Q14
-        swPWMPRD2 = (((SLONG)16384 * 3 + swOvmT1 - swOvmT2 * 3) * coef->uwPWMPd) >> 17;
-        swPWMPRD3 = (((SLONG)16384 - swOvmT1 - swOvmT2) * 3 * coef->uwPWMPd) >> 17;
+        swPWMPRD1 = (SWORD)((((SLONG)16384 * 3 + swOvmT1 + swOvmT2) * (SWORD)coef->uwPWMPd) >> 17); // Q14
+        swPWMPRD2 = (SWORD)((((SLONG)16384 * 3 + swOvmT1 - swOvmT2 * 3) * (SWORD)coef->uwPWMPd) >> 17);
+        swPWMPRD3 = (SWORD)((((SLONG)16384 - swOvmT1 - swOvmT2) * 3 * (SWORD)coef->uwPWMPd) >> 17);
         swPWMPRD11 = swPWMPRD1;
         swPWMPRD21 = swPWMPRD2;
         swPWMPRD31 = swPWMPRD3;
@@ -559,14 +571,14 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
                 if (((coef->uwHPWMPd + swPWMPRD1 - 2 * swPWMPRD2) <= pwm_pvt_swMin_Cur_Smpl_Ct) && ((swOvmT1 + swOvmT2) > coef->uwPWM7To5DutyPu))
                 {
 
-                    swPWMPRD1 = (((SLONG)swOvmT1 + swOvmT2) * coef->uwPWMPd) >> 15;
-                    swPWMPRD2 = ((SLONG)swOvmT1 * coef->uwPWMPd) >> 15;
+                    swPWMPRD1 = (SWORD)((((SLONG)swOvmT1 + swOvmT2) * (SLONG)coef->uwPWMPd) >> 15);
+                    swPWMPRD2 = (SWORD)(((SLONG)swOvmT1 * (SLONG)coef->uwPWMPd) >> 15);
                     swPWMPRD3 = 0;
-                    swPWMPRD11 = coef->uwHPWMPd;
+                    swPWMPRD11 = (SWORD)coef->uwHPWMPd;
                     swPWMPRD12 = (swPWMPRD1 << 1) - swPWMPRD11;
                     swPWMPRD31 = swPWMPRD3;
                     swPWMPRD32 = swPWMPRD3;
-                    swPWMPRD22 = coef->uwHPWMPd;
+                    swPWMPRD22 = (SWORD)coef->uwHPWMPd;
                     swPWMPRD21 = (swPWMPRD2 << 1) - swPWMPRD22;
                 }
                 else
@@ -580,9 +592,9 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
                 if (((2 * swPWMPRD2 - swPWMPRD3) <= pwm_pvt_swMin_Cur_Smpl_Ct) && ((swOvmT1 + swOvmT2) > coef->uwPWM7To5DutyPu))
                 {
 
-                    swPWMPRD1 = coef->uwHPWMPd;
-                    swPWMPRD2 = (((SLONG)16384 - swOvmT2) * coef->uwPWMPd) >> 15;
-                    swPWMPRD3 = (((SLONG)16384 - swOvmT1 - swOvmT2) * coef->uwPWMPd) >> 15;
+                    swPWMPRD1 = (SWORD)coef->uwHPWMPd;
+                    swPWMPRD2 = (SWORD)(((SLONG)16384 - swOvmT2) * (SWORD)coef->uwPWMPd >> 15);
+                    swPWMPRD3 = (SWORD)(((SLONG)16384 - swOvmT1 - swOvmT2) * (SWORD)coef->uwPWMPd >> 15);
                     swPWMPRD11 = swPWMPRD1;
                     swPWMPRD12 = swPWMPRD1;
                     swPWMPRD22 = 0;
@@ -598,7 +610,7 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
             }
             else
             {
-              
+                //do nothing
             }
         }
         out->uwOldTrig = out->uwNewTrig;
@@ -679,13 +691,13 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         out->uwNewSectorNum = uwSector;
         out->uwPWMNewSectorNum = out->uwNewSectorNum;
 
-        tmp_swPeriodA = coef->uwPWMPd - out->uwNewTIM1COMPR[0] - out->uwNewTIM1COMPR[3];
-        tmp_swPeriodB = coef->uwPWMPd - out->uwNewTIM1COMPR[1] - out->uwNewTIM1COMPR[4];
-        tmp_swPeriodC = coef->uwPWMPd - out->uwNewTIM1COMPR[2] - out->uwNewTIM1COMPR[5];
+        tmp_swPeriodA = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[0] - (SWORD)out->uwNewTIM1COMPR[3];
+        tmp_swPeriodB = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[1] - (SWORD)out->uwNewTIM1COMPR[4];
+        tmp_swPeriodC = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[2] - (SWORD)out->uwNewTIM1COMPR[5];
 
-        swUaPu = ((((SLONG)tmp_swPeriodA * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUbPu = ((((SLONG)tmp_swPeriodB * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUcPu = ((((SLONG)tmp_swPeriodC * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
+        swUaPu = (SWORD)(((tmp_swPeriodA * (SLONG)coef->ulPWMPerInv >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUbPu = (SWORD)(((tmp_swPeriodB * (SLONG)coef->ulPWMPerInv >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUcPu = (SWORD)(((tmp_swPeriodC * (SLONG)coef->ulPWMPerInv >> 5) * (SWORD)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
 
         out->swUalphaPu = (swUaPu + swUaPu - swUbPu - swUcPu) * PWM_1DIV3 >> 14; // Q14=Q14+Q14-Q14
         out->swUbetaPu = (swUbPu - swUcPu) * PWM_SQRT3_INV >> 14;                // Q14=Q14+Q14-Q14
@@ -698,15 +710,15 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         ================================================================*/
         if ((swOvmT1 + swOvmT2) > coef->uwPWM7To5DutyPu) /* Five SVPWM */
         {
-            swPWMPRD1 = coef->uwHPWMPd;
-            swPWMPRD2 = ((ULONG)(16384 - swOvmT2) * coef->uwHPWMPd) >> 14;
-            swPWMPRD3 = ((ULONG)(16384 - swOvmT1 - swOvmT2) * coef->uwHPWMPd) >> 14;
+            swPWMPRD1 = (SWORD)coef->uwHPWMPd;
+            swPWMPRD2 = (SWORD)((((SLONG)16384 - swOvmT2) * (SWORD)coef->uwHPWMPd) >> 14);
+            swPWMPRD3 = (SWORD)((((SLONG)16384 - swOvmT1 - swOvmT2) * (SWORD)coef->uwHPWMPd) >> 14);
         }
         else /* Seven SVPWM */
         {
-            swPWMPRD1 = ((ULONG)(16384 + swOvmT1 + swOvmT2) * coef->uwHHPWMPd) >> 14;
-            swPWMPRD2 = ((ULONG)(16384 + swOvmT1 - swOvmT2) * coef->uwHHPWMPd) >> 14;
-            swPWMPRD3 = ((ULONG)(16384 - swOvmT1 - swOvmT2) * coef->uwHHPWMPd) >> 14;
+            swPWMPRD1 = (SWORD)((((SLONG)16384 + swOvmT1 + swOvmT2) * (SWORD)coef->uwHHPWMPd) >> 14);
+            swPWMPRD2 = (SWORD)((((SLONG)16384 + swOvmT1 - swOvmT2) * (SWORD)coef->uwHHPWMPd) >> 14);
+            swPWMPRD3 = (SWORD)((((SLONG)16384 - swOvmT1 - swOvmT2) * (SWORD)coef->uwHHPWMPd) >> 14);
         }
 
         switch (uwSector)
@@ -780,13 +792,13 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         out->uwNewSectorNum = uwSector;
         out->uwPWMNewSectorNum = out->uwNewSectorNum;
 
-        tmp_swPeriodA = coef->uwPWMPd - out->uwNewTIM1COMPR[0] - out->uwNewTIM1COMPR[3];
-        tmp_swPeriodB = coef->uwPWMPd - out->uwNewTIM1COMPR[1] - out->uwNewTIM1COMPR[4];
-        tmp_swPeriodC = coef->uwPWMPd - out->uwNewTIM1COMPR[2] - out->uwNewTIM1COMPR[5];
+        tmp_swPeriodA = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[0] - (SWORD)out->uwNewTIM1COMPR[3];
+        tmp_swPeriodB = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[1] - (SWORD)out->uwNewTIM1COMPR[4];
+        tmp_swPeriodC = (SWORD)coef->uwPWMPd - (SWORD)out->uwNewTIM1COMPR[2] - (SWORD)out->uwNewTIM1COMPR[5];
 
-        swUaPu = ((((SLONG)tmp_swPeriodA * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUbPu = ((((SLONG)tmp_swPeriodB * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
-        swUcPu = ((((SLONG)tmp_swPeriodC * coef->ulPWMPerInv) >> 5) * in->uwVdcPu) >> 16; // Q21-Q5+Q14-Q16=Q14
+        swUaPu = (SWORD)((((tmp_swPeriodA * (SLONG)coef->ulPWMPerInv) >> 5) * (SLONG)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUbPu = (SWORD)((((tmp_swPeriodB * (SLONG)coef->ulPWMPerInv) >> 5) * (SLONG)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
+        swUcPu = (SWORD)((((tmp_swPeriodC * (SLONG)coef->ulPWMPerInv) >> 5) * (SLONG)in->uwVdcPu) >> 16); // Q21-Q5+Q14-Q16=Q14
 
         out->swUalphaPu = (swUaPu + swUaPu - swUbPu - swUcPu) * PWM_1DIV3 >> 14; // Q14=Q14+Q14-Q14
         out->swUbetaPu = (swUbPu - swUcPu) * PWM_SQRT3_INV >> 14;                // Q14=Q14+Q14-Q14
@@ -794,7 +806,7 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
         if ((16384 - swOvmT1 - swOvmT2) > coef->uwPWMMinSample1Pu)
         {
             out->uwSampleArea = IgnoreNone;
-            out->uwRDSONTrig = 129;
+            out->uwRdsonTrig = 129;
         }
         else
         {
@@ -824,7 +836,7 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
                     out->uwSampleArea = IgnoreNone;
                     break;
                 }
-                out->uwRDSONTrig = swPWMPRD3 + coef->uwSampleSteadyCt;
+                out->uwRdsonTrig = swPWMPRD3 + coef->uwSampleSteadyCt;
             }
             else
             {
@@ -852,12 +864,14 @@ void pwm_voGen(PWM_GEN_IN *in, PWM_CALC_COF *coef, PWM_GEN_OUT *out)
                     out->uwSampleArea = IgnoreNone;
                     break;
                 }
-                out->uwRDSONTrig = swPWMPRD2 + coef->uwSampleSteadyCt;
+                out->uwRdsonTrig = swPWMPRD2 + coef->uwSampleSteadyCt;
             }
         }
     }
     else
-    {}  
+    {
+    	//do nothing
+    }  
 }
 
 /************************************************************************

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

@@ -91,7 +91,9 @@ void Open2Clz_TbcupHook(void)
         align_stIn.uwObsElecThetaPu = switchhall_stOut.uwLowThetaPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     align_stIn.swCurRefrompu = swCurRefrompu; // swCurRefrompu;
     align_voOpen2Clz(&align_stIn, &align_stCoef, &align_stOut);
@@ -199,7 +201,9 @@ void StartUp_TbcdownHook(void)
         scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Speed feedback Absolute */
     scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
@@ -236,10 +240,12 @@ void Open2Clz_TbcdownHook(void)
         scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Speed feedback Absolute */
-    scm_uwSpdFbkLpfAbsPu = ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
+    scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
 
     /* Get angle for park transformation */
     scm_uwAngParkPu = scm_uwAngRefPu; // Q15
@@ -281,7 +287,9 @@ void ClzLoop_TbcdownHook(void)
         scm_uwAngRefPu = switchhall_stOut.uwLowThetaPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Speed feedback Absolute */
     scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
@@ -302,10 +310,12 @@ void ClzLoop_TbcdownHook(void)
         swAngCompPu = (SWORD)(((SLONG)switchhall_stOut.swLowSpdPu * TBC_TM) >> 10); // Q15
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     ulTmp1 = scm_uwAngParkPu + ((swAngCompPu * 3) >> 1) + cof_sl720DegreePu; 
-    scm_uwAngIParkPu = ulTmp1 & 0x7FFF;
+    scm_uwAngIParkPu = (UWORD)(ulTmp1 & 0x7FFF);
     /*=======================================================================
                         Current decoupling
     =======================================================================*/ 
@@ -317,6 +327,10 @@ void ClzLoop_TbcdownHook(void)
     {
         acr_stUdqDcpIn.swWsPu = spi_stResolverOut.swSpdFbkPu; // Q15  swSpdFbkLpfPu spi_stResolverOut.swSpdFbkPu
     }
+    else
+    {
+        //do nothing
+    }
     acr_stUdqDcpIn.swIdRefPu = scm_swIdFdbLpfPu;//scm_swIdRefPu  scm_swIdFdbLpfPu          // Q14
     acr_stUdqDcpIn.swIqRefPu = scm_swIqFdbLpfPu; //scm_swIqRefPu  scm_swIqFdbLpfPu         // Q14  
     acr_stUdqDcpIn.swUdqLimPu = scm_swVsDcpLimPu;      // Q14
@@ -390,7 +404,7 @@ void scm_voSpdCtrMdFSM(void)
         {
             if(cp_stFlg.SpiOffsetFirstSetFlg == 0)
             {
-                cp_stFlg.SpiOffsetFirstSetFinishFlg = TRUE;
+                cp_stFlg.SpiOffsetFirstSetFinishFlg = 1;
             }
             else
             {
@@ -422,7 +436,9 @@ void scm_voSpdCtrMdFSM(void)
             }
         }
         else
-        {}
+        {
+            //do nothing
+        }
 
         break;
     case StartUp:
@@ -438,12 +454,16 @@ void scm_voSpdCtrMdFSM(void)
                 {
                     if (FSM2nd_Run_state.state == Boost)
                     {
-                        cmd_stCmdOut.slIntRefPu = (((SLONG)scm_stSpdFbkLpf.slY.sw.hi * 5) << 12); // Q29  5/4
+                        cmd_stCmdOut.slIntRefPu = ((SLONG)scm_stSpdFbkLpf.slY.sw.hi * 5) << 12; // Q29  5/4
                     }
                     else if (FSM2nd_Run_state.state == Assistance)
-                    {}
+                    {
+                        //do nothing
+                    }
                     else
-                    {}
+                    {
+                        //do nothing
+                    }
                     Switch_speed_FSM(&Open2Clz_state);
                 }
             }
@@ -514,7 +534,11 @@ void scm_voSpdCtrMdFSM(void)
                 }
                 else  
                 {
+#ifdef RUN_ARCH_SIM
+                    Switch_speed_FSM(&ClzLoop_state);                   
+#else                    
                     Switch_speed_FSM(&InitPosDet_state);
+#endif
                 }
             }
         }
@@ -524,7 +548,7 @@ void scm_voSpdCtrMdFSM(void)
     }
 }
 
-void Switch_speed_FSM(SPD_STATE_HOOK *in)
+void Switch_speed_FSM(const SPD_STATE_HOOK *in)
 {
     scm_ulStatCt = 0;
     curSpeed_state = *in;

+ 22 - 8
User project/2.MotorDrive/Source/spdctrmode.c

@@ -341,7 +341,7 @@ void scm_voSpdCtrMdCoef(void)
         pwm_stGenCoefIn.uwSampleSteadyPu = cp_stControlPara.swPWMSampleToSteady;
         pwm_stGenCoefIn.uwSingelResisSamplePu = cp_stControlPara.swPWMSampleSigR;
         pwm_stGenCoefIn.uwOvmNo = cp_stControlPara.swPWMOverMdlMode;
-        pwm_stGenCoefIn.uwPWMPd = HW_PWM_PERIOD;
+        pwm_stGenCoefIn.uwPWMPd = HW_INIT_PWM_PERIOD;
         pwm_voGenCoef(&pwm_stGenCoefIn, &pwm_stGenCoef);
 
         scm_uwAcrLimCof = (UWORD)((ULONG)cp_stControlPara.swPWMMaxDuty * cp_stControlPara.uwAcrCurOutLim / 1000);   // Q15
@@ -376,7 +376,9 @@ void scm_voSpdCtrMdTbs(void)
         scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Speed feedback Absolute */
     scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi);
@@ -420,6 +422,7 @@ void scm_voSpdCtrMdTbs(void)
         }
         else
         {
+            //do nothing
         }
         cmd_stCmdIn.swSpdNowPu = scm_stSpdFbkLpf.slY.sw.hi;
         cmd_voCmdOut(&cmd_stCmdIn, &cmd_stCmdCoef, &cmd_stCmdOut);
@@ -518,7 +521,9 @@ void  scm_voTorqCtrMdTbs(void)
         scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
 
     /* Speed feedback Absolute */
     scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi);
@@ -587,7 +592,9 @@ void  scm_voTorqCtrMdTbs(void)
         swTestIqref = -swIqLowerPu;
     }
     else
-    {}
+    {
+        //do nothing
+    }
     swCurRefrompu = swTestIqref;  
     
 
@@ -709,7 +716,9 @@ void  scm_voSpdCtrMdDownTbc(void)
 //        acr_stCurIdPIIn.swUminPu = -scm_swVsLimPu - acr_stUdqDcpOut.swUdPu; // Q14       
     }
     else
-    {}
+    {
+        //do nothing
+    }
     acr_voCurPI(&acr_stCurIdPIIn, &acr_stCurIdPICoef, &acr_stCurIdPIOut);
 
     /*=======================================================================
@@ -736,7 +745,9 @@ void  scm_voSpdCtrMdDownTbc(void)
         } 
     }
     else
-    {}
+    {
+        //do nothing
+    }
     acr_voCurPI(&acr_stCurIqPIIn, &acr_stCurIqPICoef, &acr_stCurIqPIOut);
 
     if (DCPswitch == 1)
@@ -750,7 +761,9 @@ void  scm_voSpdCtrMdDownTbc(void)
         scm_swUdRefPu = acr_stCurIdPIOut.swURefPu + acr_stUdqDcpOut.swUdPu; // Q14
     }
     else
-    {}
+    {
+        //do nothing
+    }
     
     /*=======================================================================
                         IPark transformation for current
@@ -797,6 +810,7 @@ void  scm_voSpdCtrMdDownTbc(void)
        }
        else
        {
+           //do nothing
        }
        
        crd_stIParkIn.uwThetaPu = scm_uwAngIParkPu;//scm_uwAngIParkPu;
@@ -813,7 +827,7 @@ void  scm_voSpdCtrMdDownTbc(void)
     iPwm_SetCompareGroupValues16(0, pwm_stGenOut.uwNewTIM1COMPR);
     ULONG samplingTick[2];
     samplingTick[0]=pwm_stGenOut.uwSigRTrig;
-    samplingTick[1]=pwm_stGenOut.uwRDSONTrig;
+    samplingTick[1]=pwm_stGenOut.uwRdsonTrig;
     iPwm_SyncMultiSamplingCountUp(0, &samplingTick[0], 2);
 
     Test_U_in.swAlphaPu = pwm_stGenOut.swUalphaPu - scm_swUalphaCompPu; // Q14

+ 2 - 2
User project/3.BasicFunction/Source/Cadence.c

@@ -144,12 +144,12 @@ static void cadence_voCadenceHighFrequencyWork(UWORD source)
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
     }
     else
     {
-    	//do noting
+    	//do nothing
     }
 
     if (cadence_stFreGetOut.cadence_dir == CADENCE_DIR_BACKWARD) 

+ 0 - 1
User project/3.BasicFunction/Source/InputCapture.c

@@ -14,7 +14,6 @@ void IC_CountMaxISR(void)
         bikespeed_voBikeSpeedCal(uwIntSource);
     }
 }
-
 void IC_CadenceISR(void)
 {
     if(switch_flg.SysCoef_Flag == TRUE)

+ 1 - 1
User project/3.BasicFunction/Source/bikelight.c

@@ -356,7 +356,7 @@ void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta,UBYTE BackL
               }
               else
               {
-            	//do noting
+            	//do nothing
               }
 
               break;

+ 6 - 5
User project/3.BasicFunction/Source/bikespeed.c

@@ -145,8 +145,9 @@ static void bikespeed_voBikeSpeedWork(UWORD source)
             }
             else
             {
-                //do noting
+                //do nothing
             }
+            bikespeed_stFreGetOut.uwCaputureOverflowMinCntTest = bikespeed_stFreGetOut.uwCaputureOverflowMinCnt;
 
             /* BikeSpeed Freq Cal */
             bikespeed_pvt_FreqPu = (ULONG)(((UQWORD)720000 << 20) / ((UQWORD)ulCaputureCntErr * bikespeed_stFreGetCof.uwNumbersPulses * FBASE));
@@ -157,12 +158,12 @@ static void bikespeed_voBikeSpeedWork(UWORD source)
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
     }
     else
     {
-    	//do noting
+    	//do nothing
     }
    
     if (bikespeed_pvt_FreqPu > bikespeed_stFreGetCof.uwMaxBikeSpeedFre) 
@@ -420,7 +421,7 @@ void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
     }
     else if(((SWORD)ABS(out->slErrorZ1) - (SWORD)ABS(slSpdErrPu)) > 0) //Fast Approach
@@ -446,7 +447,7 @@ void bikespeed_voPI(const BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
     }
     else  //Away

+ 1 - 1
User project/3.BasicFunction/Source/can.c

@@ -838,7 +838,7 @@ void DataProcess(UWORD ID, UBYTE Mode, UWORD Cmd, UBYTE Data[]) /* parasoft-supp
             }
             else
             {
-            	//do noting
+            	//do nothing
             }
 
             cp_stFlg.ParaSaveEEFlg = TRUE;

+ 18 - 18
User project/3.BasicFunction/Source/canAppl.c

@@ -246,7 +246,7 @@ void Can_voInitMC_Run(void)
     mth_voLPFilterCoef(1000000 / 100, EVENT_1MS_HZ, &BMS_swCurIdcLpf.uwKx); // 100Hz
 }
 
-void Can_voMC_Run_1ms(void) /* parasoft-suppress METRICS-28 "鏈�」鐩�湀澶嶆潅搴︽棤娉曟洿鏀癸紝鍚庣画閬垮厤" */
+void Can_voMC_Run_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
 {
     if (cp_stBikeRunInfoPara.BikeSpeedKmH > 30)
     {
@@ -581,19 +581,19 @@ void Can_voMC_Run_200ms(void)
     MC_RunInfo.BusVoltage = (UWORD)((((ULONG)adc_stUpOut.uwVdcLpfPu + (ULONG)BMS_VoltEstimat.uwVdcCompPu) * cof_uwUbVt * 100) >> 14); ///>母线电压 1mV,地址偏移6
     //MC_RunInfo.BusCurrent = (UWORD)((ULONG)BMS_VoltEstimat.swIdcPu * cof_uwIbAp * 100 >> 14);                                  ///>母线电流 1mA,地址偏移8
     MC_RunInfo.BusCurrent = (scm_swIqFdbLpfPu * cof_uwIbAp * 10) >> 14;
-    MC_RunInfo.Cadence = (UBYTE)(((ULONG)cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20);                              ///>韪忛� 1rpm锛屽湴鍧€鍋忕Щ10
-    MC_RunInfo.Torque = (UBYTE)(((ULONG)torsensor_stTorSensorOut.uwTorqueLPFPu * cof_uwTorqNm / 10) >> 14);                    ///>韪╄笍鍔涚煩 1Nm锛屽湴鍧€鍋忕Щ11
-    MC_RunInfo.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir;                                  ///>韪╄笍鏂瑰悜 0-姝�,1-鍙�,2-鍋滄�锛屽湴鍧€鍋忕Щ12
-    MC_RunInfo.GearSt = (UBYTE)MC_ControlCode.GearSt;                                                                        ///>鍔╁姏妗d綅锛屽湴鍧€鍋忕Щ13
-    MC_RunInfo.LightSwitch = MC_ControlCode.LightSwitch;                                                              ///>鐏�紑鍏� 0xF0-鍏筹紝0xF1-寮€锛屽湴鍧€鍋忕Щ14
-    MC_RunInfo.SOC = (UBYTE)Can_SOC_Cal();                                                                                   ///>鍓╀綑鐢甸噺 1%锛屽湴鍧€鍋忕Щ15
+    MC_RunInfo.Cadence = (UBYTE)(((ULONG)cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20);                              ///>踏频 1rpm,地址偏移10
+    MC_RunInfo.Torque = (UBYTE)(((ULONG)torsensor_stTorSensorOut.uwTorqueLPFPu * cof_uwTorqNm / 10) >> 14);                    ///>踩踏力矩 1Nm,地址偏移11
+    MC_RunInfo.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir;                                  ///>踩踏方向 0-正,1-反,2-停止,地址偏移12
+    MC_RunInfo.GearSt = (UBYTE)MC_ControlCode.GearSt;                                                                        ///>助力档位,地址偏移13
+    MC_RunInfo.LightSwitch = MC_ControlCode.LightSwitch;                                                              ///>灯开关 0xF0-关,0xF1-开,地址偏移14
+    MC_RunInfo.SOC = (UBYTE)Can_SOC_Cal();                                                                                   ///>剩余电量 1%,地址偏移15
     Can_Trip_Cal();
-    MC_RunInfo.ODO_Km = (UWORD)(MC_RideLog.ODO_Km / 10);                                                                       ///>鎬婚噷绋?1km锛屽湴鍧€鍋忕Щ18
+    MC_RunInfo.ODO_Km = (UWORD)(MC_RideLog.ODO_Km / 10);                                                                       ///>总里程 1km,地址偏移18
 
     if (cp_stBikeRunInfoPara.blGearStUpdate)
     {
         MC_RunInfo.PowerPerKm =
-        		(UBYTE)(*(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10); ///>骞冲潎鍔熻€� 0.01Ah/km 锛屽湴鍧€鍋忕Щ20 /* parasoft-suppress MISRA2004-17_4 "鏈�」鐩�棤娉曟洿鏀癸紝鍚庣画閬垮厤闈炴暟缁勭储寮曟寚閽堣繍绠�" */
+        		(UBYTE)(*(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10); ///>平均功耗 0.01Ah/km ,地址偏移20 /* parasoft-suppress MISRA2004-17_4 "本项目无法更改,后续避免非数组索引指针运算" */
         cp_stBikeRunInfoPara.BMSRestChargeLast = BMS_RunInfo.RC;
         cp_stBikeRunInfoPara.uwPowerPerKm = 0;
         cp_stBikeRunInfoPara.uwAvePowerPerKm = 0;
@@ -602,10 +602,10 @@ void Can_voMC_Run_200ms(void)
         cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
         cp_stBikeRunInfoPara.uwCruisDis = 0;
     }
-    MC_RunInfo.T_PCB = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                    ///>PCB娓╁害 +40鈩冿紝鍦板潃鍋忕Щ21
-    MC_RunInfo.T_Coil = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                   ///>缁曠粍娓╁害 +40鈩冿紝鍦板潃鍋忕Щ22
-    MC_RunInfo.T_MCU = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                    ///>MCU娓╁害 +40鈩冿紝鍦板潃鍋忕Щ23
-    MC_RunInfo.Ride_Time = (UWORD)(cp_stBikeRunInfoPara.ulRiTime >> 10);     ///>寮€鏈哄悗楠戣�鏃堕棿 1s锛屽湴鍧€鍋忕Щ26
+    MC_RunInfo.T_PCB = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                    ///>PCB温度 +40℃,地址偏移21
+    MC_RunInfo.T_Coil = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                   ///>绕组温度 +40℃,地址偏移22
+    MC_RunInfo.T_MCU = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40;                    ///>MCU温度 +40℃,地址偏移23
+    MC_RunInfo.Ride_Time = (UWORD)(cp_stBikeRunInfoPara.ulRiTime >> 10);     ///>开机后骑行时间 1s,地址偏移26
 
     if (MC_WorkMode == 1)
     {
@@ -793,7 +793,7 @@ UWORD        Can_SOC_Cal(void)
     }
     else
     {
-        // do noting
+        // do nothing
     }
     return (UWORD)SOC_Value;
 }
@@ -802,11 +802,11 @@ void Can_GearSt_switch(void)
 {
     cp_stBikeRunInfoPara.uwBikeGearLast = cp_stBikeRunInfoPara.uwBikeGear;
 
-    if (MC_WorkMode == 1) // 閰嶇疆妯″紡涓嶈嚜鍔ㄥ叧闂�姪鍔�
+    if (MC_WorkMode == 1) // 配置模式不自动关闭助力
     {
         ulOBC_ComTimeOutCount = cp_ulSystickCnt;
     }
-    if ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000) // 鎺у埗鍣ㄤ笌浠�〃閫氫俊涓�柇瓒呰繃3s锛屽叧闂�姪鍔�
+    if ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000) // 控制器与仪表通信中断超过3s,关闭助力
     {
         if (MC_ControlCode.GearSt <= 0x05)
         {
@@ -822,7 +822,7 @@ void Can_GearSt_switch(void)
         }
         else
         {
-            // do noting
+            // do nothing
         }
     }
     else 
@@ -855,7 +855,7 @@ void Can_Light_switch(void)
     }
     else
     {
-        // do noting
+        // do nothing
     }
 }
 

+ 1 - 1
User project/3.BasicFunction/Source/spi_master.c

@@ -102,7 +102,7 @@ void spi_voResolverCoef(SPI_RESOLVER_COEFIN *in, SPI_RESOLVER_COEF *out)
     }
     else
     {
-    	//do noting
+    	//do nothing
     }
 
     if (in->uwFreqTbcHz < 10)

+ 16 - 16
User project/3.BasicFunction/Source/switchhall.c

@@ -273,7 +273,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
     }
     else
     {
-    	//do noting
+    	//do nothing
     }
     /*High Speed Theta Update*/ 
 //     switchhall_stOut.slHighThetaPu += (((SLONG)TBC_TM * switchhall_stOut.swHighSpdLpfPu) >> 10); // Q10+Q15-Q10=Q15 
@@ -465,7 +465,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
 
         switchhall_stOut.slInitThetaPu = cof_sl60DegreePu + switchhall_stOut.swLowThetaOffsetPu;
@@ -480,7 +480,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         break;
     case 2:
@@ -496,7 +496,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
 
         switchhall_stOut.slInitThetaPu = cof_sl300DegreePu + switchhall_stOut.swLowThetaOffsetPu;
@@ -510,7 +510,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         break;
     case 3:
@@ -526,7 +526,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         switchhall_stOut.slInitThetaPu = cof_sl360DegreePu + switchhall_stOut.swLowThetaOffsetPu;
         if ((switchhall_stOut.slLowThetaPu > (cof_sl30DegreePu + switchhall_stOut.swLowThetaOffsetPu)) && (switchhall_stOut.slLowThetaPu < (cof_sl330DegreePu + switchhall_stOut.swLowThetaOffsetPu)))
@@ -541,7 +541,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
             }
             else
             {
-            	//do noting
+            	//do nothing
             }
         }
 
@@ -559,7 +559,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
 
         switchhall_stOut.slInitThetaPu = cof_sl180DegreePu + switchhall_stOut.swLowThetaOffsetPu;
@@ -573,7 +573,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         break;
     case 5:
@@ -589,7 +589,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
 
         switchhall_stOut.slInitThetaPu = cof_sl120DegreePu + switchhall_stOut.swLowThetaOffsetPu;
@@ -603,7 +603,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         break;
     case 6:
@@ -619,7 +619,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
 
         switchhall_stOut.slInitThetaPu = cof_sl240DegreePu + switchhall_stOut.swLowThetaOffsetPu;
@@ -633,7 +633,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         break;
     default:
@@ -840,7 +840,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
         }
         else
         {
-        	//do noting
+        	//do nothing
         }
         switchhall_stOut.uwLowThetaPu = (UWORD)Hall_Theta_Temp;        
     }
@@ -863,7 +863,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
             }
             else
             {
-            	//do noting
+            	//do nothing
             }
             switchhall_stOut.uwLowThetaPu = (UWORD)Hall_Theta_Temp;                
         }
@@ -882,7 +882,7 @@ void switchhall_voPosCalTbc(void) /* parasoft-suppress METRICS-28 "本项目圈
             }
             else
             {
-            	//do noting
+            	//do nothing
             }
             switchhall_stOut.uwLowThetaPu = (UWORD)Hall_Theta_Temp;     
             

+ 8 - 8
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/crdnt.h

@@ -156,15 +156,15 @@ _CRDNT_EXT CRD_ICLARK_OUT crd_stVltIClarkOut;
  Exported Function Call Prototypes (N/A)
 *************************************************************************/
 #ifdef _CRDNT_C_
-_CRDNT_EXT void crd_voClark(CRD_CLARK_IN *in, CRD_CLARK_OUT *out);
-_CRDNT_EXT void crd_voPark(CRD_PARK_IN *in, CRD_PARK_OUT *out);
-_CRDNT_EXT void crd_voIPark(CRD_IPARK_IN *in, CRD_IPARK_OUT *out);
-_CRDNT_EXT void crd_voIClark(CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out);
+_CRDNT_EXT void crd_voClark(const CRD_CLARK_IN *in, CRD_CLARK_OUT *out);
+_CRDNT_EXT void crd_voPark(const CRD_PARK_IN *in, CRD_PARK_OUT *out);
+_CRDNT_EXT void crd_voIPark(const CRD_IPARK_IN *in, CRD_IPARK_OUT *out);
+_CRDNT_EXT void crd_voIClark(const CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out);
 #else
-_CRDNT_EXT void crd_voClark(CRD_CLARK_IN *in, CRD_CLARK_OUT *out);
-_CRDNT_EXT void crd_voPark(CRD_PARK_IN *in, CRD_PARK_OUT *out);
-_CRDNT_EXT void crd_voIPark(CRD_IPARK_IN *in, CRD_IPARK_OUT *out);
-_CRDNT_EXT void crd_voIClark(CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out);
+_CRDNT_EXT void crd_voClark(const CRD_CLARK_IN *in, CRD_CLARK_OUT *out);
+_CRDNT_EXT void crd_voPark(const CRD_PARK_IN *in, CRD_PARK_OUT *out);
+_CRDNT_EXT void crd_voIPark(const CRD_IPARK_IN *in, CRD_IPARK_OUT *out);
+_CRDNT_EXT void crd_voIClark(const CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out);
 #endif
 
 /************************************************************************

+ 0 - 28
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/glbcof.h

@@ -113,20 +113,6 @@ _GLBCOF_EXT SLONG cof_sl330DegreePu = 0;
 _GLBCOF_EXT SLONG cof_sl360DegreePu = 0;
 _GLBCOF_EXT SLONG cof_sl720DegreePu = 0;
 
-//_GLBCOF_EXT UWORD cof_uw80RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw100RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw200RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw250RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw300RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw330RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw600RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw1000RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw1500RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw2800RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw3000RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw8000RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw10000RpmPu = 0;
-//_GLBCOF_EXT UWORD cof_uw11000RpmPu = 0;
 _GLBCOF_EXT UWORD cof_uw100RpmPu = 0;
 _GLBCOF_EXT UWORD cof_uw200RpmPu = 0;
 _GLBCOF_EXT UWORD cof_uw300RpmPu = 0;
@@ -201,20 +187,6 @@ _GLBCOF_EXT SLONG cof_sl330DegreePu;
 _GLBCOF_EXT SLONG cof_sl360DegreePu;
 _GLBCOF_EXT SLONG cof_sl720DegreePu;
 
-//_GLBCOF_EXT UWORD cof_uw80RpmPu;
-//_GLBCOF_EXT UWORD cof_uw100RpmPu;
-//_GLBCOF_EXT UWORD cof_uw200RpmPu;
-//_GLBCOF_EXT UWORD cof_uw250RpmPu;
-//_GLBCOF_EXT UWORD cof_uw300RpmPu;
-//_GLBCOF_EXT UWORD cof_uw330RpmPu;
-//_GLBCOF_EXT UWORD cof_uw600RpmPu;
-//_GLBCOF_EXT UWORD cof_uw1000RpmPu;
-//_GLBCOF_EXT UWORD cof_uw1500RpmPu;
-//_GLBCOF_EXT UWORD cof_uw2800RpmPu;
-//_GLBCOF_EXT UWORD cof_uw3000RpmPu;
-//_GLBCOF_EXT UWORD cof_uw8000RpmPu;
-//_GLBCOF_EXT UWORD cof_uw10000RpmPu;
-//_GLBCOF_EXT UWORD cof_uw11000RpmPu;
 _GLBCOF_EXT UWORD cof_uw100RpmPu;
 _GLBCOF_EXT UWORD cof_uw200RpmPu;
 _GLBCOF_EXT UWORD cof_uw300RpmPu;

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

@@ -95,14 +95,14 @@ _MATHTOOL_EXT void  mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWOR
 _MATHTOOL_EXT void  mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
 _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
 _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
-_MATHTOOL_EXT UWORD mth_voArctan(ARCTAN_IN *in);
+_MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
 #else
 _MATHTOOL_EXT void  mth_voSinCos(UWORD angle, SINCOS *v);
 _MATHTOOL_EXT void  mth_voLPFilterCoef(ULONG ulLpfTime_us, ULONG ulExeFreq, UWORD *uwLPFCof);
 _MATHTOOL_EXT void  mth_voLPFilter(SWORD swLpfIn, LPF_OUT *out);
 _MATHTOOL_EXT SLONG mth_slSqrt(SLONG slInput);
 _MATHTOOL_EXT SLONG mth_slRamp(SLONG slInput, SLONG slDelta, SLONG slOutputLimit);
-_MATHTOOL_EXT UWORD mth_voArctan(ARCTAN_IN *in);
+_MATHTOOL_EXT UWORD mth_voArctan(const ARCTAN_IN *in);
 #endif
 
 /************************************************************************

+ 3 - 2
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Include/queue.h

@@ -59,8 +59,9 @@ extern FLASH_ERROR_QUEUE que_stFlashErrorLog;
 Exported Function Call Prototypes (N/A)
 ************************************************************************/
 
-extern UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, ERROR_LOG *rxdata, UBYTE length);
-extern UBYTE que_ubPopOut(FLASH_ERROR_QUEUE *Q, ERROR_LOG *buf, UBYTE length);
+extern UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, const ERROR_LOG *rxdata, UBYTE length);
+extern UBYTE que_ubPopOut(FLASH_ERROR_QUEUE *Q, ERROR_LOG buf[], UBYTE length);
+extern void que_voInit(FLASH_ERROR_QUEUE *Q);
 #endif
 
 /*************************************************************************

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

@@ -47,7 +47,7 @@ Update Time
 #define MOTOR_WELLING_CITY_48V    0x30
 #define MOTOR_WELLING_MTB_48V     0x31
 
-#define MOTOR_ID_SEL              MOTOR_WELLING_CITY_36V
+#define MOTOR_ID_SEL              MOTOR_WELLING_MTB_36V    ///< syspar.hÖÐÒ²ÐèҪѡÔñ36V/48Vϵͳ
 
 /*======================================================================*
     Motor Parameters
@@ -461,9 +461,9 @@ Update Time
 // #define HFI_PLL_CROSS_FREQ_HZ                  20      // unit: Hz, Pll cross frequency
 // #define HFI_SPD_LPF_HZ                         8      // unit: Hz, Cut-off frequency of spd lpf
 // #define HFI_MAG_SATR_AP                        240      // unit: 0.01A, Magnetic saturation current
-/************************************************************************
- TypeDefs & Structure defines
-*************************************************************************/
+/*==============================================================================
+                      Deadband Compensation parameters define
+==============================================================================*/
 /* Api Device Index Definations */
 #define ADC_IA_CH                       0
 #define ADC_IB_CH                       1
@@ -476,7 +476,11 @@ Update Time
 #define ADC_UAC_CH                      2
 
 #define GPIO_LED_PIN                    0
-#define GPIO_CAP_PIN                    1 
+#define GPIO_CAP_PIN                    1      
+/************************************************************************
+ TypeDefs & Structure defines
+*************************************************************************/
+
 /************************************************************************
  Exported Variables:
 *************************************************************************/

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

@@ -43,7 +43,7 @@ Revising History (ECL of this file):
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-void crd_voClark(CRD_CLARK_IN *in, CRD_CLARK_OUT *out)
+void crd_voClark(const CRD_CLARK_IN *in, CRD_CLARK_OUT *out)
 {
     SLONG slClark; //(Q15)
 
@@ -90,7 +90,7 @@ void crd_voClark(CRD_CLARK_IN *in, CRD_CLARK_OUT *out)
  Subroutine Call: mth_voSinCos;
  Reference: N/A
 ****************************************************************/
-void crd_voPark(CRD_PARK_IN *in, CRD_PARK_OUT *out)
+void crd_voPark(const CRD_PARK_IN *in, CRD_PARK_OUT *out)
 {
     SLONG  slPark; //(Q15)
     SINCOS stPark_SINCOS;
@@ -141,7 +141,7 @@ void crd_voPark(CRD_PARK_IN *in, CRD_PARK_OUT *out)
  Subroutine Call: mth_vo_SinCos;
  Reference: N/A
 ****************************************************************/
-void crd_voIPark(CRD_IPARK_IN *in, CRD_IPARK_OUT *out)
+void crd_voIPark(const CRD_IPARK_IN *in, CRD_IPARK_OUT *out)
 {
     SLONG  slIPark; //(Q15)
     SINCOS stIPark_SINCOS;
@@ -192,7 +192,7 @@ void crd_voIPark(CRD_IPARK_IN *in, CRD_IPARK_OUT *out)
  Subroutine Call:
  Reference: N/A
 ****************************************************************/
-void crd_voIClark(CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out)
+void crd_voIClark(const CRD_ICLARK_IN *in, CRD_ICLARK_OUT *out)
 {
     SLONG slIClark;
 

+ 0 - 11
User project/4.BasicHardwSoftwLayer/2.BasicSoftwLayer/Source/glbcof.c

@@ -123,17 +123,6 @@ void cof_voSysInit(void)
     /*=======================================================================
                              Speed value
     =======================================================================*/
-//    cof_uw80RpmPu = SPD_RPM2PU(80);
-//    cof_uw100RpmPu = SPD_RPM2PU(100);
-//    cof_uw200RpmPu = SPD_RPM2PU(200);
-//    cof_uw250RpmPu = SPD_RPM2PU(250);
-//    cof_uw300RpmPu = SPD_RPM2PU(300);
-//    cof_uw330RpmPu = SPD_RPM2PU(330);
-//    cof_uw600RpmPu = SPD_RPM2PU(600);
-//    cof_uw1000RpmPu = SPD_RPM2PU(1000);
-//    cof_uw1500RpmPu = SPD_RPM2PU(1500);
-//    cof_uw2800RpmPu = SPD_RPM2PU(2800);
-//    cof_uw3000RpmPu = SPD_RPM2PU(3000);
     cof_uw100RpmPu = SPD_RPM2PU(100);
     cof_uw200RpmPu = SPD_RPM2PU(200);
     cof_uw300RpmPu = SPD_RPM2PU(300);

+ 6 - 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(ARCTAN_IN *in)
+UWORD mth_voArctan(const ARCTAN_IN *in)
 {
     UWORD uwQuadrant, uwStep;
     SLONG slX, slY, slCurAngle, slNewX;
@@ -519,7 +519,7 @@ UWORD mth_voArctan(ARCTAN_IN *in)
             }
             else
             {
-            	//do noting
+            	//do nothing
             }
         }
     }
@@ -597,6 +597,10 @@ UWORD mth_voArctan(ARCTAN_IN *in)
         {
             slCurAngle = slCurAngle + 32768;
         }
+        else
+        {
+        	//do nothing
+        }
 
         uwEstThetaPu = (UWORD)slCurAngle;
     }

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

@@ -45,7 +45,7 @@ void que_voInit(FLASH_ERROR_QUEUE *Q)
 /******************************************************************************************************************************************************
 **  \brief
 ******************************************************************************************************************************************************/
-static BOOL que_fgEmpty(FLASH_ERROR_QUEUE *Q)
+static BOOL que_fgEmpty(const FLASH_ERROR_QUEUE *Q)
 {
     BOOL ret = FALSE;
     if (Q->ubHead == Q->ubRear)
@@ -58,7 +58,7 @@ static BOOL que_fgEmpty(FLASH_ERROR_QUEUE *Q)
 **  \brief
 **  \return
 ******************************************************************************************************************************************************/
-static BOOL que_fgFull(FLASH_ERROR_QUEUE *Q)
+static BOOL que_fgFull(const FLASH_ERROR_QUEUE *Q)
 {
     BOOL ret = FALSE;
     if (((Q->ubHead - Q->ubRear) + QUEUE_SIZE) % QUEUE_SIZE == 1)
@@ -103,7 +103,7 @@ static UBYTE que_voDelete(FLASH_ERROR_QUEUE *Q, ERROR_LOG *dat)
 /******************************************************************************************************************************************************
 **  \brief
 ******************************************************************************************************************************************************/
-UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, ERROR_LOG *rxdata, UBYTE length)
+UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, const ERROR_LOG *rxdata, UBYTE length)
 {
     for (UBYTE i = 0; i < length; i++)
     {
@@ -116,7 +116,7 @@ UBYTE que_ubPushIn(FLASH_ERROR_QUEUE *Q, ERROR_LOG *rxdata, UBYTE length)
 /******************************************************************************************************************************************************
 **  \brief Variable Defination
 ******************************************************************************************************************************************************/
-UBYTE que_ubPopOut(FLASH_ERROR_QUEUE *Q, ERROR_LOG *buf, UBYTE length)
+UBYTE que_ubPopOut(FLASH_ERROR_QUEUE *Q, ERROR_LOG buf[], UBYTE length)
 {
     if (que_fgEmpty(Q) != FALSE)
     {

+ 17 - 2
User project/5.Api_rt/api_rt_pwm.c

@@ -137,7 +137,7 @@ void iRtPwm_SyncSamplingAdcIsr(uint8_t devIndex)
     }
     else
     {
-        //do noting
+        //do nothing
     }
 
 }
@@ -496,7 +496,22 @@ void iPwm_DisableOutput(uint8_t devIndex)
 
 int8_t iPwm_GetChannelEnableState(uint8_t devIndex, uint8_t channelIndex)
 {
-    return Pwms[devIndex].OutputEnable;
+    ASSERT_LESS(devIndex, 1);
+    ////ASSERT_LESS(channelIndex, 4);
+    
+    uint32_t base = Pwms[devIndex].PwmBase;
+    uint32_t value = 0;
+
+    if (channelIndex < 64)
+    {
+        value = ((uint32_t)0x01) << (channelIndex * 4);
+    }
+    else
+    {
+        value = ((uint32_t)0x04) << ((channelIndex - 64) * 4);
+    }
+    
+    return ((TIMER_CHCTL2(base) & value) >> value);
 }
 
 void iPwm_EnableChannelOutput(uint8_t devIndex, uint8_t channelIndex)

+ 2 - 2
WLMCP_PACKED.ewp

@@ -2652,10 +2652,10 @@
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\flash_master.h</name>
                 </file>
                 <file>
-                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\FuncLayerAPI.h</name>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\i2c_master.h</name>
                 </file>
                 <file>
-                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\i2c_master.h</name>
+                    <name>$PROJ_DIR$\User project\3.BasicFunction\Include\InputCapture.h</name>
                 </file>
                 <file>
                     <name>$PROJ_DIR$\User project\3.BasicFunction\Include\power.h</name>