Skip to content

Commit

Permalink
Squashed 'panda/' changes from 9881e61..30c7ca8
Browse files Browse the repository at this point in the history
30c7ca8 bump version to 1.5.3
9403dbe Need to fix wifi test before re-enabling.
0812362 GPS UART fix until boardd is refactored (commaai#294)
ffbdb87 python2 -> 3 fixes to pedal flasher (commaai#292)
78b75ef Added build type to release version strings
736c2cb Fixed sending of bytes over PandaSerial
0894b28 Fixed USB power mode on black (commaai#291)
4b3358c patch to be able to switch from EON to PC with a Panda that has EON b… (commaai#290)
a95c44a Made setting of NOOUTPUT on no heartbeat more efficient (commaai#287)
9486836 UART instability fix with high interrupt load (commaai#283)
9a9e9d4 Fix usb_power_mode missing initialization (commaai#289)
af0960a DFU fix (commaai#288)
70219d7 match safety enum in cereal (commaai#285)
a338d39 Fix build for jenkins test
78ef4a6 Stop charge (commaai#284)
5266a40 Fix typo (commaai#286)
f4787ec Revert "turn on CDP when ignition switches on (commaai#281)"
d37daee Revert "NONE and CLIENT should be the same thing in white/grey pandas"
e97b283 NONE and CLIENT should be the same thing in white/grey pandas
8c1df55 turn on CDP when ignition switches on (commaai#281)
847a35d Fix bullet points
fac0277 Misra update (commaai#280)
5a04df6 Added description of regression tests to README
c4aabae Fixed some python3 bugs in the test scripts and PandaSerial
9af0cb3 Bump version
c4ac3d6 Disable GPS load switching on black pandas
078ee58 This is the correct table, actually
578b95e Misra table of coverage added
d383a26 bump panda
b98ca01 fix sdk build in python3 env (commaai#279)
63d3dc7 Set python3 env before runnign get_sdk, so we know if it fails
e951d79 legacy code we don't control can remain python2
11b7151 Merge pull request commaai#276 from commaai/python3
9893a84 Merge pull request commaai#277 from zorrobyte/patch-1
d326869 Revert "revert back esptool to python2 and force to build esptools with python2"
875e760 revert back esptool to python2 and force to build esptools with python2
9c40e62 needed to install python3
ed2ac87 Also moved safety tests to python3
6842b2d move esptool sdk installation before python3 env is set. Kind of a cheat
b5a2cab this hopefully fixes build test
6280509 Fixes safety replay
2c220b6 this fixes language regr test
fdbe789 use python 3 in Docker container
ee1ae4f Better hash print
0de9ef7 Revert "Final 2to3 on the whole repo"
c92fd3b Final 2to3 on the whole repo
5f2bc44 better
b2a30fd make works!
b74005d fix sign.py
fe72770 read file as byte and no tab before sleep
32a344ef6 Update README.md
2dc3409 2to3 applied
ffa68ef undo unnecessary brackets for print
dbc2480 Fix all the prints with 2to3, some need to be undo
5a7aeba xrange is gone
982c4c9 one more python3 env
1e2412a env python -> env python3

git-subtree-dir: panda
git-subtree-split: 30c7ca8
  • Loading branch information
Vehicle Researcher authored and jyoung8607 committed Oct 10, 2019
1 parent 2572ce3 commit 0c48316
Show file tree
Hide file tree
Showing 97 changed files with 1,287 additions and 793 deletions.
4 changes: 4 additions & 0 deletions boardesp/python2_make.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python2
import os
import sys
os.system(sys.argv[1])
2 changes: 1 addition & 1 deletion panda/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- run:
name: Run safety test
command: |
docker run panda_safety /bin/bash -c "cd /panda/tests/safety; ./test.sh"
docker run panda_safety /bin/bash -c "cd /panda/tests/safety; PYTHONPATH=/ ./test.sh"
misra-c2012:
machine:
Expand Down
21 changes: 20 additions & 1 deletion panda/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ RUN apt-get update && apt-get install -y \
gperf \
help2man \
iputils-ping \
libbz2-dev \
libexpat-dev \
libffi-dev \
libssl-dev \
libstdc++-arm-none-eabi-newlib \
libtool \
libtool-bin \
libusb-1.0-0 \
locales \
make \
ncurses-dev \
network-manager \
Expand All @@ -38,7 +42,21 @@ RUN apt-get update && apt-get install -y \
screen \
vim \
wget \
wireless-tools
wireless-tools \
zlib1g-dev

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
RUN pyenv install 3.7.3
RUN pyenv install 2.7.12
RUN pyenv global 3.7.3
RUN pyenv rehash

RUN pip install --upgrade pip==18.0

Expand All @@ -51,6 +69,7 @@ ENV HOME /home/batman
ENV PYTHONPATH /tmp:$PYTHONPATH

COPY ./boardesp/get_sdk_ci.sh /tmp/panda/boardesp/
COPY ./boardesp/python2_make.py /tmp/panda/boardesp/

RUN useradd --system -s /sbin/nologin pandauser
RUN mkdir -p /tmp/panda/boardesp/esp-open-sdk
Expand Down
13 changes: 0 additions & 13 deletions panda/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ pipeline {
}
}
}
stage('Test Dev Build (WIFI)') {
steps {
lock(resource: "Pandas", inversePrecedence: true, quantity: 1){
timeout(time: 60, unit: 'MINUTES') {
script {
sh "docker run --name ${env.DOCKER_NAME} --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /var/run/dbus:/var/run/dbus --net host ${env.DOCKER_IMAGE_TAG} bash -c 'cd /tmp/panda; ./run_automated_tests.sh'"
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml"
sh "docker rm ${env.DOCKER_NAME}"
}
}
}
}
}
}
post {
failure {
Expand Down
2 changes: 1 addition & 1 deletion panda/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.7
v1.5.3
2 changes: 1 addition & 1 deletion panda/board/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct board {
#define LED_GREEN 1U
#define LED_BLUE 2U

// USB power modes
// USB power modes (from cereal.log.health)
#define USB_POWER_NONE 0U
#define USB_POWER_CLIENT 1U
#define USB_POWER_CDP 2U
Expand Down
33 changes: 22 additions & 11 deletions panda/board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}

Expand All @@ -67,18 +78,15 @@ void black_set_esp_gps_mode(uint8_t mode) {
// 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:
// 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 @@ -106,7 +114,7 @@ void black_set_can_mode(uint8_t mode){
// B12,B13: OBD mode
set_gpio_alternate(GPIOB, 12, GPIO_AF9_CAN2);
set_gpio_alternate(GPIOB, 13, GPIO_AF9_CAN2);
}
}
break;
default:
puts("Tried to set unsupported CAN mode: "); puth(mode); puts("\n");
Expand Down Expand Up @@ -154,6 +162,9 @@ void black_init(void) {
// Turn on USB load switch.
black_set_usb_load_switch(true);

// Set right power mode
black_set_usb_power_mode(USB_POWER_CDP);

// Initialize harness
harness_init();

Expand Down Expand Up @@ -203,4 +214,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
};
};
54 changes: 30 additions & 24 deletions panda/board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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){
Expand All @@ -242,9 +241,6 @@ void white_init(void) {
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);

// Set USB power mode
white_set_usb_power_mode(USB_POWER_CLIENT);

// B12: GMLAN, ignition sense, pull up
set_gpio_pullup(GPIOB, 12, PULL_UP);

Expand Down Expand Up @@ -292,6 +288,16 @@ void white_init(void) {
EXTI->RTSR |= (1U << 1);
EXTI->FTSR |= (1U << 1);
NVIC_EnableIRQ(EXTI1_IRQn);

// Init usb power mode
uint32_t voltage = adc_get_voltage();
// Init in CDP mode only if panda is powered by 12V.
// Otherwise a PC would not be able to flash a standalone panda with EON build
if (voltage > 8000U) { // 8V threshold
white_set_usb_power_mode(USB_POWER_CDP);
} else {
white_set_usb_power_mode(USB_POWER_CLIENT);
}
}

const harness_configuration white_harness_config = {
Expand All @@ -310,4 +316,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
};
};
3 changes: 1 addition & 2 deletions panda/board/bootstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const board *current_board;

#include "drivers/clock.h"
#include "drivers/llgpio.h"
#include "drivers/adc.h"

#include "board.h"

Expand Down Expand Up @@ -68,8 +69,6 @@ int main(void) {
detect_configuration();
detect_board_type();

current_board->set_usb_power_mode(USB_POWER_CLIENT);

if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) {
enter_bootloader_mode = 0;
soft_flasher_start();
Expand Down
3 changes: 2 additions & 1 deletion panda/board/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PANDA_CONFIG_H

//#define DEBUG
//#define DEBUG_UART
//#define DEBUG_USB
//#define DEBUG_SPI

Expand All @@ -22,7 +23,7 @@

#include <stdbool.h>
#define NULL ((void*)0)
#define COMPILE_TIME_ASSERT(pred) ((void)sizeof(char[1 - (2 * (!(pred)))]))
#define COMPILE_TIME_ASSERT(pred) ((void)sizeof(char[1 - (2 * ((int)(!(pred))))]))

#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
Expand Down
10 changes: 10 additions & 0 deletions panda/board/drivers/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ uint32_t adc_get(unsigned int channel) {
return ADC1->JDR1;
}

uint32_t adc_get_voltage(void) {
// 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, so output in mV
return (adc_get(ADCCHAN_VOLTAGE) * 8862U) / 1000U;
}
9 changes: 4 additions & 5 deletions panda/board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void process_can(uint8_t can_number) {
to_push.RDTR = (CAN->sTxMailBox[0].TDTR & 0xFFFF000FU) | ((CAN_BUS_RET_FLAG | bus_number) << 4);
to_push.RDLR = CAN->sTxMailBox[0].TDLR;
to_push.RDHR = CAN->sTxMailBox[0].TDHR;
can_send_errs += !can_push(&can_rx_q, &to_push);
can_send_errs += can_push(&can_rx_q, &to_push) ? 0U : 1U;
}

if ((CAN->TSR & CAN_TSR_TERR0) == CAN_TSR_TERR0) {
Expand Down Expand Up @@ -367,7 +367,7 @@ void can_rx(uint8_t can_number) {
safety_rx_hook(&to_push);

current_board->set_led(LED_BLUE, true);
can_send_errs += !can_push(&can_rx_q, &to_push);
can_send_errs += can_push(&can_rx_q, &to_push) ? 0U : 1U;

// next
CAN->RF0R |= CAN_RF0R_RFOM0;
Expand All @@ -393,10 +393,9 @@ void can_send(CAN_FIFOMailBox_TypeDef *to_push, uint8_t bus_number) {
// bus number isn't passed through
to_push->RDTR &= 0xF;
if ((bus_number == 3U) && (can_num_lookup[3] == 0xFFU)) {
// TODO: why uint8 bro? only int8?
gmlan_send_errs += !bitbang_gmlan(to_push);
gmlan_send_errs += bitbang_gmlan(to_push) ? 0U : 1U;
} else {
can_fwd_errs += !can_push(can_queues[bus_number], to_push);
can_fwd_errs += can_push(can_queues[bus_number], to_push) ? 0U : 1U;
process_can(CAN_NUM_FROM_BUS_NUM(bus_number));
}
}
Expand Down
Loading

0 comments on commit 0c48316

Please sign in to comment.