|
38 | 38 | #define RETRYSLEEP (300 * 1000) //Retry sleep |
39 | 39 |
|
40 | 40 | #ifdef USE_PREINIT_DECODING |
| 41 | +static IARM_Bus_PWRMgr_PowerState_t prevState; |
41 | 42 | static void IARM_PowerChangeHandler (const PowerController_PowerState_t currentState, |
42 | 43 | const PowerController_PowerState_t newState, void* userdata); |
43 | 44 | #endif |
@@ -100,6 +101,21 @@ void getPwrContInterface() |
100 | 101 | } |
101 | 102 | usleep(RETRYSLEEP); // 300ms |
102 | 103 | } |
| 104 | + |
| 105 | + IARM_Bus_PWRMgr_PowerState_t curState; |
| 106 | + if (IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, |
| 107 | + IARM_BUS_PWRMGR_API_GetPowerState, |
| 108 | + &curState, |
| 109 | + sizeof(curState)) == IARM_RESULT_SUCCESS) |
| 110 | + { |
| 111 | + prevState = curState; |
| 112 | + MW_LOG_INFO("Initialized prevState = %d", prevState); |
| 113 | + } |
| 114 | + else { |
| 115 | + prevState = IARM_BUS_PWRMGR_POWERSTATE_ON; // fallback |
| 116 | + MW_LOG_ERR("Failed to get current power state, defaulting to ON"); |
| 117 | + } |
| 118 | + |
103 | 119 | MW_LOG_INFO("Registering power mode change callback..."); |
104 | 120 | PowerController_RegisterPowerModeChangedCallback(IARM_PowerChangeHandler, nullptr); |
105 | 121 |
|
@@ -143,12 +159,16 @@ static void IARM_PowerChangeHandler (const PowerController_PowerState_t currentS |
143 | 159 | { |
144 | 160 | MW_LOG_INFO("Entering IARM_PowerChangeHandler:State Changed currentState: %d, newState: %d", |
145 | 161 | currentState, newState); |
| 162 | + |
| 163 | + bool isOnOrStandby = (newState == IARM_BUS_PWRMGR_POWERSTATE_ON || newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY); |
146 | 164 |
|
147 | | - if(currentState == POWER_STATE_STANDBY_DEEP_SLEEP && newState != POWER_STATE_STANDBY_DEEP_SLEEP ) |
| 165 | + if((currentState == POWER_STATE_STANDBY_DEEP_SLEEP && isOnOrStandby) || |
| 166 | + (prevState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP && curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP && isOnOrStandby) ) |
148 | 167 | { |
149 | 168 | MW_LOG_INFO(" DEEPSLEEP : calling triggerFakeTune \n"); |
150 | 169 | triggerFakeTune(); |
151 | 170 | } |
| 171 | + prevState = currentState; |
152 | 172 |
|
153 | 173 | MW_LOG_INFO("Exiting IARM_PowerChangeHandler.."); |
154 | 174 | } |
|
0 commit comments