PowerManag_user.c 4.9 KB
Newer Older
时昊's avatar
时昊 committed
1 2 3
#include "PowerManagement.h"
#include "Components.h"

4
//RTC_Information_st_t g_stRTCInformation;
时昊's avatar
时昊 committed
5 6 7 8 9 10 11 12

static void Power_KL30_Init(void);
static void Power_Wakeup_Init(void);
static void Power_LVP_Init(void);
static void Power_OVP_Init(void);
static void Power_IG_OFF_Init(void);
static void Power_IG_ON_Init(void);
static void Power_Sleep_Init(void);
13

时昊's avatar
时昊 committed
14 15 16 17 18
static Power_Status_em Power_Stay_ON(void);
static Power_Status_em Power_Stay_OFF(void);
static Power_Status_em Power_Stay_Protect(void);
static Power_Status_em Power_Stay_Sleep(void);

19 20


时昊's avatar
时昊 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
static const st_PowerGroup g_stPwrTasks = {
    Power_KL30_Init,
    Power_IG_OFF_Init,
    Power_Stay_OFF,
    Power_Sleep_Init,
    Power_Stay_Sleep,
    Power_Wakeup_Init,
    Power_IG_ON_Init,
    Power_Stay_ON,
    Power_LVP_Init,
    Power_OVP_Init,
    Power_Stay_Protect,
};

void PwrMemInit(void)
{
    PowerMemInit(&g_stPwrTasks);
}

static void Power_KL30_Init(void)
{
//    ClearODO_Flag = 0;
43
    UART_Channel_Config_st_t loc_config;
时昊's avatar
时昊 committed
44
    eeprom_StoreInfo_Init();
45 46 47 48 49
    loc_config.u32UARTChEn            = 1U;
    loc_config.u32UARTbps             = 115200U;
    loc_config.pfnUARTConfirmCallBack = NULL;
    loc_config.pfnUARTReadMsgCallBack = Amt630hUartRecvData;
    RTE_UART_Init(UART_CH2, &loc_config);
时昊's avatar
时昊 committed
50
    Analog_Signal_Conv_Init();
51
    Sys_KL30_Init();
52 53
    Data_Vehicle_Speed_KL30_Wakeup_Init();
    Data_Engine_Speed_KL30_Wakeup_Init();
54 55
    LINE_IN_Init();
    Key_KL30_Init_EXample();
时昊's avatar
时昊 committed
56
    Data_User_Mileage_KL30Init();
57 58 59 60
    Fuel_KL30_Init();
    Amt630hInit();
    TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 64000000);
    TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
61 62 63 64 65 66 67 68 69 70


//    g_stRTCInformation.u8RTCSecond = 0;
//	g_stRTCInformation.u8RTCMinute = 0;
//	g_stRTCInformation.u8RTCHour = 0;          
//	g_stRTCInformation.u8RTCDayOfMonth = 1;
//	g_stRTCInformation.u8RTCMonth = 1;   
//	g_stRTCInformation.u8RTCYear = 20; 
//    RTE_RTC_Init(g_stRTCInformation);
//    RTE_DEEPSLEEP_GPIO_Interrupt_Enable(WAKEUP_KL15_In,Trigger_Rising);
时昊's avatar
时昊 committed
71
    Protocol_KL30_Wakeup_Init();
72

73 74
}
//extern uint32_t PowerIgnOffTimeLine;
时昊's avatar
时昊 committed
75 76
static void Power_Wakeup_Init(void)
{
77 78
//    PowerIgnOffTimeLine = 0;

时昊's avatar
时昊 committed
79
    Gpio_Init(Gpio_WakeUp_Init);
80

时昊's avatar
时昊 committed
81 82 83
    eeprom_StoreInfo_Init();
    Analog_Signal_Conv_Init();
    Data_User_Mileage_WakeupInit();
84 85 86 87 88 89 90 91 92 93 94 95 96

   Sys_WakeUp_Init();
   Data_Vehicle_Speed_KL30_Wakeup_Init();
   Data_Engine_Speed_KL30_Wakeup_Init();
   LINE_IN_Init();
   Key_Wakeup_Init_EXample();
   Line_In_KL15_ON_Init();
   Fuel_KL30_Init();
   Amt630hInit();
   TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 64000000);
   TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
   //Telltales_Init();
//    RTE_DEEPSLEEP_GPIO_Interrupt_Enable(WAKEUP_KL15_In,Trigger_Rising);
时昊's avatar
时昊 committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    Protocol_KL30_Wakeup_Init();
}

static void Power_LVP_Init(void)
{
    
}
static void Power_OVP_Init(void)
{
    
}

static void Power_IG_OFF_Init(void)
{
   Line_In_KL15_OFF_Init();
112

时昊's avatar
时昊 committed
113 114 115 116 117 118
}

static void Power_IG_ON_Init(void)
{
//    ClearODO_Flag = 0;
   Line_In_KL15_ON_Init();
119
   Telltales_KL15_Init();
时昊's avatar
时昊 committed
120 121 122 123 124 125
   Fuel_KL15_Init();
}

static void Power_Sleep_Init(void)
{
    TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 0);
126 127
//	//RTC_Stop();
//	rte_can_deinit(CAN_CH_0);
时昊's avatar
时昊 committed
128 129 130
	TMM0_Stop();
	TMM1_Stop();
    TMM_All_Stop();
131 132 133
   RTE_ADC_DeInit();
//	//CGC->CSC = 1 ;   //HIOSTOP = 1

时昊's avatar
时昊 committed
134
    Gpio_Init(Gpio_Sleep_Init);
135
    AMT630H_Sleep();
136 137 138
   
   Analog_Signal_Conv_Stop();
//    RTE_DEEPSLEEP_Enable();
时昊's avatar
时昊 committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
}

static Power_Status_em Power_Stay_ON(void)
{
    Power_Status_em u8PowerSts;
    u8PowerSts = EM_IGN_ON;

   if (SYS_OPR_STAT_IGN_OFF)
   {
       u8PowerSts = EM_IGN_OFF_Init;
   }

   if (SYS_OPR_STAT_HALT)
   {
       u8PowerSts = EM_IGN_LIMIT;
   }

    return u8PowerSts;
}
static Power_Status_em Power_Stay_OFF(void)
{
    Power_Status_em u8PowerSts;
    u8PowerSts = EM_IGN_OFF;

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
   if (SYS_OPR_STAT_IGN_ON)
   {
       u8PowerSts = EM_IGN_ON_Init;
   }
   else
   {
       if ((Common_GetIgnOffTime() < 20000))
       {
           u8PowerSts = EM_IGN_OFF;
       }
       else
       {
           u8PowerSts = EM_IGN_Sleep_Init;
       }
   }
时昊's avatar
时昊 committed
178 179 180 181 182 183

    return u8PowerSts;
}

static Power_Status_em Power_Stay_Protect(void)
{
184
   Power_Status_em u8PowerSts;
时昊's avatar
时昊 committed
185
//    static uint8_t  i;
186
   static uint8_t  Delaycnt;
时昊's avatar
时昊 committed
187 188


189 190 191
   /* 关闭所有外设,坪保留AD采集,电溝状思切�? */
   {

时昊's avatar
时昊 committed
192
        TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 0);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
   }
   u8PowerSts = EM_IGN_OFF_Init;
   /* 电溝模弝正常 */
   for ( ;; )
   {
       RTE_WDT_Clear();
       Gen_TimeDelay(2000u, 50u);
       Analog_Signal_Conv_Service();
       Sys_Status_Update_Service();

       if ( SYS_OPR_STAT_RUN )
       {
           return u8PowerSts;
       }
   }
时昊's avatar
时昊 committed
208 209 210 211 212 213
}

static Power_Status_em Power_Stay_Sleep(void)
{
    Power_Status_em u8PowerSts = EM_IGN_Sleep;

214 215 216 217 218 219 220 221 222
   while (1)
   {
       RTE_WDT_Clear();
       if (RTE_GPIO_Get_Level(KL15_AD_IN))/* KL15 */
       {
           u8PowerSts = EM_IGN_Wakeup;
           break;
       }
   }
时昊's avatar
时昊 committed
223 224 225 226 227

    return u8PowerSts;
}