1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-03 13:22:33 +00:00

feat(core): extend power manager backup ram data with battery critical flag

[no changelog]
This commit is contained in:
kopecdav 2025-05-05 11:26:49 +02:00 committed by kopecdav
parent 8e7d5a2a01
commit 19948372c7
3 changed files with 18 additions and 14 deletions

View File

@ -45,6 +45,7 @@ typedef enum {
*/
typedef struct {
float soc; // Captured state of charge <0, 1>
bool bat_critical;
// Captures RTC time at which SOC was captured
uint32_t last_capture_timestamp;
// Captures power manager state at bootloader exit so it could be correctly

View File

@ -30,6 +30,7 @@
#ifdef USE_OPTIGA
#include <sec/optiga_config.h>
#include <sec/optiga_hal.h>
#include <sec/optiga_transport.h>
#endif
@ -76,17 +77,15 @@ pm_status_t pm_control_hibernate() {
}
// Wait for the device to power off
systick_delay_ms(50);
//systick_delay_ms(50);
return PM_ERROR;
}
void pm_control_suspend(){
// Clear all wakeup flags. From this point, any wakeup event that
// sets a wakeup flag causes this function to return.
pm_wakeup_flags_reset();
void pm_control_suspend() {
// Clear all wakeup flags. From this point, any wakeup event that
// sets a wakeup flag causes this function to return.
pm_wakeup_flags_reset();
// Deinitialize all drivers that are not required in low-power mode
// (e.g., USB, display, touch, haptic, etc.).
@ -122,9 +121,8 @@ pm_wakeup_flags_reset();
pm_wakeup_flags_t wakeup_flags = 0;
while (true) {
pm_wakeup_flags_get(&wakeup_flags);
if(wakeup_flags != 0) {
if (wakeup_flags != 0) {
// If any wakeup flag is set, exit the loop.
break;
}
@ -148,9 +146,8 @@ pm_wakeup_flags_reset();
} while (!pm_background_tasks_suspended() && (wakeup_flags == 0));
if (true) {
pm_wakeup_flags_get(&wakeup_flags);
if(wakeup_flags != 0) {
if (wakeup_flags != 0) {
// If any wakeup flag is set, exit the loop.
break;
}
@ -214,7 +211,6 @@ pm_wakeup_flags_reset();
}
static void pm_background_tasks_suspend(void) {
// stwlc38
// npm1300
@ -225,4 +221,4 @@ static void pm_background_tasks_suspend(void) {
static bool pm_background_tasks_suspended(void) { return true; }
static void pm_background_tasks_resume(void) {}
static void pm_background_tasks_resume(void) {}

View File

@ -117,6 +117,8 @@ void pm_monitor_power_sources(void) {
// Process state machine with updated battery and power source information
pm_process_state_machine();
pm_store_data_to_backup_ram();
// Request fresh measurements
npm1300_measure(pm_pmic_data_ready, NULL);
drv->pmic_measurement_ready = false;
@ -252,7 +254,12 @@ void pm_store_power_manager_data(pm_driver_t* drv) {
backup_ram_power_manager_data_t pm_data = {0};
// Store the current state of the power manager
pm_data.soc = drv->fuel_gauge.soc;
if (drv->battery_critical) {
pm_data.soc = 0;
} else {
pm_data.soc = drv->fuel_gauge.soc;
}
pm_data.bat_critical = drv->battery_critical;
pm_data.last_capture_timestamp = systick_ms();
// Store the data in backup RAM