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-04-02 13:45:00 +08:00
|
|
|
#define POWER_SAVE_STATUS_DISABLED 0
|
2019-05-22 08:05:14 +08:00
|
|
|
#define POWER_SAVE_STATUS_ENABLED 1
|
2019-04-02 13:45:00 +08:00
|
|
|
|
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) {
|
|
|
|
puts("enable power savings\n");
|
2019-07-24 06:07:06 +08:00
|
|
|
if (board_has_gps()) {
|
2019-06-27 09:24:21 +08:00
|
|
|
char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
|
|
|
|
uart_ring *ur = get_ring_by_number(1);
|
2019-07-04 16:04:58 +08:00
|
|
|
for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
|
2019-06-27 09:24:21 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
puts("disable power savings\n");
|
2019-07-24 06:07:06 +08:00
|
|
|
if (board_has_gps()) {
|
2019-06-27 09:24:21 +08:00
|
|
|
char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
|
|
|
|
uart_ring *ur = get_ring_by_number(1);
|
2019-07-04 16:04:58 +08:00
|
|
|
for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
|
2019-06-27 09:24:21 +08:00
|
|
|
}
|
|
|
|
enable = true;
|
2019-06-27 06:52:34 +08:00
|
|
|
}
|
|
|
|
|
2019-07-24 06:07:06 +08:00
|
|
|
current_board->enable_can_transcievers(enable);
|
2019-06-27 06:52:34 +08:00
|
|
|
|
2019-08-29 03:57:42 +08:00
|
|
|
// Switch EPS/GPS
|
|
|
|
if (enable) {
|
|
|
|
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
|
|
|
|
} else {
|
|
|
|
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
|
|
|
|
}
|
2019-10-23 06:10:43 +08:00
|
|
|
|
2019-10-26 07:22:42 +08:00
|
|
|
if(board_has_gmlan()){
|
2019-07-24 06:07:06 +08:00
|
|
|
// turn on GMLAN
|
|
|
|
set_gpio_output(GPIOB, 14, enable);
|
|
|
|
set_gpio_output(GPIOB, 15, enable);
|
2019-10-26 07:22:42 +08:00
|
|
|
}
|
2019-04-02 13:45:00 +08:00
|
|
|
|
2019-10-26 07:22:42 +08:00
|
|
|
if(board_has_lin()){
|
2019-10-23 06:10:43 +08:00
|
|
|
// turn on LIN
|
2019-07-24 06:07:06 +08:00
|
|
|
set_gpio_output(GPIOB, 7, enable);
|
|
|
|
set_gpio_output(GPIOA, 14, enable);
|
|
|
|
}
|
2019-06-27 06:52:34 +08:00
|
|
|
|
2019-10-30 03:36:47 +08:00
|
|
|
// Switch off IR and fan when in power saving
|
|
|
|
if(!enable){
|
|
|
|
current_board->set_ir_power(0U);
|
|
|
|
current_board->set_fan_power(0U);
|
|
|
|
}
|
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
|
|
|
}
|