mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-26 18:02:35 +00:00
refactor(core): remove recursion from power manager state machine automat
[no changelog]
This commit is contained in:
parent
a530fb2c76
commit
48ef573649
@ -328,17 +328,15 @@ void prodtest_pm_precharge(cli_t* cli) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test consider that the device is connected with USB and placed in
|
// This test considers that the device is connected via USB and placed at
|
||||||
// ambient temperature. Battery will be charged with constanst current
|
// ambient temperature. The battery will be charged with constant current,
|
||||||
// and precharge voltage is statically taken from the battery chaging curve
|
// and the precharge voltage is statically derived from the battery charging
|
||||||
//
|
// curve.
|
||||||
// It is expected that battery voltage during the charging is being lifted
|
|
||||||
// due to effect of internal resistance of the battery. So battery voltage
|
|
||||||
// will drop a bit after the charging is stopped.
|
|
||||||
|
|
||||||
// voltage while charging is being lifted due to charging with quite high
|
// During charging, the voltage rises because of the relatively high charging
|
||||||
// charging current. When the test terminate by reaching the given woltage.
|
// current. When the test ends upon reaching the specified precharge voltage,
|
||||||
// The current and
|
// the charging current is cut off, which can cause the battery voltage to
|
||||||
|
// fall slightly.
|
||||||
float precharge_voltage_V = 3.45f;
|
float precharge_voltage_V = 3.45f;
|
||||||
|
|
||||||
pm_charging_enable();
|
pm_charging_enable();
|
||||||
@ -359,16 +357,13 @@ void prodtest_pm_precharge(cli_t* cli) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cli_trace(cli, "Battery voltage: %d.%03d V -> taret %d.%03d V",
|
cli_trace(cli, "Precharging the device to %d.%03d V",
|
||||||
(int)report.battery_voltage_v,
|
|
||||||
(int)(report.battery_voltage_v * 1000) % 1000,
|
|
||||||
(int)precharge_voltage_V,
|
|
||||||
(int)(precharge_voltage_V * 1000) % 1000);
|
|
||||||
cli_progress(cli, "%d.%03d %d.%03d", (int)report.battery_voltage_v,
|
|
||||||
(int)(report.battery_voltage_v * 1000) % 1000,
|
|
||||||
(int)precharge_voltage_V,
|
(int)precharge_voltage_V,
|
||||||
(int)(precharge_voltage_V * 1000) % 1000);
|
(int)(precharge_voltage_V * 1000) % 1000);
|
||||||
|
|
||||||
|
// Print power manager report.
|
||||||
|
prodtest_pm_report(cli);
|
||||||
|
|
||||||
if (cli_aborted(cli)) {
|
if (cli_aborted(cli)) {
|
||||||
cli_trace(cli, "aborted");
|
cli_trace(cli, "aborted");
|
||||||
break;
|
break;
|
||||||
|
@ -67,12 +67,18 @@ static const pm_state_handler_t state_handlers[] = {
|
|||||||
|
|
||||||
void pm_process_state_machine(void) {
|
void pm_process_state_machine(void) {
|
||||||
pm_driver_t* drv = &g_pm;
|
pm_driver_t* drv = &g_pm;
|
||||||
pm_internal_state_t old_state = drv->state;
|
pm_internal_state_t old_state;
|
||||||
|
pm_internal_state_t new_state;
|
||||||
|
|
||||||
// Get next state from current state's handler
|
// Loop until state machine converge to a stable state
|
||||||
pm_internal_state_t new_state = state_handlers[old_state].handle(drv);
|
while (true) {
|
||||||
|
// Get current state
|
||||||
|
old_state = drv->state;
|
||||||
|
|
||||||
// Handle state transition if needed
|
// Call state handler to process the current state
|
||||||
|
new_state = state_handlers[old_state].handle(drv);
|
||||||
|
|
||||||
|
// Check if the state has changed
|
||||||
if (new_state != old_state) {
|
if (new_state != old_state) {
|
||||||
// Exit old state
|
// Exit old state
|
||||||
if (state_handlers[old_state].exit != NULL) {
|
if (state_handlers[old_state].exit != NULL) {
|
||||||
@ -88,8 +94,10 @@ void pm_process_state_machine(void) {
|
|||||||
state_handlers[new_state].enter(drv);
|
state_handlers[new_state].enter(drv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process state machine again as new state might trigger another transition
|
} else {
|
||||||
pm_process_state_machine();
|
// State has not changed, exit the loop
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user