canAppl.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /**
  2. * @file canAppl.c
  3. * @author Zhang, Kai(zhangkai71@midea.com)
  4. * @brief
  5. * @version 0.1
  6. * @date 2022-03-02
  7. *
  8. * @copyright Copyright (c) 2022
  9. *
  10. */
  11. #include "canAppl.h"
  12. #include "CodePara.h"
  13. #include "FuncLayerAPI.h"
  14. #include "adc.h"
  15. #include "alarm.h"
  16. #include "usart.h"
  17. #include "can.h"
  18. #include "flash_master.h"
  19. #include "glbcof.h"
  20. #include "spdctrmode.h"
  21. #include "string.h"
  22. #include "syspar.h"
  23. #include "AssistCurve.h"
  24. #include "hwsetup.h"
  25. #include "spi_master.h"
  26. //#include "fp.def"
  27. #include "CadAssist.h"
  28. #include "bikeinformation.h"
  29. #include "FSM_1st.h"
  30. #include "FSM_2nd.h"
  31. /******************************
  32. *
  33. * Parameter
  34. *
  35. ******************************/
  36. typedef _Bool BOOL;
  37. MC_RunInfo_Struct_t MC_RunInfo;
  38. MC_ErrorCode_Struct_t MC_ErrorCode = CAN_MC_ALARMCODE_DEFAULT;
  39. MC_ErrorCode_CNT_RECORD_Struct_t MC_ErrorCntRecord = CAN_MC_ALARMCODE_CNT_RECORD_DEFAULT;
  40. MC_VerInfo_Struct_t MC_VerInfo;
  41. char Firmware_Special[32];
  42. MC_MacInfo_Struct_t MC_MacInfo;
  43. MC_RideLog_Struct_t MC_RideLog;
  44. BMS_RunInfo_Struct_t BMS_RunInfo;
  45. MC_ControlCode_Struct_t MC_ControlCode;
  46. MC_RunInfoToCDL_Struct_t MC_RunInfoToCDL;
  47. MC_RS_ASCII_Struct_t MC_RsASSCII;
  48. MC_UpperPCInfo_Struct_t MC_UpcInfo;
  49. BMS_VoltEstimat_Struct_t BMS_VoltEstimat;
  50. MC_Error_Address_Struct ManageError_Address;
  51. OBC_SetCustomPara_Struct_t OBC_SetCustomPara;
  52. OBC_ButtonStatus_Struct_t OBC_ButtonStatus = {0,0,0,FALSE};
  53. ULONG ulOBC_ComTimeOutCount = 0;
  54. ULONG ulBMS_ComTimeOutCount = 0;
  55. uint8_t MC_MotorSPD_rpm_Percent = 0;
  56. uint8_t MC_WorkMode;
  57. uint8_t MC_BC_COM = 1;
  58. LPF_OUT BMS_swCurIdcLpf;
  59. BOOL blBMSCommFault = FALSE;
  60. static UWORD uwRemainDistanceCal;
  61. void Can_voUpdateMC_UpcInfo(void)
  62. {
  63. MC_UpcInfo.stMotorInfo.uwPolePairs = cp_stMotorPara.swMotrPolePairs;
  64. MC_UpcInfo.stMotorInfo.uwRsmOhm = cp_stMotorPara.swRsOhm;
  65. MC_UpcInfo.stMotorInfo.uwLduH = cp_stMotorPara.uwLdmH;
  66. MC_UpcInfo.stMotorInfo.uwLquH = cp_stMotorPara.uwLqmH;
  67. MC_UpcInfo.stMotorInfo.uwFluxmWb = cp_stMotorPara.swFluxWb;
  68. MC_UpcInfo.stMotorInfo.uwIdMaxA = cp_stMotorPara.swIdMaxA;
  69. MC_UpcInfo.stMotorInfo.uwIdMinA = cp_stMotorPara.swIdMinA;
  70. MC_UpcInfo.stMotorInfo.uwRSpdRpm = cp_stMotorPara.swRSpeedRpm;
  71. MC_UpcInfo.stMotorInfo.uwRPwrWt = cp_stMotorPara.swRPwrWt;
  72. MC_UpcInfo.stMotorInfo.uwRCurA = cp_stMotorPara.swRIarmsA;
  73. MC_UpcInfo.stMotorInfo.uwRVolV = cp_stMotorPara.swRUdcV;
  74. MC_UpcInfo.stMotorInfo.uwJD = cp_stMotorPara.swJD;
  75. MC_UpcInfo.stMotorInfo.uwTorMaxNm = cp_stMotorPara.swTorMax;
  76. MC_UpcInfo.stBikeInfo.uwWheelPerimeter = ass_ParaCong.uwWheelPerimeter;
  77. MC_UpcInfo.stBikeInfo.uwMechRationMotor = ass_ParaCong.uwMechRationMotorEEPROM;//(UWORD)(((ULONG)ass_ParaCong.uwMechRationMotor*1000)/1024);
  78. MC_UpcInfo.stBikeInfo.uwThrottleMaxSpdKmH = ass_ParaCong.uwThrottleMaxSpdKmH;
  79. MC_UpcInfo.stBikeInfo.uwCartSpdKmH = ass_ParaCong.uwCartSpdKmH;
  80. MC_UpcInfo.stBikeInfo.uwNmFrontChainring = ass_ParaCong.uwNmFrontChainring;
  81. MC_UpcInfo.stBikeInfo.uwNmBackChainring = ass_ParaCong.uwNmBackChainring;
  82. MC_UpcInfo.stBikeInfo.uwAssistSelect1 = ass_ParaCong.uwAssistSelect1;
  83. MC_UpcInfo.stBikeInfo.uwAssistSelect2 = ass_ParaCong.uwAssistSelect2;
  84. MC_UpcInfo.stBikeInfo.uwLightConfig = ass_ParaCong.uwLightConfig;
  85. MC_UpcInfo.stBikeInfo.swWheelSizeAdjust = ass_ParaCong.swDeltPerimeter;
  86. MC_UpcInfo.stBikeInfo.uwStartMode = ass_ParaCong.uwStartMode;
  87. MC_UpcInfo.stBikeInfo.uwAutoPowerOffTime = ass_ParaCong.uwAutoPowerOffTime;
  88. MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetOrigin =0;// spi_stResolverOut.swSpiThetaOffsetOrignPu;
  89. MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetNow = 0;//spi_stResolverOut.swSpiThetaOffsetPu;
  90. MC_UpcInfo.stMContorlInfo.uwIPeakMaxA = cp_stMotorPara.swIpeakMaxA;
  91. MC_UpcInfo.stMContorlInfo.uwAlamOCurA = cp_stControlPara.swAlmOverCurrentVal;
  92. MC_UpcInfo.stMContorlInfo.uwAlamOVolV = cp_stControlPara.swAlmOverVolVal1;
  93. MC_UpcInfo.stMContorlInfo.uwAlamUVolV = cp_stControlPara.swAlmUnderVolVal1;
  94. MC_UpcInfo.stMContorlInfo.uwAlamOverSpdRpm = cp_stControlPara.swAlmOverSpdVal;
  95. MC_UpcInfo.stMContorlInfo.uwAlamOverHeatCe = cp_stControlPara.swAlmOverHeatCeVal;
  96. MC_UpcInfo.stMContorlInfo.uwAlamRecHeatCe = cp_stControlPara.swAlmRecOHeatVal;
  97. MC_UpcInfo.stMContorlInfo.uwPwrLimitStartCe = cp_stControlPara.swAlmPwrLimitStartTempVal;
  98. MC_UpcInfo.stMContorlInfo.uwAlamMotorOverHeatCe = cp_stControlPara.swAlmMotorOverHeatCeVal;
  99. MC_UpcInfo.stMContorlInfo.uwAlamMotorRecHeatCe = cp_stControlPara.swAlmMotorRecOHeatVal;
  100. MC_UpcInfo.stMContorlInfo.uwPwrLimitMotorStartCe = cp_stControlPara.swAlmPwrLimitMotorStartTempVal;
  101. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetOrigin = torsensor_stTorSensorCof.uwTorqueOffsetOrign;
  102. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow1 = torsensor_stTorSensorCof.uwTorqueOffsetNow1;
  103. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow2 = torsensor_stTorSensorCof.uwTorqueOffsetNow2;
  104. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow3 = torsensor_stTorSensorCof.uwTorqueOffsetNow3;
  105. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow4 = torsensor_stTorSensorCof.uwTorqueOffsetNow4;
  106. MC_UpcInfo.stSensorInfo.uwBikeTorMaxNm = torsensor_stTorSensorCof.uwMaxSensorTorquePu;
  107. MC_UpcInfo.stSensorInfo.uwBikeTor1StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep1RealNm;
  108. MC_UpcInfo.stSensorInfo.uwBikeTor1StepADC = torsensor_stTorSensorCof.uwBikeTorStep1ADC;
  109. MC_UpcInfo.stSensorInfo.uwBikeTor2StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep2RealNm;
  110. MC_UpcInfo.stSensorInfo.uwBikeTor2StepADC = torsensor_stTorSensorCof.uwBikeTorStep2ADC;
  111. MC_UpcInfo.stSensorInfo.uwBikeTor3StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep3RealNm;
  112. MC_UpcInfo.stSensorInfo.uwBikeTor3StepADC = torsensor_stTorSensorCof.uwBikeTorStep3ADC;
  113. MC_UpcInfo.stSensorInfo.uwBikeTor4StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep4RealNm;
  114. MC_UpcInfo.stSensorInfo.uwBikeTor4StepADC = torsensor_stTorSensorCof.uwBikeTorStep4ADC;
  115. MC_UpcInfo.stSensorInfo.uwTorque_SensorPulseNm = cadence_stFreGetCof.uwTorque_NumbersPulses;
  116. MC_UpcInfo.stSensorInfo.uwBikeSpdSensorPulseNm = bikespeed_stFreGetCof.uwNumbersPulses;
  117. MC_UpcInfo.stSensorInfo.uwCad_SensorPulseNm= cadence_stFreGetCof.uwCad_NumbersPulses;
  118. MC_UpcInfo.stAssistInfo.swStartupGain = ass_ParaSet.uwStartupCoef;
  119. MC_UpcInfo.stAssistInfo.swStartcruiseGain = ass_ParaSet.uwStartupCruiseCoef;
  120. MC_UpcInfo.stAssistInfo.uwAssistStartNm = ass_ParaSet.uwAssistStartNm;
  121. MC_UpcInfo.stAssistInfo.uwAssistStopNm = ass_ParaSet.uwAssistStopNm;
  122. MC_UpcInfo.stAssistInfo.uwStartUpGainStep = ass_ParaSet.uwStartUpGainStep;
  123. MC_UpcInfo.stAssistInfo.uwStartUpCadNm = ass_ParaSet.uwStartUpCadNm;
  124. MC_UpcInfo.stAssistInfo.uwTorLPFCadNm = ass_ParaSet.uwTorLPFCadNm;
  125. MC_UpcInfo.stAssistInfo.uwSpeedAssistSpdRpm = ass_ParaSet.uwSpeedAssistSpdRpm;
  126. MC_UpcInfo.stAssistInfo.uwSpeedAssistIMaxA = ass_ParaSet.uwSpeedAssistIMaxA;
  127. MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStart = ass_ParaSet.uwAssistLimitBikeSpdStart;
  128. MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStop = ass_ParaSet.uwAssistLimitBikeSpdStop;
  129. MC_UpcInfo.stAssistInfo.uwCadenceAssistWeight = ass_ParaSet.uwCadenceWeight;
  130. MC_UpcInfo.stAssistInfo.uwCadAssPidKp = ass_stCadAssSpdCtl.uwPidKp;
  131. MC_UpcInfo.stAssistInfo.swCadAssPidLimMax = ass_stCadAssSpdCtl.swPidLimMax;
  132. MC_UpcInfo.stAssistInfo.swCadAssPidVolDec = ass_stCadAssSpdCtl.swPidVolDec;
  133. MC_UpcInfo.stAssistInfo.swCadAssTargetAssCurAcc = ass_stCadAssParaPro.swTargetAssCurAcc;
  134. MC_UpcInfo.stAssistInfo.uwMaxCadRpm = ass_stCadAssCoef.uwMaxCadRpm;
  135. MC_UpcInfo.stAssistInfo.reserve2 = ass_stReservePara.uwReserve2;
  136. MC_UpcInfo.stAssistInfo.reserve3 = ass_stReservePara.uwReserve3;
  137. MC_UpcInfo.stAssistInfo.reserve4 = ass_stReservePara.uwReserve4;
  138. MC_UpcInfo.stHistoryInfo.uwOpenTimes = cp_stHistoryPara.uwOpenTimes;
  139. MC_UpcInfo.stHistoryInfo.uwUsedTimeH = (UWORD)(cp_stHistoryPara.ulUsedTime >> 16);
  140. MC_UpcInfo.stHistoryInfo.uwUsedTimeL = (UWORD)(cp_stHistoryPara.ulUsedTime);
  141. MC_UpcInfo.stHistoryInfo.swNTCTempMaxCe = cp_stHistoryPara.swNTCTempMaxCe;
  142. MC_UpcInfo.stHistoryInfo.swNTCTempMinCe = cp_stHistoryPara.swNTCTempMinCe;
  143. ;
  144. MC_UpcInfo.stHistoryInfo.uwAlamHOcurTimes = cp_stHistoryPara.uwAlamHOcurTimes;
  145. MC_UpcInfo.stHistoryInfo.uwAlamSOcurTimes = cp_stHistoryPara.uwAlamSOcurTimes;
  146. MC_UpcInfo.stHistoryInfo.uwAlamOHeatTimes = cp_stHistoryPara.uwAlamOHeatTimes;
  147. MC_UpcInfo.stHistoryInfo.uwAlamRotorLockTimes = cp_stHistoryPara.uwAlamRotorLockTimes;
  148. MC_UpcInfo.stHistoryInfo.uwAlamPhsLossTimes = cp_stHistoryPara.uwAlamPhsLossTimes;
  149. MC_UpcInfo.stHistoryInfo.uwAlamOVolTimes = cp_stHistoryPara.uwAlamOVolTimes;
  150. MC_UpcInfo.stHistoryInfo.uwAlamUVolTimes = cp_stHistoryPara.uwAlamUVolTimes;
  151. MC_UpcInfo.stHistoryInfo.uwAlamComOTimeTimes = cp_stHistoryPara.uwAlamComOTimeTimes;
  152. MC_UpcInfo.stHistoryInfo.uwG1AvgPwrConsumption = cp_stHistoryPara.uwG1AvgPwrConsumption;
  153. MC_UpcInfo.stHistoryInfo.uwG2AvgPwrConsumption = cp_stHistoryPara.uwG2AvgPwrConsumption;
  154. MC_UpcInfo.stHistoryInfo.uwG3AvgPwrConsumption = cp_stHistoryPara.uwG3AvgPwrConsumption;
  155. MC_UpcInfo.stHistoryInfo.uwG4AvgPwrConsumption = cp_stHistoryPara.uwG4AvgPwrConsumption;
  156. MC_UpcInfo.stHistoryInfo.uwG5AvgPwrConsumption = cp_stHistoryPara.uwG5AvgPwrConsumption;
  157. MC_UpcInfo.stHistoryInfo.uwODOTripH = (UWORD)(cp_stHistoryPara.ulODOTrip >> 16);
  158. MC_UpcInfo.stHistoryInfo.uwODOTripL = (UWORD)cp_stHistoryPara.ulODOTrip;
  159. MC_UpcInfo.stHistoryInfo.uwODOTimeH = (UWORD)(cp_stHistoryPara.ulODOTime >> 16);
  160. MC_UpcInfo.stHistoryInfo.uwODOTimeL = (UWORD)cp_stHistoryPara.ulODOTime;
  161. MC_UpcInfo.stHistoryInfo.uwTripSumH = (UWORD)(cp_stHistoryPara.ulTripSum >> 16);
  162. MC_UpcInfo.stHistoryInfo.uwTripSumL = (UWORD)cp_stHistoryPara.ulTripSum;
  163. MC_UpcInfo.stHistoryInfo.uwTripSumTimeH = (UWORD)(cp_stHistoryPara.ulTripSumTime >> 16);
  164. MC_UpcInfo.stHistoryInfo.uwTripSumTimeL = (UWORD)cp_stHistoryPara.ulTripSumTime;
  165. MC_UpcInfo.stHistoryInfo.uwTorSensorAlamTimes = cp_stHistoryPara.uwTorSensorAlamTimes;
  166. MC_UpcInfo.stHistoryInfo.uwCadSensorAlamTimes = cp_stHistoryPara.uwCadSensorAlamTimes;
  167. MC_UpcInfo.stHistoryInfo.uwBikeSpdSensorAlamTimes = cp_stHistoryPara.uwBikeSpdSensorAlamTimes;
  168. MC_UpcInfo.stHistoryInfo.uwPosSensorAlamTimes = cp_stHistoryPara.uwPosSensorAlamTimes;
  169. MC_UpcInfo.stTestParaInfo.uwEEFirstDefaultSetFlg = cp_stFlg.ParaFirstSetFlg;
  170. // MC_UpcInfo.stTestParaInfo.uwSPIOffsetFirstSetFlg = cp_stFlg.SpiOffsetFirstSetFlg;
  171. MC_UpcInfo.stTestParaInfo.RunModelSelect = cp_stFlg.RunModelSelect;
  172. MC_UpcInfo.stTestParaInfo.ThetaGetModelSelect = cp_stFlg.ThetaGetModelSelect;
  173. MC_UpcInfo.stTestParaInfo.CurrentSampleModelSelect = cp_stFlg.CurrentSampleModelSelect;
  174. MC_UpcInfo.stTestParaInfo.RotateDirectionSelect = cp_stFlg.RotateDirectionSelect;
  175. MC_UpcInfo.stTestParaInfo.uwInitPosCurAmp = cp_stControlPara.swAlignCurAp;
  176. MC_UpcInfo.stTestParaInfo.uwVFControlVolAmp = cp_stControlPara.swDragVolAp;
  177. MC_UpcInfo.stTestParaInfo.uwIFControlCurAmp = cp_stControlPara.swDragCurAp;
  178. MC_UpcInfo.stTestParaInfo.uwVFIFTargetFreHz = cp_stControlPara.swDragSpdHz;
  179. MC_UpcInfo.stTestParaInfo.uwSpeedLoopAccRate = 500;
  180. MC_UpcInfo.stTestParaInfo.uwSpeedLoopDecRate = 100;
  181. MC_UpcInfo.stTestParaInfo.uwSpeedLoopBandWidthHz = cp_stControlPara.swAsrPIBandwidth;
  182. MC_UpcInfo.stTestParaInfo.uwSpeedLoopCoefM = cp_stControlPara.swAsrPIM;
  183. MC_UpcInfo.stTestParaInfo.uwCuerrentLoopBandWidthHz = cp_stControlPara.swAcrPIBandwidth;
  184. MC_UpcInfo.stTestParaInfo.uwCurrentLoopCoefM = cp_stControlPara.swAcrRaCoef;
  185. MC_UpcInfo.stTestParaInfo.uwFluxObsBandWidthHz = cp_stControlPara.swObsFluxPICrossfreHz;
  186. MC_UpcInfo.stTestParaInfo.uwFluxObsCoefM = cp_stControlPara.swObsFluxPIDampratio;
  187. MC_UpcInfo.stTestParaInfo.uwThetaObsPLLBandWidthHz = cp_stControlPara.swObsSpdPLLBandWidthHz;
  188. MC_UpcInfo.stTestParaInfo.uwThetaObsPLLCoefM = cp_stControlPara.swObsSpdPLLM;
  189. MC_UpcInfo.stTestParaInfo.uwJm = cp_stMotorPara.swJD ;
  190. MC_UpcInfo.stTestParaInfo.uwPWMMaxDuty = cp_stControlPara.swPWMMaxDuty;
  191. MC_UpcInfo.stTestParaInfo.uwPWM7to5Duty = cp_stControlPara.swPWM7to5Duty;
  192. MC_UpcInfo.stTestParaInfo.uwPwrLimit = cp_stControlPara.swPwrLimitValWt;
  193. MC_UpcInfo.stTestParaInfo.uwPwrLimitError = cp_stControlPara.swPwrLimitErrWt;
  194. MC_UpcInfo.stTestParaInfo.uwPwrLimitKp = cp_stControlPara.swPwrLimitKpPu;
  195. MC_UpcInfo.stTestParaInfo.uwPwrLimitKi = cp_stControlPara.swPwrLimitKiPu;
  196. OBC_SetCustomPara.uwWheelPerimeter = ass_ParaCong.uwWheelPerimeter + ass_ParaCong.swDeltPerimeter;
  197. OBC_SetCustomPara.StartUpMod = 1;
  198. OBC_SetCustomPara.BikeSpeedLimit = ass_ParaSet.uwAssistLimitBikeSpdStart;
  199. OBC_SetCustomPara.DeltPerimeter = ass_ParaCong.swDeltPerimeter;
  200. OBC_SetCustomPara.AssistMod = ass_ParaSet.uwAsssistSelectNum;
  201. OBC_SetCustomPara.AutoPowerOffTime = ass_ParaCong.uwAutoPowerOffTime;
  202. }
  203. UWORD SizeMCUP;
  204. void Can_voInitMC_Run(void)
  205. {
  206. // flash_voVerRead();
  207. // flash_voErrorRead();
  208. // MC版本信息初始化,Mode和SN从EEPROM读取
  209. strncpy(MC_VerInfo.HW_Version, (char *)"88K7000101V1 ", 16); //长度不超过16
  210. // Software version
  211. char chFwVersion[16]="V1r0r0_";
  212. // strncat(chFwVersion,COMPLIE_TIME,9); // Commit time COMPLIE_TIME
  213. // strncat(chFwVersion,(char *)"20250103 08:55:00",9);
  214. strncpy(MC_VerInfo.FW_Version, (char *)chFwVersion, 16);
  215. // Firmware Special Info
  216. char chFrimware[32]="NC2025X000-MS0000-V0r0. ";
  217. // strncat(chFrimware,FINGER_PRINT,8); // Git Version
  218. // strncat(chFrimware,(char *)"12345678",8); // Git Version
  219. if(cp_stFlg.RunModelSelect == CadAssist)
  220. {
  221. strncat(chFrimware,"C",1); // Cadance assist end with "C" Torque assist end with "T"
  222. }
  223. else if(cp_stFlg.RunModelSelect == TorqAssist)
  224. {
  225. strncat(chFrimware,"T",1); // Torque Assist end with "T", Cadence Assist end with "C"
  226. }
  227. else
  228. {
  229. /* 不做处理*/
  230. }
  231. strncpy(Firmware_Special, (char *)chFrimware, 32);
  232. //电机型号
  233. // memcpy(MC_VerInfo.Mode, Syspara2.flash_stPara.ubMotorVersion, sizeof(Syspara2.flash_stPara.ubMotorVersion));
  234. // memcpy(MC_VerInfo.SN_Num, Syspara2.flash_stPara.ubSN, sizeof(Syspara2.flash_stPara.ubSN));
  235. memcpy(MC_VerInfo.Mode, Productionpara.ubMotorVersion, sizeof(Productionpara.ubMotorVersion));
  236. memcpy(MC_VerInfo.SN_Num, Productionpara.ubSN, sizeof(Productionpara.ubSN));
  237. // MC生产信息
  238. memcpy(MC_MacInfo.Manufacturer, Productionpara.ubProdInfo.Manufacturer, sizeof(Productionpara.ubProdInfo));
  239. //自定义字符串
  240. memcpy(MC_RsASSCII.CustomASCII1, Syspara2.flash_stPara.ubRsASSCII.CustomASCII1, sizeof(MC_RsASSCII.CustomASCII1));
  241. memcpy(MC_RsASSCII.CustomASCII2, Syspara2.flash_stPara.ubRsASSCII.CustomASCII2, sizeof(MC_RsASSCII.CustomASCII2));
  242. memcpy(MC_RsASSCII.CustomASCII3, Syspara2.flash_stPara.ubRsASSCII.CustomASCII3, sizeof(MC_RsASSCII.CustomASCII3));
  243. //控制参数
  244. memcpy(&MC_UpcInfo.stTestParaInfo.uwTestParaSaveFlg, &Syspara2.flash_stPara.stTestParaInfo.uwTestParaSaveFlg, sizeof(MC_UpcInfo.stTestParaInfo));
  245. BMS_VoltEstimat.uwInterResistpu = ((ULONG)1700 << 15) / cof_uwRbOm; //Q15 0.1mOhm BMS internal resistance 150mOhm + 20mOhm
  246. mth_voLPFilterCoef(1000000 / 100, EVENT_1MS_HZ, &BMS_swCurIdcLpf.uwKx); //100Hz
  247. uwRemainDistanceCal = 0xffff; // init invalid value
  248. }
  249. void Can_voMC_Run_1ms(void)
  250. {
  251. static UWORD time_s=0;
  252. if (cp_stBikeRunInfoPara.BikeSpeedKmH > 30)
  253. {
  254. cp_stBikeRunInfoPara.ulRiTime++;
  255. }
  256. else
  257. {}
  258. if(++time_s>60000)
  259. {
  260. cp_stHistoryPara.ulUsedTime++;
  261. time_s=0;
  262. }
  263. // Error Cnt record and Error Display Set
  264. MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms ++;
  265. UART_RxBuff_Struct_OBC.ul_UartComTimeOutCount++;
  266. UART_RxBuff_Struct_BMS.ul_UartComTimeOutCount++;
  267. if(MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms == ALAM_DETECT_CNT_IN_1ms && MC_ErrorCode.Code == 0)
  268. {
  269. MC_ErrorCntRecord.Protect_OverCurrentCnt = 0;
  270. MC_ErrorCntRecord.Protect_OverVoltageCnt = 0;
  271. MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0;
  272. MC_ErrorCntRecord.Protect_LockRotorCnt = 0;
  273. MC_ErrorCntRecord.Protect_OverTempCnt = 0;
  274. MC_ErrorCntRecord.Fault_PhaseLineCnt = 0;
  275. MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms = 0;
  276. }
  277. else
  278. {}
  279. //故障日志获取故障状态
  280. if (alm_blAlmOccrFlg == TRUE)
  281. {
  282. if (alm_blAlmSingleRecordDoneFlg == FALSE)//
  283. {
  284. if (alm_unCode.bit.IPMFlt == 1) //硬件过流
  285. {
  286. MC_ErrorCntRecord.Protect_OverCurrentCnt++;
  287. cp_stHistoryPara.uwAlamHOcurTimes++;
  288. if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  289. {
  290. if(MC_ErrorCode.ERROR_Bit.Protect_OverCurrent==0)
  291. {
  292. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1;
  293. /*error log updata*/
  294. ErrorLog_Updata();
  295. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  296. }
  297. }
  298. }
  299. if (alm_unCode.bit.OvrCur == 1) //软件过流
  300. {
  301. MC_ErrorCntRecord.Protect_OverCurrentCnt++;
  302. cp_stHistoryPara.uwAlamSOcurTimes++;
  303. if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  304. {
  305. if(MC_ErrorCode.ERROR_Bit.Protect_OverCurrent==0)
  306. {
  307. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1;
  308. /*error log updata*/
  309. ErrorLog_Updata();
  310. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  311. }
  312. }
  313. }
  314. if (alm_unCode.bit.OvrVlt == 1) //过压
  315. {
  316. MC_ErrorCntRecord.Protect_OverVoltageCnt++;
  317. cp_stHistoryPara.uwAlamOVolTimes++;
  318. if (MC_ErrorCntRecord.Protect_OverVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  319. {
  320. if(MC_ErrorCode.ERROR_Bit.Protect_OverVoltage==0)
  321. {
  322. MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 1;
  323. /*error log updata*/
  324. ErrorLog_Updata();
  325. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  326. }
  327. }
  328. }
  329. if (alm_unCode.bit.UndrVlt == 1) //欠压
  330. {
  331. MC_ErrorCntRecord.Protect_UnderVoltageCnt++;
  332. cp_stHistoryPara.uwAlamUVolTimes++;
  333. if (MC_ErrorCntRecord.Protect_UnderVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  334. {
  335. if(MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage==0)
  336. {
  337. MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 1;
  338. /*error log updata*/
  339. ErrorLog_Updata();
  340. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  341. }
  342. }
  343. }
  344. if (alm_unCode.bit.RotorLock == 1) //堵转
  345. {
  346. MC_ErrorCntRecord.Protect_LockRotorCnt++;
  347. cp_stHistoryPara.uwAlamRotorLockTimes++;
  348. if (MC_ErrorCntRecord.Protect_LockRotorCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  349. {
  350. if(MC_ErrorCode.ERROR_Bit.Protect_LockRotor==0)
  351. {
  352. MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 1;
  353. /*error log updata*/
  354. ErrorLog_Updata();
  355. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  356. }
  357. }
  358. }
  359. if (alm_unCode.bit.IPMOvrHeat == 1)//PCB过热
  360. {
  361. MC_ErrorCntRecord.Protect_OverTempCnt++;
  362. cp_stHistoryPara.uwAlamOHeatTimes++;
  363. if (MC_ErrorCntRecord.Protect_OverTempCnt == ALAM_DISPLAY_CNT_0LEVEL)
  364. {
  365. if(MC_ErrorCode.ERROR_Bit.Protect_OverTemp==0)
  366. {
  367. MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 1;
  368. /*error log updata*/
  369. ErrorLog_Updata();
  370. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  371. }
  372. }
  373. }
  374. if (alm_unCode.bit.PhsLoss == 1) //缺相
  375. {
  376. MC_ErrorCntRecord.Fault_PhaseLineCnt++;
  377. cp_stHistoryPara.uwAlamPhsLossTimes++;
  378. if (MC_ErrorCntRecord.Fault_PhaseLineCnt == ALAM_DISPLAY_CNT_0LEVEL)
  379. {
  380. if(MC_ErrorCode.ERROR_Bit.Fault_PhaseLine==0)
  381. {
  382. MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 1;
  383. /*error log updata*/
  384. ErrorLog_Updata();
  385. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  386. }
  387. }
  388. }
  389. // if(alm_unCode.bit.CommOvrTm)
  390. // {
  391. // cp_stHistoryPara.uwAlamComOTimeTimes++;
  392. // }
  393. // if (alm_unCode.bit.SpiThetaFlt == 1) //位置传感器故障
  394. // {
  395. // MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 1;
  396. // /*error log updata*/
  397. // ErrorLog_Updata();
  398. // que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  399. // }
  400. if (alm_unBikeCode.bit.BikeSpdSen == 1) //速度传感器故障
  401. {
  402. if(MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor==0)
  403. {
  404. MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 1;
  405. cp_stHistoryPara.uwBikeSpdSensorAlamTimes++;
  406. /*error log updata*/
  407. ErrorLog_Updata();
  408. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  409. }
  410. }
  411. if (alm_unBikeCode.bit.CadenceSen == 1) //踏频传感器故障
  412. {
  413. cp_stHistoryPara.uwCadSensorAlamTimes++;
  414. if(MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor==0)
  415. {
  416. MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 1;
  417. /*error log updata*/
  418. ErrorLog_Updata();
  419. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  420. }
  421. }
  422. if (alm_unBikeCode.bit.PCBNTC == 1) //PCB温度
  423. {
  424. if(MC_ErrorCode.ERROR_Bit.Fault_PCBNTC==0)
  425. {
  426. MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 1;
  427. /*error log updata*/
  428. ErrorLog_Updata();
  429. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  430. }
  431. }
  432. // if (alm_unBikeCode.bit.Throttle == 1) //油门故障
  433. // {
  434. // MC_ErrorCode.ERROR_Bit.Fault_Throttle = 1;
  435. // /*error log updata*/
  436. // ErrorLog_Updata();
  437. // que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  438. // }
  439. if (alm_unBikeCode.bit.TorqSen == 1) //力矩传感器故障
  440. {
  441. if(MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor==0)
  442. {
  443. MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 1;
  444. /*error log updata*/
  445. cp_stHistoryPara.uwTorSensorAlamTimes++;
  446. ErrorLog_Updata();
  447. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  448. }
  449. }
  450. // 电机霍尔故障
  451. if (alm_unCode.bit.HallLoss == 1)
  452. {
  453. MC_ErrorCntRecord.Fault_HallSensorCnt++;
  454. if (MC_ErrorCntRecord.Fault_HallSensorCnt >= ALAM_DISPLAY_CNT_0LEVEL)
  455. {
  456. MC_ErrorCntRecord.Fault_HallSensorCnt = ALAM_DISPLAY_CNT_0LEVEL+1;
  457. if(MC_ErrorCode.ERROR_Bit.Fault_HallSensor == 0)
  458. {
  459. cp_stHistoryPara.uwPosSensorAlamTimes++;
  460. MC_ErrorCode.ERROR_Bit.Fault_HallSensor = 1;
  461. /*error log updata*/
  462. ErrorLog_Updata();
  463. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  464. }
  465. }
  466. }
  467. //电机温度过热
  468. if (alm_unCode.bit.MotorOvrHeat == 1)
  469. {
  470. MC_ErrorCntRecord.Protect_MotorOverTempCnt++;
  471. if (MC_ErrorCntRecord.Protect_MotorOverTempCnt >= ALAM_DISPLAY_CNT_0LEVEL)
  472. {
  473. MC_ErrorCntRecord.Protect_MotorOverTempCnt = ALAM_DISPLAY_CNT_0LEVEL+1;
  474. if(MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp == 0)
  475. {
  476. cp_stHistoryPara.uwAlamOHeatTimes++;
  477. MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp = 1;
  478. /*error log updata*/
  479. ErrorLog_Updata();
  480. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  481. }
  482. }
  483. }
  484. alm_blAlmSingleRecordDoneFlg = TRUE;
  485. }
  486. }
  487. // Claear error Display
  488. if (MC_ErrorCode.ERROR_Bit.Protect_OverCurrent == 1)
  489. {
  490. if (alm_unCode.bit.IPMFlt != 1 && alm_unCode.bit.OvrCur != 1)
  491. {
  492. MC_ErrorCntRecord.Protect_OverCurrentCnt = 0;
  493. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 0;
  494. }
  495. }
  496. if (MC_ErrorCode.ERROR_Bit.Protect_OverVoltage == 1)
  497. {
  498. if (alm_unCode.bit.OvrVlt != 1)
  499. {
  500. MC_ErrorCntRecord.Protect_OverVoltageCnt = 0;
  501. MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 0;
  502. }
  503. }
  504. if (MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage == 1)
  505. {
  506. if (alm_unCode.bit.UndrVlt != 1)
  507. {
  508. MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0;
  509. MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 0;
  510. }
  511. }
  512. if (MC_ErrorCode.ERROR_Bit.Protect_LockRotor == 1)
  513. {
  514. if (alm_unCode.bit.RotorLock != 1)
  515. {
  516. MC_ErrorCntRecord.Protect_LockRotorCnt = 0;
  517. MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 0;
  518. }
  519. }
  520. if (MC_ErrorCode.ERROR_Bit.Protect_OverTemp == 1)
  521. {
  522. if (alm_unCode.bit.IPMOvrHeat != 1)
  523. {
  524. MC_ErrorCntRecord.Protect_OverTempCnt = 0;
  525. MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 0;
  526. }
  527. }
  528. if (MC_ErrorCode.ERROR_Bit.Fault_PhaseLine == 1)
  529. {
  530. if (alm_unCode.bit.PhsLoss != 1)
  531. {
  532. MC_ErrorCntRecord.Fault_PhaseLineCnt = 0;
  533. MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 0;
  534. }
  535. }
  536. // if (MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor == 1)
  537. // {
  538. // if (alm_unCode.bit.SpiThetaFlt != 1)
  539. // {
  540. // MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 0;
  541. // }
  542. // }
  543. if (MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor == 1)
  544. {
  545. if (alm_unBikeCode.bit.BikeSpdSen != 1)
  546. {
  547. MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 0;
  548. }
  549. }
  550. if (MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor == 1)
  551. {
  552. if (alm_unBikeCode.bit.CadenceSen != 1)
  553. {
  554. MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 0;
  555. }
  556. }
  557. if (MC_ErrorCode.ERROR_Bit.Fault_PCBNTC == 1)
  558. {
  559. if (alm_unBikeCode.bit.PCBNTC != 1)
  560. {
  561. MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 0;
  562. }
  563. }
  564. if (MC_ErrorCode.ERROR_Bit.Fault_Throttle == 1)
  565. {
  566. if (alm_unBikeCode.bit.Throttle != 1)
  567. {
  568. MC_ErrorCode.ERROR_Bit.Fault_Throttle = 0;
  569. }
  570. }
  571. if (MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor == 1)
  572. {
  573. if (alm_unBikeCode.bit.TorqSen != 1)
  574. {
  575. MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 0;
  576. }
  577. }
  578. if (MC_ErrorCode.ERROR_Bit.Fault_HallSensor == 1)
  579. {
  580. if (alm_unCode.bit.HallLoss != 1)
  581. {
  582. MC_ErrorCntRecord.Fault_HallSensorCnt = 0;
  583. MC_ErrorCode.ERROR_Bit.Fault_HallSensor = 0;
  584. }
  585. }
  586. if (MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp == 1)
  587. {
  588. if (alm_unCode.bit.MotorOvrHeat != 1)
  589. {
  590. MC_ErrorCntRecord.Protect_MotorOverTempCnt = 0;
  591. MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp = 0;
  592. }
  593. }
  594. SWORD TempPower;
  595. if (FSM2nd_Run_state.state == Exit)
  596. {
  597. TempPower = 0;
  598. }
  599. else
  600. {
  601. TempPower = scm_stMotoPwrInLpf.slY.sw.hi;
  602. }
  603. BMS_VoltEstimat.swIdcPu = (SWORD)(((SLONG)TempPower << 13) / (SLONG)adc_stUpOut.uwVdcLpfPu); // Q15+Q13-Q14=Q14 Calculated dc current
  604. if (BMS_VoltEstimat.swIdcPu < 0)
  605. {
  606. BMS_VoltEstimat.swIdcPu = 0;
  607. }
  608. mth_voLPFilter(BMS_VoltEstimat.swIdcPu, &BMS_swCurIdcLpf);
  609. BMS_VoltEstimat.uwVdcCompPu = (ULONG)BMS_swCurIdcLpf.slY.sw.hi * BMS_VoltEstimat.uwInterResistpu >> 15; //Q14+Q15-Q15=Q14
  610. }
  611. void Can_voMC_Run_5ms(void)
  612. {
  613. cp_stBikeRunInfoPara.BikeSpeedKmH =
  614. (((SQWORD)bikespeed_stFreGetOut.uwLPFFrequencyPu * FBASE * (ass_ParaCong.uwWheelPerimeter + ass_ParaCong.swDeltPerimeter) * 36 >> 20) * 1048 * 10) >>20; // 1048 = Q20(1/1000) 0.1 km/h
  615. MC_RunInfo.BusVoltage = ((SLONG)adc_stUpOut.uwVdcPu * cof_uwUbVt >> 14) * 100;
  616. MC_RunInfo.MotorSpeed = (SLONG)scm_uwSpdFbkLpfAbsPu * cof_uwVbRpm >> 15;
  617. MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH;//cp_stBikeRunInfoPara.BikeSpeedKmH; // MC_RunInfo.MotorSpeed / 10 ;
  618. }
  619. void Can_voMC_Run_200ms(void)
  620. {
  621. // UWORD TempPower;
  622. // 电池通讯异常采用控制器计算电量
  623. if((cp_ulSystickCnt - ulBMS_ComTimeOutCount) > 3000)
  624. {
  625. blBMSCommFault = TRUE; // communication abnormal
  626. }
  627. else
  628. {
  629. blBMSCommFault = FALSE; // communication normal
  630. }
  631. Can_MaxMinTempHistory();
  632. Can_GearSt_switch();
  633. SizeMCUP = sizeof(MC_UpcInfo.stAssistInfo);
  634. if (MC_BC_COM == 0)
  635. {
  636. MC_RunInfoToCDL.Torque = ((ULONG)maf_torque.value * TORQUEBASE / 10) >> 14; // 0.1 Nm
  637. MC_RunInfoToCDL.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir; // 踩踏方向 0-正,1-反,2-停止,
  638. MC_RunInfoToCDL.Cadence = (cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwVbRpm) >> 20; // rpm
  639. MC_RunInfoToCDL.GearSt = MC_ControlCode.GearSt;
  640. MC_RunInfoToCDL.T_PCB = adc_stUpOut.PCBTemp + 40;
  641. MC_RunInfoToCDL.T_Coil = adc_stUpOut.PCBTemp + 40;
  642. MC_RunInfoToCDL.BusVoltage = ((ULONG)adc_stUpOut.uwVdcLpfPu * cof_uwUbVt * 100) >> 14; // 1mV
  643. // MC_RunInfoToCDL.BusCurrent = (((ULONG)scm_stMotoPwrInLpf.slY.sw.hi << 13) / adc_stUpOut.uwVdcLpfPu * cof_uwIbAp * 100) >> 14; // 1mA
  644. MC_RunInfoToCDL.BusCurrent = ((ULONG)adc_stUpOut.uwIbusAvgLpfPu) * cof_uwIbAp * 10 >> 14; ///>母线电流 1mA,地址偏移8
  645. MC_RunInfoToCDL.MotorSpeed = (SLONG)scm_stSpdFbkLpf.slY.sw.hi * cof_uwVbRpm >> 15;
  646. // MC_RunInfoToCDL.BikeSpeed =
  647. // (((SQWORD)bikespeed_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * ass_ParaCong.uwWheelPerimeter * 3216 * 36 >> 15) * 1050) >>
  648. // 35; // 600 0.1cm 3216 = Q10(3.1415926) 105 = Q20(1/10000) 0.1 km/h;
  649. //
  650. MC_RunInfoToCDL.BikeSpeed =
  651. (((SQWORD)bikespeed_stFreGetOut.uwLPFFrequencyPu * FBASE * ass_ParaCong.uwWheelPerimeter * 36 >> 20) * 1048 * 10) >> 20;
  652. // MC_RunInfoToCDL.BikeSpeed = MC_RunInfoToCDL.MotorSpeed /10;
  653. MC_RunInfoToCDL.IqCurrent = ((SLONG)scm_swIqRefPu * cof_uwIbAp * 100) >> 14;
  654. MC_RunInfoToCDL.AlarmCode = MC_ErrorCode.Code && 0x00FF;
  655. //SendData(ID_MC_TO_CDL, MODE_REPORT, 0xF112, (uint8_t *)&MC_RunInfoToCDL.Torque);
  656. }
  657. MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH; ///>车速 0.1km/h,地址偏移0
  658. if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  659. {
  660. MC_RunInfo.MotorSpeed = (SLONG)abs(switchhall_stOut.swLowSpdLpfPu) * cof_uwVbRpm >> 15; ///>输出转速 1rpm,地址偏移2 if(scm_swMotorPwrInLpfWt > 5000)
  661. }
  662. else
  663. {
  664. MC_RunInfo.MotorSpeed = (SLONG)abs(scm_stSpdFbkLpf.slY.sw.hi)* cof_uwVbRpm >> 15;
  665. }
  666. if(scm_swMotorPwrInLpfWt > 5000)
  667. {
  668. scm_swMotorPwrInLpfWt = 5000;
  669. }
  670. if(scm_swMotorPwrInLpfWt < 0 )
  671. {
  672. scm_swMotorPwrInLpfWt = 0;
  673. }
  674. if(hw_blPWMOnFlg == FALSE)
  675. {
  676. scm_swMotorPwrInLpfWt = 0;
  677. }
  678. else
  679. {
  680. }
  681. MC_RunInfo.Power = scm_swMotorPwrInLpfWt / 10; ///>电功率 1W,地址偏移4
  682. MC_RunInfo.BusVoltage = ((ULONG)adc_stUpOut.uwVdcLpfPu * cof_uwUbVt * 100) >> 14; ///>母线电压 1mV,地址偏移6
  683. // MC_RunInfo.BusVoltage = ((ULONG)(adc_stUpOut.uwVdcLpfPu + BMS_VoltEstimat.uwVdcCompPu) * cof_uwUbVt * 100) >> 14; ///>母线电压 1mV,地址偏移6
  684. // if (scm_stMotoPwrInLpf.slY.sw.hi < 10)
  685. // {
  686. // TempPower = 0;
  687. // }
  688. // else
  689. // {
  690. // TempPower = scm_stMotoPwrInLpf.slY.sw.hi;
  691. // }
  692. // MC_RunInfo.BusCurrent = (((ULONG)TempPower << 13) / adc_stUpOut.uwVdcLpfPu) * cof_uwIbAp * 100 >> 14; ///>母线电流 1mA,地址偏移8
  693. MC_RunInfo.BusCurrent = ((ULONG)adc_stUpOut.uwIbusAvgLpfPu) * cof_uwIbAp * 10 >> 14; ///14 >母线电流 1mA,地址偏移8
  694. MC_RunInfo.Cadence = (cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20; ///>踏频 1rpm,地址偏移10
  695. MC_RunInfo.Torque = ((ULONG)torsensor_stTorSensorOut.uwTorqueLPFPu * cof_uwTorqNm / 10) >> 14; ///>踩踏力矩 1Nm,地址偏移11
  696. MC_RunInfo.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir; ///>踩踏方向 0-正,1-反,2-停止,地址偏移12
  697. MC_RunInfo.GearSt = MC_ControlCode.GearSt; ///>助力档位,地址偏移13
  698. MC_RunInfo.LightSwitch = MC_ControlCode.LightSwitch; ///>灯开关 0xF0-关,0xF1-开,地址偏移14
  699. MC_RunInfo.SOC = Can_SOC_Cal(); ///>剩余电量 1%,地址偏移15
  700. if(hw_blPWMOnFlg == FALSE)
  701. {
  702. MC_RunInfo.BusCurrent=0;
  703. }
  704. // MC_RunInfo.ODO_Km = MC_RideLog.ODO_Km / 10; ///>总里程 1km,地址偏移18
  705. Can_Trip_Cal();
  706. if (cp_stBikeRunInfoPara.blGearStUpdate)
  707. {
  708. if(cp_stBikeRunInfoPara.uwBikeGear > 0 &&(cp_stBikeRunInfoPara.uwBikeGear <=5))
  709. {
  710. MC_RunInfo.PowerPerKm =
  711. *(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10; //>平均功耗 0.01Ah/km ,地址偏移20
  712. uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
  713. }
  714. else
  715. {
  716. MC_RunInfo.PowerPerKm = 0;
  717. uwRemainDistanceCal = 0xffff; //invalid value
  718. }
  719. cp_stBikeRunInfoPara.BMSRestChargeLast = BMS_RunInfo.RC;
  720. cp_stBikeRunInfoPara.uwPowerPerKm = 0;
  721. cp_stBikeRunInfoPara.uwAvePowerPerKm = 0;
  722. cp_stBikeRunInfoPara.uwPowerPerKmSum = 0;
  723. memset(cp_stBikeRunInfoPara.uwPowerPerKmBuf, 0, sizeof(cp_stBikeRunInfoPara.uwPowerPerKmBuf));
  724. cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
  725. cp_stBikeRunInfoPara.uwCruisDis = 0;
  726. }
  727. if(blBMSCommFault == TRUE)
  728. {
  729. MC_RunInfo.RemainDistance = 0xeeee; /* no bms info*/
  730. }
  731. else
  732. {
  733. MC_RunInfo.RemainDistance = uwRemainDistanceCal;
  734. }
  735. MC_RunInfo.T_PCB = adc_stUpOut.PCBTemp + 40; ///>PCB温度 +40℃,地址偏移21
  736. MC_RunInfo.T_Coil = adc_stUpOut.MotorTemp + 40; ///>绕组温度 +40℃,地址偏移22
  737. MC_RunInfo.T_MCU = adc_stUpOut.PCBTemp + 40; ///>MCU温度 +40℃,地址偏移23
  738. MC_RunInfo.Ride_Time = cp_stBikeRunInfoPara.ulRiTime >> 10; ///>开机后骑行时间 1s,地址偏移26
  739. MC_RunInfo.TorqueSensorData1=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow1;
  740. MC_RunInfo.TorqueSensorData2=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow2;
  741. MC_RunInfo.TorqueSensorData3=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow3;
  742. static UBYTE test1 = 0;
  743. if (MC_WorkMode == 1)
  744. {
  745. #if(UART_ID==3)
  746. test1++;
  747. if(test1>=5)
  748. #else
  749. test1++;
  750. if(test1>=2)
  751. #endif
  752. {
  753. test1=0;
  754. SendData(&UART_TxBuff_Struct_OBC, ID_MC_BC, MODE_REPORT, 0x1020, (uint8_t *)&MC_RunInfo.BikeSpeed);
  755. }
  756. }
  757. }
  758. void Can_Trip_Cal(void)
  759. {
  760. if (bikespeed_stFreGetOut.blUpdateTripCntFlg == TRUE)
  761. {
  762. MC_RunInfo.Ride_Km++;
  763. cp_stHistoryPara.ulODOTrip++; // Unit: 0.1km
  764. cp_stHistoryPara.ulTripSum++;
  765. Can_RemainTrip_Cal();
  766. bikespeed_stFreGetOut.blUpdateTripCntFlg = FALSE;
  767. }
  768. MC_RideLog.ODO_Km = cp_stHistoryPara.ulODOTrip;
  769. MC_RideLog.TRIP_Km = cp_stHistoryPara.ulTripSum;
  770. MC_RideLog.ODO_Time = cp_stHistoryPara.ulODOTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60; // min
  771. MC_RideLog.TRIP_Time = cp_stHistoryPara.ulTripSumTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60; // min
  772. }
  773. void Can_RemainTrip_Cal(void)
  774. {
  775. if(blBMSCommFault == FALSE)
  776. {
  777. UWORD uwCruisCoef; //功耗系数 Q12
  778. cp_stBikeRunInfoPara.uwCruisDis++; // 0.1 km
  779. if (cp_stBikeRunInfoPara.uwCruisDis >= 5) // 5 = 0.5km
  780. {
  781. cp_stBikeRunInfoPara.uwCruisDis = 0;
  782. cp_stBikeRunInfoPara.BMSRestChargeNow = BMS_RunInfo.RC;
  783. cp_stBikeRunInfoPara.uwPowerPerKm = (cp_stBikeRunInfoPara.BMSRestChargeLast - cp_stBikeRunInfoPara.BMSRestChargeNow)
  784. << 1; // BMS_RunInfo.RC (BMSRestChargeLast - BMSRestChargeNow) /0.5 km
  785. cp_stBikeRunInfoPara.BMSRestChargeLast = cp_stBikeRunInfoPara.BMSRestChargeNow;
  786. cp_stBikeRunInfoPara.uwPowerPerKmSum -= cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT];
  787. cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT] = cp_stBikeRunInfoPara.uwPowerPerKm;
  788. cp_stBikeRunInfoPara.uwPowerPerKmSum += cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT];
  789. if (cp_stBikeRunInfoPara.uwPowerPerKmBuf[31] == 0)
  790. {
  791. cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum / (cp_stBikeRunInfoPara.uwAvePowerCNT + 1);
  792. }
  793. else
  794. {
  795. cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum >> 5;
  796. }
  797. cp_stBikeRunInfoPara.uwAvePowerCNT++;
  798. if (cp_stBikeRunInfoPara.uwAvePowerCNT >= 32)
  799. {
  800. cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
  801. }
  802. if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 0)
  803. {
  804. if (cp_stBikeRunInfoPara.uwBikeGear == 1)
  805. {
  806. uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG1AvgPwrConsumption;
  807. cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12;
  808. cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12;
  809. cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12;
  810. cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12;
  811. cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12;
  812. MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG1AvgPwrConsumption / 10;
  813. }
  814. else if (cp_stBikeRunInfoPara.uwBikeGear == 2)
  815. {
  816. uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG2AvgPwrConsumption;
  817. cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12;
  818. cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12;
  819. cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12;
  820. cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12;
  821. cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12;
  822. MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG2AvgPwrConsumption / 10;
  823. }
  824. else if (cp_stBikeRunInfoPara.uwBikeGear == 3)
  825. {
  826. uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG3AvgPwrConsumption;
  827. cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12;
  828. cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12;
  829. cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12;
  830. cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12;
  831. cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12;
  832. MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG3AvgPwrConsumption / 10;
  833. }
  834. else if (cp_stBikeRunInfoPara.uwBikeGear == 4)
  835. {
  836. uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG4AvgPwrConsumption;
  837. cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12;
  838. cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12;
  839. cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12;
  840. cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12;
  841. cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12;
  842. MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG4AvgPwrConsumption / 10;
  843. }
  844. else if (cp_stBikeRunInfoPara.uwBikeGear == 5)
  845. {
  846. uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG5AvgPwrConsumption;
  847. cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12;
  848. cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12;
  849. cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12;
  850. cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12;
  851. cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12;
  852. MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG5AvgPwrConsumption / 10;
  853. }
  854. else
  855. {
  856. uwCruisCoef = 4096;
  857. }
  858. uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
  859. }
  860. }
  861. }
  862. }
  863. #if (IPM_VOLTAGE_SEL == IPM_VOLTAGE_48V)
  864. SLONG slBMSMaxVol = 54000;
  865. SLONG slBMSMinVol = 40500;
  866. #elif (IPM_VOLTAGE_SEL == IPM_VOLTAGE_36V)
  867. SLONG slBMSMaxVol = 41500;
  868. SLONG slBMSMinVol = 31000;
  869. #else
  870. SLONG slBMSMaxVol = 41500;
  871. SLONG slBMSMinVol = 31000;
  872. #endif
  873. SWORD SOC_Cnt, SOC_Value;
  874. SWORD SOC_MIN=50;
  875. SLONG Voltage_Sum;
  876. static BOOL blSOCfirstSet = FALSE;
  877. UWORD Can_SOC_Cal(void)
  878. {
  879. UWORD templenght, VoltageAvg = 0;
  880. // 开机1s等待电压稳定后初始化电量
  881. if (cp_ulSystickCnt < 500)
  882. {
  883. return (UWORD)0;
  884. }
  885. if(blBMSCommFault == FALSE)
  886. {
  887. SOC_Value = BMS_RunInfo.SOC;
  888. if((blSOCfirstSet == FALSE) && ( ulBMS_ComTimeOutCount !=0) )// 开机初始化一次电量
  889. {
  890. SOC_MIN = BMS_RunInfo.SOC;
  891. blSOCfirstSet = TRUE;
  892. }
  893. }
  894. else if(blSOCfirstSet == FALSE)// 开机初始化一次电量
  895. {
  896. if(0 == ulBMS_ComTimeOutCount)
  897. {
  898. if (MC_RunInfo.BusVoltage >= slBMSMaxVol)
  899. {
  900. SOC_Value = 100;
  901. }
  902. else if (MC_RunInfo.BusVoltage <= slBMSMinVol)
  903. {
  904. SOC_Value = 0;
  905. }
  906. else
  907. {
  908. SOC_Value = (SWORD)(((SLONG)MC_RunInfo.BusVoltage - slBMSMinVol) * 100 / (slBMSMaxVol - slBMSMinVol));
  909. }
  910. SOC_MIN = SOC_Value;
  911. }
  912. else
  913. {
  914. SOC_MIN = BMS_RunInfo.SOC;
  915. }
  916. blSOCfirstSet = TRUE;
  917. }
  918. // 1min更新一次电量
  919. else
  920. {
  921. templenght = 300; // 60s in 200ms time task
  922. SOC_Cnt++;
  923. Voltage_Sum += MC_RunInfo.BusVoltage;
  924. if (SOC_Cnt >= templenght) // 60s
  925. {
  926. VoltageAvg = (UWORD)(Voltage_Sum / templenght);
  927. if (VoltageAvg <= slBMSMinVol)
  928. {
  929. SOC_Value = 0;
  930. }
  931. else
  932. {
  933. SOC_Value = (SWORD)(((SLONG)VoltageAvg - (SLONG)slBMSMinVol) * 100 / ((SLONG)slBMSMaxVol - (SLONG)slBMSMinVol));
  934. }
  935. if (SOC_Value < SOC_MIN)
  936. {
  937. SOC_MIN = SOC_Value;
  938. }
  939. else
  940. {
  941. }
  942. SOC_Cnt = 0;
  943. Voltage_Sum = 0;
  944. }
  945. // 电量仅递减
  946. if (SOC_Value > SOC_MIN)
  947. {
  948. SOC_Value = SOC_MIN;
  949. }
  950. else if (SOC_Value < 0)
  951. {
  952. SOC_Value = 0;
  953. }
  954. else
  955. {
  956. // do noting
  957. }
  958. }
  959. return (UWORD)SOC_Value;
  960. }
  961. void Can_MaxMinTempHistory(void)
  962. {
  963. if (adc_stUpOut.PCBTemp > ((SWORD)cp_stHistoryPara.swNTCTempMaxCe))
  964. {
  965. cp_stHistoryPara.swNTCTempMaxCe = adc_stUpOut.PCBTemp;
  966. }
  967. else
  968. {}
  969. if (adc_stUpOut.PCBTemp < ((SWORD)cp_stHistoryPara.swNTCTempMinCe))
  970. {
  971. cp_stHistoryPara.swNTCTempMinCe = adc_stUpOut.PCBTemp;
  972. }
  973. else
  974. {}
  975. }
  976. void Can_GearSt_switch(void)
  977. {
  978. cp_stBikeRunInfoPara.uwBikeGearLast = cp_stBikeRunInfoPara.uwBikeGear;
  979. if (MC_WorkMode == 1) // 配置模式不自动关闭助力
  980. {
  981. ulOBC_ComTimeOutCount = cp_ulSystickCnt;
  982. }
  983. if ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000) // 控制器与仪表通信中断超过3s,关闭助力
  984. {
  985. if (MC_ControlCode.GearSt <= 0x05)
  986. {
  987. cp_stBikeRunInfoPara.uwBikeGear = MC_ControlCode.GearSt;
  988. }
  989. else if (MC_ControlCode.GearSt == 0x33)
  990. {
  991. cp_stBikeRunInfoPara.uwBikeGear = 5;
  992. }
  993. else if(MC_ControlCode.GearSt == 0x22)
  994. {
  995. cp_stBikeRunInfoPara.uwBikeGear = 0x22;
  996. }
  997. else
  998. {
  999. cp_stBikeRunInfoPara.uwBikeGear = 0;
  1000. }
  1001. }
  1002. #if 0//(BIKE_OXFORD_EN==0)
  1003. else
  1004. {
  1005. MC_ControlCode.GearSt = MC_GearSt_OFF;
  1006. MC_RunInfo.GearSt = 0x00;
  1007. cp_stBikeRunInfoPara.uwBikeGear = 0x00;
  1008. }
  1009. #endif
  1010. if (cp_stBikeRunInfoPara.uwBikeGear != cp_stBikeRunInfoPara.uwBikeGearLast)
  1011. {
  1012. cp_stBikeRunInfoPara.blGearStUpdate = TRUE;
  1013. }
  1014. else
  1015. {
  1016. cp_stBikeRunInfoPara.blGearStUpdate = FALSE;
  1017. }
  1018. }
  1019. void Can_Light_switch(void)
  1020. {
  1021. /* light switch*/
  1022. if (MC_ControlCode.LightSwitch == 0xF0)
  1023. {
  1024. cp_stBikeRunInfoPara.uwLightSwitch = 0;
  1025. }
  1026. else if (MC_ControlCode.LightSwitch == 0xF1)
  1027. {
  1028. cp_stBikeRunInfoPara.uwLightSwitch = 1;
  1029. }
  1030. }
  1031. void Can_AssistCoef_Read(UPC_CurveOrderInfo_Struct_t *order)
  1032. {
  1033. MC_UpcInfo.stAssistInfo.stCurveOrderInfo = *order;
  1034. memcpy(&MC_UpcInfo.stAssistInfo.slTorquePolyA, &Syspara2.flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], sizeof(POLY_COEF));
  1035. memcpy(&MC_UpcInfo.stAssistInfo.slCadencePolyA, &Syspara2.flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], sizeof(POLY_COEF));
  1036. }
  1037. void Can_AssistCoef_Write(UPC_CurveOrderInfo_Struct_t *order)
  1038. {
  1039. memcpy(&Syspara2.flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], &MC_UpcInfo.stAssistInfo.slTorquePolyA, sizeof(POLY_COEF));
  1040. memcpy(&Syspara2.flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], &MC_UpcInfo.stAssistInfo.slCadencePolyA, sizeof(POLY_COEF));
  1041. }
  1042. void ErrorLog_Updata(void)
  1043. {
  1044. que_stErrorLog.ErrorCode = MC_ErrorCode.Code;
  1045. que_stErrorLog.RunTime = cp_stHistoryPara.ulUsedTime;//MC_RunInfo.Ride_Time;
  1046. que_stErrorLog.RunInfo = MC_RunInfo;
  1047. //memcpy((uint8_t*)&que_stErrorLog.RunInfo, (uint8_t*)&MC_RunInfo.BikeSpeed, sizeof(MC_RunInfo_Struct_t));
  1048. que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  1049. que_stErrorLog.IqVoltagePu = scm_swUqRefPu;
  1050. que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  1051. que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
  1052. }