Skip to content

Commit 6f532c6

Browse files
robbederksrbiasini
authored andcommitted
Black panda Jenkins (commaai#256)
* 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
1 parent d68508c commit 6f532c6

21 files changed

+936
-339
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.o
55
*.so
66
*.d
7+
*.dump
78
a.out
89
*~
910
.#*
@@ -12,4 +13,5 @@ pandacan.egg-info/
1213
board/obj/
1314
examples/output.csv
1415
.DS_Store
16+
.vscode
1517
nosetests.xml

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.4.3
1+
v1.4.6

board/board_declarations.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct board {
2424
};
2525

2626
// ******************* Definitions ********************
27-
// These should match the enum in cereal/log.capnp
27+
// These should match the enums in cereal/log.capnp and __init__.py
2828
#define HW_TYPE_UNKNOWN 0U
2929
#define HW_TYPE_WHITE_PANDA 1U
3030
#define HW_TYPE_GREY_PANDA 2U
@@ -54,4 +54,4 @@ struct board {
5454
#define CAN_MODE_OBD_CAN2 3U
5555

5656
// ********************* Globals **********************
57-
uint8_t usb_power_mode = USB_POWER_NONE;
57+
uint8_t usb_power_mode = USB_POWER_NONE;

board/boards/black.h

+26-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ void black_enable_can_transciever(uint8_t transciever, bool enabled) {
2323
}
2424

2525
void black_enable_can_transcievers(bool enabled) {
26-
for(uint8_t i=1; i<=4U; i++)
26+
for(uint8_t i=1U; i<=4U; i++){
2727
black_enable_can_transciever(i, enabled);
28+
}
2829
}
2930

3031
void black_set_led(uint8_t color, bool enabled) {
@@ -43,26 +44,41 @@ void black_set_led(uint8_t color, bool enabled) {
4344
}
4445
}
4546

46-
void black_set_usb_power_mode(uint8_t mode){
47+
void black_set_gps_load_switch(bool enabled) {
48+
set_gpio_output(GPIOC, 12, enabled);
49+
}
50+
51+
void black_set_usb_load_switch(bool enabled) {
52+
set_gpio_output(GPIOB, 1, !enabled);
53+
}
54+
55+
void black_set_usb_power_mode(uint8_t mode) {
4756
usb_power_mode = mode;
48-
puts("Trying to set USB power mode on black panda. This is not supported.\n");
57+
if (mode == USB_POWER_NONE) {
58+
black_set_usb_load_switch(false);
59+
} else {
60+
black_set_usb_load_switch(true);
61+
}
4962
}
5063

5164
void black_set_esp_gps_mode(uint8_t mode) {
5265
switch (mode) {
5366
case ESP_GPS_DISABLED:
54-
// ESP OFF
67+
// GPS OFF
5568
set_gpio_output(GPIOC, 14, 0);
5669
set_gpio_output(GPIOC, 5, 0);
70+
black_set_gps_load_switch(false);
5771
break;
5872
case ESP_GPS_ENABLED:
59-
// ESP ON
73+
// GPS ON
6074
set_gpio_output(GPIOC, 14, 1);
6175
set_gpio_output(GPIOC, 5, 1);
76+
black_set_gps_load_switch(true);
6277
break;
6378
case ESP_GPS_BOOTMODE:
6479
set_gpio_output(GPIOC, 14, 1);
6580
set_gpio_output(GPIOC, 5, 0);
81+
black_set_gps_load_switch(true);
6682
break;
6783
default:
6884
puts("Invalid ESP/GPS mode\n");
@@ -132,9 +148,11 @@ void black_init(void) {
132148
// C8: FAN aka TIM3_CH3
133149
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
134150

135-
// C12: GPS load switch. Turn on permanently for now
136-
set_gpio_output(GPIOC, 12, true);
137-
//set_gpio_output(GPIOC, 12, false); //TODO: stupid inverted switch on prototype
151+
// Turn on GPS load switch.
152+
black_set_gps_load_switch(true);
153+
154+
// Turn on USB load switch.
155+
black_set_usb_load_switch(true);
138156

139157
// Initialize harness
140158
harness_init();

board/boards/white.h

+7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ void white_init(void) {
285285

286286
// Set normal CAN mode
287287
white_set_can_mode(CAN_MODE_NORMAL);
288+
289+
// Setup ignition interrupts
290+
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
291+
EXTI->IMR |= (1U << 1);
292+
EXTI->RTSR |= (1U << 1);
293+
EXTI->FTSR |= (1U << 1);
294+
NVIC_EnableIRQ(EXTI1_IRQn);
288295
}
289296

290297
const harness_configuration white_harness_config = {

board/main.c

+18-28
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ void started_interrupt_handler(uint8_t interrupt_line) {
7878
// jenky debounce
7979
delay(100000);
8080

81-
// set power savings mode here
82-
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
83-
set_power_save_state(power_save_state);
81+
// set power savings mode here if on EON build
82+
#ifdef EON
83+
int power_save_state = current_board->check_ignition() ? POWER_SAVE_STATUS_DISABLED : POWER_SAVE_STATUS_ENABLED;
84+
set_power_save_state(power_save_state);
85+
#endif
8486
}
8587
EXTI->PR = (1U << interrupt_line);
8688
}
@@ -100,14 +102,6 @@ void EXTI3_IRQHandler(void) {
100102
started_interrupt_handler(3);
101103
}
102104

103-
void started_interrupt_init(void) {
104-
SYSCFG->EXTICR[1] = SYSCFG_EXTICR1_EXTI1_PA;
105-
EXTI->IMR |= (1U << 1);
106-
EXTI->RTSR |= (1U << 1);
107-
EXTI->FTSR |= (1U << 1);
108-
NVIC_EnableIRQ(EXTI1_IRQn);
109-
}
110-
111105
// ****************************** safety mode ******************************
112106

113107
// this is the only way to leave silent mode
@@ -116,30 +110,29 @@ void set_safety_mode(uint16_t mode, int16_t param) {
116110
if (err == -1) {
117111
puts("Error: safety set mode failed\n");
118112
} else {
119-
if (mode == SAFETY_NOOUTPUT) {
120-
can_silent = ALL_CAN_SILENT;
121-
} else {
122-
can_silent = ALL_CAN_LIVE;
123-
}
124-
125113
switch (mode) {
126114
case SAFETY_NOOUTPUT:
127115
set_intercept_relay(false);
128116
if(hw_type == HW_TYPE_BLACK_PANDA){
129117
current_board->set_can_mode(CAN_MODE_NORMAL);
130118
}
119+
can_silent = ALL_CAN_SILENT;
131120
break;
132121
case SAFETY_ELM327:
133122
set_intercept_relay(false);
123+
heartbeat_counter = 0U;
134124
if(hw_type == HW_TYPE_BLACK_PANDA){
135125
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
136126
}
127+
can_silent = ALL_CAN_LIVE;
137128
break;
138129
default:
139130
set_intercept_relay(true);
131+
heartbeat_counter = 0U;
140132
if(hw_type == HW_TYPE_BLACK_PANDA){
141133
current_board->set_can_mode(CAN_MODE_NORMAL);
142134
}
135+
can_silent = ALL_CAN_LIVE;
143136
break;
144137
}
145138
if (safety_ignition_hook() != -1) {
@@ -464,7 +457,10 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
464457
break;
465458
// **** 0xe6: set USB power
466459
case 0xe6:
467-
if (setup->b.wValue.w == 1U) {
460+
if (setup->b.wValue.w == 0U) {
461+
puts("user setting NONE mode\n");
462+
current_board->set_usb_power_mode(USB_POWER_NONE);
463+
} else if (setup->b.wValue.w == 1U) {
468464
puts("user setting CDP mode\n");
469465
current_board->set_usb_power_mode(USB_POWER_CDP);
470466
} else if (setup->b.wValue.w == 2U) {
@@ -610,11 +606,10 @@ void TIM3_IRQHandler(void) {
610606
pending_can_live = 0;
611607
}
612608
#ifdef DEBUG
613-
//TODO: re-enable
614-
//puts("** blink ");
615-
//puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
616-
//puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
617-
//puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
609+
puts("** blink ");
610+
puth(can_rx_q.r_ptr); puts(" "); puth(can_rx_q.w_ptr); puts(" ");
611+
puth(can_tx1_q.r_ptr); puts(" "); puth(can_tx1_q.w_ptr); puts(" ");
612+
puth(can_tx2_q.r_ptr); puts(" "); puth(can_tx2_q.w_ptr); puts("\n");
618613
#endif
619614

620615
// set green LED to be controls allowed
@@ -730,11 +725,6 @@ int main(void) {
730725
/*if (current_board->check_ignition()) {
731726
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
732727
}*/
733-
734-
if (hw_type != HW_TYPE_BLACK_PANDA) {
735-
// interrupt on started line
736-
started_interrupt_init();
737-
}
738728
#endif
739729

740730
// 48mhz / 65536 ~= 732 / 732 = 1

board/power_saving.h

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ void set_power_save_state(int state) {
2828
// Switch CAN transcievers
2929
current_board->enable_can_transcievers(enable);
3030

31+
// Switch EPS/GPS
32+
if (enable) {
33+
current_board->set_esp_gps_mode(ESP_GPS_ENABLED);
34+
} else {
35+
current_board->set_esp_gps_mode(ESP_GPS_DISABLED);
36+
}
37+
3138
if(hw_type != HW_TYPE_BLACK_PANDA){
3239
// turn on GMLAN
3340
set_gpio_output(GPIOB, 14, enable);

python/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ class Panda(object):
135135
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
136136
REQUEST_OUT = usb1.ENDPOINT_OUT | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
137137

138+
HW_TYPE_UNKNOWN = '\x00'
139+
HW_TYPE_WHITE_PANDA = '\x01'
140+
HW_TYPE_GREY_PANDA = '\x02'
141+
HW_TYPE_BLACK_PANDA = '\x03'
142+
HW_TYPE_PEDAL = '\x04'
143+
138144
def __init__(self, serial=None, claim=True):
139145
self._serial = serial
140146
self._handle = None
@@ -363,11 +369,14 @@ def get_version(self):
363369
def get_type(self):
364370
return self._handle.controlRead(Panda.REQUEST_IN, 0xc1, 0, 0, 0x40)
365371

372+
def is_white(self):
373+
return self.get_type() == Panda.HW_TYPE_WHITE_PANDA
374+
366375
def is_grey(self):
367-
return self.get_type() == "\x02"
376+
return self.get_type() == Panda.HW_TYPE_GREY_PANDA
368377

369378
def is_black(self):
370-
return self.get_type() == "\x03"
379+
return self.get_type() == Panda.HW_TYPE_BLACK_PANDA
371380

372381
def get_serial(self):
373382
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xd0, 0, 0, 0x20)
@@ -470,6 +479,7 @@ def can_recv(self):
470479
break
471480
except (usb1.USBErrorIO, usb1.USBErrorOverflow):
472481
print("CAN: BAD RECV, RETRYING")
482+
time.sleep(0.1)
473483
return parse_can_buffer(dat)
474484

475485
def can_clear(self, bus):

tests/automated/1_program.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import os
22
from panda import Panda
3-
from helpers import panda_color_to_serial, test_white_and_grey
3+
from helpers import panda_type_to_serial, test_white_and_grey, test_all_pandas, panda_connect_and_init
44

5-
@test_white_and_grey
6-
@panda_color_to_serial
7-
def test_recover(serial=None):
8-
p = Panda(serial=serial)
5+
@test_all_pandas
6+
@panda_connect_and_init
7+
def test_recover(p):
98
assert p.recover(timeout=30)
109

11-
@test_white_and_grey
12-
@panda_color_to_serial
13-
def test_flash(serial=None):
14-
p = Panda(serial=serial)
10+
@test_all_pandas
11+
@panda_connect_and_init
12+
def test_flash(p):
1513
p.flash()

0 commit comments

Comments
 (0)