123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- //#include "api.h"
- #include "board_config.h"
- #include "tbc.h"
- #include "tbs.h"
- #include "sys_task.h"
- #include "TimeTask_Event.h"
- #include "InputCapture.h"
- #include "syspar.h"
- #include "user.h"
- #include "TimeTask_Event.h"
- #include "FSM_1st.h"
- #include "FSM_2nd.h"
- #include "usart.h"
- #include "can.h"
- #include "cmdgennew.h"
- #include "canAppl.h"
- #include "flash_master.h"
- #include "torquesensor.h"
- #include "power.h"
- #include "FuncLayerAPI.h"
- #include "MosResCalib.h"
- void PeripheralInit();
- void PeripheralStart();
- void StartSelectAssistMode(void);
- void AppInit()
- {
- /* 初始化外设(Api层级配置)并配置调度逻辑 */
- PeripheralInit();
- // /* 1 电机控制环路初始化 */
- // /* 1.1 初始化PU值系统 */
- // /* 1.2 初始化参数系统 */
- // /* 1.3 算法模块初始化 */
- //
- // McPipelineInit();
- // McModulesConfig();
- // McPipelineModulesInit();
- // McPipelineStaticCoef();
- //
- // /* 2 控制组件初始化 */
- //
- // SysCtrlInit();
- // McCtrlInit();
- //
- // /* 状态机初始化 */
- //
- // SysFsmInit();
- // CtrlFsmInit();
- // McFsmInit();
- //
- // /* 故障处理初始化 */
- //
- // AlmInit();
- //
- // /* 串口调试初始化 */
- //
- // uart_voMonitorInit();
- /* Code Para Init */
- CodeParaInit();
- ass_voParameterInit();
- /* AssitPara Init */
- AssitEEInit();
- /* Para Copy */
- mn_voParaSet();
- if(cp_stFlg.ParaFirstSetFlg == 0)
- {
-
- //clear Err Value
- //flash_voErrorClear();
- flash_voSysParaInit();
- CodeHistoryParaDelete();
- mn_voEEHistoryParaUpdate();
- flash_voSysParaWrite();
- flash_HistoryWrite();
- mn_voParaSet();
- }
- bikelight_voBikeLightCoef(ass_ParaCong.uwLightConfig); //灯压
- /* 上位机参数更新 */
- Can_voUpdateMC_UpcInfo();
- /* System parameter initial */
- mn_voSoftwareInit();
- /* 启动外设 */
- PeripheralStart();
- }
- void AppLoop()
- {
- /* Control mode FSM reset */
- if (!sysfsm_stFlg.blFSMRstOvrFlg)
- {
- RUN_FSM_voInit();
- Switch_speed_FSMInit();
- sysfsm_stFlg.blFSMRstOvrFlg = TRUE;
- }
- /* Control mode variable clear */
- if (!sysfsm_stFlg.blCtrlMdVarClcOvrFlg)
- {
- sysfsm_stFlg.blCtrlMdVarClcOvrFlg = TRUE;
- }
- CanRx_Process();
- //ReadFrame_Poll2();
- // uart_voMainDec();
- UsartRx_Process(&UART_RxBuff_Struct_OBC, &UART_TxBuff_Struct_OBC, &stUSART_FrameBuf_OBC);
- UsartRx_Process(&UART_RxBuff_Struct_BMS, &UART_TxBuff_Struct_BMS, &stUSART_FrameBuf_BMS);
-
- TimingTaskLoopServer();
- ReceiveCmdHandle();
- // StartSelectAssistMode();
- if (cp_stFlg.ParaUpdateFlg == TRUE)
- {
- mn_voParaUpdate();
- }
- if (FSM2nd_Run_state.state == Exit)
- {
- if (cp_stFlg.ParaHistorySaveEEFinishFlg == FALSE)
- {
- DISABLE_IRQ; /* MCU Core and GPIO configuration */
- cp_stHistoryPara.ulODOTime = MC_RideLog.ODO_Time;
- cp_stHistoryPara.ulTripSumTime = MC_RideLog.TRIP_Time;
- cp_stHistoryPara.ulRealODOTime += (cp_stBikeRunInfoPara.ulRealODOTime >> 10);
- cp_stBikeRunInfoPara.ulRiTime = 0;
- cp_stBikeRunInfoPara.ulRiTirpTime = 0;
- cp_stBikeRunInfoPara.ulRealODOTime = 0;
- mn_voEEHistoryParaUpdate();
- /* Error Log Write */
- flash_voErrorWrite(); //故障日志+历史信息
- flash_HistoryWrite();
- if (cp_stFlg.ParaSaveEEFlg == TRUE)
- {
- mn_voEEUperParaUpdate();
- cp_stFlg.ParaSaveEEFinishFlg = TRUE;
- cp_stFlg.ParaSaveEEFlg = FALSE;
- }
- flash_voSysParaWrite();
- flash_voProductParaWrite();
- cp_stFlg.ParaHistorySaveEEFinishFlg = TRUE;
- ENABLE_IRQ; /* MCU Core and GPIO configuration */
- }
- }
- }
- void PeripheralInit()
- {
- /* Pwm配置 */
- // iPwm_BindDeviceInterrupt(0, ApiPwm_CountZeroInt, tbc_voUpIsr);
- // iPwm_BindDeviceInterrupt(0, ApiPwm_CountMaxInt, tbc_voDownIsr);
- // iPwm_EnableDeviceInterrupt(0, ApiPwm_CountZeroInt);
- // iPwm_EnableDeviceInterrupt(0, ApiPwm_CountMaxInt);
- /* Tbs 定时器配置 */
- // iTimer_BindInterrupt(HW_TBS_TIMER, tbs_voIsr);
- //iTimer_EnableInterrupt(HW_TBS_TIMER);
-
- /* Event1ms 定时器配置 */
- // iTimer_BindInterrupt(HW_EVENT1MS_TIMER, Event_1ms);
- // iTimer_EnableInterrupt(HW_EVENT1MS_TIMER);
-
- /* 1ms 定时器配置 */
- // iTimer_BindInterrupt(HW_SYSTICK_TIMER, SysTask1Ms);
- // iTimer_EnableInterrupt(HW_SYSTICK_TIMER);
-
- // iCap_BindDeviceInterrupt(HW_BIKESPD_CAD_CAP,ic_voBikeSensorCntMaxIsr);
- // iCap_BindChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(2),ic_voCadenceIsr);
- // iCap_BindChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(3),ic_voBikeSpdIsr);
- // iCap_EnableDeviceInterrupt(HW_BIKESPD_CAD_CAP);
- // iCap_EnableChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(2));
- // iCap_EnableChannelInterrupt(HW_BIKESPD_CAD_CAP,CAP_CH(3));
- //
- // iCap_BindDeviceInterrupt(HW_MOTOR_HALL_CAP,ic_voHallCntMaxIsr);
- // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(0),ic_voHallCh1Isr);
- // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(1),ic_voHallCh2Isr);
- // iCap_BindChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(2),ic_voHallCh3Isr);
- // iCap_EnableDeviceInterrupt(HW_MOTOR_HALL_CAP);
- // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(0));
- // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(1));
- // iCap_EnableChannelInterrupt(HW_MOTOR_HALL_CAP,CAP_CH(2));
- }
- void PeripheralStart()
- {
- // iPwm_EnableCount(0);
- // iTimer_Start(HW_TBS_TIMER);
- // iTimer_Start(HW_SYSTICK_TIMER);
- }
|