Skip to content

Commit

Permalink
Black panda Jenkins (#256)
Browse files Browse the repository at this point in the history
* Jenkins test refactor and black panda addition

* Added HW types needed by previous commit

* Fixed ignition interrupts when not on EON build

* Added functions for load switches

* More test scripts for black panda

* Added NONE power mode to the code

* Fixed race condition when setting GPIO pins was interrupted.

* Added relay test script

* Fixed flashing with critical sections and GPS load switch

* Fixing critical depth after reboot

* Made the loopback test asserting

* Made critical depth a local variable to avoid race conditions

* Added GPS to power savings mode

* Fixed DFU mode on white panda and bumped version

* Fixed PEDAL_USB compilation error

* Fixed misra compliance of new critical depth code

* Cleaned up heartbeat logic in the testing code. Re-added ALL_CAN_BUT_MAIN_SILENT. Bumped version. Improved critical section code.

* Fixed DFU flashing (once again)

* Fixed VERSION

* Added relay endurance test

* Changed to alloutput on ELM mode for fingerprinting.

* Fixed minor remarks
  • Loading branch information
robbederks authored and rbiasini committed Aug 28, 2019
1 parent d68508c commit 6f532c6
Show file tree
Hide file tree
Showing 21 changed files with 936 additions and 339 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.o
*.so
*.d
*.dump
a.out
*~
.#*
Expand All @@ -12,4 +13,5 @@ pandacan.egg-info/
board/obj/
examples/output.csv
.DS_Store
.vscode
nosetests.xml
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.3
v1.4.6
4 changes: 2 additions & 2 deletions board/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct board {
};

// ******************* Definitions ********************
// These should match the enum in cereal/log.capnp
// These should match the enums in cereal/log.capnp and __init__.py
#define HW_TYPE_UNKNOWN 0U
#define HW_TYPE_WHITE_PANDA 1U
#define HW_TYPE_GREY_PANDA 2U
Expand Down Expand Up @@ -54,4 +54,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_NONE;
34 changes: 26 additions & 8 deletions board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ void black_enable_can_transciever(uint8_t transciever, bool enabled) {
}

void black_enable_can_transcievers(bool enabled) {
for(uint8_t i=1; i<=4U; i++)
for(uint8_t i=1U; i<=4U; i++){
black_enable_can_transciever(i, enabled);
}
}

void black_set_led(uint8_t color, bool enabled) {
Expand All @@ -43,26 +44,41 @@ void black_set_led(uint8_t color, bool enabled) {
}
}

void black_set_usb_power_mode(uint8_t mode){
void black_set_gps_load_switch(bool enabled) {
set_gpio_output(GPIOC, 12, enabled);
}

void black_set_usb_load_switch(bool enabled) {
set_gpio_output(GPIOB, 1, !enabled);
}

void black_set_usb_power_mode(uint8_t mode) {
usb_power_mode = mode;
puts("Trying to set USB power mode on black panda. This is not supported.\n");
if (mode == USB_POWER_NONE) {
black_set_usb_load_switch(false);
} else {
black_set_usb_load_switch(true);
}
}

void black_set_esp_gps_mode(uint8_t mode) {
switch (mode) {
case ESP_GPS_DISABLED:
// ESP OFF
// GPS OFF
set_gpio_output(GPIOC, 14, 0);
set_gpio_output(GPIOC, 5, 0);
black_set_gps_load_switch(false);
break;
case ESP_GPS_ENABLED:
// ESP ON
// GPS ON
set_gpio_output(GPIOC, 14, 1);
set_gpio_output(GPIOC, 5, 1);
black_set_gps_load_switch(true);
break;
case ESP_GPS_BOOTMODE:
set_gpio_output(GPIOC, 14, 1);
set_gpio_output(GPIOC, 5, 0);
black_set_gps_load_switch(true);
break;
default:
puts("Invalid ESP/GPS mode\n");
Expand Down Expand Up @@ -132,9 +148,11 @@ void black_init(void) {
// C8: FAN aka TIM3_CH3
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);

// C12: GPS load switch. Turn on permanently for now
set_gpio_output(GPIOC, 12, true);
//set_gpio_output(GPIOC, 12, false); //TODO: stupid inverted switch on prototype
// Turn on GPS load switch.
black_set_gps_load_switch(true);

// Turn on USB load switch.
black_set_usb_load_switch(true);

// Initialize harness
harness_init();
Expand Down
7 changes: 7 additions & 0 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ void white_init(void) {

// Set normal CAN mode
white_set_can_mode(CAN_MODE_NORMAL);

// Setup ignition interrupts
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
EXTI->IMR |= (1U << 1);
EXTI->RTSR |= (1U << 1);
EXTI->FTSR |= (1U << 1);
NVIC_EnableIRQ(EXTI1_IRQn);
}

const harness_configuration white_harness_config = {
Expand Down
46 changes: 18 additions & 28 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ void started_interrupt_handler(uint8_t interrupt_line) {
// jenky debounce
delay(100000);

// set power savings mode here
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
set_power_save_state(power_save_state);
// set power savings mode here if on EON build
#ifdef EON
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
set_power_save_state(power_save_state);
#endif
}
EXTI->PR = (1U << interrupt_line);
}
Expand All @@ -100,14 +102,6 @@ void EXTI3_IRQHandler(void) {
started_interrupt_handler(3);
}

void started_interrupt_init(void) {
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
EXTI->IMR |= (1U << 1);
EXTI->RTSR |= (1U << 1);
EXTI->FTSR |= (1U << 1);
NVIC_EnableIRQ(EXTI1_IRQn);
}

// ****************************** safety mode ******************************

// this is the only way to leave silent mode
Expand All @@ -116,30 +110,29 @@ void set_safety_mode(uint16_t mode, int16_t param) {
if (err == -1) {
puts("Error: safety set mode failed\n");
} else {
if (mode == SAFETY_NOOUTPUT) {
can_silent = ALL_CAN_SILENT;
} else {
can_silent = ALL_CAN_LIVE;
}

switch (mode) {
case SAFETY_NOOUTPUT:
set_intercept_relay(false);
if(hw_type == HW_TYPE_BLACK_PANDA){
current_board->set_can_mode(CAN_MODE_NORMAL);
}
can_silent = ALL_CAN_SILENT;
break;
case SAFETY_ELM327:
set_intercept_relay(false);
heartbeat_counter = 0U;
if(hw_type == HW_TYPE_BLACK_PANDA){
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
}
can_silent = ALL_CAN_LIVE;
break;
default:
set_intercept_relay(true);
heartbeat_counter = 0U;
if(hw_type == HW_TYPE_BLACK_PANDA){
current_board->set_can_mode(CAN_MODE_NORMAL);
}
can_silent = ALL_CAN_LIVE;
break;
}
if (safety_ignition_hook() != -1) {
Expand Down Expand Up @@ -464,7 +457,10 @@ 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 == 1U) {
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) {
Expand Down Expand Up @@ -610,11 +606,10 @@ void TIM3_IRQHandler(void) {
pending_can_live = 0;
}
#ifdef DEBUG
//TODO: re-enable
//puts("** blink ");
//puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
//puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
//puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
puts("** blink ");
puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
#endif

// set green LED to be controls allowed
Expand Down Expand Up @@ -730,11 +725,6 @@ int main(void) {
/*if (current_board->check_ignition()) {
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
}*/

if (hw_type != HW_TYPE_BLACK_PANDA) {
// interrupt on started line
started_interrupt_init();
}
#endif

// 48mhz / 65536 ~= 732 / 732 = 1
Expand Down
7 changes: 7 additions & 0 deletions board/power_saving.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ void set_power_save_state(int state) {
// Switch CAN transcievers
current_board->enable_can_transcievers(enable);

// Switch EPS/GPS
if (enable) {
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
} else {
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
}

if(hw_type != HW_TYPE_BLACK_PANDA){
// turn on GMLAN
set_gpio_output(GPIOB, 14, enable);
Expand Down
14 changes: 12 additions & 2 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class Panda(object):
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
REQUEST_OUT = usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE

HW_TYPE_UNKNOWN = '\x00'
HW_TYPE_WHITE_PANDA = '\x01'
HW_TYPE_GREY_PANDA = '\x02'
HW_TYPE_BLACK_PANDA = '\x03'
HW_TYPE_PEDAL = '\x04'

def __init__(self, serial=None, claim=True):
self._serial = serial
self._handle = None
Expand Down Expand Up @@ -363,11 +369,14 @@ def get_version(self):
def get_type(self):
return self._handle.controlRead(Panda.REQUEST_IN, 0xc1, 0, 0, 0x40)

def is_white(self):
return self.get_type() == Panda.HW_TYPE_WHITE_PANDA

def is_grey(self):
return self.get_type() == "\x02"
return self.get_type() == Panda.HW_TYPE_GREY_PANDA

def is_black(self):
return self.get_type() == "\x03"
return self.get_type() == Panda.HW_TYPE_BLACK_PANDA

def get_serial(self):
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20)
Expand Down Expand Up @@ -470,6 +479,7 @@ def can_recv(self):
break
except (usb1.USBErrorIO, usb1.USBErrorOverflow):
print("CAN: BAD RECV, RETRYING")
time.sleep(0.1)
return parse_can_buffer(dat)

def can_clear(self, bus):
Expand Down
16 changes: 7 additions & 9 deletions tests/automated/1_program.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
from panda import Panda
from helpers import panda_color_to_serial, test_white_and_grey
from helpers import panda_type_to_serial, test_white_and_grey, test_all_pandas, panda_connect_and_init

@test_white_and_grey
@panda_color_to_serial
def test_recover(serial=None):
p = Panda(serial=serial)
@test_all_pandas
@panda_connect_and_init
def test_recover(p):
assert p.recover(timeout=30)

@test_white_and_grey
@panda_color_to_serial
def test_flash(serial=None):
p = Panda(serial=serial)
@test_all_pandas
@panda_connect_and_init
def test_flash(p):
p.flash()
Loading

0 comments on commit 6f532c6

Please sign in to comment.