PowerManagement_user.c 10.5 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include "PowerManagement.h"
#include "System_Monitor.h"
#include "Common_Interface.h"
#include "Data_CoolantTemperature.h"
#include "Data_VehicleSpeed.h"
#include "Data_EngineSpeed.h"
#include "Service_TPMS.h"
#include "Services_Mileage.h"
#include "Data_Gear.h"
#include "Data_Time.h"
#include "AC_TEMP.h"
#include "Service_OFF_Time.h"
#include "RTE_CAN_NM.h"
#include "Telltales.h"
#include "Line_in.h"
#include "Seg_Ref.h"
#include "Seatbelt.h"
#include "Door.h"
#include "Data_AirPressure.h"
#include "Key.h"
#include "Menu.h"
#include "Services_ODO_User.h"
#include "AvgSpeed.h"
#include "Maintenance.h"
#include "GaugesInterface.h"
#include "Popup_Scheduler.h"
#include "GPIO.h"
#include "dr7f701441.dvf.h"
#include "Sound_Scheduler.h"
#include "Sound_Player.h"
#include "RTE_PWM_OUT.h"
32
#include "BackLight_APP.h"
hu's avatar
hu committed
33 34
#include "Clock.h"
#include "TimerB.h"
hu's avatar
hu committed
35
#include "SEG_DISPLAY.h"
hu's avatar
hu committed
36 37 38 39 40 41 42 43 44
#include "CD4051.h"
#include "GaugesInterface.h"
#include "DisplaySch_user.h"
#include "Data_FuelConsump.h"
#include "IS31FL3236.h"

#include "GUI.h"
#include "Data_Fuel_User.h"

hu's avatar
hu committed
45
#include "app_Service.h"
hu's avatar
hu committed
46
#include "UART.h"
hu's avatar
hu committed
47 48 49 50
#include "kwp2000_tp.h"
#include "kwp2000_protocol.h"
#include "kwp2000_service.h"

51
#include "RTE_TIME.h"
52 53 54 55 56
#include "Watchdog.h"
#include "GenDelay.h"
#include "DoCAN_ISO15765.h"
#include "UDS_ISO14229_Server.h"
#include "Analog_Signals.h"
57

hu's avatar
hu committed
58 59 60 61 62 63 64 65 66 67 68
#define POWER_NM_SLEEP  0U
#define POWER_NM_WAKEUP 1U



static uint8_t PowerGetNMStatus(void);


Power_Status_t Power_KL30_Init ( void )
{
    Power_Status_t u8PowerSts;
69
    RTE_RTC_KL30_Init();
hu's avatar
hu committed
70
    CD4051B_KL15Init();
hu's avatar
hu committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    /*电源 指示灯 硬线 通用信息部分  赵建智 维护开始*/
    ClearNoInitArea();
    Common_DataInit();
    Sys_KL30_Init();
    Line_In_KL30_Init();
    Telltales_Left_Right_KL30_Init();
    Telltales_KL30_Init();
    SEG_BUFF_Init();
    DispSch_TotalInit();
    /*电源 指示灯 硬线 通用信息部分  赵建智 维护结束*/

    /*车速 转速 水温表头 初始化 田雨 维护开始*/
    UserGaugeK30Init();
    /*车速 转速 水温表头 初始化 田雨 维护开始*/

    /*里程 大小计部分 刘明月 胡志松 辛雨 维护开始*/
    Service_OFF_Timing_KL30Init();
    Data_User_Mileage_KL30Init();
    Data_AvgSpeed_KL30_Init();
    Data_Maintenance_Service_KL30_Init();
    /*里程 大小计部分 刘明月 胡志松 辛雨 维护结束*/

    /*室外温度 胎压部分  档位 清大计 报警 对时 胡迎秋 维护开始*/
    Data_AC_Temp_KL30_Init();
    Data_TPMS_KL30_Init();
    Data_Gear_KL30_Init();
    Data_ODO_Clear_KL30Init();
    /*室外温度 胎压部分  档位 清大计 报警 对时 胡迎秋 维护结束*/

    /*安全带 车门部分  李茂军维护开始*/
    SeatbeltInit();
    Door_WakeUpInit();
    /*安全带 车门部分  李茂军维护结束*/

    /*按键部分 杨真东维护开始*/
    Key_Init();

108 109 110
    VCC12V0_OUT_EN = 1U;        /*12V 电源使能*/
    VCC05V0_OUT_EN = 1U;        /*外设5V 电源使能*/
    D1530_EN_MCU_OUT = 1U;      /*1530 使能*/
hu's avatar
hu committed
111
    //BL_ACC_EN = 1U;       /*8867 使能*/
112 113
    Fuel_VCC05V_OUT_EN = 1U ;   /*燃油电源 使能*/
    AIR_5V_OUT_EN = 1u;         /*气压 5V*/
hu's avatar
hu committed
114
    ACC5V_LED_PWM_MCU = 1u;
hu's avatar
hu committed
115
    BUZZER_ACC_OUT_EN = 1u;
hu's avatar
hu committed
116

hu's avatar
hu committed
117
    IS31_Init();
hu's avatar
hu committed
118

hu's avatar
hu committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    Sound_Scheduler_Init();
    Sound_Player_Init();
    RTE_PWM_Init();
    /*按键部分 杨真东维护结束*/

    /*报警调度初始化*/
    Popup_Scheduler_Init();
    /*报警调度初始化*/

    /*5s不按按键计时清零*/
    //LongTimeNoKey_Operation_TimeRest();
    BL_Init();

    /*****油耗类****/
    Fuel_User_KL30_Init();
    u8PowerSts = m_IGN_OFF_Init;
    return  u8PowerSts;
}


void Power_Sleep_Init(void)
{
hu's avatar
hu committed
141
    /*数据*/
hu's avatar
hu committed
142 143 144 145
    Speed_Sleep_Init();
    Tacho_Sleep_Init();
    Coolant_Sleep_Init();

146 147 148
    /*燃油库睡眠前需要调用 ----20220503----*/
    Fuel_User_Sleep_Init();

hu's avatar
hu committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    /*外设*/
    Seg_Display_OFF();
    IS31_Shutdown();
    UART_Sleep_Init();
    Buzzer_Shutdown(); /*蜂鸣器*/
    TimerB_PWM_Channel_Sleep(TIMERB_0_CH15);
    TimerB_PWM_Channel_Sleep(TIMERB_2_CH1);
    TimerB_PWM_Channel_Sleep(TIMERB_2_CH7);
    TimerB_PWM_Channel_Sleep(TIMERB_1_CH15);

    VCC12V0_OUT_EN = 0u;        /*12V 电源使能*/
    VCC05V0_OUT_EN = 0u;        /*外设5V 电源使能*/
    D1530_EN_MCU_OUT = 0u;      /*1530 使能*/
    //BL_ACC_EN = 1U;             /*8867 使能*/
    Fuel_VCC05V_OUT_EN = 0u ;   /*燃油电源 使能*/
    AIR_5V_OUT_EN = 0u;         /*气压 5V*/
    ACC5V_LED_PWM_MCU = 0u;
    BUZZER_ACC_OUT_EN = 0u;

hu's avatar
hu committed
168 169 170 171 172 173
    GPIO_Init(GPIO_SLEEP_MODE );
}


Power_Status_t Power_Wakeup_Init ( void )
{
hu's avatar
hu committed
174 175
    Kwp2000_Init();

hu's avatar
hu committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    Power_Status_t u8PowerSts;
    /*电源 指示灯 硬线 通用信息部分  赵建智 维护开始*/
    Common_DataInit();
    Sys_WakeUp_Init();
    Line_In_KL30_Init();
    Telltales_Left_Right_KL30_Init();
    Telltales_KL30_Init();
    SEG_BUFF_Init();
    DispSch_TotalInit();
    /*电源 指示灯 硬线 通用信息部分  赵建智 维护结束*/
    Telltales_Wakeup_Init();
    Data_Time_WakeUp_Init();
    /*车速 转速 水温表头 初始化 田雨 维护开始*/
    UserGaugeK30Init();
    /*车速 转速 水温表头 初始化 田雨 维护开始*/
    Data_User_Mileage_KL15Init();
    Maintenance_WakeUp_Init();
    /*安全带 车门部分  李茂军维护开始*/
    SeatbeltInit();
    Door_WakeUpInit();
    /*安全带 车门部分  李茂军维护结束*/
    RTE_PWM_Init();

199 200 201
    /*燃油新增 ----20220503----*/
    Fuel_User_Wakeup_Init();

hu's avatar
hu committed
202 203 204
    VCC12V0_OUT_EN = 1u;        /*12V 电源使能*/
    VCC05V0_OUT_EN = 1u;        /*外设5V 电源使能*/
    D1530_EN_MCU_OUT = 1u;      /*1530 使能*/
hu's avatar
hu committed
205
    //BL_ACC_EN = 1U;             /*8867 使能*/
hu's avatar
hu committed
206
    Fuel_VCC05V_OUT_EN = 1u ;   /*燃油电源 使能*/
207
    AIR_5V_OUT_EN = 1u;         /*气压 5V*/
hu's avatar
hu committed
208
    ACC5V_LED_PWM_MCU = 1u;
hu's avatar
hu committed
209
    BUZZER_ACC_OUT_EN = 1u;
210

hu's avatar
hu committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
    IS31_Init();
    /*报警调度初始化*/
    Popup_Scheduler_Init();
    /*报警调度初始化*/
    Sound_Scheduler_Init();
    Sound_Player_Init();
    u8PowerSts = m_IGN_OFF_Init;
    return  u8PowerSts;
}




void Power_IG_OFF_Init(void)
{
    Line_In_KL15_OFF_Init();
    Speed_KL15_OFF_Init();
    Tacho_KL15_OFF_Init();
    Coolant_KL15_OFF_Init();
    //Maintenance_KL15_OFF_Init();
    /*表头参数初始OFF下调用 added by yutian*/
    GaugesK15Init_OFF() ;/*仪表IGOFF调用*/
    /*end*/
    /*报警调度*/
    Popup_Scheduler_OFF();
    //Menu_Init_IG(0u);
    GUI_Display_KL15_OFF_Init();
hu's avatar
hu committed
238 239 240

    /*关闭所有断码*/
    Seg_Display_OFF();
hu's avatar
hu committed
241 242 243
}
void Power_IG_ON_Init(void)
{
hu's avatar
hu committed
244
    Kwp2000_Init();
hu's avatar
hu committed
245
    DiagnosisInit_main();
hu's avatar
hu committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259
    Data_ODO_Clear_KL15Init();
    Telltales_KL15_Init();
    Line_In_KL15_ON_Init();
    Coolant_KL15_ON_Init();
    Data_Time_KL15_Init();
    Data_AC_Temp_KL15_Init();
    Data_TPMS_KL15_ON_Init();
    Service_OFF_Timing_KL15Init();
    Tacho_KL15_ON_Init();
    Speed_KL15_ON_Init();
    Data_Gear_KL15_Init();
    /*表头数据处理 added by yutian*/
    UserGaugeK15Init() ;/*仪表IGON调用*/
    /*end*/
hu's avatar
hu committed
260
    CD4051B_KL15Init();
hu's avatar
hu committed
261 262
    /*5s不按按键计时清零*/
    //LongTimeNoKey_Operation_TimeRest();
263

hu's avatar
hu committed
264
    DispSch_TotalInit();
hu's avatar
hu committed
265
    GUI_Display_KL15_ON_Init();
266 267 268

    /*气压1 气压2 WET气压数据初始化*/
    AirPressure_KL15_ON_Init();
hu's avatar
hu committed
269
}
270

hu's avatar
hu committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
Power_Status_t Power_Stay_ON(void)
{
    Power_Status_t u8PowerSts;
    uint8_t u8Condition1;
    uint8_t u8Condition2;
    uint8_t u8Condition3;
    u8Condition1 = Common_Get_IG_Sts() ;
    u8Condition2 = Common_Get_IG_Sts_Valid();
    u8Condition3 = System_FUN_KL30_Status_Get();
    if ((u8Condition1 == COMMON_POWER_ON ) && ( u8Condition2 == COMMON_Valid))
    {
        u8PowerSts = m_IGN_ON;
    }
    else
    {
        if ((u8Condition1 == COMMON_POWER_OFF ) && (u8Condition2 == COMMON_Valid))
        {
            u8PowerSts = m_IGN_OFF_Init;
        }
        else
        {
            u8PowerSts = m_IGN_ON;
        }
    }
    if (((u8Condition3 == 1u) || (u8Condition3 >= 7u)))
    {
        u8PowerSts = m_IGN_LIMIT;
    }
    return  u8PowerSts;
}

Power_Status_t Power_Stay_OFF(void)
{
    Power_Status_t u8PowerSts;
    uint8_t u8Condition1;
    uint8_t u8Condition2;
307 308
    uint32_t Get_Menu_Off_Time;

hu's avatar
hu committed
309 310
    u8Condition1 = Common_Get_IG_Sts() ;
    u8Condition2 = Common_Get_IG_Sts_Valid();
311
    Get_Menu_Off_Time = Coom_Get_Menu_Off_Time();
hu's avatar
hu committed
312 313 314 315 316 317 318 319 320

    if ((u8Condition1 == COMMON_POWER_ON ) && (u8Condition2 == COMMON_Valid))
    {
        u8PowerSts = m_IGN_ON_Init;
    }
    else
    {
        if ((u8Condition1 == COMMON_POWER_OFF ) && (u8Condition2 == COMMON_Valid))
        {
321 322 323 324 325
            if (
                (PowerGetNMStatus() == POWER_NM_SLEEP) &&
                (LED_WAKEUP == LEVEL_LOW) &&
                (Get_Menu_Off_Time >= 150100u)
            )
hu's avatar
hu committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
            {
                u8PowerSts = m_IGN_Sleep_Init;
            }
            else
            {
                u8PowerSts = m_IGN_OFF;
            }
        }
        else
        {
            u8PowerSts = m_IGN_OFF;
        }
    }
    return  u8PowerSts;
}



Power_Status_t  Power_Stay_Protect(void)
{
hu's avatar
hu committed
346
    Power_Status_t u8PowerSts = m_IGN_OFF_Init;
347 348
	uint32_t Delaycnt = 0;
    /*关应用 123……*/
hu's avatar
hu committed
349

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

    for (;;)
    {
        /*喂狗*/
        WDT_Clear( );
        //CAN_SET_APP_SEND(1u);
        //CAN_SET_NM_SEND(1u);
        CAN_TX_SetEnable(0);
        /*一定周期调用2ms*/
        //Gen_TimeDelay(2000u, 50u);
        DoCAN_Communication_Service( );
        UDS_Server_Application_Service( );
        UDS_10ms_Service( );
        //RTE_ADC_Services( );
        Analog_Signal_Conv_Service();
        Sys_Status_Update_Service( );
        Delaycnt++;
        if ( Delaycnt >= 5u )
        {
            Delaycnt = 0u;
            Can_BusOff_Fun();
        }
        /*- 电源模式正常,退出 -*/
        if ( SYS_OPR_STAT_RUN )
        {
            //CAN_SET_APP_SEND(0u);
            //CAN_SET_NM_SEND(0u);
            CAN_TX_SetEnable(0x55);
            /*初始化需要*/
            //BackLight_30_Init( );
            return u8PowerSts;
        }
    }
hu's avatar
hu committed
383

hu's avatar
hu committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
    return  u8PowerSts;
}



Power_Status_t Power_Stay_Sleep ( void )
{
    Power_Status_t u8PowerSts;

    Sys_Enter_Sleep_Mode();




    u8PowerSts = m_IGN_OFF_Init;
    return  u8PowerSts;
}


static uint8_t PowerGetNMStatus(void)
{
    uint8_t u8NMStatus = 0U;
    NM_Mode_t m_condition;
    m_condition = RTE_CAN_NM_GetStatus();

    if (m_condition == NM_Mode_Sleep)
    {
        u8NMStatus = POWER_NM_SLEEP;
    }
    else
    {
        u8NMStatus = POWER_NM_WAKEUP;
    }


419

hu's avatar
hu committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436

    return u8NMStatus;
}




void ClearNoInitArea(void)
{
    uint32_t  *pRam;
    uint32_t  p;
    pRam = (unsigned int*)0x3FCE4000ul;
    for (p = 0ul; p < 4096ul; p ++)
    {
        pRam[ p ] = 0ul;
    }
}