mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-19 01:33:52 +08:00
* Let refactoring begin! * Fix pedal build * Fix pedal safety tests * Forgot few TIM2 instances * Try this way with misra * More misras... * More misras... * Still fighting with misra blindfolded * Almost got it! * Last misra error.. * Last misra error.. * Misra works locally.. * Maybe this? * Looks like it was cppcheck bug, revert changes * Suggested changes and reverts * File structure change * revert includes * remove spaces * remove timer delay * endings * more typing * rename early to early_initialization * Remove delay_us * Revert RTC default values * Revert initialization sequence * Fix quotes * Revert * Return TIM6EN * Alias slow timer to TICK_TIMER * Refactor files structure * Remove definition of PANDA * Abstract timers * Fix include * tick_timer_init * Split usb driver * Move LL stuff: adc * Move LL stuff: usb * Fix include again... * Will check pedal builds also locally.. * Move LL stuff: CAN * Move LL stuff: clock * Rename common to peripherals and move * Move board HAL * Change include, not needed for pedal * llgpio to gpio and new lines fix * remove board_has_relay, not used * Remove board_functions.h and add to board struct * Move include * Fk MISRA... * has_onboard_gmlan to has_hw_gmlan * Typos * Move board_declarations include * Shuffle * More abstraction * fix paths, fix cppcheck test * Fix for pedal build with USB
60 lines
1.9 KiB
C
60 lines
1.9 KiB
C
// 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
|
|
|
|
#define POWER_SAVE_STATUS_DISABLED 0
|
|
#define POWER_SAVE_STATUS_ENABLED 1
|
|
|
|
int power_save_status = POWER_SAVE_STATUS_DISABLED;
|
|
|
|
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");
|
|
if (current_board->has_gps) {
|
|
const char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
|
|
uart_ring *ur = get_ring_by_number(1);
|
|
for (unsigned int i = 0; i < sizeof(UBLOX_SLEEP_MSG) - 1U; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
|
|
}
|
|
} else {
|
|
puts("disable power savings\n");
|
|
if (current_board->has_gps) {
|
|
const char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
|
|
uart_ring *ur = get_ring_by_number(1);
|
|
for (unsigned int i = 0; i < sizeof(UBLOX_WAKE_MSG) - 1U; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
|
|
}
|
|
enable = true;
|
|
}
|
|
|
|
current_board->enable_can_transceivers(enable);
|
|
|
|
// Switch EPS/GPS
|
|
if (enable) {
|
|
current_board->set_gps_mode(GPS_ENABLED);
|
|
} else {
|
|
current_board->set_gps_mode(GPS_DISABLED);
|
|
}
|
|
|
|
if(current_board->has_hw_gmlan){
|
|
// turn on GMLAN
|
|
set_gpio_output(GPIOB, 14, enable);
|
|
set_gpio_output(GPIOB, 15, enable);
|
|
}
|
|
|
|
if(current_board->has_lin){
|
|
// turn on LIN
|
|
set_gpio_output(GPIOB, 7, enable);
|
|
set_gpio_output(GPIOA, 14, enable);
|
|
}
|
|
|
|
// Switch off IR when in power saving
|
|
if(!enable){
|
|
current_board->set_ir_power(0U);
|
|
}
|
|
|
|
power_save_status = state;
|
|
}
|
|
}
|