mirror of https://github.com/commaai/panda.git
Stop charge (#284)
* CDP by default in EON build on white panda * Cleaned up power mode setting * send usb power mode in health * cleaner CDP setting on ignition * bump panda
This commit is contained in:
parent
5266a40287
commit
78ef4a6ebc
|
@ -36,11 +36,10 @@ struct board {
|
|||
#define LED_GREEN 1U
|
||||
#define LED_BLUE 2U
|
||||
|
||||
// USB power modes
|
||||
#define USB_POWER_NONE 0U
|
||||
#define USB_POWER_CLIENT 1U
|
||||
#define USB_POWER_CDP 2U
|
||||
#define USB_POWER_DCP 3U
|
||||
// USB power modes (from cereal.log.health)
|
||||
#define USB_POWER_CLIENT 0U
|
||||
#define USB_POWER_CDP 1U
|
||||
#define USB_POWER_DCP 2U
|
||||
|
||||
// ESP modes
|
||||
#define ESP_GPS_DISABLED 0U
|
||||
|
@ -54,4 +53,4 @@ struct board {
|
|||
#define CAN_MODE_OBD_CAN2 3U
|
||||
|
||||
// ********************* Globals **********************
|
||||
uint8_t usb_power_mode = USB_POWER_NONE;
|
||||
uint8_t usb_power_mode = USB_POWER_CDP;
|
||||
|
|
|
@ -38,7 +38,7 @@ void black_set_led(uint8_t color, bool enabled) {
|
|||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -53,11 +53,22 @@ void black_set_usb_load_switch(bool enabled) {
|
|||
}
|
||||
|
||||
void black_set_usb_power_mode(uint8_t mode) {
|
||||
usb_power_mode = mode;
|
||||
if (mode == USB_POWER_NONE) {
|
||||
black_set_usb_load_switch(false);
|
||||
} else {
|
||||
black_set_usb_load_switch(true);
|
||||
bool valid = false;
|
||||
switch (mode) {
|
||||
case USB_POWER_CLIENT:
|
||||
black_set_usb_load_switch(false);
|
||||
valid = true;
|
||||
break;
|
||||
case USB_POWER_CDP:
|
||||
black_set_usb_load_switch(true);
|
||||
valid = true;
|
||||
break;
|
||||
default:
|
||||
puts("Invalid USB power mode\n");
|
||||
break;
|
||||
}
|
||||
if (valid) {
|
||||
usb_power_mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,4 +211,4 @@ const board board_black = {
|
|||
.set_can_mode = black_set_can_mode,
|
||||
.usb_power_mode_tick = black_usb_power_mode_tick,
|
||||
.check_ignition = black_check_ignition
|
||||
};
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ void white_set_led(uint8_t color, bool enabled) {
|
|||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void white_set_can_mode(uint8_t mode){
|
|||
|
||||
// A8,A15: normal CAN3 mode
|
||||
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||
break;
|
||||
case CAN_MODE_GMLAN_CAN3:
|
||||
// A8,A15: disable CAN3 mode
|
||||
|
@ -143,7 +143,7 @@ void white_set_can_mode(uint8_t mode){
|
|||
// B5,B6: normal CAN2 mode
|
||||
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
||||
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
|
||||
break;
|
||||
|
@ -152,7 +152,9 @@ void white_set_can_mode(uint8_t mode){
|
|||
|
||||
uint64_t marker = 0;
|
||||
void white_usb_power_mode_tick(uint64_t tcnt){
|
||||
#ifndef BOOTSTUB
|
||||
|
||||
// on EON or BOOTSTUB, no state machine
|
||||
#if !defined(BOOTSTUB) && !defined(EON)
|
||||
#define CURRENT_THRESHOLD 0xF00U
|
||||
#define CLICKS 5U // 5 seconds to switch modes
|
||||
|
||||
|
@ -177,22 +179,19 @@ void white_usb_power_mode_tick(uint64_t tcnt){
|
|||
}
|
||||
break;
|
||||
case USB_POWER_CDP:
|
||||
// On the EON, if we get into CDP mode we stay here. No need to go to DCP.
|
||||
#ifndef EON
|
||||
// been CLICKS clicks since we switched to CDP
|
||||
if ((tcnt-marker) >= CLICKS) {
|
||||
// measure current draw, if positive and no enumeration, switch to DCP
|
||||
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
|
||||
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
|
||||
white_set_usb_power_mode(USB_POWER_DCP);
|
||||
marker = tcnt;
|
||||
}
|
||||
}
|
||||
// keep resetting the timer if there's no current draw in CDP
|
||||
if (current >= CURRENT_THRESHOLD) {
|
||||
// been CLICKS clicks since we switched to CDP
|
||||
if ((tcnt-marker) >= CLICKS) {
|
||||
// measure current draw, if positive and no enumeration, switch to DCP
|
||||
if (!is_enumerated && (current < CURRENT_THRESHOLD)) {
|
||||
puts("USBP: no enumeration with current draw, switching to DCP mode\n");
|
||||
white_set_usb_power_mode(USB_POWER_DCP);
|
||||
marker = tcnt;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// keep resetting the timer if there's no current draw in CDP
|
||||
if (current >= CURRENT_THRESHOLD) {
|
||||
marker = tcnt;
|
||||
}
|
||||
break;
|
||||
case USB_POWER_DCP:
|
||||
// been at least CLICKS clicks since we switched to DCP
|
||||
|
@ -213,9 +212,9 @@ void white_usb_power_mode_tick(uint64_t tcnt){
|
|||
puts("USB power mode invalid\n"); // set_usb_power_mode prevents assigning invalid values
|
||||
break;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
UNUSED(tcnt);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
bool white_check_ignition(void){
|
||||
|
@ -242,8 +241,10 @@ void white_init(void) {
|
|||
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
|
||||
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
|
||||
|
||||
// Set USB power mode
|
||||
// on PC, set USB power mode to CLIENT
|
||||
#ifndef EON
|
||||
white_set_usb_power_mode(USB_POWER_CLIENT);
|
||||
#endif
|
||||
|
||||
// B12: GMLAN, ignition sense, pull up
|
||||
set_gpio_pullup(GPIOB, 12, PULL_UP);
|
||||
|
@ -310,4 +311,4 @@ const board board_white = {
|
|||
.set_can_mode = white_set_can_mode,
|
||||
.usb_power_mode_tick = white_usb_power_mode_tick,
|
||||
.check_ignition = white_check_ignition
|
||||
};
|
||||
};
|
||||
|
|
22
board/main.c
22
board/main.c
|
@ -78,10 +78,14 @@ void started_interrupt_handler(uint8_t interrupt_line) {
|
|||
// jenky debounce
|
||||
delay(100000);
|
||||
|
||||
// set power savings mode here if on EON build
|
||||
#ifdef EON
|
||||
// set power savings mode here if on EON build
|
||||
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
|
||||
set_power_save_state(power_save_state);
|
||||
// set CDP usb power mode everytime that the car starts to make sure EON is charging
|
||||
if (current_board->check_ignition()) {
|
||||
current_board->set_usb_power_mode(USB_POWER_CDP);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
EXTI->PR = (1U << interrupt_line);
|
||||
|
@ -159,6 +163,7 @@ int get_health_pkt(void *dat) {
|
|||
uint8_t controls_allowed_pkt;
|
||||
uint8_t gas_interceptor_detected_pkt;
|
||||
uint8_t car_harness_status_pkt;
|
||||
uint8_t usb_power_mode_pkt;
|
||||
} *health = dat;
|
||||
|
||||
//Voltage will be measured in mv. 5000 = 5V
|
||||
|
@ -195,6 +200,7 @@ int get_health_pkt(void *dat) {
|
|||
health->can_fwd_errs_pkt = can_fwd_errs;
|
||||
health->gmlan_send_errs_pkt = gmlan_send_errs;
|
||||
health->car_harness_status_pkt = car_harness_status;
|
||||
health->usb_power_mode_pkt = usb_power_mode;
|
||||
|
||||
return sizeof(*health);
|
||||
}
|
||||
|
@ -460,19 +466,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
|
|||
break;
|
||||
// **** 0xe6: set USB power
|
||||
case 0xe6:
|
||||
if (setup->b.wValue.w == 0U) {
|
||||
puts("user setting NONE mode\n");
|
||||
current_board->set_usb_power_mode(USB_POWER_NONE);
|
||||
} else if (setup->b.wValue.w == 1U) {
|
||||
puts("user setting CDP mode\n");
|
||||
current_board->set_usb_power_mode(USB_POWER_CDP);
|
||||
} else if (setup->b.wValue.w == 2U) {
|
||||
puts("user setting DCP mode\n");
|
||||
current_board->set_usb_power_mode(USB_POWER_DCP);
|
||||
} else {
|
||||
puts("user setting CLIENT mode\n");
|
||||
current_board->set_usb_power_mode(USB_POWER_CLIENT);
|
||||
}
|
||||
current_board->set_usb_power_mode(setup->b.wValue.w);
|
||||
break;
|
||||
// **** 0xf0: do k-line wValue pulse on uart2 for Acura
|
||||
case 0xf0:
|
||||
|
|
Loading…
Reference in New Issue