Skip to content

Commit

Permalink
fix tests and remove rev b support
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed May 19, 2019
1 parent 3e199cb commit 047bd72
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 58 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ a.out
dist/
pandacan.egg-info/
board/obj/
examples/output.csv
.DS_Store
examples/output.csv
.DS_Store
nosetests.xml
2 changes: 1 addition & 1 deletion board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void can_set_gmlan(int bus) {
can_num_lookup[1] = -1;
can_num_lookup[3] = 1;
can_init(1);
} else if (bus == 2 && revision == PANDA_REV_C) {
} else if (bus == 2) {
puts("GMLAN on CAN3\n");
// GMLAN on CAN3
set_can_mode(2, 1);
Expand Down
20 changes: 6 additions & 14 deletions board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void set_can_mode(int can, int use_gmlan) {
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
#ifdef CAN3
} else if (revision == PANDA_REV_C && can == 2) {
} else if (can == 2) {
// A8,A15: disable normal mode
set_gpio_mode(GPIOA, 8, MODE_INPUT);
set_gpio_mode(GPIOA, 15, MODE_INPUT);
Expand All @@ -218,11 +218,9 @@ void set_can_mode(int can, int use_gmlan) {
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
#ifdef CAN3
} else if (can == 2) {
if(revision == PANDA_REV_C){
// B3,B4: disable gmlan mode
set_gpio_mode(GPIOB, 3, MODE_INPUT);
set_gpio_mode(GPIOB, 4, MODE_INPUT);
}
// B3,B4: disable gmlan mode
set_gpio_mode(GPIOB, 3, MODE_INPUT);
set_gpio_mode(GPIOB, 4, MODE_INPUT);
// A8,A15: normal mode
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
Expand Down Expand Up @@ -377,11 +375,7 @@ void gpio_init() {

#ifdef PANDA
// K-line enable moved from B4->B7 to make room for GMLAN on CAN3
if (revision == PANDA_REV_C) {
set_gpio_output(GPIOB, 7, 1); // REV C
} else {
set_gpio_output(GPIOB, 4, 1); // REV AB
}
set_gpio_output(GPIOB, 7, 1); // REV C

// C12,D2: K-Line setup on UART 5
set_gpio_alternate(GPIOC, 12, GPIO_AF8_UART5);
Expand All @@ -399,9 +393,7 @@ void gpio_init() {
set_gpio_pullup(GPIOC, 11, PULL_UP);
#endif

if (revision == PANDA_REV_C) {
set_usb_power_mode(USB_POWER_CLIENT);
}
set_usb_power_mode(USB_POWER_CLIENT);
}

// ********************* early bringup *********************
Expand Down
52 changes: 22 additions & 30 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,15 @@ int get_health_pkt(void *dat) {

//Voltage will be measured in mv. 5000 = 5V
uint32_t voltage = adc_get(ADCCHAN_VOLTAGE);
if (revision == PANDA_REV_AB) {
//REVB has a 100, 27 (27/127) voltage divider
//Here is the calculation for the scale
//ADCV = VIN_S * (27/127) * (4095/3.3)
//RETVAL = ADCV * s = VIN_S*1000
//s = 1000/((4095/3.3)*(27/127)) = 3.79053046

//Avoid needing floating point math
health->voltage = (voltage * 3791) / 1000;
} else {
//REVC has a 10, 1 (1/11) voltage divider
//Here is the calculation for the scale (s)
//ADCV = VIN_S * (1/11) * (4095/3.3)
//RETVAL = ADCV * s = VIN_S*1000
//s = 1000/((4095/3.3)*(1/11)) = 8.8623046875

//Avoid needing floating point math
health->voltage = (voltage * 8862) / 1000;
}

// REVC has a 10, 1 (1/11) voltage divider
// Here is the calculation for the scale (s)
// ADCV = VIN_S * (1/11) * (4095/3.3)
// RETVAL = ADCV * s = VIN_S*1000
// s = 1000/((4095/3.3)*(1/11)) = 8.8623046875

// Avoid needing floating point math
health->voltage = (voltage * 8862) / 1000;

#ifdef PANDA
health->current = adc_get(ADCCHAN_CURRENT);
Expand Down Expand Up @@ -386,17 +376,15 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {
break;
// **** 0xe6: set USB power
case 0xe6:
if (revision == PANDA_REV_C) {
if (setup->b.wValue.w == 1) {
puts("user setting CDP mode\n");
set_usb_power_mode(USB_POWER_CDP);
} else if (setup->b.wValue.w == 2) {
puts("user setting DCP mode\n");
set_usb_power_mode(USB_POWER_DCP);
} else {
puts("user setting CLIENT mode\n");
set_usb_power_mode(USB_POWER_CLIENT);
}
if (setup->b.wValue.w == 1) {
puts("user setting CDP mode\n");
set_usb_power_mode(USB_POWER_CDP);
} else if (setup->b.wValue.w == 2) {
puts("user setting DCP mode\n");
set_usb_power_mode(USB_POWER_DCP);
} else {
puts("user setting CLIENT mode\n");
set_usb_power_mode(USB_POWER_CLIENT);
}
break;
// **** 0xf0: do k-line wValue pulse on uart2 for Acura
Expand Down Expand Up @@ -540,6 +528,10 @@ int main() {
puts(is_giant_panda ? " GIANTpanda detected\n" : " not GIANTpanda\n");
puts(is_grey_panda ? " gray panda detected!\n" : " white panda\n");
puts(is_entering_bootmode ? " ESP wants bootmode\n" : " no bootmode\n");

// non rev c panda are no longer supported
while (revision != PANDA_REV_C);

gpio_init();

#ifdef PANDA
Expand Down
14 changes: 4 additions & 10 deletions board/power_saving.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ void power_save_enable(void) {

#ifdef PANDA
//Turn off LIN K
if (revision == PANDA_REV_C) {
set_gpio_output(GPIOB, 7, 0); // REV C
} else {
set_gpio_output(GPIOB, 4, 0); // REV AB
}
set_gpio_output(GPIOB, 7, 0); // REV C

// LIN L
set_gpio_output(GPIOA, 14, 0);
#endif
Expand Down Expand Up @@ -90,11 +87,8 @@ void power_save_disable(void) {

#ifdef PANDA
//Turn on LIN K
if (revision == PANDA_REV_C) {
set_gpio_output(GPIOB, 7, 1); // REV C
} else {
set_gpio_output(GPIOB, 4, 1); // REV AB
}
set_gpio_output(GPIOB, 7, 1); // REV C

// LIN L
set_gpio_output(GPIOA, 14, 1);
#endif
Expand Down
2 changes: 1 addition & 1 deletion run_automated_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ else
TESTSUITE_NAME="Panda_Test-DEV"
fi

PYTHONPATH="." nosetests -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s tests/automated/$1*.py
PYTHONPATH="." python $(which nosetests) -v --with-xunit --xunit-file=./$TEST_FILENAME --xunit-testsuite-name=$TESTSUITE_NAME -s tests/automated/$1*.py

0 comments on commit 047bd72

Please sign in to comment.