You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
6 years ago
|
#define POWER_SAVE_STATUS_DISABLED 0
|
||
6 years ago
|
#define POWER_SAVE_STATUS_ENABLED 1
|
||
6 years ago
|
|
||
6 years ago
|
int power_save_status = POWER_SAVE_STATUS_DISABLED;
|
||
6 years ago
|
|
||
|
void power_save_enable(void) {
|
||
6 years ago
|
if (power_save_status == POWER_SAVE_STATUS_ENABLED) return;
|
||
|
puts("enable power savings\n");
|
||
|
|
||
|
// turn off can
|
||
6 years ago
|
set_can_enable(CAN1, 0);
|
||
|
set_can_enable(CAN2, 0);
|
||
|
set_can_enable(CAN3, 0);
|
||
|
|
||
6 years ago
|
// turn off GMLAN
|
||
6 years ago
|
set_gpio_output(GPIOB, 14, 0);
|
||
|
set_gpio_output(GPIOB, 15, 0);
|
||
|
|
||
6 years ago
|
// turn off LIN
|
||
|
set_gpio_output(GPIOB, 7, 0);
|
||
6 years ago
|
set_gpio_output(GPIOA, 14, 0);
|
||
|
|
||
|
if (is_grey_panda) {
|
||
6 years ago
|
char UBLOX_SLEEP_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x08\x00\x17\x78";
|
||
6 years ago
|
uart_ring *ur = get_ring_by_number(1);
|
||
6 years ago
|
for (int i = 0; i < sizeof(UBLOX_SLEEP_MSG)-1; i++) while (!putc(ur, UBLOX_SLEEP_MSG[i]));
|
||
6 years ago
|
}
|
||
|
|
||
|
power_save_status = POWER_SAVE_STATUS_ENABLED;
|
||
|
}
|
||
|
|
||
|
void power_save_disable(void) {
|
||
6 years ago
|
if (power_save_status == POWER_SAVE_STATUS_DISABLED) return;
|
||
|
puts("disable power savings\n");
|
||
6 years ago
|
|
||
6 years ago
|
// turn on can
|
||
6 years ago
|
set_can_enable(CAN1, 1);
|
||
|
set_can_enable(CAN2, 1);
|
||
|
set_can_enable(CAN3, 1);
|
||
|
|
||
6 years ago
|
// turn on GMLAN
|
||
6 years ago
|
set_gpio_output(GPIOB, 14, 1);
|
||
|
set_gpio_output(GPIOB, 15, 1);
|
||
|
|
||
6 years ago
|
// turn on LIN
|
||
|
set_gpio_output(GPIOB, 7, 1);
|
||
6 years ago
|
set_gpio_output(GPIOA, 14, 1);
|
||
|
|
||
|
if (is_grey_panda) {
|
||
6 years ago
|
char UBLOX_WAKE_MSG[] = "\xb5\x62\x06\x04\x04\x00\x01\x00\x09\x00\x18\x7a";
|
||
6 years ago
|
uart_ring *ur = get_ring_by_number(1);
|
||
6 years ago
|
for (int i = 0; i < sizeof(UBLOX_WAKE_MSG)-1; i++) while (!putc(ur, UBLOX_WAKE_MSG[i]));
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
power_save_status = POWER_SAVE_STATUS_DISABLED;
|
||
6 years ago
|
}
|
||
|
|