2024-09-20 12:15:08 +08:00
|
|
|
#include "power_saving_declarations.h"
|
|
|
|
|
2019-12-06 06:19:29 +08:00
|
|
|
// WARNING: To stay in compliance with the SIL2 rules laid out in STM UM1840, we should never implement any of the available hardware low power modes.
|
|
|
|
// See rule: CoU_3
|
|
|
|
|
2019-05-22 08:05:14 +08:00
|
|
|
int power_save_status = POWER_SAVE_STATUS_DISABLED;
|
2019-04-02 13:45:00 +08:00
|
|
|
|
2019-06-27 09:24:21 +08:00
|
|
|
void set_power_save_state(int state) {
|
|
|
|
|
|
|
|
bool is_valid_state = (state == POWER_SAVE_STATUS_ENABLED) || (state == POWER_SAVE_STATUS_DISABLED);
|
|
|
|
if (is_valid_state && (state != power_save_status)) {
|
|
|
|
bool enable = false;
|
|
|
|
if (state == POWER_SAVE_STATUS_ENABLED) {
|
2022-11-30 14:55:10 +08:00
|
|
|
print("enable power savings\n");
|
2023-08-07 03:29:54 +08:00
|
|
|
|
2023-06-29 03:33:17 +08:00
|
|
|
// Disable CAN interrupts
|
|
|
|
if (harness.status == HARNESS_STATUS_FLIPPED) {
|
|
|
|
llcan_irq_disable(cans[0]);
|
|
|
|
} else {
|
|
|
|
llcan_irq_disable(cans[2]);
|
|
|
|
}
|
|
|
|
llcan_irq_disable(cans[1]);
|
2019-06-27 09:24:21 +08:00
|
|
|
} else {
|
2022-11-30 14:55:10 +08:00
|
|
|
print("disable power savings\n");
|
2023-06-29 03:33:17 +08:00
|
|
|
|
|
|
|
if (harness.status == HARNESS_STATUS_FLIPPED) {
|
|
|
|
llcan_irq_enable(cans[0]);
|
|
|
|
} else {
|
|
|
|
llcan_irq_enable(cans[2]);
|
|
|
|
}
|
|
|
|
llcan_irq_enable(cans[1]);
|
|
|
|
|
2019-06-27 09:24:21 +08:00
|
|
|
enable = true;
|
2019-06-27 06:52:34 +08:00
|
|
|
}
|
|
|
|
|
2020-09-28 22:19:09 +08:00
|
|
|
current_board->enable_can_transceivers(enable);
|
2019-06-27 06:52:34 +08:00
|
|
|
|
2020-01-24 08:54:34 +08:00
|
|
|
// Switch off IR when in power saving
|
2019-10-30 03:36:47 +08:00
|
|
|
if(!enable){
|
|
|
|
current_board->set_ir_power(0U);
|
2020-06-04 06:08:57 +08:00
|
|
|
}
|
2019-10-26 07:22:42 +08:00
|
|
|
|
2019-06-27 09:24:21 +08:00
|
|
|
power_save_status = state;
|
2019-06-27 06:52:34 +08:00
|
|
|
}
|
2019-04-02 13:45:00 +08:00
|
|
|
}
|