mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-25 09:22:33 +00:00
refactor(core): refactor power manager syscalls
[no changelog]
This commit is contained in:
parent
0cd38186bf
commit
6e82c2415f
@ -46,7 +46,7 @@ FEATURE_FLAGS = {
|
|||||||
"AES_GCM": BENCHMARK or THP,
|
"AES_GCM": BENCHMARK or THP,
|
||||||
}
|
}
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic", "ble", "tropic", "powerctl", "display"]
|
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic", "ble", "tropic", "power_manager", "display"]
|
||||||
if DISABLE_OPTIGA:
|
if DISABLE_OPTIGA:
|
||||||
if PYOPT != '0':
|
if PYOPT != '0':
|
||||||
raise RuntimeError("DISABLE_OPTIGA requires PYOPT=0")
|
raise RuntimeError("DISABLE_OPTIGA requires PYOPT=0")
|
||||||
|
@ -30,7 +30,7 @@ FEATURE_FLAGS = {
|
|||||||
"AES_GCM": True,
|
"AES_GCM": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic", "ble", "tropic", "powerctl", "display", "applet"]
|
FEATURES_WANTED = ["input", "sd_card", "rgb_led", "dma2d", "consumption_mask", "usb" ,"optiga", "haptic", "ble", "tropic", "power_manager", "display", "applet"]
|
||||||
if DISABLE_OPTIGA:
|
if DISABLE_OPTIGA:
|
||||||
# TODO use PYOPT instead of PRODUCTION, same as in firmware, blocked on #4253
|
# TODO use PYOPT instead of PRODUCTION, same as in firmware, blocked on #4253
|
||||||
if PRODUCTION:
|
if PRODUCTION:
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include "battery_model.h"
|
#include "battery_model.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -282,3 +283,5 @@ float battery_soc(float ocv, float temperature, bool discharging_mode) {
|
|||||||
: BATTERY_OCV_CHARGE_PARAMS[0];
|
: BATTERY_OCV_CHARGE_PARAMS[0];
|
||||||
return calc_soc_from_ocv(params, ocv);
|
return calc_soc_from_ocv(params, ocv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
#include "fuel_gauge.h"
|
#include "fuel_gauge.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "battery_model.h"
|
#include "battery_model.h"
|
||||||
@ -142,3 +142,5 @@ float fuel_gauge_update(fuel_gauge_state_t* state, uint32_t dt_ms,
|
|||||||
|
|
||||||
return state->soc_latched;
|
return state->soc_latched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include <trezor_bsp.h>
|
#include <trezor_bsp.h>
|
||||||
#include <trezor_rtl.h>
|
#include <trezor_rtl.h>
|
||||||
@ -234,3 +235,5 @@ static void pm_background_tasks_suspend(void) {
|
|||||||
static bool pm_background_tasks_suspended(void) { return true; }
|
static bool pm_background_tasks_suspended(void) { return true; }
|
||||||
|
|
||||||
static void pm_background_tasks_resume(void) {}
|
static void pm_background_tasks_resume(void) {}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include <sys/backup_ram.h>
|
#include <sys/backup_ram.h>
|
||||||
#include <sys/irq.h>
|
#include <sys/irq.h>
|
||||||
@ -415,3 +416,5 @@ static void pm_shutdown_timer_handler(void* context) {
|
|||||||
drv->shutdown_timer_elapsed = true;
|
drv->shutdown_timer_elapsed = true;
|
||||||
pm_process_state_machine();
|
pm_process_state_machine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include <sys/backup_ram.h>
|
#include <sys/backup_ram.h>
|
||||||
#include <sys/pmic.h>
|
#include <sys/pmic.h>
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
#include <io/backlight.h>
|
#include <io/backlight.h>
|
||||||
#include <sys/bootutils.h>
|
#include <sys/bootutils.h>
|
||||||
@ -275,3 +276,5 @@ void pm_exit_shutting_down(pm_driver_t* drv) {
|
|||||||
systimer_unset(drv->shutdown_timer);
|
systimer_unset(drv->shutdown_timer);
|
||||||
drv->shutdown_timer_elapsed = false;
|
drv->shutdown_timer_elapsed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#ifdef KERNEL_MODE
|
#ifdef KERNEL_MODE
|
||||||
|
|
||||||
// Battery powered devices (USE_POWERCTL) should not stall
|
// Battery powered devices (USE_POWER_MANAGER) should not stall
|
||||||
// after showing RSOD, as it would drain the battery.
|
// after showing RSOD, as it would drain the battery.
|
||||||
#ifdef USE_POWER_MANAGER
|
#ifdef USE_POWER_MANAGER
|
||||||
#ifdef RSOD_INFINITE_LOOP
|
#ifdef RSOD_INFINITE_LOOP
|
||||||
|
@ -61,8 +61,8 @@
|
|||||||
#include <sec/optiga.h>
|
#include <sec/optiga.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWER_MANAGER
|
||||||
#include <sys/powerctl.h>
|
#include <sys/power_manager.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_RGB_LED
|
#ifdef USE_RGB_LED
|
||||||
@ -732,18 +732,18 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args,
|
|||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWER_MANAGER
|
||||||
case SYSCALL_POWERCTL_SUSPEND: {
|
case SYSCALL_POWER_MANAGER_SUSPEND: {
|
||||||
powerctl_suspend();
|
args[0] = pm_suspend();
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SYSCALL_POWERCTL_HIBERNATE: {
|
case SYSCALL_POWER_MANAGER_HIBERNATE: {
|
||||||
args[0] = powerctl_hibernate();
|
args[0] = pm_hibernate();
|
||||||
}
|
}
|
||||||
|
|
||||||
case SYSCALL_POWERCTL_GET_STATUS: {
|
case SYSCALL_POWER_MANAGER_GET_STATE: {
|
||||||
powerctl_status_t *status = (powerctl_status_t *)args[0];
|
pm_state_t *status = (pm_state_t *)args[0];
|
||||||
args[0] = powerctl_get_status__verified(status);
|
args[0] = pm_get_state__verified(status);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -149,9 +149,9 @@ typedef enum {
|
|||||||
SYSCALL_BLE_CAN_READ,
|
SYSCALL_BLE_CAN_READ,
|
||||||
SYSCALL_BLE_READ,
|
SYSCALL_BLE_READ,
|
||||||
|
|
||||||
SYSCALL_POWERCTL_SUSPEND,
|
SYSCALL_POWER_MANAGER_SUSPEND,
|
||||||
SYSCALL_POWERCTL_HIBERNATE,
|
SYSCALL_POWER_MANAGER_HIBERNATE,
|
||||||
SYSCALL_POWERCTL_GET_STATUS,
|
SYSCALL_POWER_MANAGER_GET_STATE,
|
||||||
|
|
||||||
SYSCALL_JPEGDEC_OPEN,
|
SYSCALL_JPEGDEC_OPEN,
|
||||||
SYSCALL_JPEGDEC_CLOSE,
|
SYSCALL_JPEGDEC_CLOSE,
|
||||||
|
@ -680,24 +680,27 @@ uint32_t ble_read(uint8_t *data, uint16_t len) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// powerctl.h
|
// power_manager.h
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWER_MANAGER
|
||||||
|
|
||||||
#include <sys/powerctl.h>
|
#include <sys/power_manager.h>
|
||||||
|
|
||||||
void powerctl_suspend(void) { syscall_invoke0(SYSCALL_POWERCTL_SUSPEND); }
|
pm_status_t pm_suspend(void) {
|
||||||
|
return (pm_status_t)syscall_invoke0(SYSCALL_POWER_MANAGER_SUSPEND);
|
||||||
bool powerctl_hibernate(void) {
|
|
||||||
return (bool)syscall_invoke0(SYSCALL_POWERCTL_HIBERNATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerctl_get_status(powerctl_status_t *status) {
|
pm_status_t pm_hibernate(void) {
|
||||||
return (bool)syscall_invoke1((uint32_t)status, SYSCALL_POWERCTL_GET_STATUS);
|
return (pm_status_t)syscall_invoke0(SYSCALL_POWER_MANAGER_HIBERNATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_POWERCTL
|
pm_status_t pm_get_status(pm_state_t *status) {
|
||||||
|
return (pm_status_t)syscall_invoke1((uint32_t)status,
|
||||||
|
SYSCALL_POWER_MANAGER_GET_STATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USE_POWER_MANAGER
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// jpegdec.h
|
// jpegdec.h
|
||||||
|
@ -817,22 +817,22 @@ access_violation:
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWER_MANAGER
|
||||||
|
|
||||||
bool powerctl_get_status__verified(powerctl_status_t *status) {
|
pm_status_t pm_get_state__verified(pm_state_t *status) {
|
||||||
if (!probe_write_access(status, sizeof(*status))) {
|
if (!probe_write_access(status, sizeof(*status))) {
|
||||||
goto access_violation;
|
goto access_violation;
|
||||||
}
|
}
|
||||||
|
|
||||||
powerctl_status_t status_copy = {0};
|
pm_state_t status_copy = {0};
|
||||||
bool retval = powerctl_get_status(&status_copy);
|
pm_status_t retval = pm_get_state(&status_copy);
|
||||||
*status = status_copy;
|
*status = status_copy;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
access_violation:
|
access_violation:
|
||||||
apptask_access_violation();
|
apptask_access_violation();
|
||||||
return false;
|
return PM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -209,11 +209,11 @@ secbool ble_read__verified(uint8_t *data, size_t len);
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWER_MANAGER
|
||||||
|
|
||||||
#include <sys/powerctl.h>
|
#include <sys/power_manager.h>
|
||||||
|
|
||||||
bool powerctl_get_status__verified(powerctl_status_t *status);
|
pm_status_t pm_get_state__verified(pm_state_t *status);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user