canAppl.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. /******************************
  12. *
  13. * Include Files
  14. *
  15. ******************************/
  16. #include "canAppl.h"
  17. #include "syspar.h"
  18. #include "user.h"
  19. #include "CodePara.h"
  20. #include "can.h"
  21. #include "flash_master.h"
  22. #include "AssistCurve.h"
  23. #include "spi_master.h"
  24. #include "torquesensor.h"
  25. #include "FSM_1st.h"
  26. #include "FSM_2nd.h"
  27. #include "sys_ctrl.h"
  28. #include "string.h"
  29. //#include "hwsetup.h"
  30. #include "fp.def"
  31. #include "queue.h"
  32. #include "api.h"
  33. #include "bikethrottle.h"
  34. /******************************
  35. *
  36. * Parameter
  37. *
  38. ******************************/
  39. MC_RunInfo_Struct_t MC_RunInfo;
  40. MC_ErrorCode_Struct_t MC_ErrorCode = CAN_MC_ALARMCODE_DEFAULT;
  41. MC_ErrorCode_CNT_RECORD_Struct_t MC_ErrorCntRecord = CAN_MC_ALARMCODE_CNT_RECORD_DEFAULT;
  42. MC_VerInfo_Struct_t MC_VerInfo;
  43. char Firmware_Special[32];
  44. MC_MacInfo_Struct_t MC_MacInfo;
  45. MC_RideLog_Struct_t MC_RideLog;
  46. BMS_RunInfo_Struct_t BMS_RunInfo;
  47. MC_ControlCode_Struct_t MC_ControlCode;
  48. MC_RunInfoToCDL_Struct_t MC_RunInfoToCDL;
  49. MC_RS_ASCII_Struct_t MC_RsASSCII;
  50. MC_UpperPCInfo_Struct_t MC_UpcInfo;
  51. BMS_VoltEstimat_Struct_t BMS_VoltEstimat;
  52. OBC_SetCustomPara_Struct_t OBC_SetCustomPara;
  53. OBC_ButtonStatus_Struct_t OBC_ButtonStatus = {0, 0, 0};
  54. ULONG ulOBC_ComTimeOutCount = 0;
  55. ULONG ulBMS_ComTimeOutCount = 0;
  56. UBYTE MC_MotorSPD_rpm_Percent = 0;
  57. UBYTE MC_WorkMode;
  58. UBYTE MC_BC_COM = 0;
  59. static LPF_OUT BMS_swCurIdcLpf;
  60. BOOL blBMSCommFault = FALSE;
  61. static UWORD uwRemainDistanceCal;
  62. UWORD ulPowerOnUsedTime = 0;
  63. BOOL AngleTest = FALSE;
  64. static SLONG slBMSMaxVol = 42000;
  65. static SLONG slBMSMinVol = 32000;
  66. void Can_voUpdateMC_UpcInfo(void)
  67. {
  68. MC_UpcInfo.stMotorInfo.uwPolePairs = cp_stMotorPara.swMotrPolePairs;
  69. MC_UpcInfo.stMotorInfo.uwRsmOhm = cp_stMotorPara.swRsOhm;
  70. MC_UpcInfo.stMotorInfo.uwLduH = cp_stMotorPara.swLdmH;
  71. MC_UpcInfo.stMotorInfo.uwLquH = cp_stMotorPara.swLqmH;
  72. MC_UpcInfo.stMotorInfo.uwFluxmWb = cp_stMotorPara.swFluxWb;
  73. MC_UpcInfo.stMotorInfo.uwIdMaxA = cp_stMotorPara.swIdMaxA;
  74. MC_UpcInfo.stMotorInfo.uwIdMinA = cp_stMotorPara.swIdMinA;
  75. MC_UpcInfo.stMotorInfo.uwRSpdRpm = cp_stMotorPara.swRSpeedRpm;
  76. MC_UpcInfo.stMotorInfo.uwRPwrWt = cp_stMotorPara.swRPwrWt;
  77. MC_UpcInfo.stMotorInfo.uwRCurA = cp_stMotorPara.swRIarmsA;
  78. MC_UpcInfo.stMotorInfo.uwRVolV = cp_stMotorPara.swRUdcV;
  79. MC_UpcInfo.stMotorInfo.uwJD = cp_stMotorPara.swJD;
  80. MC_UpcInfo.stMotorInfo.uwTorMaxNm = cp_stMotorPara.swTorMax;
  81. MC_UpcInfo.stBikeInfo.uwWheelPerimeter = ass_stParaCong.uwWheelPerimeter;
  82. MC_UpcInfo.stBikeInfo.uwMechRationMotor = ass_stParaCong.uwMechRationMotor;
  83. MC_UpcInfo.stBikeInfo.uwThrottleMaxSpdKmH = ass_stParaCong.uwThrottleMaxSpdKmH;
  84. MC_UpcInfo.stBikeInfo.uwCartSpdKmH = ass_stParaCong.uwCartSpdKmH;
  85. MC_UpcInfo.stBikeInfo.uwNmFrontChainring = ass_stParaCong.uwNmFrontChainring;
  86. MC_UpcInfo.stBikeInfo.uwNmBackChainring = ass_stParaCong.uwNmBackChainring;
  87. MC_UpcInfo.stBikeInfo.uwAssistSelect1 = ass_stParaCong.uwAssistSelect1;
  88. MC_UpcInfo.stBikeInfo.uwAssistSelect2 = ass_stParaCong.uwAssistSelect2;
  89. MC_UpcInfo.stBikeInfo.uwLightVoltage = ass_stParaCong.uwLightVoltage;
  90. MC_UpcInfo.stBikeInfo.swWheelSizeAdjust = ass_stParaCong.swDeltPerimeter;
  91. MC_UpcInfo.stBikeInfo.uwStartMode = ass_stParaCong.uwStartMode;
  92. MC_UpcInfo.stBikeInfo.uwAutoPowerOffTime = ass_stParaCong.uwAutoPowerOffTime;
  93. MC_UpcInfo.stBikeInfo.uwThrottleSmooth = ass_stParaCong.uwThrottleSmooth;
  94. MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetOrigin = spi_stResolverOut.swSpiThetaOffsetOrignPu;
  95. MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetNow = spi_stResolverOut.swSpiThetaOffsetPu;
  96. MC_UpcInfo.stMContorlInfo.uwIPeakMaxA = cp_stMotorPara.swIpeakMaxA;
  97. MC_UpcInfo.stMContorlInfo.uwAlamOCurA = cp_stControlPara.swAlmOverCurrentVal;
  98. MC_UpcInfo.stMContorlInfo.uwAlamOVolV = cp_stControlPara.swAlmOverVolVal1;
  99. MC_UpcInfo.stMContorlInfo.uwAlamUVolV = cp_stControlPara.swAlmUnderVolVal1;
  100. MC_UpcInfo.stMContorlInfo.uwAlamOverSpdRpm = cp_stControlPara.swAlmOverSpdVal;
  101. MC_UpcInfo.stMContorlInfo.uwAlamOverHeatCe = cp_stControlPara.swAlmOverHeatCeVal;
  102. MC_UpcInfo.stMContorlInfo.uwAlamRecHeatCe = cp_stControlPara.swAlmRecOHeatVal;
  103. MC_UpcInfo.stMContorlInfo.uwPwrLimitStartCe = cp_stControlPara.swAlmPwrLimitStartTempVal;
  104. // MC_UpcInfo.stMContorlInfo.uwAlamMotorOverHeatCe = cp_stControlPara.swAlmMotorOverHeatCeVal;
  105. // MC_UpcInfo.stMContorlInfo.uwAlamMotorRecHeatCe = cp_stControlPara.swAlmMotorRecOHeatVal;
  106. // MC_UpcInfo.stMContorlInfo.uwPwrLimitMotorStartCe = cp_stControlPara.swAlmPwrLimitMotorStartTempVal;
  107. MC_UpcInfo.stMContorlInfo.uwControlFunEN = cp_stControlPara.uwControlFunEN;
  108. MC_UpcInfo.stMContorlInfo.uwThrottleGearEN = cp_stControlPara.uwThrottleGearEN;
  109. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetOrigin = torsensor_stTorSensorCof.uwTorqueOffsetOrign;
  110. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow1 = torsensor_stTorSensorCof.uwTorqueOffsetNow1;
  111. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow2 = torsensor_stTorSensorCof.uwTorqueOffsetNow2;
  112. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow3 = torsensor_stTorSensorCof.uwTorqueOffsetNow3;
  113. MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow4 = torsensor_stTorSensorCof.uwTorqueOffsetNow4;
  114. MC_UpcInfo.stSensorInfo.uwBikeTorMaxNm = torsensor_stTorSensorCof.uwMaxSensorTorquePu;
  115. MC_UpcInfo.stSensorInfo.uwBikeTor1StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep1RealNm;
  116. MC_UpcInfo.stSensorInfo.uwBikeTor1StepADC = torsensor_stTorSensorCof.uwBikeTorStep1ADC;
  117. MC_UpcInfo.stSensorInfo.uwBikeTor2StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep2RealNm;
  118. MC_UpcInfo.stSensorInfo.uwBikeTor2StepADC = torsensor_stTorSensorCof.uwBikeTorStep2ADC;
  119. MC_UpcInfo.stSensorInfo.uwBikeTor3StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep3RealNm;
  120. MC_UpcInfo.stSensorInfo.uwBikeTor3StepADC = torsensor_stTorSensorCof.uwBikeTorStep3ADC;
  121. MC_UpcInfo.stSensorInfo.uwBikeTor4StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep4RealNm;
  122. MC_UpcInfo.stSensorInfo.uwBikeTor4StepADC = torsensor_stTorSensorCof.uwBikeTorStep4ADC;
  123. MC_UpcInfo.stSensorInfo.uwCadSensorPulseNm = cadence_stFreGetCof.uwNumbersPulses;
  124. MC_UpcInfo.stSensorInfo.uwBikeSpdSensorPulseNm = bikespeed_stFreGetCof.uwNumbersPulses;
  125. MC_UpcInfo.stAssistInfo.swStartupGain = ass_stParaSet.uwStartupCoef;
  126. MC_UpcInfo.stAssistInfo.swStartcruiseGain = ass_stParaSet.uwStartupCruiseCoef;
  127. MC_UpcInfo.stAssistInfo.uwAssistStartNm = ass_stParaSet.uwAssistStartNm;
  128. MC_UpcInfo.stAssistInfo.uwAssistStopNm = ass_stParaSet.uwAssistStopNm;
  129. MC_UpcInfo.stAssistInfo.uwStartUpGainStep = ass_stParaSet.uwStartUpGainStep;
  130. MC_UpcInfo.stAssistInfo.uwStartUpCadNm = ass_stParaSet.uwStartUpCadNm;
  131. MC_UpcInfo.stAssistInfo.uwTorLPFCadNm = ass_stParaSet.uwTorLPFCadNm;
  132. MC_UpcInfo.stAssistInfo.uwSpeedAssistSpdRpm = ass_stParaSet.uwSpeedAssistSpdRpm;
  133. MC_UpcInfo.stAssistInfo.uwSpeedAssistIMaxA = ass_stParaSet.uwSpeedAssistIMaxA;
  134. MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStart = ass_stParaSet.uwAssistLimitBikeSpdStart;
  135. MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStop = ass_stParaSet.uwAssistLimitBikeSpdStop;
  136. MC_UpcInfo.stAssistInfo.uwCadenceAssistWeight = ass_stParaSet.uwCadenceWeight;
  137. MC_UpcInfo.stRideParaInfo.ucAssistRatioGain1 = ass_stCalCoef.ucAssistRatioGain[0];
  138. MC_UpcInfo.stRideParaInfo.ucAssistRatioGain2 = ass_stCalCoef.ucAssistRatioGain[1];
  139. MC_UpcInfo.stRideParaInfo.ucAssistRatioGain3 = ass_stCalCoef.ucAssistRatioGain[2];
  140. MC_UpcInfo.stRideParaInfo.ucAssistRatioGain4 = ass_stCalCoef.ucAssistRatioGain[3];
  141. MC_UpcInfo.stRideParaInfo.ucAssistRatioGain5 = ass_stCalCoef.ucAssistRatioGain[4];
  142. MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain1 = ass_stCalCoef.ucAssistAccelerationGain[0];
  143. MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain2 = ass_stCalCoef.ucAssistAccelerationGain[1];
  144. MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain3 = ass_stCalCoef.ucAssistAccelerationGain[2];
  145. MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain4 = ass_stCalCoef.ucAssistAccelerationGain[3];
  146. MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain5 = ass_stCalCoef.ucAssistAccelerationGain[4];
  147. MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain1 = ass_stCalCoef.ucMaxCurrentGain[0];
  148. MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain2 = ass_stCalCoef.ucMaxCurrentGain[1];
  149. MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain3 = ass_stCalCoef.ucMaxCurrentGain[2];
  150. MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain4 = ass_stCalCoef.ucMaxCurrentGain[3];
  151. MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain5 = ass_stCalCoef.ucMaxCurrentGain[4];
  152. MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain1 = ass_stCalCoef.ucMaxTorqueGain[0];
  153. MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain2 = ass_stCalCoef.ucMaxTorqueGain[1];
  154. MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain3 = ass_stCalCoef.ucMaxTorqueGain[2];
  155. MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain4 = ass_stCalCoef.ucMaxTorqueGain[3];
  156. MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain5 = ass_stCalCoef.ucMaxTorqueGain[4];
  157. MC_UpcInfo.stBikeInfo2.uwNoneOBCEnable = ass_stParaCong.uwNoneOBCEnable;
  158. MC_UpcInfo.stBikeInfo2.uwRearLightCycle = ass_stParaCong.uwRearLightCycle;
  159. MC_UpcInfo.stBikeInfo2.uwRearLightDuty = ass_stParaCong.uwRearLightDuty;
  160. MC_UpcInfo.stBikeInfo2.swDeltaBikeSpeedLimit = ass_stParaCong.swDeltaBikeSpeedLimit;
  161. MC_UpcInfo.stHistoryInfo.uwOpenTimes = cp_stHistoryPara.uwOpenTimes;
  162. MC_UpcInfo.stHistoryInfo.uwUsedTimeH = (UWORD)(cp_stHistoryPara.ulUsedTime >> 16);
  163. MC_UpcInfo.stHistoryInfo.uwUsedTimeL = (UWORD)(cp_stHistoryPara.ulUsedTime);
  164. MC_UpcInfo.stHistoryInfo.uwNTCTempMaxCe = cp_stHistoryPara.uwNTCTempMaxCe;
  165. MC_UpcInfo.stHistoryInfo.uwNTCTempMinCe = cp_stHistoryPara.uwNTCTempMinCe;
  166. MC_UpcInfo.stHistoryInfo.uwAlamHOcurTimes = cp_stHistoryPara.uwAlamHOcurTimes;
  167. MC_UpcInfo.stHistoryInfo.uwAlamSOcurTimes = cp_stHistoryPara.uwAlamSOcurTimes;
  168. MC_UpcInfo.stHistoryInfo.uwAlamOHeatTimes = cp_stHistoryPara.uwAlamOHeatTimes;
  169. MC_UpcInfo.stHistoryInfo.uwAlamRotorLockTimes = cp_stHistoryPara.uwAlamRotorLockTimes;
  170. MC_UpcInfo.stHistoryInfo.uwAlamPhsLossTimes = cp_stHistoryPara.uwAlamPhsLossTimes;
  171. MC_UpcInfo.stHistoryInfo.uwAlamOVolTimes = cp_stHistoryPara.uwAlamOVolTimes;
  172. MC_UpcInfo.stHistoryInfo.uwAlamUVolTimes = cp_stHistoryPara.uwAlamUVolTimes;
  173. MC_UpcInfo.stHistoryInfo.uwAlamComOTimeTimes = cp_stHistoryPara.uwAlamComOTimeTimes;
  174. MC_UpcInfo.stHistoryInfo.uwG1AvgPwrConsumption = cp_stHistoryPara.uwG1AvgPwrConsumption;
  175. MC_UpcInfo.stHistoryInfo.uwG2AvgPwrConsumption = cp_stHistoryPara.uwG2AvgPwrConsumption;
  176. MC_UpcInfo.stHistoryInfo.uwG3AvgPwrConsumption = cp_stHistoryPara.uwG3AvgPwrConsumption;
  177. MC_UpcInfo.stHistoryInfo.uwG4AvgPwrConsumption = cp_stHistoryPara.uwG4AvgPwrConsumption;
  178. MC_UpcInfo.stHistoryInfo.uwG5AvgPwrConsumption = cp_stHistoryPara.uwG5AvgPwrConsumption;
  179. MC_UpcInfo.stHistoryInfo.uwODOTripH = (UWORD)(cp_stHistoryPara.ulODOTrip >> 16);
  180. MC_UpcInfo.stHistoryInfo.uwODOTripL = (UWORD)cp_stHistoryPara.ulODOTrip;
  181. MC_UpcInfo.stHistoryInfo.uwODOTimeH = (UWORD)(cp_stHistoryPara.ulODOTime >> 16);
  182. MC_UpcInfo.stHistoryInfo.uwODOTimeL = (UWORD)cp_stHistoryPara.ulODOTime;
  183. MC_UpcInfo.stHistoryInfo.uwTripSumH = (UWORD)(cp_stHistoryPara.ulTripSum >> 16);
  184. MC_UpcInfo.stHistoryInfo.uwTripSumL = (UWORD)cp_stHistoryPara.ulTripSum;
  185. MC_UpcInfo.stHistoryInfo.uwTripSumTimeH = (UWORD)(cp_stHistoryPara.ulTripSumTime >> 16);
  186. MC_UpcInfo.stHistoryInfo.uwTripSumTimeL = (UWORD)cp_stHistoryPara.ulTripSumTime;
  187. MC_UpcInfo.stHistoryInfo.uwTorSensorAlamTimes = cp_stHistoryPara.uwTorSensorAlamTimes;
  188. MC_UpcInfo.stHistoryInfo.uwCadSensorAlamTimes = cp_stHistoryPara.uwCadSensorAlamTimes;
  189. MC_UpcInfo.stHistoryInfo.uwBikeSpdSensorAlamTimes = cp_stHistoryPara.uwBikeSpdSensorAlamTimes;
  190. MC_UpcInfo.stHistoryInfo.uwPosSensorAlamTimes = cp_stHistoryPara.uwPosSensorAlamTimes;
  191. MC_UpcInfo.stHistoryInfo.uwRealODOTripH = (UWORD)(cp_stHistoryPara.ulRealODOTrip >> 16);
  192. MC_UpcInfo.stHistoryInfo.uwRealODOTripL = (UWORD)cp_stHistoryPara.ulRealODOTrip;
  193. MC_UpcInfo.stHistoryInfo.uwRealODOTimeH = (UWORD)(cp_stHistoryPara.ulRealODOTime >> 16);
  194. MC_UpcInfo.stHistoryInfo.uwRealODOTimeL = (UWORD)cp_stHistoryPara.ulRealODOTime;
  195. MC_UpcInfo.stTestParaInfo.uwEEFirstDefaultSetFlg = cp_stFlg.ParaFirstSetFlg;
  196. MC_UpcInfo.stTestParaInfo.uwSPIOffsetFirstSetFlg = cp_stFlg.SpiOffsetFirstSetFlg;
  197. MC_UpcInfo.stTestParaInfo.RunModelSelect = cp_stFlg.RunModelSelect;
  198. MC_UpcInfo.stTestParaInfo.ThetaGetModelSelect = cp_stFlg.ThetaGetModelSelect;
  199. MC_UpcInfo.stTestParaInfo.CurrentSampleModelSelect = cp_stFlg.CurrentSampleModelSelect;
  200. MC_UpcInfo.stTestParaInfo.RotateDirectionSelect = cp_stFlg.RotateDirectionSelect;
  201. MC_UpcInfo.stTestParaInfo.uwInitPosCurAmp = cp_stControlPara.swAlignCurAp;
  202. MC_UpcInfo.stTestParaInfo.uwVFControlVolAmp = cp_stControlPara.swDragVolAp;
  203. MC_UpcInfo.stTestParaInfo.uwIFControlCurAmp = cp_stControlPara.swDragCurAp;
  204. MC_UpcInfo.stTestParaInfo.uwVFIFTargetFreHz = cp_stControlPara.swDragSpdHz;
  205. MC_UpcInfo.stTestParaInfo.uwSpeedLoopAccRate = 500;
  206. MC_UpcInfo.stTestParaInfo.uwSpeedLoopDecRate = 100;
  207. MC_UpcInfo.stTestParaInfo.uwSpeedLoopBandWidthHz = cp_stControlPara.swAsrPIBandwidth;
  208. MC_UpcInfo.stTestParaInfo.uwSpeedLoopCoefM = cp_stControlPara.swAsrPIM;
  209. MC_UpcInfo.stTestParaInfo.uwCuerrentLoopBandWidthHz = cp_stControlPara.swAcrPIBandwidth;
  210. MC_UpcInfo.stTestParaInfo.uwCurrentLoopCoefM = cp_stControlPara.swAcrRaCoef;
  211. MC_UpcInfo.stTestParaInfo.uwFluxObsBandWidthHz = cp_stControlPara.swObsFluxPICrossfreHz;
  212. MC_UpcInfo.stTestParaInfo.uwFluxObsCoefM = cp_stControlPara.swObsFluxPIDampratio;
  213. MC_UpcInfo.stTestParaInfo.uwThetaObsPLLBandWidthHz = cp_stControlPara.swObsSpdPLLBandWidthHz;
  214. MC_UpcInfo.stTestParaInfo.uwThetaObsPLLCoefM = cp_stControlPara.swObsSpdPLLM;
  215. MC_UpcInfo.stTestParaInfo.uwJm = cp_stMotorPara.swJD;
  216. MC_UpcInfo.stTestParaInfo.uwPWMMaxDuty = cp_stControlPara.swPWMMaxDuty;
  217. MC_UpcInfo.stTestParaInfo.uwPWM7to5Duty = cp_stControlPara.swPWM7to5Duty;
  218. MC_UpcInfo.stTestParaInfo.uwPwrLimit = cp_stControlPara.swPwrLimitValWt;
  219. MC_UpcInfo.stTestParaInfo.uwPwrLimitError = cp_stControlPara.swPwrLimitErrWt;
  220. MC_UpcInfo.stTestParaInfo.uwPwrLimitKp = cp_stControlPara.swPwrLimitKpPu;
  221. MC_UpcInfo.stTestParaInfo.uwPwrLimitKi = cp_stControlPara.swPwrLimitKiPu;
  222. OBC_SetCustomPara.uwWheelPerimeter = (UBYTE)ass_stParaCong.uwWheelPerimeter;
  223. OBC_SetCustomPara.StartUpMod = (UBYTE)ass_stParaCong.uwStartMode;
  224. OBC_SetCustomPara.BikeSpeedLimit = (UBYTE)ass_stParaSet.uwAssistLimitBikeSpdStart;
  225. OBC_SetCustomPara.DeltDiameter = (SBYTE)ass_stParaCong.swDeltPerimeter;
  226. OBC_SetCustomPara.AssistMod = (UBYTE)ass_stParaSet.uwAsssistSelectNum;
  227. OBC_SetCustomPara.AutoPowerOffTime = (UBYTE)ass_stParaCong.uwAutoPowerOffTime;
  228. OBC_SetCustomPara.scDeltaBikeSpeedLimit = (SBYTE)ass_stParaCong.swDeltaBikeSpeedLimit;
  229. if(cp_stMotorPara.swRUdcV == 360)
  230. {
  231. slBMSMaxVol = 42000;
  232. slBMSMinVol = 32000;
  233. }
  234. else if(cp_stMotorPara.swRUdcV == 480)
  235. {
  236. slBMSMaxVol = 54600;
  237. slBMSMinVol = 41600;
  238. }
  239. else
  240. {
  241. slBMSMaxVol = 42000;
  242. slBMSMinVol = 32000;
  243. }
  244. }
  245. static UWORD SizeMCUP;
  246. void Can_voInitMC_Run(void)
  247. {
  248. UBYTE MCU_ID[12];
  249. ULONG MCU_ID_CRC32;
  250. flash_voRead();
  251. // Hardware version
  252. #if ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V))
  253. if(cp_stMotorPara.swRUdcV == 480)
  254. {
  255. strncpy(MC_VerInfo.HW_Version, (char *)"CITY-48V", 8);
  256. }
  257. else
  258. {
  259. strncpy(MC_VerInfo.HW_Version, (char *)"CITY-36V", 8);
  260. }
  261. #elif ((MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
  262. if(cp_stMotorPara.swRUdcV == 480)
  263. {
  264. strncpy(MC_VerInfo.HW_Version, (char *)"MTB-48V ", 8);
  265. }
  266. else
  267. {
  268. strncpy(MC_VerInfo.HW_Version, (char *)"MTB-36V ", 8);
  269. }
  270. #else
  271. strncpy(MC_VerInfo.HW_Version, (char *)"TEST ", 8);
  272. #endif
  273. strncpy(MC_VerInfo.HW_Version + 8, (char *)"GD .", 4);
  274. memcpy((uint8_t*)MCU_ID, (uint8_t*)(HW_ID_START_ADDRESS), 12);
  275. MCU_ID_CRC32 = CRC32_Calculate(MCU_ID,12);
  276. memcpy((uint8_t*)(MC_VerInfo.HW_Version + 12), (uint8_t*)(&MCU_ID_CRC32), 4);
  277. // Software version
  278. char chFwVersion[16]="V1r1r0_";
  279. strncat(chFwVersion,COMMIT_TIME,9);
  280. strncpy(MC_VerInfo.FW_Version, (char *)chFwVersion, 16);
  281. // Firmware Special Info
  282. char chFrimware[32]="TC00000-MC00000-V0r0. ";
  283. #if(GIANT_ENABLE == 1)
  284. strncpy(chFrimware, (char *)"TW2024X002-CB0072-V0r0.", 23);
  285. #endif
  286. #if(HUAYAO_ENABLE == 1)
  287. strncpy(chFrimware, (char *)"EC2024X079-MA0062-V0r0.", 23);
  288. #endif
  289. strncat(chFrimware,FINGER_PRINT,9);
  290. strncpy(Firmware_Special, (char *)chFrimware, 32);
  291. // Model name
  292. memcpy(MC_VerInfo.Mode, flash_stPara.ubMotorVersion, sizeof(flash_stPara.ubMotorVersion));
  293. // SN
  294. memcpy(MC_VerInfo.SN_Num, flash_stPara.ubSN, sizeof(flash_stPara.ubSN));
  295. // ProductLabel
  296. memcpy(MC_VerInfo.ProductLabel, flash_stPara.ucProductLabel, sizeof(flash_stPara.ucProductLabel));
  297. // Product information
  298. // memcpy(MC_MacInfo.Manufacturer, flash_stPara.ubProdInfo.Manufacturer, sizeof(flash_stPara.ubProdInfo));
  299. memcpy(&MC_MacInfo, &flash_stPara.ubProdInfo, sizeof(flash_stPara.ubProdInfo));
  300. // User information
  301. memcpy(MC_RsASSCII.CustomASCII1, flash_stPara.ubRsASSCII.CustomASCII1, sizeof(MC_RsASSCII.CustomASCII1));
  302. memcpy(MC_RsASSCII.CustomASCII2, flash_stPara.ubRsASSCII.CustomASCII2, sizeof(MC_RsASSCII.CustomASCII2));
  303. memcpy(MC_RsASSCII.CustomASCII3, flash_stPara.ubRsASSCII.CustomASCII3, sizeof(MC_RsASSCII.CustomASCII3));
  304. BMS_VoltEstimat.uwInterResistpu = (UWORD)(((ULONG)1700 << 15) / cof_uwRbOm); // Q15 0.1mOhm BMS internal resistance 150mOhm + 20mOhm
  305. mth_voLPFilterCoef(1000000 / 100, EVENT_1MS_HZ, &BMS_swCurIdcLpf.uwKx); // 100Hz
  306. uwRemainDistanceCal = 0xffff; // init invalid value
  307. }
  308. void Can_voMC_Run_1ms(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
  309. {
  310. if (cp_stBikeRunInfoPara.BikeSpeedKmH > 30)
  311. {
  312. cp_stBikeRunInfoPara.ulRiTime++;
  313. }
  314. if(++ulPowerOnUsedTime>=60000) //1min
  315. {
  316. cp_stHistoryPara.ulUsedTime++;
  317. ulPowerOnUsedTime=0;
  318. }
  319. // Error Cnt record and Error Display Set
  320. MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms++;
  321. if (MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms == ALAM_DETECT_CNT_IN_1ms && MC_ErrorCode.Code == 0)
  322. {
  323. MC_ErrorCntRecord.Protect_OverCurrentCnt = 0;
  324. MC_ErrorCntRecord.Protect_OverVoltageCnt = 0;
  325. MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0;
  326. MC_ErrorCntRecord.Protect_LockRotorCnt = 0;
  327. MC_ErrorCntRecord.Protect_OverTempCnt = 0;
  328. MC_ErrorCntRecord.Fault_PhaseLineCnt = 0;
  329. MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms = 0;
  330. }
  331. if (alm_blAlmOccrFlg == TRUE)
  332. {
  333. if (alm_blAlmSingleRecordDoneFlg == FALSE)
  334. {
  335. if (alm_unCode.bit.IPMFlt == 1)
  336. {
  337. MC_ErrorCntRecord.Protect_OverCurrentCnt++;
  338. cp_stHistoryPara.uwAlamHOcurTimes++;
  339. if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  340. {
  341. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1;
  342. /*error log updata*/
  343. ErrorLog_Updata();
  344. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  345. }
  346. }
  347. if (alm_unCode.bit.OvrCur == 1)
  348. {
  349. MC_ErrorCntRecord.Protect_OverCurrentCnt++;
  350. cp_stHistoryPara.uwAlamSOcurTimes++;
  351. if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  352. {
  353. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1;
  354. /*error log updata*/
  355. ErrorLog_Updata();
  356. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  357. }
  358. }
  359. if (alm_unCode.bit.OvrVlt == 1)
  360. {
  361. MC_ErrorCntRecord.Protect_OverVoltageCnt++;
  362. cp_stHistoryPara.uwAlamOVolTimes++;
  363. if (MC_ErrorCntRecord.Protect_OverVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  364. {
  365. MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 1;
  366. /*error log updata*/
  367. ErrorLog_Updata();
  368. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  369. }
  370. }
  371. if (alm_unCode.bit.UndrVlt == 1)
  372. {
  373. MC_ErrorCntRecord.Protect_UnderVoltageCnt++;
  374. cp_stHistoryPara.uwAlamUVolTimes++;
  375. if (MC_ErrorCntRecord.Protect_UnderVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  376. {
  377. MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 1;
  378. /*error log updata*/
  379. ErrorLog_Updata();
  380. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  381. }
  382. }
  383. if (alm_unCode.bit.RotorLock == 1)
  384. {
  385. MC_ErrorCntRecord.Protect_LockRotorCnt++;
  386. cp_stHistoryPara.uwAlamRotorLockTimes++;
  387. if (MC_ErrorCntRecord.Protect_LockRotorCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL
  388. {
  389. MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 1;
  390. /*error log updata*/
  391. ErrorLog_Updata();
  392. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  393. }
  394. }
  395. if (alm_unCode.bit.IPMOvrHeat == 1)
  396. {
  397. MC_ErrorCntRecord.Protect_OverTempCnt++;
  398. cp_stHistoryPara.uwAlamOHeatTimes++;
  399. if (MC_ErrorCntRecord.Protect_OverTempCnt == ALAM_DISPLAY_CNT_0LEVEL)
  400. {
  401. MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 1;
  402. /*error log updata*/
  403. ErrorLog_Updata();
  404. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  405. }
  406. }
  407. if (alm_unCode.bit.PhsLoss == 1)
  408. {
  409. MC_ErrorCntRecord.Fault_PhaseLineCnt++;
  410. cp_stHistoryPara.uwAlamPhsLossTimes++;
  411. if (MC_ErrorCntRecord.Fault_PhaseLineCnt == ALAM_DISPLAY_CNT_0LEVEL)
  412. {
  413. MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 1;
  414. /*error log updata*/
  415. ErrorLog_Updata();
  416. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  417. }
  418. }
  419. // if(alm_unCode.bit.CommOvrTm)
  420. // {
  421. // cp_stHistoryPara.uwAlamComOTimeTimes++;
  422. // }
  423. if (alm_unCode.bit.SpiThetaFlt == 1)
  424. {
  425. MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 1;
  426. /*error log updata*/
  427. ErrorLog_Updata();
  428. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  429. }
  430. if (alm_unBikeCode.bit.BikeSpdSen == 1)
  431. {
  432. MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 1;
  433. /*error log updata*/
  434. ErrorLog_Updata();
  435. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  436. }
  437. if (alm_unBikeCode.bit.CadenceSen == 1)
  438. {
  439. cp_stHistoryPara.uwCadSensorAlamTimes++;
  440. MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 1;
  441. /*error log updata*/
  442. ErrorLog_Updata();
  443. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  444. }
  445. if (alm_unBikeCode.bit.PCBNTC == 1)
  446. {
  447. MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 1;
  448. /*error log updata*/
  449. ErrorLog_Updata();
  450. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  451. }
  452. if (alm_unBikeCode.bit.Throttle == 1)
  453. {
  454. MC_ErrorCode.ERROR_Bit.Fault_GasSensor = 1;
  455. /*error log updata*/
  456. ErrorLog_Updata();
  457. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  458. }
  459. if (alm_unBikeCode.bit.TorqSen == 1)
  460. {
  461. MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 1;
  462. /*error log updata*/
  463. ErrorLog_Updata();
  464. que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1);
  465. }
  466. alm_blAlmSingleRecordDoneFlg = TRUE;
  467. }
  468. }
  469. // Claear error Display
  470. if (MC_ErrorCode.ERROR_Bit.Protect_OverCurrent == 1)
  471. {
  472. if (alm_unCode.bit.IPMFlt != 1 && alm_unCode.bit.OvrCur != 1)
  473. {
  474. MC_ErrorCntRecord.Protect_OverCurrentCnt = 0;
  475. MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 0;
  476. }
  477. }
  478. if (MC_ErrorCode.ERROR_Bit.Protect_OverVoltage == 1)
  479. {
  480. if (alm_unCode.bit.OvrVlt != 1)
  481. {
  482. MC_ErrorCntRecord.Protect_OverVoltageCnt = 0;
  483. MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 0;
  484. }
  485. }
  486. if (MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage == 1)
  487. {
  488. if (alm_unCode.bit.UndrVlt != 1)
  489. {
  490. MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0;
  491. MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 0;
  492. }
  493. }
  494. if (MC_ErrorCode.ERROR_Bit.Protect_LockRotor == 1)
  495. {
  496. if (alm_unCode.bit.RotorLock != 1)
  497. {
  498. MC_ErrorCntRecord.Protect_LockRotorCnt = 0;
  499. MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 0;
  500. }
  501. }
  502. if (MC_ErrorCode.ERROR_Bit.Protect_OverTemp == 1)
  503. {
  504. if (alm_unCode.bit.IPMOvrHeat != 1)
  505. {
  506. MC_ErrorCntRecord.Protect_OverTempCnt = 0;
  507. MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 0;
  508. }
  509. }
  510. if (MC_ErrorCode.ERROR_Bit.Fault_PhaseLine == 1)
  511. {
  512. if (alm_unCode.bit.PhsLoss != 1)
  513. {
  514. MC_ErrorCntRecord.Fault_PhaseLineCnt = 0;
  515. MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 0;
  516. }
  517. }
  518. if (MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor == 1)
  519. {
  520. if (alm_unCode.bit.SpiThetaFlt != 1)
  521. {
  522. MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 0;
  523. }
  524. }
  525. if (MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor == 1)
  526. {
  527. if (alm_unBikeCode.bit.BikeSpdSen != 1)
  528. {
  529. MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 0;
  530. }
  531. }
  532. if (MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor == 1)
  533. {
  534. if (alm_unBikeCode.bit.CadenceSen != 1)
  535. {
  536. MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 0;
  537. }
  538. }
  539. if (MC_ErrorCode.ERROR_Bit.Fault_PCBNTC == 1)
  540. {
  541. if (alm_unBikeCode.bit.PCBNTC != 1)
  542. {
  543. MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 0;
  544. }
  545. }
  546. if (MC_ErrorCode.ERROR_Bit.Fault_GasSensor == 1)
  547. {
  548. if (alm_unBikeCode.bit.Throttle != 1)
  549. {
  550. MC_ErrorCode.ERROR_Bit.Fault_GasSensor = 0;
  551. }
  552. }
  553. if (MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor == 1)
  554. {
  555. if (alm_unBikeCode.bit.TorqSen != 1)
  556. {
  557. MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 0;
  558. }
  559. }
  560. SWORD TempPower;
  561. if (FSM2nd_Run_state.state == Exit)
  562. {
  563. TempPower = 0;
  564. }
  565. else
  566. {
  567. TempPower = scm_stMotoPwrInLpf.slY.sw.hi;
  568. }
  569. BMS_VoltEstimat.swIdcPu = (SWORD)(((SLONG)TempPower << 13) / (SLONG)adc_stUpOut.uwVdcLpfPu); // Q15+Q13-Q14=Q14 Calculated dc current
  570. if (BMS_VoltEstimat.swIdcPu < 0)
  571. {
  572. BMS_VoltEstimat.swIdcPu = 0;
  573. }
  574. mth_voLPFilter(BMS_VoltEstimat.swIdcPu, &BMS_swCurIdcLpf);
  575. BMS_VoltEstimat.uwVdcCompPu = (UWORD)((ULONG)BMS_swCurIdcLpf.slY.sw.hi * BMS_VoltEstimat.uwInterResistpu >> 15); // Q14+Q15-Q15=Q14
  576. }
  577. void Can_voMC_Run_5ms(void)
  578. {
  579. cp_stBikeRunInfoPara.BikeSpeedKmH =
  580. (UWORD)((((UQWORD)bikespeed_stFreGetOut.uwLPFFrequencyPu * FBASE * (ass_stParaCong.uwWheelPerimeter + ass_stParaCong.swDeltPerimeter) * 36 >> 20) *
  581. 1048 * 10) >> 20); // 1048 = Q20(1/1000) 0.1 km/h
  582. #ifdef TEST
  583. do
  584. {
  585. ULONG ulBikeSpeedCalTrip = 0;
  586. static ULONG ulBikeSpeedCalTripCount = 0;
  587. cp_stBikeRunInfoPara.BikeSpeedKmH = (((ULONG)cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20) \
  588. * ass_stParaCong.uwNmFrontChainring/ass_stParaCong.uwNmBackChainring*(ass_stParaCong.uwWheelPerimeter + ass_stParaCong.swDeltPerimeter)*6/1000;
  589. ulBikeSpeedCalTripCount++;
  590. ulBikeSpeedCalTrip = cp_stBikeRunInfoPara.BikeSpeedKmH * 5 * ulBikeSpeedCalTripCount / 36000;
  591. if(ulBikeSpeedCalTrip > 100)
  592. {
  593. ulBikeSpeedCalTripCount = 0;
  594. bikespeed_stFreGetOut.blUpdateTripCntFlg = TRUE;
  595. }
  596. }while(0);
  597. #endif
  598. }
  599. void Can_voMC_Run_200ms(void)
  600. {
  601. SWORD TempPower;
  602. if((cp_ulSystickCnt - ulBMS_ComTimeOutCount) > 3000)
  603. {
  604. blBMSCommFault = TRUE; // communication abnormal
  605. }
  606. else
  607. {
  608. blBMSCommFault = FALSE; // communication normal
  609. }
  610. Can_GearSt_switch();
  611. SizeMCUP = sizeof(MC_UpcInfo.stAssistInfo);
  612. if (MC_BC_COM == 1)
  613. {
  614. MC_RunInfoToCDL.SysStatus = FSM1st_Sys_state.state;
  615. MC_RunInfoToCDL.SubStatus = FSM2nd_Run_state.state;
  616. MC_RunInfoToCDL.MotorStatus = curSpeed_state.state;
  617. MC_RunInfoToCDL.AssitStatus = Ass_FSM;
  618. MC_RunInfoToCDL.Id = scm_swIdRefPu;
  619. MC_RunInfoToCDL.Iq = scm_swIqRefPu;
  620. MC_RunInfoToCDL.Ud = scm_swUdRefPu;
  621. MC_RunInfoToCDL.Uq = scm_swUqRefPu;
  622. MC_RunInfoToCDL.InstantTorq = torsensor_stTorSensorOut.uwTorqueReg;
  623. MC_RunInfoToCDL.FilteTorq = torsensor_stTorSensorOut.uwTorqueLPFPu;
  624. MC_RunInfoToCDL.FreqTorq = ass_stTorqMafValue.slAverValue;
  625. MC_RunInfoToCDL.RS[0] = scm_swIdFdbLpfPu;
  626. MC_RunInfoToCDL.RS[1] = scm_swIqFdbLpfPu;
  627. MC_RunInfoToCDL.RS[2] = ass_stCalOut.swTorAss2CurrentTemp;
  628. MC_RunInfoToCDL.RS[3] = bikethrottle_stBikeThrottleOut.uwThrottlePercent;
  629. SendData(ID_MC_TO_CDL, MODE_REPORT, 0xBA20, (UBYTE *)&MC_RunInfoToCDL.SysStatus);
  630. }
  631. MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH; //0.1km/h
  632. MC_RunInfo.MotorSpeed = (SWORD)((SLONG)scm_uwSpdFbkLpfAbsPu * (SLONG)cof_uwVbRpm >> 15); //1rpm
  633. TempPower = scm_swMotorPwrInLpfWt;
  634. if (TempPower > 5000)
  635. {
  636. TempPower = 5000;
  637. }
  638. if (TempPower < 0)
  639. {
  640. TempPower = 0;
  641. }
  642. if (sysctrl_stPwmState.blPwmOnflg == FALSE)
  643. {
  644. TempPower = 0;
  645. }
  646. else
  647. {
  648. }
  649. do
  650. {
  651. SWORD PowerTemp1 = 0;
  652. static SLONG PowerFlt = 0;
  653. PowerTemp1 = ((TempPower / 10) * 5 ) >> 3;
  654. PowerTemp1 = (PowerTemp1 < 25) ? 0 : PowerTemp1;
  655. PowerFlt += ((PowerTemp1 << 10) - PowerFlt) >> 3;
  656. MC_RunInfo.Power = (PowerFlt < 0) ? 0 : (PowerFlt) >> 10;
  657. }while(0);
  658. //MC_RunInfo.Power = TempPower / 10; //>电功率 1W
  659. //MC_RunInfo.Power = (scm_swIqFdbLpfPu * 250 * cof_uwIbAp / 1500) >> 14; //MaxIq = 15A,MaxPower=250W
  660. MC_RunInfo.BusVoltage = (UWORD)((((ULONG)adc_stUpOut.uwVdcLpfPu + (ULONG)BMS_VoltEstimat.uwVdcCompPu) * cof_uwUbVt * 100) >> 14); //母线电压 1mV
  661. //MC_RunInfo.BusCurrent = (UWORD)((ULONG)BMS_VoltEstimat.swIdcPu * cof_uwIbAp * 100 >> 14); //母线电流 1mA
  662. BMS_VoltEstimat.uwIbusLpf = (BMS_swCurIdcLpf.slY.sw.hi * cof_uwIbAp * 15) >> 14;//mA
  663. MC_RunInfo.BusCurrent = (ABS(scm_swIqFdbLpfPu) * cof_uwIbAp * 10) >> 14;
  664. MC_RunInfo.Cadence = (UBYTE)(((ULONG)cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20); //踏频 1rpm
  665. MC_RunInfo.Torque = (UBYTE)(((ULONG)torsensor_stTorSensorOut.uwTorqueLPFPu * cof_uwTorqNm / 10) >> 14); //踩踏力矩 1Nm
  666. MC_RunInfo.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir; //踩踏方向 0-正,1-反,2-停止
  667. MC_RunInfo.GearSt = (UBYTE)MC_ControlCode.GearSt; //助力档位
  668. MC_RunInfo.LightSwitch = MC_ControlCode.LightSwitch; //灯开关 0xF0-关,0xF1-开
  669. MC_RunInfo.SOC = (UBYTE)Can_SOC_Cal(); //剩余电量 1%
  670. Can_Trip_Cal();
  671. MC_RunInfo.TorqueReg = iAdc_GetResultPointer(0)[HW_ADC_TORQ_CH];; //力矩AD值
  672. if (cp_stBikeRunInfoPara.blGearStUpdate)
  673. {
  674. if((cp_stBikeRunInfoPara.uwBikeGear > 0) && (cp_stBikeRunInfoPara.uwBikeGear <= 5))
  675. {
  676. MC_RunInfo.PowerPerKm =
  677. (UBYTE)(*(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10); //平均功耗 0.01Ah/km /* parasoft-suppress MISRA2004-17_4 "本项目无法更改,后续避免非数组索引指针运算" */
  678. uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
  679. }
  680. else
  681. {
  682. MC_RunInfo.PowerPerKm = 0;
  683. uwRemainDistanceCal = 0xffff; //invalid value
  684. }
  685. cp_stBikeRunInfoPara.BMSRestChargeLast = BMS_RunInfo.RC;
  686. cp_stBikeRunInfoPara.uwPowerPerKm = 0;
  687. cp_stBikeRunInfoPara.uwAvePowerPerKm = 0;
  688. cp_stBikeRunInfoPara.uwPowerPerKmSum = 0;
  689. memset(cp_stBikeRunInfoPara.uwPowerPerKmBuf, 0, sizeof(cp_stBikeRunInfoPara.uwPowerPerKmBuf));
  690. cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
  691. cp_stBikeRunInfoPara.uwCruisDis = 0;
  692. }
  693. if(blBMSCommFault == TRUE)
  694. {
  695. MC_RunInfo.RemainDistance = 0xeeee; /* no bms info*/
  696. }
  697. else
  698. {
  699. MC_RunInfo.RemainDistance = uwRemainDistanceCal;
  700. }
  701. MC_RunInfo.T_PCB = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40; //>PCB温度 +40℃
  702. MC_RunInfo.T_Coil = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40; //绕组温度 +40℃
  703. MC_RunInfo.T_MCU = (UBYTE)adc_stUpOut.PCBTemp + (UBYTE)40; //MCU温度 +40℃,
  704. MC_RunInfo.Ride_Time = (UWORD)(cp_stBikeRunInfoPara.ulRiTime >> 10); //开机后骑行时间 1s
  705. if (MC_WorkMode == 1)
  706. {
  707. SendData(ID_MC_BC, MODE_REPORT, 0x1020, (UBYTE *)&MC_RunInfo.BikeSpeed);
  708. }
  709. }
  710. void Can_Trip_Cal(void)
  711. {
  712. if (bikespeed_stFreGetOut.blUpdateTripCntFlg == TRUE)
  713. {
  714. MC_RunInfo.Ride_Km++;
  715. cp_stHistoryPara.ulODOTrip++; // Unit: 0.1km
  716. cp_stHistoryPara.ulRealODOTrip++; // Unit: 0.1km
  717. cp_stHistoryPara.ulTripSum++;
  718. Can_RemainTrip_Cal();
  719. bikespeed_stFreGetOut.blUpdateTripCntFlg = FALSE;
  720. }
  721. MC_RideLog.ODO_Km = cp_stHistoryPara.ulODOTrip;
  722. MC_RideLog.TRIP_Km = cp_stHistoryPara.ulTripSum;
  723. MC_RideLog.ODO_Time = cp_stHistoryPara.ulODOTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60; // min
  724. MC_RideLog.TRIP_Time = cp_stHistoryPara.ulTripSumTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60; // min
  725. cp_stHistoryPara.ulRealODOTime = cp_stHistoryPara.ulRealODOTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60;
  726. /*TRIP里程超9999.9km时,清除TRIP里程和时间*/
  727. if(MC_RideLog.TRIP_Km > 99999)
  728. {
  729. cp_stHistoryPara.ulTripSum = 0;
  730. cp_stHistoryPara.ulTripSumTime = 0;
  731. MC_RunInfo.Ride_Km = 0;
  732. MC_RunInfo.Ride_Time = 0;
  733. MC_RideLog.TRIP_Km = 0;
  734. MC_RideLog.TRIP_Time = 0;
  735. cp_stHistoryPara.ulODOTime = cp_stHistoryPara.ulODOTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60;
  736. cp_stBikeRunInfoPara.ulRiTime = 0;
  737. }
  738. }
  739. void Can_RemainTrip_Cal(void)
  740. {
  741. if(blBMSCommFault == FALSE)
  742. {
  743. UWORD uwCruisCoef; //单位功耗
  744. cp_stBikeRunInfoPara.uwCruisDis++; // 0.1 km
  745. if (cp_stBikeRunInfoPara.uwCruisDis >= 5) // 5 = 0.5km
  746. {
  747. cp_stBikeRunInfoPara.uwCruisDis = 0;
  748. cp_stBikeRunInfoPara.BMSRestChargeNow = BMS_RunInfo.RC;
  749. cp_stBikeRunInfoPara.uwPowerPerKm = (cp_stBikeRunInfoPara.BMSRestChargeLast - cp_stBikeRunInfoPara.BMSRestChargeNow)
  750. << 1; // BMS_RunInfo.RC (BMSRestChargeLast - BMSRestChargeNow) /0.5 km
  751. cp_stBikeRunInfoPara.BMSRestChargeLast = cp_stBikeRunInfoPara.BMSRestChargeNow;
  752. cp_stBikeRunInfoPara.uwPowerPerKmSum -= cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT];
  753. cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT] = cp_stBikeRunInfoPara.uwPowerPerKm;
  754. cp_stBikeRunInfoPara.uwPowerPerKmSum += cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT];
  755. if (cp_stBikeRunInfoPara.uwPowerPerKmBuf[31] == 0)
  756. {
  757. cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum / (cp_stBikeRunInfoPara.uwAvePowerCNT + 1);
  758. }
  759. else
  760. {
  761. cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum >> 5;
  762. }
  763. cp_stBikeRunInfoPara.uwAvePowerCNT++;
  764. if (cp_stBikeRunInfoPara.uwAvePowerCNT >= 32)
  765. {
  766. cp_stBikeRunInfoPara.uwAvePowerCNT = 0;
  767. }
  768. /*限制功耗防止续航里程过大或过小*/
  769. if(cp_stBikeRunInfoPara.uwAvePowerPerKm < 50)
  770. {
  771. cp_stBikeRunInfoPara.uwAvePowerPerKm = 50; /*limit min*/
  772. }
  773. else if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 500)
  774. {
  775. cp_stBikeRunInfoPara.uwAvePowerPerKm = 500; /*limit max*/
  776. }
  777. else
  778. {
  779. /* no deal with */
  780. }
  781. if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 0)
  782. {
  783. if (cp_stBikeRunInfoPara.uwBikeGear == 1)
  784. {
  785. uwCruisCoef = (UWORD)(((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG1AvgPwrConsumption);
  786. cp_stHistoryPara.uwG1AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12);
  787. cp_stHistoryPara.uwG2AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12);
  788. cp_stHistoryPara.uwG3AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12);
  789. cp_stHistoryPara.uwG4AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12);
  790. cp_stHistoryPara.uwG5AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12);
  791. MC_RunInfo.PowerPerKm = (UBYTE)(cp_stHistoryPara.uwG1AvgPwrConsumption / 10);
  792. }
  793. else if (cp_stBikeRunInfoPara.uwBikeGear == 2)
  794. {
  795. uwCruisCoef = (UWORD)(((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG2AvgPwrConsumption);
  796. cp_stHistoryPara.uwG1AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12);
  797. cp_stHistoryPara.uwG2AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12);
  798. cp_stHistoryPara.uwG3AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12);
  799. cp_stHistoryPara.uwG4AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12);
  800. cp_stHistoryPara.uwG5AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12);
  801. MC_RunInfo.PowerPerKm = (UBYTE)(cp_stHistoryPara.uwG2AvgPwrConsumption / 10);
  802. }
  803. else if (cp_stBikeRunInfoPara.uwBikeGear == 3)
  804. {
  805. uwCruisCoef = (UWORD)(((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG3AvgPwrConsumption);
  806. cp_stHistoryPara.uwG1AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12);
  807. cp_stHistoryPara.uwG2AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12);
  808. cp_stHistoryPara.uwG3AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12);
  809. cp_stHistoryPara.uwG4AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12);
  810. cp_stHistoryPara.uwG5AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12);
  811. MC_RunInfo.PowerPerKm = (UBYTE)(cp_stHistoryPara.uwG3AvgPwrConsumption / 10);
  812. }
  813. else if (cp_stBikeRunInfoPara.uwBikeGear == 4)
  814. {
  815. uwCruisCoef = (UWORD)(((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG4AvgPwrConsumption);
  816. cp_stHistoryPara.uwG1AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12);
  817. cp_stHistoryPara.uwG2AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12);
  818. cp_stHistoryPara.uwG3AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12);
  819. cp_stHistoryPara.uwG4AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12);
  820. cp_stHistoryPara.uwG5AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12);
  821. MC_RunInfo.PowerPerKm = (UBYTE)(cp_stHistoryPara.uwG4AvgPwrConsumption / 10);
  822. }
  823. else if (cp_stBikeRunInfoPara.uwBikeGear == 5)
  824. {
  825. uwCruisCoef = (UWORD)(((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG5AvgPwrConsumption);
  826. cp_stHistoryPara.uwG1AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12);
  827. cp_stHistoryPara.uwG2AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12);
  828. cp_stHistoryPara.uwG3AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12);
  829. cp_stHistoryPara.uwG4AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12);
  830. cp_stHistoryPara.uwG5AvgPwrConsumption = (UWORD)((ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12);
  831. MC_RunInfo.PowerPerKm = (UBYTE)(cp_stHistoryPara.uwG5AvgPwrConsumption / 10);
  832. }
  833. else
  834. {
  835. uwCruisCoef = 4096;
  836. }
  837. uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10;
  838. }
  839. }
  840. }
  841. }
  842. //#if ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_36V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_36V))
  843. //static SLONG slBMSMaxVol = 42000;
  844. //static SLONG slBMSMinVol = 32000;
  845. //#elif ((MOTOR_ID_SEL == MOTOR_WELLING_CITY_48V) || (MOTOR_ID_SEL == MOTOR_WELLING_MTB_48V))
  846. //static SLONG slBMSMaxVol = 54600;
  847. //static SLONG slBMSMinVol = 41600;
  848. //#endif
  849. static SWORD SOC_Cnt, SOC_Value, SOC_MIN;
  850. static ULONG Voltage_Sum;
  851. static BOOL blSOCfirstSet = FALSE;
  852. UWORD Can_SOC_Cal(void)
  853. {
  854. UWORD templenght, VoltageAvg = 0;
  855. if (cp_ulSystickCnt < 1000)
  856. {
  857. return (UWORD)0;
  858. }
  859. if(blBMSCommFault == FALSE)
  860. {
  861. SOC_Value = BMS_RunInfo.SOC;
  862. }
  863. else if (blSOCfirstSet == FALSE)
  864. {
  865. if(0 == ulBMS_ComTimeOutCount)
  866. {
  867. if (MC_RunInfo.BusVoltage >= slBMSMaxVol)
  868. {
  869. SOC_Value = 100;
  870. }
  871. else if (MC_RunInfo.BusVoltage <= slBMSMinVol)
  872. {
  873. SOC_Value = 0;
  874. }
  875. else
  876. {
  877. SOC_Value = (SWORD)(((SLONG)MC_RunInfo.BusVoltage - slBMSMinVol) * 100 / (slBMSMaxVol - slBMSMinVol));
  878. }
  879. SOC_MIN = SOC_Value;
  880. }
  881. else
  882. {
  883. SOC_MIN = BMS_RunInfo.SOC;
  884. }
  885. blSOCfirstSet = TRUE;
  886. }
  887. else
  888. {
  889. templenght = 300; // 60s in 200ms time task
  890. SOC_Cnt++;
  891. Voltage_Sum += MC_RunInfo.BusVoltage;
  892. if (SOC_Cnt >= templenght) // 60s
  893. {
  894. VoltageAvg = (UWORD)(Voltage_Sum / templenght);
  895. if (VoltageAvg <= slBMSMinVol)
  896. {
  897. SOC_Value = 0;
  898. }
  899. else
  900. {
  901. SOC_Value = (SWORD)(((SLONG)VoltageAvg - (SLONG)slBMSMinVol) * 100 / ((SLONG)slBMSMaxVol - (SLONG)slBMSMinVol));
  902. }
  903. if (SOC_Value < SOC_MIN)
  904. {
  905. SOC_MIN = SOC_Value;
  906. }
  907. else
  908. {
  909. }
  910. SOC_Cnt = 0;
  911. Voltage_Sum = 0;
  912. }
  913. if (SOC_Value > SOC_MIN)
  914. {
  915. SOC_Value = SOC_MIN;
  916. }
  917. else if (SOC_Value < 0)
  918. {
  919. SOC_Value = 0;
  920. }
  921. else
  922. {
  923. // do nothing
  924. }
  925. }
  926. return (UWORD)SOC_Value;
  927. }
  928. void Can_GearSt_switch(void)
  929. {
  930. cp_stBikeRunInfoPara.uwBikeGearLast = cp_stBikeRunInfoPara.uwBikeGear;
  931. if (MC_WorkMode == 1)
  932. {
  933. ulOBC_ComTimeOutCount = cp_ulSystickCnt;
  934. }
  935. #ifdef RUN_ARCH_SIM
  936. ulOBC_ComTimeOutCount = cp_ulSystickCnt;
  937. #endif
  938. if ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000)
  939. {
  940. if (MC_ControlCode.GearSt <= 0x05)
  941. {
  942. cp_stBikeRunInfoPara.uwBikeGear = (UWORD)MC_ControlCode.GearSt;
  943. }
  944. else if (MC_ControlCode.GearSt == 0x33)
  945. {
  946. cp_stBikeRunInfoPara.uwBikeGear = 5;
  947. }
  948. else if (MC_ControlCode.GearSt == 0x22)
  949. {
  950. cp_stBikeRunInfoPara.uwBikeGear = 0x22;
  951. }
  952. else
  953. {
  954. // do nothing
  955. }
  956. }
  957. else
  958. {
  959. MC_ControlCode.GearSt = MC_GearSt_OFF;
  960. MC_RunInfo.GearSt = 0x00;
  961. cp_stBikeRunInfoPara.uwBikeGear = 0x00;
  962. }
  963. if((ass_stParaCong.uwNoneOBCEnable & 0xFF) == 0xAA)
  964. {
  965. ulOBC_ComTimeOutCount = cp_ulSystickCnt;
  966. MC_ControlCode.GearSt = MC_GearSt_SMART;
  967. MC_RunInfo.GearSt = MC_GearSt_SMART;
  968. cp_stBikeRunInfoPara.uwBikeGear = 5;
  969. }
  970. if (cp_stBikeRunInfoPara.uwBikeGear != cp_stBikeRunInfoPara.uwBikeGearLast)
  971. {
  972. cp_stBikeRunInfoPara.blGearStUpdate = TRUE;
  973. scm_voLimit_Power(cp_stBikeRunInfoPara.uwBikeGear, ass_uwPwrCurLim, ass_stCalCoef.ucMaxCurrentGain);//功率限制
  974. }
  975. else
  976. {
  977. cp_stBikeRunInfoPara.blGearStUpdate = FALSE;
  978. }
  979. }
  980. void Can_Light_switch(void)
  981. {
  982. /* light switch*/
  983. if (MC_ControlCode.LightSwitch == 0xF1)
  984. {
  985. cp_stBikeRunInfoPara.uwLightSwitch = 1;
  986. }
  987. else if (MC_ControlCode.LightSwitch == 0xF0)
  988. {
  989. cp_stBikeRunInfoPara.uwLightSwitch = 0;
  990. }
  991. else
  992. {
  993. // do nothing
  994. }
  995. }
  996. void Can_AssistCoef_Read(const UPC_CurveOrderInfo_Struct_t *order)
  997. {
  998. MC_UpcInfo.stAssistInfo.stCurveOrderInfo = *order;
  999. memcpy(&MC_UpcInfo.stAssistInfo.slTorquePolyA, &flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], sizeof(POLY_COEF));
  1000. memcpy(&MC_UpcInfo.stAssistInfo.slCadencePolyA, &flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], sizeof(POLY_COEF));
  1001. }
  1002. void Can_AssistCoef_Write(const UPC_CurveOrderInfo_Struct_t *order)
  1003. {
  1004. memcpy(&flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], &MC_UpcInfo.stAssistInfo.slTorquePolyA, sizeof(POLY_COEF));
  1005. memcpy(&flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], &MC_UpcInfo.stAssistInfo.slCadencePolyA, sizeof(POLY_COEF));
  1006. }
  1007. void ErrorLog_Updata(void)
  1008. {
  1009. que_stErrorLog.ErrorCode = MC_ErrorCode.Code;
  1010. que_stErrorLog.RunTime = cp_stHistoryPara.ulUsedTime;//MC_RunInfo.Ride_Time;
  1011. que_stErrorLog.RunInfo = MC_RunInfo;
  1012. //memcpy((uint8_t*)&que_stErrorLog.RunInfo, (uint8_t*)&MC_RunInfo.BikeSpeed, sizeof(MC_RunInfo_Struct_t));
  1013. que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu;
  1014. que_stErrorLog.IqVoltagePu = scm_swUqRefPu;
  1015. que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu;
  1016. que_stErrorLog.IdVoltagePu = scm_swUdRefPu;
  1017. }