app.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //#include "api.h"
  2. #include "board_config.h"
  3. #include "tbc.h"
  4. #include "tbs.h"
  5. #include "sys_task.h"
  6. #include "TimeTask_Event.h"
  7. #include "InputCapture.h"
  8. #include "syspar.h"
  9. #include "user.h"
  10. #include "TimeTask_Event.h"
  11. #include "FSM_1st.h"
  12. #include "FSM_2nd.h"
  13. #include "usart.h"
  14. #include "can.h"
  15. #include "cmdgennew.h"
  16. #include "canAppl.h"
  17. #include "flash_master.h"
  18. #include "torquesensor.h"
  19. #include "power.h"
  20. #include "FuncLayerAPI.h"
  21. #include "MosResCalib.h"
  22. void PeripheralInit();
  23. void PeripheralStart();
  24. void StartSelectAssistMode(void);
  25. void AppInit()
  26. {
  27. /* 初始化外设(Api层级配置)并配置调度逻辑 */
  28. PeripheralInit();
  29. // /* 1 电机控制环路初始化 */
  30. // /* 1.1 初始化PU值系统 */
  31. // /* 1.2 初始化参数系统 */
  32. // /* 1.3 算法模块初始化 */
  33. //
  34. // McPipelineInit();
  35. // McModulesConfig();
  36. // McPipelineModulesInit();
  37. // McPipelineStaticCoef();
  38. //
  39. // /* 2 控制组件初始化 */
  40. //
  41. // SysCtrlInit();
  42. // McCtrlInit();
  43. //
  44. // /* 状态机初始化 */
  45. //
  46. // SysFsmInit();
  47. // CtrlFsmInit();
  48. // McFsmInit();
  49. //
  50. // /* 故障处理初始化 */
  51. //
  52. // AlmInit();
  53. //
  54. // /* 串口调试初始化 */
  55. //
  56. // uart_voMonitorInit();
  57. /* Code Para Init */
  58. CodeParaInit();
  59. ass_voParameterInit();
  60. /* AssitPara Init */
  61. AssitEEInit();
  62. /* Para Copy */
  63. mn_voParaSet();
  64. if(cp_stFlg.ParaFirstSetFlg == 0)
  65. {
  66. //clear Err Value
  67. //flash_voErrorClear();
  68. flash_voSysParaInit();
  69. CodeHistoryParaDelete();
  70. mn_voEEHistoryParaUpdate();
  71. flash_voSysParaWrite();
  72. flash_HistoryWrite();
  73. mn_voParaSet();
  74. }
  75. bikelight_voBikeLightCoef(ass_ParaCong.uwLightConfig); //灯压
  76. /* 上位机参数更新 */
  77. Can_voUpdateMC_UpcInfo();
  78. /* System parameter initial */
  79. mn_voSoftwareInit();
  80. /* 启动外设 */
  81. PeripheralStart();
  82. }
  83. void AppLoop()
  84. {
  85. /* Control mode FSM reset */
  86. if (!sysfsm_stFlg.blFSMRstOvrFlg)
  87. {
  88. RUN_FSM_voInit();
  89. Switch_speed_FSMInit();
  90. sysfsm_stFlg.blFSMRstOvrFlg = TRUE;
  91. }
  92. /* Control mode variable clear */
  93. if (!sysfsm_stFlg.blCtrlMdVarClcOvrFlg)
  94. {
  95. sysfsm_stFlg.blCtrlMdVarClcOvrFlg = TRUE;
  96. }
  97. CanRx_Process();
  98. //ReadFrame_Poll2();
  99. // uart_voMainDec();
  100. UsartRx_Process(&UART_RxBuff_Struct_OBC, &UART_TxBuff_Struct_OBC, &stUSART_FrameBuf_OBC);
  101. UsartRx_Process(&UART_RxBuff_Struct_BMS, &UART_TxBuff_Struct_BMS, &stUSART_FrameBuf_BMS);
  102. TimingTaskLoopServer();
  103. ReceiveCmdHandle();
  104. // StartSelectAssistMode();
  105. if (cp_stFlg.ParaUpdateFlg == TRUE)
  106. {
  107. mn_voParaUpdate();
  108. }
  109. if (FSM2nd_Run_state.state == Exit)
  110. {
  111. if (cp_stFlg.ParaHistorySaveEEFinishFlg == FALSE)
  112. {
  113. DISABLE_IRQ; /* MCU Core and GPIO configuration */
  114. cp_stHistoryPara.ulODOTime = MC_RideLog.ODO_Time;
  115. cp_stHistoryPara.ulTripSumTime = MC_RideLog.TRIP_Time;
  116. cp_stHistoryPara.ulRealODOTime+= (cp_stBikeRunInfoPara.ulRealODOTime >>10);
  117. cp_stBikeRunInfoPara.ulRiTime=0;
  118. cp_stBikeRunInfoPara.ulRiTirpTime=0;
  119. cp_stBikeRunInfoPara.ulRealODOTime =0;
  120. mn_voEEHistoryParaUpdate();
  121. /* Error Log Write */
  122. flash_voErrorWrite(); //故障日志+历史信息
  123. flash_HistoryWrite();
  124. if (cp_stFlg.ParaSaveEEFlg == TRUE)
  125. {
  126. mn_voEEUperParaUpdate();
  127. cp_stFlg.ParaSaveEEFinishFlg = TRUE;
  128. cp_stFlg.ParaSaveEEFlg = FALSE;
  129. }
  130. flash_voSysParaWrite();
  131. flash_voProductParaWrite();
  132. cp_stFlg.ParaHistorySaveEEFinishFlg = TRUE;
  133. ENABLE_IRQ; /* MCU Core and GPIO configuration */
  134. }
  135. }
  136. }
  137. void PeripheralInit()
  138. {
  139. /* Pwm配置 */
  140. // iPwm_BindDeviceInterrupt(0, ApiPwm_CountZeroInt, tbc_voUpIsr);
  141. // iPwm_BindDeviceInterrupt(0, ApiPwm_CountMaxInt, tbc_voDownIsr);
  142. // iPwm_EnableDeviceInterrupt(0, ApiPwm_CountZeroInt);
  143. // iPwm_EnableDeviceInterrupt(0, ApiPwm_CountMaxInt);
  144. /* Tbs 定时器配置 */
  145. // iTimer_BindInterrupt(HW_TBS_TIMER, tbs_voIsr);
  146. //iTimer_EnableInterrupt(HW_TBS_TIMER);
  147. /* Event1ms 定时器配置 */
  148. // iTimer_BindInterrupt(HW_EVENT1MS_TIMER, Event_1ms);
  149. // iTimer_EnableInterrupt(HW_EVENT1MS_TIMER);
  150. /* 1ms 定时器配置 */
  151. // iTimer_BindInterrupt(HW_SYSTICK_TIMER, SysTask1Ms);
  152. // iTimer_EnableInterrupt(HW_SYSTICK_TIMER);
  153. // iCap_BindDeviceInterrupt(HW_BIKESPD_CAD_CAP,ic_voBikeSensorCntMaxIsr);
  154. // iCap_BindChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(2),ic_voCadenceIsr);
  155. // iCap_BindChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(3),ic_voBikeSpdIsr);
  156. // iCap_EnableDeviceInterrupt(HW_BIKESPD_CAD_CAP);
  157. // iCap_EnableChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(2));
  158. // iCap_EnableChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(3));
  159. //
  160. // iCap_BindDeviceInterrupt(HW_MOTOR_HALL_CAP,ic_voHallCntMaxIsr);
  161. // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(0),ic_voHallCh1Isr);
  162. // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(1),ic_voHallCh2Isr);
  163. // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(2),ic_voHallCh3Isr);
  164. // iCap_EnableDeviceInterrupt(HW_MOTOR_HALL_CAP);
  165. // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(0));
  166. // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(1));
  167. // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(2));
  168. }
  169. void PeripheralStart()
  170. {
  171. // iPwm_EnableCount(0);
  172. // iTimer_Start(HW_TBS_TIMER);
  173. // iTimer_Start(HW_SYSTICK_TIMER);
  174. }