Files
panda-meb/board/power_saving.h

53 lines
1.5 KiB
C
Raw Permalink Normal View History

#include "power_saving_declarations.h"
// 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-21 17:05:14 -07:00
int power_save_status = POWER_SAVE_STATUS_DISABLED;
void enable_can_transceivers(bool enabled) {
// Leave main CAN always on for CAN-based ignition detection
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
for(uint8_t i=1U; i<=4U; i++){
current_board->enable_can_transceiver(i, (i == main_bus) || enabled);
}
}
2019-06-26 18:24:21 -07:00
void set_power_save_state(int state) {
2019-06-26 18:24:21 -07:00
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) {
print("enable power savings\n");
2023-08-06 12:29:54 -07: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-26 18:24:21 -07:00
} else {
print("disable power savings\n");
if (harness.status == HARNESS_STATUS_FLIPPED) {
llcan_irq_enable(cans[0]);
} else {
llcan_irq_enable(cans[2]);
}
llcan_irq_enable(cans[1]);
2019-06-26 18:24:21 -07:00
enable = true;
2019-06-26 15:52:34 -07:00
}
enable_can_transceivers(enable);
2019-06-26 15:52:34 -07:00
// Switch off IR when in power saving
if(!enable){
current_board->set_ir_power(0U);
}
2019-06-26 18:24:21 -07:00
power_save_status = state;
2019-06-26 15:52:34 -07:00
}
}