Skip to content

Commit

Permalink
Squashed 'panda/' changes from 38dc4e6..1282e8f
Browse files Browse the repository at this point in the history
1282e8f cap libusb1 version in setup (#183)
64bcc89 Subaru: 545 msg must be generated
9159df9 Merge branch '0.5.10-chyrsler'
f8ab74a L-line relay (#166)
11c4cdc Cleanup leftover jenkins command
22572d9 Fix Jenkins build dockerfiles with same name
1d2f8f0 Jenkins (#179)
f383eee Power saving: wake on RX and don't print durint IRQ
9540db7 Chrysler safety: better to mention messages we don't want to forward
1049502 chrysler: forward bus 0 to bus 2 (#177)
4276c38 Additional Power saving (#170)

git-subtree-dir: panda
git-subtree-split: 1282e8f
  • Loading branch information
Vehicle Researcher committed Apr 23, 2019
1 parent 27ef9f2 commit 3c25760
Show file tree
Hide file tree
Showing 37 changed files with 947 additions and 107 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.DS_Store
boardesp/esp-open-sdk
64 changes: 64 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM ubuntu:16.04
ENV PYTHONUNBUFFERED 1

RUN apt-get update && apt-get install -y \
autoconf \
automake \
bash \
bison \
bzip2 \
curl \
dfu-util \
flex \
g++ \
gawk \
gcc \
git \
gperf \
help2man \
iputils-ping \
libexpat-dev \
libstdc++-arm-none-eabi-newlib \
libtool \
libtool-bin \
libusb-1.0-0 \
make \
ncurses-dev \
network-manager \
python-dev \
python-serial \
sed \
texinfo \
unrar-free \
unzip \
wget \
build-essential \
python-dev \
python-pip \
screen \
vim \
wget \
wireless-tools

RUN pip install --upgrade pip==18.0

COPY requirements.txt /tmp/
RUN pip install -r /tmp/requirements.txt

RUN mkdir -p /home/batman
ENV HOME /home/batman

ENV PYTHONPATH /tmp:$PYTHONPATH

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

RUN useradd --system -s /sbin/nologin pandauser
RUN mkdir -p /tmp/panda/boardesp/esp-open-sdk
RUN chown pandauser /tmp/panda/boardesp/esp-open-sdk
USER pandauser
RUN cd /tmp/panda/boardesp && ./get_sdk_ci.sh
USER root

COPY ./xx/pandaextra /tmp/pandaextra

ADD ./panda.tar.gz /tmp/panda
55 changes: 55 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
pipeline {
agent any
environment {
AUTHOR = """${sh(
returnStdout: true,
script: "git --no-pager show -s --format='%an' ${GIT_COMMIT}"
).trim()}"""

DOCKER_IMAGE_TAG = "panda:build-${env.BUILD_ID}"
DOCKER_NAME = "panda-test-${env.BUILD_ID}"
}
stages {
stage('Build Docker Image') {
steps {
timeout(time: 60, unit: 'MINUTES') {
script {
sh 'git clone --no-checkout --depth 1 git@github.com:commaai/xx.git || true'
sh 'cd xx && git fetch origin && git checkout origin/master -- pandaextra && cd ..' // Needed for certs for panda flashing
sh 'git archive -v -o panda.tar.gz --format=tar.gz HEAD'
dockerImage = docker.build("${env.DOCKER_IMAGE_TAG}")
}
}
}
}
stage('Test Dev Build') {
steps {
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
timeout(time: 60, unit: 'MINUTES') {
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 '"
}
}
}
}
stage('Test EON Build') {
steps {
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
timeout(time: 60, unit: 'MINUTES') {
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml"
sh "touch EON && docker cp EON ${env.DOCKER_NAME}:/EON"
sh "docker start -a ${env.DOCKER_NAME}"
}
}
}
}
}
post {
always {
script {
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_EON.xml"
sh "docker rm ${env.DOCKER_NAME}"
}
junit "test_results*.xml"
}
}
}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.2.0
v1.2.1
73 changes: 55 additions & 18 deletions board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define ALL_CAN_BUT_MAIN_SILENT 0xFE
#define ALL_CAN_LIVE 0

#include "lline_relay.h"

int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT;

// ********************* instantiate queues *********************
Expand All @@ -23,6 +25,11 @@ can_buffer(tx2_q, 0x100)
can_ring *can_queues[] = {&can_tx1_q, &can_tx2_q};
#endif

#ifdef PANDA
// Forward declare
void power_save_reset_timer();
#endif

// ********************* interrupt safe queue *********************

int can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem) {
Expand Down Expand Up @@ -213,7 +220,7 @@ void can_init(uint8_t can_number) {
CAN->FMR &= ~(CAN_FMR_FINIT);

// enable certain CAN interrupts
CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0;
CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE;

switch (can_number) {
case 0:
Expand Down Expand Up @@ -293,7 +300,6 @@ void can_set_gmlan(int bus) {
void can_sce(CAN_TypeDef *CAN) {
enter_critical_section();

can_err_cnt += 1;
#ifdef DEBUG
if (CAN==CAN1) puts("CAN1: ");
if (CAN==CAN2) puts("CAN2: ");
Expand All @@ -315,23 +321,42 @@ void can_sce(CAN_TypeDef *CAN) {

uint8_t can_number = CAN_NUM_FROM_CANIF(CAN);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
if (can_autobaud_enabled[bus_number] && (CAN->ESR & CAN_ESR_LEC)) {
can_autobaud_speed_increment(can_number);
can_set_speed(can_number);
}

// clear current send
CAN->TSR |= CAN_TSR_ABRQ0;
CAN->MSR &= ~(CAN_MSR_ERRI);
CAN->MSR = CAN->MSR;
if (CAN->MSR & CAN_MSR_WKUI) {
//Waking from sleep
#ifdef DEBUG
puts("WAKE\n");
#endif
set_can_enable(CAN, 1);
CAN->MSR &= ~(CAN_MSR_WKUI);
CAN->MSR = CAN->MSR;
#ifdef PANDA
power_save_reset_timer();
#endif
} else {
can_err_cnt += 1;


if (can_autobaud_enabled[bus_number] && (CAN->ESR & CAN_ESR_LEC)) {
can_autobaud_speed_increment(can_number);
can_set_speed(can_number);
}

// clear current send
CAN->TSR |= CAN_TSR_ABRQ0;
CAN->MSR &= ~(CAN_MSR_ERRI);
CAN->MSR = CAN->MSR;
}
exit_critical_section();
}

// ***************************** CAN *****************************

void process_can(uint8_t can_number) {
if (can_number == 0xff) return;
#ifdef PANDA
power_save_reset_timer();
#endif

enter_critical_section();

Expand Down Expand Up @@ -375,6 +400,13 @@ void process_can(uint8_t can_number) {
}

if (can_pop(can_queues[bus_number], &to_send)) {
if (CAN->MCR & CAN_MCR_SLEEP) {
set_can_enable(CAN, 1);
CAN->MCR &= ~(CAN_MCR_SLEEP);
CAN->MCR |= CAN_MCR_INRQ;
while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK);
CAN->MCR &= ~(CAN_MCR_INRQ);
}
can_tx_cnt += 1;
// only send if we have received a packet
CAN->sTxMailBox[0].TDLR = to_send.RDLR;
Expand All @@ -390,6 +422,9 @@ void process_can(uint8_t can_number) {
// CAN receive handlers
// blink blue when we are receiving CAN messages
void can_rx(uint8_t can_number) {
#ifdef PANDA
power_save_reset_timer();
#endif
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
while (CAN->RF0R & CAN_RF0R_FMP0) {
Expand Down Expand Up @@ -420,14 +455,16 @@ void can_rx(uint8_t can_number) {

// forwarding (panda only)
#ifdef PANDA
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
if (bus_fwd_num != -1) {
CAN_FIFOMailBox_TypeDef to_send;
to_send.RIR = to_push.RIR | 1; // TXRQ
to_send.RDTR = to_push.RDTR;
to_send.RDLR = to_push.RDLR;
to_send.RDHR = to_push.RDHR;
can_send(&to_send, bus_fwd_num);
if ((get_lline_status() != 0) || !relay_control) { //Relay engaged or relay isn't controlled, allow fwd
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
if (bus_fwd_num != -1) {
CAN_FIFOMailBox_TypeDef to_send;
to_send.RIR = to_push.RIR | 1; // TXRQ
to_send.RDTR = to_push.RDTR;
to_send.RDLR = to_push.RDLR;
to_send.RDHR = to_push.RDHR;
can_send(&to_send, bus_fwd_num);
}
}
#endif

Expand Down
88 changes: 88 additions & 0 deletions board/drivers/lline_relay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifdef PANDA

int relay_control = 0; // True if relay is controlled through l-line

/* Conrol a relay connected to l-line pin */

// 160us cycles, 1 high, 25 low

volatile int turn_on_relay = 0;
volatile int on_cycles = 25;

//5s timeout
#define LLINE_TIMEOUT_CYCLES 31250
volatile int timeout_cycles = LLINE_TIMEOUT_CYCLES;

void TIM5_IRQHandler(void) {
if (TIM5->SR & TIM_SR_UIF) {
on_cycles--;
timeout_cycles--;
if (timeout_cycles == 0) {
turn_on_relay = 0;
}
if (on_cycles > 0) {
if (turn_on_relay) {
set_gpio_output(GPIOC, 10, 0);
}
}
else {
set_gpio_output(GPIOC, 10, 1);
on_cycles = 25;
}
}
TIM5->ARR = 160-1;
TIM5->SR = 0;
}

void lline_relay_init (void) {
set_lline_output(0);
relay_control = 1;
set_gpio_output(GPIOC, 10, 1);

// setup
TIM5->PSC = 48-1; // tick on 1 us
TIM5->CR1 = TIM_CR1_CEN; // enable
TIM5->ARR = 50-1; // 50 us
TIM5->DIER = TIM_DIER_UIE; // update interrupt
TIM5->CNT = 0;

NVIC_EnableIRQ(TIM5_IRQn);

#ifdef DEBUG
puts("INIT LLINE\n");
puts(" SR ");
putui(TIM5->SR);
puts(" PSC ");
putui(TIM5->PSC);
puts(" CR1 ");
putui(TIM5->CR1);
puts(" ARR ");
putui(TIM5->ARR);
puts(" DIER ");
putui(TIM5->DIER);
puts(" SR ");
putui(TIM5->SR);
puts(" CNT ");
putui(TIM5->CNT);
puts("\n");
#endif
}

void lline_relay_release (void) {
set_lline_output(0);
relay_control = 0;
puts("RELEASE LLINE\n");
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
NVIC_DisableIRQ(TIM5_IRQn);
}

void set_lline_output(int to_set) {
timeout_cycles = LLINE_TIMEOUT_CYCLES;
turn_on_relay = to_set;
}

int get_lline_status() {
return turn_on_relay;
}

#endif
7 changes: 5 additions & 2 deletions board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ void periph_init() {
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
Expand Down Expand Up @@ -390,7 +392,9 @@ void gpio_init() {
set_gpio_output(GPIOA, 14, 1);

// C10,C11: L-Line setup on USART 3
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
// LLine now used for relay output
set_gpio_output(GPIOC, 10, 1);
//set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
set_gpio_pullup(GPIOC, 11, PULL_UP);
#endif
Expand Down Expand Up @@ -475,4 +479,3 @@ void early() {
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
}
}

Loading

0 comments on commit 3c25760

Please sign in to comment.