/**
    @copyright None
    @file      control.c
    @author    Comment Vivre
    @date      2025-12-29
    @brief     None
*/
#include <MyProject.h>

Start_Test_t xdata startTest;
/**
    @function     Motor_Start_Test
    @brief        电机启动测试
    @date         2025-12-23
*/
void Motor_Start_Test(void)
{
    // 有故障 结束测试
    if (FaultSource != SYS_NO_FAULT)
    {
        startTest.State = TEST_FAULT;
        isCtrlPowOn = false;
        startTest.RunTime = 0;
        startTest.StopTime = 0;
    }
    
    switch (startTest.State)
    {
        // 停止
        case TEST_MOTOR_STOP:
            isCtrlPowOn = false;
            loopCtrl.TargetRef = 0;
            
            if (++startTest.StopTime > MOTOR_STOP_TIME)
            {
                startTest.StopTime = 0;
                startTest.State = TEST_MOTOR_START;
            }
            
            break;
            
        // 启动
        case TEST_MOTOR_START:
            isCtrlPowOn = true;
            loopCtrl.TargetRef = MOTOR_START_TEST_SPEED;
            
            if (++startTest.RunTime > MOTOR_RUN_TIME)
            {
                startTest.RunTime = 0;
                startTest.State = TEST_MOTOR_STOP;
            }
            
            break;
            
        case TEST_FAULT:
            break;
    }
}

/**
    @function     Get_Target_Ref
    @brief        速度给定
    @date         2025-11-01
*/
void Get_Target_Ref(void)
{
    #if (SPEED_MODE == NONEMODE)
    isCtrlPowOn = true;
    loopCtrl.TargetRef = _Q15(3500.0 / MOTOR_SPEED_BASE);
    #elif (SPEED_MODE == PWMMODE)
    Input_Capture_Calc();
    #elif (SPEED_MODE == STARTTEST)
    Motor_Start_Test();
    #endif
}



