Explorar o código

整改代码规范问题

CN\guohui27 %!s(int64=2) %!d(string=hai) anos
pai
achega
21aeed0835

+ 4 - 20
User project/1.FrameLayer/Include/FSM_1st.h

@@ -12,31 +12,26 @@
 #ifndef FSM1ST_H
 #define FSM1ST_H
 
-#include "typedefine.h"
 /****************************************
  *
  *          Definitions & Macros
  *
  ****************************************/
-
 #define SYS_RDY_FLG_DEFAULT               \
     {                                     \
         FALSE, FALSE, FALSE, FALSE, FALSE \
-    } // Default value of FW_CTRL_OUT
+    } 
 
 #define SYS_FSM_FLG_DEFAULT                         \
     {                                               \
-        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0 \
-    } // Default value of FW_CTRL_OUT
+        FALSE, FALSE, FALSE, FALSE, FALSE, FALSE \
+    } 
 
-#define DISPLAY_DISABLE_CNT 15 * 60 * 1000 // 15mins
-#define SHUT_DOWN_CNT       30 * 60 * 1000 // 30min
 /***************************************
  *
  *          Type  Definations
  *
  ***************************************/
-
 /**
  * @brief Type of signal
  *
@@ -59,7 +54,6 @@ typedef enum
     SysInit = 0,
     SysRdy = 1,
     SysFault = 2,
-
 } SYS_FSM_STATUS;
 
 /**
@@ -68,13 +62,12 @@ typedef enum
  */
 typedef struct
 {
-    BOOL HMI_Flag; ///<
+    BOOL HMI_Flag; 
     BOOL SysCoef_Flag;
     BOOL SysRdy_Flag;
     BOOL SysRun_Flag;
     BOOL SysWarnning_Flag;
     BOOL SysFault_Flag;
-    int  Standby_flg;
 } SYS_FMS_FLAG;
 
 /**
@@ -108,15 +101,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;
-extern ULONG          swSwitchStateCnts;
-extern SYS_FSM_STATUS FaultFROM;
-
 /***************************************
  *
  *          Function  Definations
@@ -220,11 +209,6 @@ void FSM_1st_Main(void);
  */
 void RlyOnInit(void);
 
-/**
- * @brief Build communication with BMS and Display
- *
- */
-void CommuInit(void);
 /**
  * @brief System FSM initialization
  *

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

@@ -18,7 +18,6 @@
  *          Definitions & Macros
  *
  ****************************************/
-
 #define CTRLMD_FSM_FLG_DEFAULT \
     {                          \
         FALSE, TRUE            \

+ 45 - 126
User project/1.FrameLayer/Source/FSM_1st.c

@@ -8,7 +8,11 @@
  * @copyright Copyright (c) 2021
  *
  */
-
+/******************************
+ *
+ *  Included File
+ *
+ ******************************/
 #include "syspar.h"
 #include "user.h"
 #include "FSM_1st.h"
@@ -25,17 +29,15 @@ FSM_SYS_HOOK   FSM1st_Sys_state;
 FSM_SYS_HOOK   SysInit_state = {SysInit, SysInit_hook, SysInit_TbcUphook, SysInit_TbcDownhook, SysInit_Tbshook};
 FSM_SYS_HOOK   SysRdy_state = {SysRdy, SysRdy_hook, SysRdy_TbcUphook, SysRdy_TbcDownhook, SysRdy_Tbshook};
 FSM_SYS_HOOK   SysFault_state = {SysFault, SysFault_hook, SysFault_TbcUphook, SysFault_TbcDownhook, SysFault_Tbshook};
-SYS_FSM_STATUS FaultFROM = SysInit;
 SYS_FMS_FLAG   switch_flg = SYS_FSM_FLG_DEFAULT;
 SYS_RDY_FLG    sysfsm_stFlg = SYS_RDY_FLG_DEFAULT;
 SIGNAL_STATE   signal_state;
-ULONG          swShutCnt = 0;
-ULONG          HMI_SEND = 0;
-ULONG          swSwitchStateCnts = 0;
-ULONG          sysfsm_ulRlyVltCt = 0;
-ULONG          sysfsm_ulRlyActCt = 0;
 void (*switchfuction[3][3])(void) = {ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun, ReadytoRun};
-
+/******************************
+ *
+ *  Function
+ *
+ ******************************/
 void FSM_voInit(void)
 {
     FSM1st_Sys_state = SysInit_state;
@@ -43,14 +45,11 @@ void FSM_voInit(void)
     switch_flg.SysRdy_Flag = FALSE;
     switch_flg.SysRun_Flag = FALSE;
     switch_flg.SysFault_Flag = FALSE;
-    switch_flg.Standby_flg = 0;
-
     signal_state.Sensor = FALSE;
     signal_state.Assist = FALSE;
     signal_state.Switched = FALSE;
     signal_state.Light = FALSE;
     signal_state.Display = FALSE;
-
     sysfsm_stFlg.CommuRdy_Flag = TRUE;
 }
 
@@ -59,11 +58,10 @@ void FSM_1st_Main(void)
     switch (FSM1st_Sys_state.state)
     {
     case SysInit:
-        /*code*/
+        /* Fault detection*/
         if (switch_flg.SysFault_Flag == 1)
         {
             Switch_sys_FSM(&SysFault_state);
-            FaultFROM = SysInit;
         }
 
         if (switch_flg.SysRdy_Flag == 1)
@@ -72,52 +70,14 @@ void FSM_1st_Main(void)
             RUN_FSM_voInit();
             Switch_sys_FSM(&SysRdy_state);
         }
-
+        
         break;
-
     case SysRdy:
-
-        swSwitchStateCnts++;
         /* Fault detection*/
         if (switch_flg.SysFault_Flag == 1)
         {
             Switch_sys_FSM(&SysFault_state);
-            FaultFROM = SysRdy;
-        }
-        /* Shut down detection*/
-        if (signal_state.Switched == 1)
-        {
-            swShutCnt++;
-            if (swShutCnt >= 1000)
-            {
-                swShutCnt = 0;
-            }
-        }
-        else
-        {
-            swShutCnt = 0;
-        }
-        /* Code here*/
-        if (switch_flg.SysRun_Flag == 0)
-        {
-            if (swSwitchStateCnts <= DISPLAY_DISABLE_CNT)
-            {
-                switch_flg.Standby_flg = 1; /* send display disable message*/
-            }
-            else if (swSwitchStateCnts <= SHUT_DOWN_CNT)
-            {
-                switch_flg.Standby_flg = 2; //* EEPROM write and send BMS shut down message */
-            }
-            else
-            {
-                switch_flg.Standby_flg = 3; //* EEPROM write and send BMS shut down message */
-            }
-        }
-        else
-        {
-            /* system run*/
         }
-
         break;
 
     case SysFault:
@@ -135,30 +95,27 @@ void FSM_1st_Main(void)
 
 void SysInit_hook(void)
 {
-    /* code */
-
-    /* CommunicationInit */
-    CommuInit();
-    if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg && sysfsm_stFlg.CommuRdy_Flag)
+    if (sysfsm_stFlg.blADCInitOvrFlg && sysfsm_stFlg.CommuRdy_Flag)
     {
-        /* BikeLightInit */
+        /* Bike Light Init */
         bikelight_voBikeLightInit();
 
-        /* BikeThrottleInit */
+        /* Bike Throttle Init */
         bikethrottle_voBikeThrottleInit();
        
-        /* TorqueSensorInit */
+        /* Torque Sensor Init */
         torsensor_voTorSensorInit();
-        /* BikeSpd Loop Coef Cal */
-        bikemotorspdCoef();
-        
+
+        /* Bike Speed Init */
+        bikespeed_voBikeSpeedInit();
+
+        /* Bike Speed PI Init */
+        bikespeed_voPIInit();
+  
+        /* Bike Brake Init */
         bikebrake_voBikeBrakeInit();
-        /* Assist Coef Cal */
-        AssitCoefInit();
-        
+
         switch_flg.SysRdy_Flag = TRUE;
-        /* Bike Speed Loop Init*/
-        bikeSpdPIOutInit();
     }
 }
 
@@ -173,31 +130,37 @@ void SysInit_Tbshook(void)
 
 void SysRdy_hook(void)
 {
-    //  Coef Init
+    /* System Coef Cal */
     if (switch_flg.SysCoef_Flag == FALSE)
     {
-        AssitCoefInit();
         bikelight_voBikeLightCoef(ass_ParaCong.uwLightVoltage);
-        bikespeed_voBikeSpeedCof();
+
         bikethrottle_voBikeThrottleCof();
+
+        torsensor_voTorSensorCof();
+
+        bikespeed_voBikeSpeedCof();
+
+        bikespeed_voPICoef();
+
         cadence_voCadenceCof();
+
         display_voDisplayCoef();
-        torsensor_voTorSensorCof();
+                    
+        ass_voAssitCoef();    
+
         scm_voSpdCtrMdCoef();
+
         switch_flg.SysCoef_Flag = TRUE;
     }
 
-    //  Coef Update
+    /* System Coef Update */
     if (cp_stFlg.ParaAssistUpdateFinishFlg == TRUE && cp_stFlg.ParaUpdateFlg == FALSE)
     {
         if (FSM2nd_Run_state.state == Exit)
         {
-            AssitCoefInit();
+            ass_voAssitCoef();
             bikelight_voBikeLightCoef(ass_ParaCong.uwLightVoltage);
-            bikespeed_voBikeSpeedCof();
-            // bikethrottle_voBikeThrottleCof();
-            cadence_voCadenceCof();
-            // display_voDisplayCoef();
             torsensor_voTorSensorCof();
             cp_stFlg.ParaAssistUpdateFinishFlg = FALSE;
         }
@@ -230,11 +193,11 @@ void SysRdy_hook(void)
     else
     {}
 
-    //   2ND FSM Control
+    /* 2ND FSM Control */
     FSM_2nd_Main();
     FSM2nd_Run_state.Event_hook();
 
-    //   Run Flg Judge
+    /* System Run Flg Judge */
     if ((signal_state.Assist == 0 && signal_state.Sensor == 0) || (switch_flg.SysFault_Flag) || (power_stPowStateOut.powerstate == POWER_OFF) ||
         (switch_flg.SysCoef_Flag == FALSE) || (((cp_stFlg.ParaMotorDriveUpdateFinishFlg == TRUE) || ( cp_stFlg.ParaAssistUpdateFinishFlg == TRUE))&&FSM2nd_Run_state.state == Exit) )     
     {
@@ -245,21 +208,6 @@ void SysRdy_hook(void)
         switch_flg.SysRun_Flag = TRUE;
     }
 
-
-    if (switch_flg.SysRun_Flag == 0)
-    {
-
-        if (switch_flg.Standby_flg == 1)
-        {
-            /* send display disable message*/
-        }
-        else if (switch_flg.Standby_flg == 2)
-        {
-            /* EEPROM write and send BMS shut down message */
-        }
-    }
-    else
-    {}
 }
 
 void SysRdy_TbcUphook(void)
@@ -276,11 +224,12 @@ void SysRdy_Tbshook(void)
 
 void SysFault_TbcUphook(void)
 {
-    /* Add your code below */
+    /* Motor Fault Handle */
     alm_voHandleTBC(&alm_stIn);
 }
 void SysFault_hook(void)
 {
+    /* Bike Sensor Fault Handle */
     alm_voHandle1MS(&alm_stBikeIn);
 }
 void SysFault_TbcDownhook(void)
@@ -290,8 +239,6 @@ void SysFault_Tbshook(void)
 
 void Switch_sys_FSM(FSM_SYS_HOOK *in)
 {
-    swSwitchStateCnts = 0;
-    switch_flg.Standby_flg = 0;
     void (*function)(void) = switchfuction[FSM1st_Sys_state.state][in->state];
     function();
     FSM1st_Sys_state = *in;
@@ -299,31 +246,3 @@ void Switch_sys_FSM(FSM_SYS_HOOK *in)
 
 void ReadytoRun(void)
 {}
-
-void CommuInit(void)
-{
-    if (sysfsm_stFlg.CommuRdy_Flag == FALSE)
-    {
-        static ULONG sysfsm_ulCommuCt = 0;
-        sysfsm_ulCommuCt++;
-        if (sysfsm_ulCommuCt <= 100)
-        {
-            switch_flg.Standby_flg = 1;
-            if (switch_flg.HMI_Flag == 1)
-            {}
-        }
-        else if (sysfsm_ulCommuCt <= 800)
-        {
-            switch_flg.Standby_flg = 2;
-            /*  code */
-        }
-        else
-        {
-
-            switch_flg.Standby_flg = 3;
-            /* alarm */
-        }
-    }
-    else
-    {}
-}

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

@@ -8,7 +8,11 @@
  * @copyright Copyright (c) 2021
  *
  */
-
+/******************************
+ *
+ *  Included File
+ *
+ ******************************/
 #include "syspar.h"
 #include "user.h"
 #include "FSM_1st.h"
@@ -24,7 +28,11 @@ FSM_RUN_HOOK    Exit_state = {Exit, Exit_hook, Exit_tbcuphook, Exit_tbcdownhook,
 FSM_RUN_HOOK    Assistance_state = {Assistance, Assistance_hook, Assistance_tbcuphook, Assistance_tbcdownhook, Assistance_tbshook};
 FSM_RUN_HOOK    Boost_state = {Boost, Boost_hook, Boost_tbcuphook, Boost_tbcdownhook, Boost_tbshook};
 CTRLMD_FSM_FLG1 cmfsm_stFlg = CTRLMD_FSM_FLG_DEFAULT;
-
+/******************************
+ *
+ *  Function
+ *
+ ******************************/
 void RUN_FSM_voInit(void)
 {
     FSM2nd_Run_state = Exit_state;
@@ -36,23 +44,20 @@ void FSM_2nd_Main(void)
     switch (FSM2nd_Run_state.state)
     {
     case Exit:
-        /* code */
         if (switch_flg.SysRun_Flag == 1)
         {
             if (signal_state.Sensor == 1)
             {
-
-                /* PWM on */
+                /* 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;
-
                 hw_voPWMOn();
 
-                /* Init */
+                /* 3rd FSM Init */
                 Switch_speed_FSMInit();
 
                 /* switch to Boost FSM */
@@ -61,7 +66,7 @@ void FSM_2nd_Main(void)
             if (signal_state.Assist == 1)
             {
 
-                /* PWM on */
+                /* PWM On */
                 pwm_stGenOut.uwNewTIM1COMPR[0] = HW_HHPWM_PERIOD;
                 pwm_stGenOut.uwNewTIM1COMPR[1] = HW_HHPWM_PERIOD;
                 pwm_stGenOut.uwNewTIM1COMPR[2] = HW_HHPWM_PERIOD;
@@ -70,37 +75,31 @@ void FSM_2nd_Main(void)
                 pwm_stGenOut.uwNewTIM1COMPR[5] = HW_HHPWM_PERIOD;
                 hw_voPWMOn();
 
-                /* Init */
+                /* 3rd FSM Init */
                 Switch_speed_FSMInit();
 
                 /* switch to Boost FSM */
                 Switch_Second_FSM(&Boost_state);
             }
         }
+        
         break;
     case Assistance:
-
         if ((!switch_flg.SysRun_Flag) && cmfsm_stFlg.blMotorStopFlg && (curSpeed_state.state == Stop))
         {
             Switch_Second_FSM(&Exit_state);
         }
-        break;
 
+        break;
     case Boost:
-
-        //        if ((signal_state.Sensor == 1) && (switch_flg.SysRun_Flag))
-        //        {
-        //            Switch_Second_FSM(&Assistance_state);
-        //        }
-
         if ((!switch_flg.SysRun_Flag) && cmfsm_stFlg.blMotorStopFlg && (curSpeed_state.state == Stop))
         {
             Switch_Second_FSM(&Exit_state);
         }
-        break;
 
+        break;
     case Cruise:
-        /* code */
+       
         break;
 
     default:
@@ -149,7 +148,6 @@ void Exit_tbshook(void)
 
 void Switch_Second_FSM(FSM_RUN_HOOK *in)
 {
-    swSwitchStateCnts = 0;
     FSM2nd_Run_state = *in;
 }
 

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

@@ -21,7 +21,6 @@
 #include "can.h"
 #include "canAppl.h"
 #include "flash_master.h"
-#include "queue.h"
 #include "gd32f30x.h"
 #include "string.h"
 #include "syspar.h"
@@ -44,8 +43,7 @@ static SQWORD TimingTaskTimerTickTempOld = 0;
 static SQWORD TimingTaskTimerTickPassed = 0;
 static UWORD  LoopServerExecutedFlag = 0;
 static UWORD  AssistCNT = 0;
-UWORD socTest = 100;
-BOOL tstMafClrFlg = FALSE;
+static BOOL tstMafClrFlg = FALSE;
 /******************************
  *
  *  Function
@@ -58,7 +56,6 @@ void  Event_1ms(void)
     FSM1st_Sys_state.Event_hook();
     
     /* Power control */
-//    power_voPowerManagement(cp_stFlg.ParaHistorySaveEEFinishFlg, cp_stFlg.ParaSaveEEFlg);
     power_voPowerManagement(ass_ParaCong.uwAutoPowerOffTime * 60, cp_ulSystickCnt, OBC_ButtonStatus.ulButtonSetTimeCnt, \
                             MC_RunInfo.Torque, MC_RunInfo.Cadence, MC_RunInfo.BikeSpeed, \
                             cp_stFlg.ParaHistorySaveEEFinishFlg, cp_stFlg.ParaSaveEEFlg);
@@ -69,33 +66,31 @@ void  Event_1ms(void)
     /* Torque move average filter */
     if (cadence_stFreGetOut.uwForwardCnt > 0)
     {
-        torsensor_voCadenceCnt();
         cadence_stFreGetOut.uwForwardCnt = 0;
-        maf_torque.value = torsensor_stTorSensorOut.uwTorquePu;
-        MoveAverageFilter(&maf_torque);
+        ass_stTorqMafValue.value = torsensor_stTorSensorOut.uwTorquePu;
+        ass_voMoveAverageFilter(&ass_stTorqMafValue);
         
-        //////Iqref maf test, dont add torq obs//////
-        if(tstTorqPIFlg == 1)
+        /* Iqref maf test, dont add torq obs */
+        if(ass_CalOut.blTorqPIFlg)
         {
-            maf_uqlimit.value = ass_stTorqPIOut.swIRefPu;
-            MoveAverageFilter(&maf_uqlimit);
+            ass_stUqLimMafValue.value = ass_stTorqPIOut.swIRefPu;
+            ass_voMoveAverageFilter(&ass_stUqLimMafValue);
             tstMafClrFlg = FALSE;
         }
-        else if((tstTorqPIFlg == 0) && (tstMafClrFlg == FALSE))
+        else if((!ass_CalOut.blTorqPIFlg) && (tstMafClrFlg == FALSE))
         {
-            MoveAverageFilterClear(&maf_uqlimit);
+            ass_voMoveAverageFilterClear(&ass_stUqLimMafValue);
             tstMafClrFlg = TRUE;
         }    
         
     }
+
     /* Torque info update */
     torsensor_voTorADC();
-//    torsensor_voDynamicOffset();
-//    torsensor_voTorADCwithTemp();
 
     /* Torque assist calculation*/
-//    ass_CalIn.swFlxIqLimit = MC_RunInfo.SOC;
-    ass_CalIn.SOCValue = socTest;
+    //ass_CalIn.SOCValue = 100;
+    ass_CalIn.swFlxIqLimit = MC_RunInfo.SOC;
     if(cp_stFlg.RunModelSelect == CityBIKE )
     {
         ass_CalIn.swDirection = -1;
@@ -119,45 +114,21 @@ void  Event_1ms(void)
     ass_CalIn.uwSpdFbkAbsPu = scm_uwSpdFbkLpfAbsPu;
     ass_CalIn.swSpdFbkPu = scm_stSpdFbkLpf.slY.sw.hi;
     ass_CalIn.uwBaseSpdrpm = cof_uwVbRpm;
-    ass_CalIn.uwtorque = maf_torque.AverValue; // maf_torque.AverValue;//torsensor_stTorSensorOut.uwTorqueLPFPu;
+    ass_CalIn.uwtorque = ass_stTorqMafValue.AverValue; //torsensor_stTorSensorOut.uwTorqueLPFPu;
     ass_CalIn.uwtorquelpf = torsensor_stTorSensorOut.uwTorqueLPFPu;
     ass_CalIn.uwtorquePer = torsensor_stTorSensorOut.uwTorquePu;
     ass_CalIn.swCurFdbPu = scm_swIqFdbLpfPu;
     ass_CalIn.swCurRefPu = scm_swIqRefPu;
-    Assist();
+    ass_voAssist();
     
-    uart_swTorqRefNm = Assist_torqueper;
+    uart_swTorqRefNm = ass_CalOut.swAssitCurRef;
     
-      /////////test///////////
+    /////////Constant Current Control Test///////////
 //    if((cp_stFlg.RunModelSelect == CityBIKE) || (cp_stFlg.RunModelSelect == MountainBIKE))
 //    {
 //            
 //      ass_CalOut.swVoltLimitPu = scm_swVsDcpLimPu;
-//       uart_swTorqRefNm = ass_CalIn.swDirection * ass_ParaSet.uwSpeedAssistIMaxA;
-////      if(MC_ControlCode.GearSt == 0x01)
-////      {
-////          uart_swTorqRefNm = ass_CalIn.swDirection * 546;
-////      }
-////      else if(MC_ControlCode.GearSt == 0x02)
-////      {
-////          uart_swTorqRefNm = ass_CalIn.swDirection * 546 * 2;
-////      }
-////      else if(MC_ControlCode.GearSt == 0x03)
-////      {
-////          uart_swTorqRefNm = ass_CalIn.swDirection * 546 * 3;     
-////      }
-////      else if(MC_ControlCode.GearSt == 0x04)
-////      {
-////          uart_swTorqRefNm = ass_CalIn.swDirection * 546 * 4;  
-////      }
-////      else if(MC_ControlCode.GearSt == 0x33 || MC_ControlCode.GearSt == 0x05)
-////      {
-////          uart_swTorqRefNm = ass_CalIn.swDirection * 546 * 5;
-////      }
-////      else
-////      {
-////          uart_swTorqRefNm = 0;
-////      }
+//      uart_swTorqRefNm = ass_CalIn.swDirection * ass_ParaSet.uwSpeedAssistIMaxA;
 //      
 //      if(uart_swTorqRefNm != 0)
 //      {
@@ -170,7 +141,6 @@ void  Event_1ms(void)
 //          
 //    }
     
-
     /* Torque assist mode flag */
     if (ass_CalCoef.blAssistflag == TRUE && cp_stFlg.RunPermitFlg == TRUE && cp_stFlg.SpiOffsetFirstSetFlg ==1)
     {
@@ -188,24 +158,6 @@ void  Event_1ms(void)
     /* Speed assist mode flag */
     if((cp_stFlg.RunModelSelect == CityBIKE) || (cp_stFlg.RunModelSelect == MountainBIKE))
     {
-        #if 0  // By throttle ADC signal
-        if(bikethrottle_stBikeThrottleOut.uwThrottlePercent < 500)
-        {
-            AssistCNT ++;
-            if(AssistCNT > 1000 && cp_stFlg.RunPermitFlg == TRUE)
-            {
-                signal_state.Assist = TRUE;
-                AssistCNT = 1000;
-            }
-        }
-        else
-        {   
-            AssistCNT = 0;
-            signal_state.Assist = FALSE;
-        }
-        #elif 0 // By walk assist GPIO signal
-        
-        #elif 1 //By can bus command code
         if(cp_stBikeRunInfoPara.uwBikeGear == 0x22)
         {
             AssistCNT ++;
@@ -220,11 +172,10 @@ void  Event_1ms(void)
             AssistCNT = 0;
             signal_state.Assist = FALSE;
         }
-        #endif
 
         if(signal_state.Assist == TRUE)
         {
-            //6km/H = 100m/min  1.67m/s
+            //6km/H = 100m/min = 1.67m/s
             if(cp_stFlg.RunModelSelect == CityBIKE)
             {
                 uart_slSpdRefRpm = -(10000/(ass_ParaCong.uwWheelDiameter))*ass_ParaCong.uwNmBackChainring*ass_ParaCong.uwMechRationMotor/ass_ParaCong.uwNmFrontChainring;
@@ -260,6 +211,7 @@ void  Event_1ms(void)
 
 void Event_5ms(void)
 {
+    /* Upper Computer Info Update */
     Can_voMC_Run_5ms();
 }
 
@@ -284,8 +236,9 @@ void Event_10ms(void)
             uart_slSpdRefRpm = -((SLONG)MC_MotorSPD_rpm_Percent*5000)/100;
         }
      
-        /* bikespeed closeloop control  */
-//         bikemotorspdref();
+        /*  Use Bike Speed PI */
+//         bikespeed_voPuCal();
+//         bikespeed_voPI(&bikespeed_stPIIn, &bikeSpdPIOut);
 //         ass_CalIn.swDirection =-1;       
 //         uart_slSpdRefRpm = bikeSpdPIOut.swSpdRefRpm * ass_CalIn.swDirection;
 
@@ -293,7 +246,6 @@ void Event_10ms(void)
          {
              uart_slSpdRefRpm = 0;
          }
-
     }
     
     /* Bike light control */
@@ -302,45 +254,34 @@ void Event_10ms(void)
 
     /* Trip cal when open */
     bikespeed_votempTripCal();
-
 }
 
 
 void  Event_20ms(void)
 {
+    /* MCU Self Check */
     stl_voDoRunTimeChecks();
 }
 
 void Event_100ms(void)
 {
+    /* Bike Speed LPF */
     bikespeed_stFreGetOut.uwLPFFrequencyPu = (bikespeed_stFreGetOut.uwLPFFrequencyPu * bikespeed_stFreGetCof.uwBikeSpeedLPFGain +
                                               bikespeed_stFreGetOut.uwFrequencyPu * (100 - bikespeed_stFreGetCof.uwBikeSpeedLPFGain)) /
                                              100;
-    
-
 }
 
-UWORD ReadorWrite = 2;
 void  Event_200ms(void)
 {
-  
- // SendData(ID_MC_BC, MODE_REPORT, 0x1020, (uint8_t *)&MC_RunInfo.BikeSpeed);
-    if (ReadorWrite == 3)
-    {
-        stErrorLog.NotesInfo1 = 1;
-        stErrorLog.NotesInfo2 = 2;
-        stErrorLog.NotesInfo3 = 3;
-        que_ubPushIn(&stFlashErrorLog, &stErrorLog, sizeof(stErrorLog));
-        ReadorWrite = 2;
-    }
-
+    /* Upper Computer Info Update */
     Can_voMC_Run_200ms();
 
+    /* Bike Sesor Suply Voltage Fault Detect */
     bikelight_voGetBikeLightError(adc_stUpOut.uwU6VPu);
     display_voGetDisplayError(adc_stUpOut.uwU12VPu);
     bikespeed_voGetBikeSpeedPwrError(adc_stUpOut.uwU5VPu);
 
-    /* Bike faults 200ms detect */
+    /* Bike Sensor Faults Detect */
 //    if((cp_stFlg.RunModelSelect == MountainBIKE) || (cp_stFlg.RunModelSelect == CityBIKE))
 //    {
 //        alm_stBikeIn.uwTroqReg = torsensor_stTorSensorOut.uwTorqueReg;

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

@@ -4,19 +4,28 @@
 */
 
 /*
-    Copyright (C) 2017 GigaDevice
+    Copyright (C) 2022 GigaDevice
 
-    2017-06-06, V1.0.0, firmware for GD32F3x0
+    2022-12-01, V1.0.0, firmware for GD32F3x0
 */
 
+/******************************
+ * Include File
+ ******************************/
 #include "gd32f30x_it.h"
 #include "user.h"
 #include "TimeTask_Event.h"
 #include "syspar.h"
 #include "can.h"
 
+/******************************
+ *  Parameter
+ ******************************/
 extern uint8_t data;
 
+/******************************
+ *  Function
+ ******************************/
 /*!
     \brief      this function handles NMI exception
     \param[in]  none
@@ -115,16 +124,14 @@ void PendSV_Handler(void)
 */
 void SysTick_Handler(void)
 {
-    /* Add your code below */
-  
-    clas_ubSystickFlg = 1; // for TUV
-
     cp_ulSystickCnt ++;
+    /* MCU Self Check*/
+    clas_ubSystickFlg = 1; 
     stl_voSystickProc();
-    /* TBT interrupt */
-    tbt_voIsr();
     /* UART Timeout */
     UART_voApplTimer();
+    /* TBT interrupt */
+    //tbt_voIsr();
 }
 /*!
     \brief      
@@ -132,13 +139,12 @@ void SysTick_Handler(void)
     \param[out] none
     \retval     none
 */
-UWORD tstcccmin=2000, tstcccmax=0,tstccccnt;
+
 void ADC0_1_IRQHandler(void)
 {
     clasB_uwADCCnt++;
-    
     //GPIO_OCTL(GPIOC) |= 0x0800; //TEST PC11
-   
+
     if (cp_stFlg.CurrentSampleModelSelect == COMBINATION)
     {
         if (ADC_STAT(ADC0) & ADC_INT_FLAG_EOIC)
@@ -149,29 +155,7 @@ void ADC0_1_IRQHandler(void)
             
 //            adc_disable(ADC0);            
 //            timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_3, pwm_stGenOut.uwSigRTrig);
-//            adc_interrupt_flag_clear(ADC0 , ADC_INT_FLAG_EOIC);
-            if(curSpeed_state.state == ClzLoop)
-            {
-              tstccccnt ++;
-              if(tstccccnt>100)
-              {
-                tstccccnt = 100;
-                 if(adc_uwRdsonWReg < tstcccmin)
-                 {
-                   tstcccmin = adc_uwRdsonWReg;
-                 }
-                 
-                 if(adc_uwRdsonWReg > tstcccmax)
-                 {
-                   tstcccmax = adc_uwRdsonWReg;
-                 }
-              }
-
-               
-            }
-             
-            
-            
+//            adc_interrupt_flag_clear(ADC0 , ADC_INT_FLAG_EOIC);                      
             /* ADC0 disable */
             ADC_CTL1(ADC0) &= ~((uint32_t)ADC_CTL1_ADCON);
             /* ADC1 trigger set */
@@ -186,11 +170,9 @@ void ADC0_1_IRQHandler(void)
             if (pwm_stGenOut.blSampleCalibFlag == TRUE)
             {
                 adc_uwADDMAPhase1 = ADC_IDATA0(ADC1);
-            }
-            
+            }            
 //            adc_disable(ADC1);              
 //            adc_interrupt_flag_clear(ADC1 , ADC_INT_FLAG_EOIC);
-
             /* ADC1 disable */
             ADC_CTL1(ADC1) &= ~((uint32_t)ADC_CTL1_ADCON);
             /* ADC1 interrupt flag clear */
@@ -203,7 +185,7 @@ void ADC0_1_IRQHandler(void)
     else
     {
     }
-    
+
     //GPIO_OCTL(GPIOC) &= ~0x0800; //TEST PC11
 }
 
@@ -245,7 +227,6 @@ void TIMER0_UP_TIMER9_IRQHandler(void)
                 adc_enable(ADC0);
                 // adc_interrupt_enable(ADC0 , ADC_INT_EOIC);
                 //adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
-
                 /* Software trigger for regular sampling*/
                 adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL); 
                 
@@ -368,7 +349,7 @@ void USART0_IRQHandler(void)
 void DMA1_Channel2_IRQHandler(void)
 {
     static UWORD uwTempCount = 0;
-    // Read PC Conmand
+    /* Read PC Conmand */
     if (dma_flag_get(DMA1, DMA_CH2, DMA_INT_FLAG_FTF))
     {
         UART_voCBDoneRead(UART_ERR_OK, 22);
@@ -379,7 +360,7 @@ void DMA1_Channel2_IRQHandler(void)
         DMA_CH2CNT(DMA1) = uwTempCount;
         DMA_CH2CTL(DMA1) |= DMA_CHXCTL_CHEN;
     }
-    // RX error
+    /* RX error */
     if (dma_flag_get(DMA1, DMA_CH2, DMA_FLAG_ERR))
     {
         DMA_CH2CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
@@ -415,7 +396,7 @@ void DMA1_Channel4_IRQHandler(void)
         DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
         UART_stParaStatus.bWriteBusy = FALSE;
     }
-    // TX error
+    /*  TX error */
     if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR))
     {
         if (UART_stParaStatus.bParaStart)
@@ -435,7 +416,6 @@ void DMA1_Channel4_IRQHandler(void)
     \param[out] none
     \retval     none
 */
-UWORD uwCnts = 0;
 void  CAN0_RX0_IRQHandler(void)
 {
     can_message_receive(CAN0, CAN_FIFO0, pRxMsg);

+ 14 - 15
User project/1.FrameLayer/Source/main.c

@@ -47,19 +47,14 @@
 int   main(void)
 {
     SCB->VTOR = 0x08003000;
-    /*Bootloader configuration*/
-    //    #ifdef BOOTLOADER
-    //        boot_voBootloader();
-    //    #endif
     /* Disable all interrupts */
-    DISABLE_IRQ; /* MCU Core and GPIO configuration */
+    DISABLE_IRQ; 
+    /* MCU Core and GPIO configuration */
     hw_voHardwareSetup1();
-    /* Code Init */
+    /* Code Para Init */
     CodeParaInit();
     /* AssitPara Init */
-    AssitEEInit();
-    /* IPM selection */
-    // mn_voIPMSelection();
+    ass_voAssitEEInit();
     /* Peripheral configuration */
     hw_voHardwareSetup2();
     /* PowerInit */
@@ -72,15 +67,15 @@ int   main(void)
     if(cp_stFlg.ParaFirstSetFlg == 0)
     {
         flash_voParaInit();
-        /* Parameter default value write*/ 
+        /* Parameter Default Value Write*/ 
         i2c_voDefaultWriteBuffer();
         i2c_voInfoWrite2EE(&i2c_stTXCoef, &i2c_stTXOut);
-        
+        /* Cycling History Info clear */ 
         CodeHistoryParaDelete();
         mn_voEEHistoryParaUpdate();
         i2c_voHistoryWriteBuffer();
         i2c_voHistoryWrite2EE(&i2c_stTXCoef, &i2c_stTXOut); 
-        
+        /* Read EE and Update code para */
         mn_voParaSet();
     }
     Can_voUpdateMC_UpcInfo();
@@ -90,11 +85,13 @@ int   main(void)
     hw_voTimEn();
     /* Interrupts of peripherals enable*/
     hw_voEnInt();
-    /*Spi error comp*/
+    /* Spi Position Comp */
     spi_voReadWriteSeneorReg();
-    /* self test init */
+    /* Error Log Read */
+    flash_voErrorRead();
+    /* MCU Self Test Init */
     stl_voRunTimeChecksInit();
-    /* watchdog 1s */
+    /* Watchdog 1s */
     hw_voIWDGInit(FWDGT_PSC_DIV32,1250);//1s  
     /* Enable all interrupts */
     ENABLE_IRQ;
@@ -153,6 +150,8 @@ int   main(void)
                     i2c_voHistoryWrite2EE(&i2c_stTXCoef, &i2c_stTXOut);
                     cp_stFlg.ParaHistorySaveEEFinishFlg = TRUE;
                     flash_voWrite();
+                    /* Error Log Write */
+                    flash_voErrorWrite();
                     if (cp_stFlg.ParaSaveEEFlg == TRUE)
                     {
                         mn_voEEUperParaUpdate();

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

@@ -49,25 +49,24 @@ Revising History (ECL of this file):
 ****************************************************************/
 void tbc_voUpIsr(void)
 {
+    /* Uart Monitor */
     UART_voAppMonitor();
-   
+
+    /* Motor Position Cal */
     if( cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER )
     {
-        /*Resolver lock data*/
         spi_voResolverLock();
-        /* Resolver data read */
         spi_voResolver(&spi_stResolverCoef, &spi_stResolverOut);
     }
     else if( cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL )
     {
-        /*Switchhall Position Cal*/
         switchhall_voPosCalTbc();
     }
     else
     {
-
     }
 
+    /* 1st FSM */
     FSM1st_Sys_state.Tbcup_hook();
 }
 
@@ -80,24 +79,24 @@ void tbc_voUpIsr(void)
  Subroutine Call: ...;
  Reference: N/A
 ****************************************************************/
+BOOL tbc_pvt_blErrorFlag = 0;
 void tbc_voDownIsr(void)
 {
+    /* ADC Sample */
     adc_voSampleUp(&adc_stCof, &adc_stUpOut);
     
     /* Alarm detect */
     alm_stIn.blADCInitOvrFlg = sysfsm_stFlg.blADCInitOvrFlg;
-
-    alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu;    // Q14
-    alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt; // unit: 0.1w
+    alm_stIn.uwIpeakPu = adc_stDownOut.uwIpeakPu;    
+    alm_stIn.swMotorPwrInWt = scm_swMotorPwrInLpfWt;  
     alm_stIn.uwIaAbsPu = adc_stDownOut.uwIaAbsPu;
-
-    alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu;      // Q14
-    alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu;      // Q14
-    alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; // Q14
-    alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu;   // Q14
+    alm_stIn.uwIbAbsPu = adc_stDownOut.uwIbAbsPu;      
+    alm_stIn.uwIcAbsPu = adc_stDownOut.uwIcAbsPu;      
+    alm_stIn.swIalhpaPu = crd_stCurClarkOut.swAlphaPu; 
+    alm_stIn.swIbetaPu = crd_stCurClarkOut.swBetaPu;   
     alm_stIn.swIqRefPu = scm_swIqRefPu;
-    alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;        // Q14
-    alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; // Q15
+    alm_stIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;        
+    alm_stIn.uwSpdFbkLpfAbsPu = scm_uwSpdFbkLpfAbsPu; 
     if (scm_swSpdRefPu >= 0)
     {
         alm_stIn.uwSpdRefAbsPu = (UWORD)scm_swSpdRefPu;
@@ -111,17 +110,19 @@ void tbc_voDownIsr(void)
     alm_stIn.swDrumSpdAbsNowRpm = uart_swDrumSpdAbsNowRpm;
     alm_stIn.swDrumSpdAbsPreRpm = uart_swDrumSpdAbsPreRpm;
     alm_stIn.blSpiThetaFltFlg = spi_stResolverOut.blSpiThetaFltFlg;
-
     alm_voDetecTBC(&alm_stIn, &alm_stDetectTbcCoef);
+    
+    /* MCU Fault Detect */
     if((FALSE == UART_bInsertPendTx)&&(UART_bMonSwitch == FALSE))
     {
       stl_voTbcProc();
     }
 
-    /* System FSM */
+    /* Error Log */
     switch_flg.SysFault_Flag = alm_blAlmOccrFlg;
-    if (switch_flg.SysFault_Flag == TRUE)
+    if (switch_flg.SysFault_Flag == TRUE && tbc_pvt_blErrorFlag == 0)
     {
+        tbc_pvt_blErrorFlag = TRUE;
         stErrorLog.ErrorCode = alm_unCode.all;
         stErrorLog.RunTime = MC_RunInfo.Ride_Time;
         stErrorLog.RunInfo = MC_RunInfo;
@@ -130,9 +131,14 @@ void tbc_voDownIsr(void)
         stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
         stErrorLog.IdVoltagePu = scm_swUdRefPu;
 
-        //      que_ubPushIn( &stFlashErrorLog, &stErrorLog, 54 );
+        que_ubPushIn( &stFlashErrorLog, &stErrorLog, 1);  
+    }
+    else if(switch_flg.SysFault_Flag == FALSE)
+    {
+        tbc_pvt_blErrorFlag = FALSE;
     }
 
+    /* ADC Init Finish Flag */
     if (adc_stDownOut.blADCCalibFlg && adc_stUpOut.blADCCalibFlg)
     {
         sysfsm_stFlg.blADCInitOvrFlg = TRUE;
@@ -142,14 +148,13 @@ void tbc_voDownIsr(void)
         sysfsm_stFlg.blADCInitOvrFlg = FALSE;
     }
 
-    /* ADC sample */
+    /* ADC Sample */
     adc_voSampleDown(&adc_stCof, &adc_stDownOut);
 
-    /* ADC Rdson calibration with single resistance*/
+    /* ADC Rdson Calibration with Single Resistance*/
     adc_voSRCalibration(&adc_stCof, &adc_stUpOut, &adc_stDownOut);
 
-    /* System FSM */
-
+    /* 1st FSM */
     FSM1st_Sys_state.TbcDown_hook();
 }
 

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

@@ -46,9 +46,8 @@ void tbs_voIsr(void)
     /* Alarm detect */
     alm_voDetecTBS(&alm_stIn, &alm_stDetectTbsCoef);
 
+    /* 1st FSM */
     FSM1st_Sys_state.Tbs_hook();
-
-    /* System FSM */
 }
 
 /*************************************************************************

+ 0 - 147
User project/2.MotorDrive/Include/fluxweaken.h

@@ -1,147 +0,0 @@
-/************************************************************************
- Project:             Welling FAN Motor Developing platform
- Filename:            fluxweaken.h
- Partner Filename:    fluxweaken.c
- Description:         Partner file of fluxweaken.c
- Complier:            IAR Embedded Workbench for ARM 7.80, IAR Systems.
- CPU TYPE :           ST32F0xx
-*************************************************************************
- Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
-*************************************************************************
-Revising History (ECL of this file):
-20191225, by cyf, create this file;
-************************************************************************/
-#include "typedefine.h"
-#include "macroequ.h"
-/************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
-*************************************************************************/
-#ifndef FWCTRl_H
-#define FWCTRl_H
-/************************************************************************
- Compiler Directives (N/A)
-*************************************************************************/
-#ifdef _FWCTRL_C_
-#define FWCTRl_EXT
-#else
-#define FWCTRl_EXT extern
-#endif
-/************************************************************************
- Definitions & Macros
-*************************************************************************/
-
-/************************************************************************
- Constant Table (N/A)  Is = 0.6A ,Iq^2 = Is^2 - Id^2
-*************************************************************************/
-//#if (USER_MOTOR_ID == USER_HUAWEI_V2)
-
-#define FW_CNTS 17
-static const SWORD fw_swIqLimTab[FW_CNTS] = {
-    10240, //	0,id = 0A ,Iqlimit = 0.6A
-    10240, //	1,id = -0.025A
-    10240, //	2,id = -0.05A
-    10240, //	3,id = -0.075A
-    10240, //	4,id = -0.1A
-    10240, //	5,id = -0.125A
-    10240, //	6,id = -0.15A
-    10240, //	7,id = -0.175A
-    10240, //	8,id = -0.2A
-    10240, //	9,id = -0.225A
-    10240, //	10,id = -0.25A
-    10240, //	11,id = -0.275A
-    10240, //	12,id = -0.3A
-    10240, //	13,id = -0.325A
-    10240, //	14,id = -0.35A
-    10240, //	15,id = -0.375A
-    10240, //	16,id = -0.4A
-};
-//#endif
-
-/************************************************************************
- TypeDefs & Structure defines (N/A)
-*************************************************************************/
-typedef struct
-{
-    UWORD uwUdcCnt;
-    UWORD uwUdcMinPu;
-    UWORD uwUdcPu;
-    SWORD swEnable;
-    SWORD swIdFwoutPu;
-    SLONG slIdFwoutPu;
-    SWORD swFwIqLimPu;
-    SWORD swVolErrPu;
-    UWORD uwFwCoefPu; // Q14
-} FW_OUT;
-
-typedef struct
-{
-    UWORD uwKpPu;          // Q14
-    UWORD uwKitPu;         // Q14
-    SWORD swIdMinPu;       // Q14
-    SWORD swIdCharacterPu; // Q14
-    SWORD swIqMinPu;
-    SWORD swIqMaxPu;
-} FW_COFIN;
-
-typedef struct
-{
-    UWORD uwKpPu;          // Q14
-    UWORD uwKitPu;         // Q14
-    SWORD swIdMinPu;       // Q14
-    SWORD swIdCharacterPu; // Q14
-    SWORD swIqMinPu;
-    SWORD swIqMaxPu;
-} FW_COF;
-
-typedef struct
-{
-    SWORD swPwmalphaPu; // Q14
-    SWORD swPwmbetaPu;  // Q14
-    UWORD uwUdcPu;      // Q14
-} FW_IN;
-/************************************************************************
- Exported Variables
-*************************************************************************/
-#ifdef _FWCTRL_C_
-FWCTRl_EXT FW_OUT fw_stFluxWeakeningOutPu;
-FWCTRl_EXT FW_COF fw_stFluxWeakeningCoefPu;
-#else
-FWCTRl_EXT FW_OUT fw_stFluxWeakeningOutPu;
-FWCTRl_EXT FW_COF fw_stFluxWeakeningCoefPu;
-#endif
-/************************************************************************
- RAM ALLOCATION:
-*************************************************************************/
-#define fw_stFluxWeakeningInPu     (*(FW_IN *)TBC_BUFFER)
-#define fw_stFluxWeakeningCoefInPu (*(FW_COFIN *)MN_BUFFER)
-/************************************************************************
- Exported Function Call Prototypes
-*************************************************************************/
-#ifdef _FWCTRL_C_
-FWCTRl_EXT void fw_voFluxWeakeningGen(FW_IN *IN, FW_COF *COF, FW_OUT *OUT);
-FWCTRl_EXT void fw_voFluxWeakeningCoef(FW_COFIN *COFIN, FW_COF *COF);
-FWCTRl_EXT void fw_voInit(void);
-#else
-FWCTRl_EXT void fw_voFluxWeakeningGen(FW_IN *IN, FW_COF *COF, FW_OUT *OUT);
-FWCTRl_EXT void fw_voFluxWeakeningCoef(FW_COFIN *COFIN, FW_COF *COF);
-FWCTRl_EXT void fw_voInit(void);
-#endif
-/************************************************************************
- Local Function Call Prototypes (N/A)
-*************************************************************************/
-
-/************************************************************************
- Flag Define (N/A)
-*************************************************************************/
-#endif
-
-/************************************************************************
- Copyright (c) 2019 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
-*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
-*************************************************************************/

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

@@ -65,7 +65,6 @@ void scm_voSpdCtrMdInit(void)
     spi_voResolverInit();
     /* Speed PI init */
     asr_voSpdPIInit();
-    bikeSpdPIOutInit();
     /* Flux weakening init */
     flx_voInit();
     //  fw_voInit();

+ 21 - 41
User project/3.BasicFunction/Include/AssistCurve.h

@@ -12,8 +12,6 @@
 #ifndef ASSISTCURVE_H
 #define ASSISTCURVE_H
 
-#include "typedefine.h"
-#include "macroequ.h"
 #include "asr.h"
 /****************************************
  *
@@ -309,6 +307,8 @@ typedef struct
     
     SWORD swVoltLimitPu;
     BOOL blAssHoldFlag;
+    BOOL blTorqPIFlg;
+    SWORD swAssitCurRef;
 } ASS_PER_OUT;
 
 /**
@@ -355,14 +355,14 @@ typedef struct
 typedef struct
 {
     UWORD uwIqLimitInitAbs;
-    UWORD uwIqLimitStartSoc; // IqLimit
+    UWORD uwIqLimitStartSoc; 
     UWORD uwIqLimitEndSoc;
     SWORD swIqLImitK;
 } ASS_LIMIT_ACCORDING_VOL_COF;
 
 typedef struct
 {
-    UWORD uwIqLimitAbs; // IqLimit
+    UWORD uwIqLimitAbs; 
 } ASS_LIMIT_ACCORDING_VOL_OUT;
 
 typedef struct
@@ -386,32 +386,19 @@ typedef struct
  *           Exported variable
  *
  ****************************************/
-   
-   
-extern ASS_LIMIT_ACCORDING_VOL_OUT ass_CurLimitCalBMSOut;
-extern ASS_LIMIT_ACCORDING_VOL_COF ass_CurLimCalBMSCoef;
-
 extern ASS_FSM_STATUS Ass_FSM;
 
+extern ASS_PER_IN   ass_CalIn;
+extern ASS_PER_COEF ass_CalCoef;
 extern ASS_PER_OUT  ass_CalOut;
-extern SWORD Assist_torqueper;
-
 
 extern ASS_PARA_CONFIGURE ass_ParaCong;
 extern ASS_PARA_SET       ass_ParaSet;
 
-extern ASS_PER_IN   ass_CalIn;
-extern ASS_PER_COEF ass_CalCoef;
-
-extern ASS_CURLIM_OUT  ass_CurLimOut;
+extern ASS_LIMIT_ACCORDING_VOL_COF ass_CurLimCalBMSCoef;
+extern ASS_LIMIT_ACCORDING_VOL_OUT ass_CurLimitCalBMSOut;
 extern ASS_CURLIM_COEF ass_CurLimCoef;
-
-extern SWORD  MAF_buffer[64];
-extern MAF_IN maf_torque;
-extern SWORD  MAF_uq_buffer[64];
-extern MAF_IN maf_uqlimit;
-extern UWORD tstUqLimFlag;
-extern UWORD tstTorqPIFlg;
+extern ASS_CURLIM_OUT  ass_CurLimOut;
 
 extern ASR_SPDPI_IN  asr_stTorqSpdPIIn;
 extern ASR_SPDPI_OUT asr_stTorqSpdPIOut;
@@ -420,6 +407,11 @@ extern ASR_SPDPI_COFIN asr_stTorqSpdPICoefIn;
 
 extern ASS_TORQ_PI_IN ass_stTorqPIIn;
 extern ASS_TORQ_PI_OUT ass_stTorqPIOut;
+
+extern SWORD  ass_swTorqMafBuf[64];
+extern MAF_IN ass_stTorqMafValue;
+extern SWORD  ass_swUqLimMafBuf[64];
+extern MAF_IN ass_stUqLimMafValue;
 /************************************************************************
  Ram Allocation
 *************************************************************************/
@@ -429,23 +421,11 @@ extern ASS_TORQ_PI_OUT ass_stTorqPIOut;
  *          Function  Definations
  *
  ***************************************/
-/**
- * @brief Assistant force curve
- *
- * @param in
- * @return UWORD
- */
-void AssitEEInit(void);
-void AssitCoefInit(void);
-void Assist(void);
-void MoveAverageFilter(MAF_IN *in);
-void MoveAverageFilterClear(MAF_IN *in);
-void AssistCurrentLimitAccordingBMS(UWORD uwSOCvalue);
-
-void AssitTorqPI(ASS_TORQ_PI_IN *in, ASS_TORQ_PI_OUT *out);
-/**
- * @brief 选择相应档位曲线
- *
- */
-void AssistMode_Select(void);
+void ass_voAssitEEInit(void);
+void ass_voAssitCoef(void);
+void ass_voAssist(void);
+void ass_voMoveAverageFilter(MAF_IN *in);
+void ass_voMoveAverageFilterClear(MAF_IN *in);
+void ass_voAssitTorqPI(ASS_TORQ_PI_IN *in, ASS_TORQ_PI_OUT *out);
+
 #endif

+ 9 - 9
User project/3.BasicFunction/Include/bikespeed.h

@@ -119,21 +119,21 @@ typedef struct // Input of "BikeSpdREFPI"
     SLONG slSpdFdkPu; //  bikeSpeed feedback,Q0
     SWORD swbikespdMax;      // bikespeed output maximum limit
     SWORD swbikespdMin;  // bikespeed output minimum limit
-} BikeSpdPI_IN;
+} BIKESPDPI_IN;
 
 typedef struct
 {
    SLONG slErrorZ1;
-   SLONG slmotorspeedref;
+   SLONG slMotorspeedref;
    SWORD swMotorSpeedRef;
    SWORD swSpdRefRpm;
-} MOTORSPEED_OUT;
+} BIKESPDPI_OUT;
 
 typedef struct
 {
     UWORD  uwKpPu;
     UWORD  uwKiPu;
-}BikeSpdCoef;
+}BIKESPDPI_COF;
 
 /****************************************
  *
@@ -142,7 +142,7 @@ typedef struct
  ****************************************/
 
 extern BIKESPEED_COF bikespeed_stFreGetCof;
-extern MOTORSPEED_OUT bikeSpdPIOut;
+extern BIKESPDPI_OUT bikespeed_stPIOut;
 /***************************************
  *
  *          Function  Definations
@@ -153,10 +153,10 @@ void bikespeed_voBikeSpeedCof(void);
 void bikespeed_voBikeSpeedCal(UWORD source);
 void bikespeed_voGetBikeSpeedPwrError(UWORD BikeSpeedPwrVolPu);
 void bikespeed_votempTripCal(void);
-void bikemotorspdref(void);
-void bikemotorspdCoef(void);
-void BikeSpdPI(BikeSpdPI_IN *in, MOTORSPEED_OUT *out);
-void bikeSpdPIOutInit(void);
+void bikespeed_voPIInit(void);
+void bikespeed_voPICoef(void);
+void bikespeed_voPuCal(void);
+void bikespeed_voPI(BIKESPDPI_IN *in, BIKESPDPI_OUT *out);
 /************************************************************************
  Flag Define (N/A)
 *************************************************************************/

+ 3 - 3
User project/3.BasicFunction/Include/classB.h

@@ -36,17 +36,17 @@ WLBDM_M0_SR_20170814-new FSM1.1, by cyf, create this file;
 /* 1:enable FLASH CRC selftest 
    0:disable 
    */
-#define FLASHSTEN 0
+#define FLASHSTEN 1
 
 /* 1:enable clock selftest 
    0:disable 
    */
-#define CLOCKSTEN 0
+#define CLOCKSTEN 1
 
 /* 1:enable microchip fault detection 
    0:disable 
    */
-#define CHIP_FAULT_DETECTION 0
+#define CHIP_FAULT_DETECTION 1
 
 /************************************************************************
  TypeDefs & Structure defines (N/A)

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 88 - 871
User project/3.BasicFunction/Source/AssistCurve.c


+ 36 - 44
User project/3.BasicFunction/Source/bikespeed.c

@@ -31,9 +31,9 @@
 BIKESPEED_COF bikespeed_stFreGetCof = BIKESPEED_COF_DEFAULT;
 BIKESPEED_OUT bikespeed_stFreGetOut = BIKESPEED_OUT_DEFAULT;
 
-MOTORSPEED_OUT bikeSpdPIOut;
-BikeSpdPI_IN bikespdPIin;
-BikeSpdCoef  bikespeedcof;
+BIKESPDPI_IN bikespeed_stPIIn;
+BIKESPDPI_COF  bikespeed_stPICof;
+BIKESPDPI_OUT bikespeed_stPIOut;
 /***************************************************************
  Function: bikespeed_voBikeSpeedCof;
  Description: Bike speed cof calculation
@@ -320,56 +320,58 @@ void bikespeed_voBikeSpeedCal(UWORD source)
  Subroutine Call: N/A;
  Reference: N/A
 ****************************************************************/
-void bikemotorspdCoef(void)
+void bikespeed_voPIInit(void)
 {
-     bikespeedcof.uwKpPu = 20000 ;   //Q15
-     bikespeedcof.uwKiPu = 8000 ;  //Q15
+    bikespeed_stPIOut.slErrorZ1 = 0;
+    bikespeed_stPIOut.slMotorspeedref = 0;
+    bikespeed_stPIOut.swMotorSpeedRef = 0;
+    bikespeed_stPIOut.swSpdRefRpm = 0 ;   
 }
 
+void bikespeed_voPICoef(void)
+{
+     bikespeed_stPICof.uwKpPu = 20000 ;   //Q15
+     bikespeed_stPICof.uwKiPu = 8000 ;    //Q15
+}
 
-void bikemotorspdref(void)
+void bikespeed_voPuCal(void)
 {
-    SWORD BikeSpeedKmHREF = 0;  //km/h
-    SLONG slBikeSpdRefPu = 0; //Q20
+    SWORD swBikeSpeedKmh = 0;  //km/h
+    SLONG slBikeSpdRefPu = 0;  //Q20
     
     if(MC_ControlCode.GearSt == 0x01)
     {
-         BikeSpeedKmHREF=10;
+        swBikeSpeedKmh = 10;
     }
     else if(MC_ControlCode.GearSt == 0x02)
     {
-      BikeSpeedKmHREF=15;
+        swBikeSpeedKmh = 15;
     }
     else if(MC_ControlCode.GearSt == 0x03)
     {
-     BikeSpeedKmHREF=20;
+        swBikeSpeedKmh = 20;
     }
     else if(MC_ControlCode.GearSt == 0x04)
     {
-     BikeSpeedKmHREF=25;
+        swBikeSpeedKmh = 25;
     }
     else if(MC_ControlCode.GearSt == 0x33 || MC_ControlCode.GearSt == 0x05)
     {
-      BikeSpeedKmHREF=30;
-
+        swBikeSpeedKmh = 30;
     }
     else
-    {
-      
+    {     
     }
-     slBikeSpdRefPu = BikeSpeedKmHREF * 1000 * 29127 / ass_ParaCong.uwWheelDiameter / FBASE ; //f(Q20)
 
-       
-     bikespdPIin.slSpdRefPu = slBikeSpdRefPu; // Q20
-     bikespdPIin.slSpdFdkPu = bikespeed_stFreGetOut.uwLPFFrequencyPu ;  //Q20
+    slBikeSpdRefPu = swBikeSpeedKmh * 1000 * 29127 / ass_ParaCong.uwWheelDiameter / FBASE ; //f(Q20)
      
-     bikespdPIin.swbikespdMax= USER_MOTOR_5500RPM2PU  ;  //    Q15
-     bikespdPIin.swbikespdMin= - USER_MOTOR_5500RPM2PU ;
-
-     BikeSpdPI(&bikespdPIin, &bikeSpdPIOut);
+    bikespeed_stPIIn.slSpdRefPu = slBikeSpdRefPu; // Q20
+    bikespeed_stPIIn.slSpdFdkPu = bikespeed_stFreGetOut.uwLPFFrequencyPu ;  //Q20
+    bikespeed_stPIIn.swbikespdMax= USER_MOTOR_5500RPM2PU  ;  //    Q15
+    bikespeed_stPIIn.swbikespdMin= - USER_MOTOR_5500RPM2PU ;
 }
 
-void BikeSpdPI(BikeSpdPI_IN *in, MOTORSPEED_OUT *out)
+void bikespeed_voPI(BIKESPDPI_IN *in, BIKESPDPI_OUT *out)
 {
       SLONG  slbikespeederr; 
       SLONG  slDeltaErr;
@@ -413,33 +415,33 @@ void BikeSpdPI(BikeSpdPI_IN *in, MOTORSPEED_OUT *out)
       }
   
     //kp output
-    motorspeedrefp = (SQWORD)slDeltaErr * bikespeedcof.uwKpPu >> 5 ; //Q30
+    motorspeedrefp = (SQWORD)slDeltaErr * bikespeed_stPICof.uwKpPu >> 5 ; //Q30
    
     /* Calculate the integral output */
-    motorspeedrefi = (SQWORD)slbikespeederr * bikespeedcof.uwKiPu >> 5 ; //Q30
+    motorspeedrefi = (SQWORD)slbikespeederr * bikespeed_stPICof.uwKiPu >> 5 ; //Q30
     
     /* Calculate the Controller output */
-    motorspeedref = motorspeedrefp + motorspeedrefi + out->slmotorspeedref ; //Q30
+    motorspeedref = motorspeedrefp + motorspeedrefi + out->slMotorspeedref ; //Q30
     /* motorspeed output limit */
     if (motorspeedref > slmotorspdMax)
     {
-        out->slmotorspeedref = slmotorspdMax;
+        out->slMotorspeedref = slmotorspdMax;
     }
     else if (motorspeedref < slmotorspdMin)
     {
-        out->slmotorspeedref = slmotorspdMin;
+        out->slMotorspeedref = slmotorspdMin;
     }
     else
     {
-        out->slmotorspeedref = motorspeedref;
+        out->slMotorspeedref = motorspeedref;
     }
     
     if( (in->slSpdRefPu == 0) && ( in->slSpdFdkPu == 0))
     {
-      out->slmotorspeedref = 0 ;
+      out->slMotorspeedref = 0 ;
     }
   
-    out->swMotorSpeedRef = out->slmotorspeedref >> 15 ; // motorspeedrmp,Q15
+    out->swMotorSpeedRef = out->slMotorspeedref >> 15 ; // motorspeedrmp,Q15
        
     out->slErrorZ1 = slbikespeederr ;
     
@@ -448,16 +450,6 @@ void BikeSpdPI(BikeSpdPI_IN *in, MOTORSPEED_OUT *out)
     
    
 }
-
-void bikeSpdPIOutInit(void)
-{
-    bikeSpdPIOut.slErrorZ1 = 0;
-    bikeSpdPIOut.slmotorspeedref = 0;
-    bikeSpdPIOut.swMotorSpeedRef = 0;
-    bikeSpdPIOut.swSpdRefRpm = 0 ;
-    
-}
-
 /*************************************************************************
  Local Functions (N/A)
 *************************************************************************/

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

@@ -500,7 +500,6 @@ void Can_voMC_Run_5ms(void)
         20; //    1048 = Q20(1/1000)    0.1 km/h
     MC_RunInfo.BusVoltage = ((SLONG)adc_stUpOut.uwVdcPu * cof_uwUbVt >> 14) * 100;
     MC_RunInfo.MotorSpeed = (SLONG)scm_uwSpdFbkLpfAbsPu * cof_uwVbRpm >> 15;
- //   MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH; //cp_stBikeRunInfoPara.BikeSpeedKmH; // MC_RunInfo.MotorSpeed / 10 ;
     MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH;//MC_RunInfo.MotorSpeed / 10;
 }
 
@@ -511,7 +510,7 @@ void Can_voMC_Run_200ms(void)
     SizeMCUP = sizeof(MC_UpcInfo.stAssistInfo);
     if (MC_BC_COM == 0)
     {
-        MC_RunInfoToCDL.Torque = ((ULONG)maf_torque.value * TORQUEBASE / 10) >> 14;           // 0.1 Nm
+        MC_RunInfoToCDL.Torque = ((ULONG)ass_stTorqMafValue.value * TORQUEBASE / 10) >> 14;           // 0.1 Nm
         MC_RunInfoToCDL.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir; // 踩踏方向 0-正,1-反,2-停止,
         MC_RunInfoToCDL.Cadence = (cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwVbRpm) >> 20; // rpm
         MC_RunInfoToCDL.GearSt = MC_ControlCode.GearSt;

+ 5 - 0
User project/3.BasicFunction/Source/flash_master.c

@@ -116,4 +116,9 @@ void flash_voErrorRead(void)
 {
     UWORD count_len = sizeof(FLASH_ERROR_QUEUE) / 2;
     FLASH_voReadMoreData(StartServerManageErrorFlashAddress, (UWORD *)(&stFlashErrorLog), count_len);
+    
+    if(stFlashErrorLog.ubHead == 0xFF)
+    {
+       que_voInit(&stFlashErrorLog);
+    }   
 }

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

@@ -94,7 +94,6 @@ POLY_COEF TorqSencitiveCoef = TORQUESENSITIVE_COF_DEFAULT;
 ****************************************************************/
 void torsensor_voTorSensorCof(void)
 {
-
     ULONG ulLpfTm = 0;
     UWORD i = 0;
       

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

@@ -61,6 +61,7 @@ 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 void que_voInit(FLASH_ERROR_QUEUE *Q);
 #endif
 
 /*************************************************************************

+ 0 - 6
WLMCP.ewp

@@ -2502,9 +2502,6 @@
                 <file>
                     <name>$PROJ_DIR$\User project\2.MotorDrive\Include\dbc.h</name>
                 </file>
-                <file>
-                    <name>$PROJ_DIR$\User project\2.MotorDrive\Include\fluxweaken.h</name>
-                </file>
                 <file>
                     <name>$PROJ_DIR$\User project\2.MotorDrive\Include\flxwkn.h</name>
                 </file>
@@ -2570,9 +2567,6 @@
                     <file>
                         <name>$PROJ_DIR$\User project\2.MotorDrive\Source\packed\dbc.c</name>
                     </file>
-                    <file>
-                        <name>$PROJ_DIR$\User project\2.MotorDrive\Source\packed\fluxweaken.c</name>
-                    </file>
                     <file>
                         <name>$PROJ_DIR$\User project\2.MotorDrive\Source\packed\flxwkn.c</name>
                     </file>

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio