Skip to content

Commit 3c25760

Browse files
author
Vehicle Researcher
committed
Squashed 'panda/' changes from 38dc4e6..1282e8f
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
1 parent 27ef9f2 commit 3c25760

37 files changed

+947
-107
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.git
2+
.DS_Store
3+
boardesp/esp-open-sdk

Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
FROM ubuntu:16.04
2+
ENV PYTHONUNBUFFERED 1
3+
4+
RUN apt-get update && apt-get install -y \
5+
autoconf \
6+
automake \
7+
bash \
8+
bison \
9+
bzip2 \
10+
curl \
11+
dfu-util \
12+
flex \
13+
g++ \
14+
gawk \
15+
gcc \
16+
git \
17+
gperf \
18+
help2man \
19+
iputils-ping \
20+
libexpat-dev \
21+
libstdc++-arm-none-eabi-newlib \
22+
libtool \
23+
libtool-bin \
24+
libusb-1.0-0 \
25+
make \
26+
ncurses-dev \
27+
network-manager \
28+
python-dev \
29+
python-serial \
30+
sed \
31+
texinfo \
32+
unrar-free \
33+
unzip \
34+
wget \
35+
build-essential \
36+
python-dev \
37+
python-pip \
38+
screen \
39+
vim \
40+
wget \
41+
wireless-tools
42+
43+
RUN pip install --upgrade pip==18.0
44+
45+
COPY requirements.txt /tmp/
46+
RUN pip install -r /tmp/requirements.txt
47+
48+
RUN mkdir -p /home/batman
49+
ENV HOME /home/batman
50+
51+
ENV PYTHONPATH /tmp:$PYTHONPATH
52+
53+
COPY ./boardesp/get_sdk_ci.sh /tmp/panda/boardesp/
54+
55+
RUN useradd --system -s /sbin/nologin pandauser
56+
RUN mkdir -p /tmp/panda/boardesp/esp-open-sdk
57+
RUN chown pandauser /tmp/panda/boardesp/esp-open-sdk
58+
USER pandauser
59+
RUN cd /tmp/panda/boardesp && ./get_sdk_ci.sh
60+
USER root
61+
62+
COPY ./xx/pandaextra /tmp/pandaextra
63+
64+
ADD ./panda.tar.gz /tmp/panda

Jenkinsfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
pipeline {
2+
agent any
3+
environment {
4+
AUTHOR = """${sh(
5+
returnStdout: true,
6+
script: "git --no-pager show -s --format='%an' ${GIT_COMMIT}"
7+
).trim()}"""
8+
9+
DOCKER_IMAGE_TAG = "panda:build-${env.BUILD_ID}"
10+
DOCKER_NAME = "panda-test-${env.BUILD_ID}"
11+
}
12+
stages {
13+
stage('Build Docker Image') {
14+
steps {
15+
timeout(time: 60, unit: 'MINUTES') {
16+
script {
17+
sh 'git clone --no-checkout --depth 1 [email protected]:commaai/xx.git || true'
18+
sh 'cd xx && git fetch origin && git checkout origin/master -- pandaextra && cd ..' // Needed for certs for panda flashing
19+
sh 'git archive -v -o panda.tar.gz --format=tar.gz HEAD'
20+
dockerImage = docker.build("${env.DOCKER_IMAGE_TAG}")
21+
}
22+
}
23+
}
24+
}
25+
stage('Test Dev Build') {
26+
steps {
27+
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
28+
timeout(time: 60, unit: 'MINUTES') {
29+
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 '"
30+
}
31+
}
32+
}
33+
}
34+
stage('Test EON Build') {
35+
steps {
36+
lock(resource: "Pandas", inversePrecedence: true, quantity:1){
37+
timeout(time: 60, unit: 'MINUTES') {
38+
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_dev.xml"
39+
sh "touch EON && docker cp EON ${env.DOCKER_NAME}:/EON"
40+
sh "docker start -a ${env.DOCKER_NAME}"
41+
}
42+
}
43+
}
44+
}
45+
}
46+
post {
47+
always {
48+
script {
49+
sh "docker cp ${env.DOCKER_NAME}:/tmp/panda/nosetests.xml test_results_EON.xml"
50+
sh "docker rm ${env.DOCKER_NAME}"
51+
}
52+
junit "test_results*.xml"
53+
}
54+
}
55+
}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.2.0
1+
v1.2.1

board/drivers/can.h

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#define ALL_CAN_BUT_MAIN_SILENT 0xFE
44
#define ALL_CAN_LIVE 0
55

6+
#include "lline_relay.h"
7+
68
int can_live = 0, pending_can_live = 0, can_loopback = 0, can_silent = ALL_CAN_SILENT;
79

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

28+
#ifdef PANDA
29+
// Forward declare
30+
void power_save_reset_timer();
31+
#endif
32+
2633
// ********************* interrupt safe queue *********************
2734

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

215222
// enable certain CAN interrupts
216-
CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0;
223+
CAN->IER |= CAN_IER_TMEIE | CAN_IER_FMPIE0 | CAN_IER_WKUIE;
217224

218225
switch (can_number) {
219226
case 0:
@@ -293,7 +300,6 @@ void can_set_gmlan(int bus) {
293300
void can_sce(CAN_TypeDef *CAN) {
294301
enter_critical_section();
295302

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

316322
uint8_t can_number = CAN_NUM_FROM_CANIF(CAN);
317323
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
318-
if (can_autobaud_enabled[bus_number] && (CAN->ESR & CAN_ESR_LEC)) {
319-
can_autobaud_speed_increment(can_number);
320-
can_set_speed(can_number);
321-
}
322324

323-
// clear current send
324-
CAN->TSR |= CAN_TSR_ABRQ0;
325-
CAN->MSR &= ~(CAN_MSR_ERRI);
326-
CAN->MSR = CAN->MSR;
325+
if (CAN->MSR & CAN_MSR_WKUI) {
326+
//Waking from sleep
327+
#ifdef DEBUG
328+
puts("WAKE\n");
329+
#endif
330+
set_can_enable(CAN, 1);
331+
CAN->MSR &= ~(CAN_MSR_WKUI);
332+
CAN->MSR = CAN->MSR;
333+
#ifdef PANDA
334+
power_save_reset_timer();
335+
#endif
336+
} else {
337+
can_err_cnt += 1;
338+
327339

340+
if (can_autobaud_enabled[bus_number] && (CAN->ESR & CAN_ESR_LEC)) {
341+
can_autobaud_speed_increment(can_number);
342+
can_set_speed(can_number);
343+
}
344+
345+
// clear current send
346+
CAN->TSR |= CAN_TSR_ABRQ0;
347+
CAN->MSR &= ~(CAN_MSR_ERRI);
348+
CAN->MSR = CAN->MSR;
349+
}
328350
exit_critical_section();
329351
}
330352

331353
// ***************************** CAN *****************************
332354

333355
void process_can(uint8_t can_number) {
334356
if (can_number == 0xff) return;
357+
#ifdef PANDA
358+
power_save_reset_timer();
359+
#endif
335360

336361
enter_critical_section();
337362

@@ -375,6 +400,13 @@ void process_can(uint8_t can_number) {
375400
}
376401

377402
if (can_pop(can_queues[bus_number], &to_send)) {
403+
if (CAN->MCR & CAN_MCR_SLEEP) {
404+
set_can_enable(CAN, 1);
405+
CAN->MCR &= ~(CAN_MCR_SLEEP);
406+
CAN->MCR |= CAN_MCR_INRQ;
407+
while((CAN->MSR & CAN_MSR_INAK) != CAN_MSR_INAK);
408+
CAN->MCR &= ~(CAN_MCR_INRQ);
409+
}
378410
can_tx_cnt += 1;
379411
// only send if we have received a packet
380412
CAN->sTxMailBox[0].TDLR = to_send.RDLR;
@@ -390,6 +422,9 @@ void process_can(uint8_t can_number) {
390422
// CAN receive handlers
391423
// blink blue when we are receiving CAN messages
392424
void can_rx(uint8_t can_number) {
425+
#ifdef PANDA
426+
power_save_reset_timer();
427+
#endif
393428
CAN_TypeDef *CAN = CANIF_FROM_CAN_NUM(can_number);
394429
uint8_t bus_number = BUS_NUM_FROM_CAN_NUM(can_number);
395430
while (CAN->RF0R & CAN_RF0R_FMP0) {
@@ -420,14 +455,16 @@ void can_rx(uint8_t can_number) {
420455

421456
// forwarding (panda only)
422457
#ifdef PANDA
423-
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
424-
if (bus_fwd_num != -1) {
425-
CAN_FIFOMailBox_TypeDef to_send;
426-
to_send.RIR = to_push.RIR | 1; // TXRQ
427-
to_send.RDTR = to_push.RDTR;
428-
to_send.RDLR = to_push.RDLR;
429-
to_send.RDHR = to_push.RDHR;
430-
can_send(&to_send, bus_fwd_num);
458+
if ((get_lline_status() != 0) || !relay_control) { //Relay engaged or relay isn't controlled, allow fwd
459+
int bus_fwd_num = can_forwarding[bus_number] != -1 ? can_forwarding[bus_number] : safety_fwd_hook(bus_number, &to_push);
460+
if (bus_fwd_num != -1) {
461+
CAN_FIFOMailBox_TypeDef to_send;
462+
to_send.RIR = to_push.RIR | 1; // TXRQ
463+
to_send.RDTR = to_push.RDTR;
464+
to_send.RDLR = to_push.RDLR;
465+
to_send.RDHR = to_push.RDHR;
466+
can_send(&to_send, bus_fwd_num);
467+
}
431468
}
432469
#endif
433470

board/drivers/lline_relay.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#ifdef PANDA
2+
3+
int relay_control = 0; // True if relay is controlled through l-line
4+
5+
/* Conrol a relay connected to l-line pin */
6+
7+
// 160us cycles, 1 high, 25 low
8+
9+
volatile int turn_on_relay = 0;
10+
volatile int on_cycles = 25;
11+
12+
//5s timeout
13+
#define LLINE_TIMEOUT_CYCLES 31250
14+
volatile int timeout_cycles = LLINE_TIMEOUT_CYCLES;
15+
16+
void TIM5_IRQHandler(void) {
17+
if (TIM5->SR & TIM_SR_UIF) {
18+
on_cycles--;
19+
timeout_cycles--;
20+
if (timeout_cycles == 0) {
21+
turn_on_relay = 0;
22+
}
23+
if (on_cycles > 0) {
24+
if (turn_on_relay) {
25+
set_gpio_output(GPIOC, 10, 0);
26+
}
27+
}
28+
else {
29+
set_gpio_output(GPIOC, 10, 1);
30+
on_cycles = 25;
31+
}
32+
}
33+
TIM5->ARR = 160-1;
34+
TIM5->SR = 0;
35+
}
36+
37+
void lline_relay_init (void) {
38+
set_lline_output(0);
39+
relay_control = 1;
40+
set_gpio_output(GPIOC, 10, 1);
41+
42+
// setup
43+
TIM5->PSC = 48-1; // tick on 1 us
44+
TIM5->CR1 = TIM_CR1_CEN; // enable
45+
TIM5->ARR = 50-1; // 50 us
46+
TIM5->DIER = TIM_DIER_UIE; // update interrupt
47+
TIM5->CNT = 0;
48+
49+
NVIC_EnableIRQ(TIM5_IRQn);
50+
51+
#ifdef DEBUG
52+
puts("INIT LLINE\n");
53+
puts(" SR ");
54+
putui(TIM5->SR);
55+
puts(" PSC ");
56+
putui(TIM5->PSC);
57+
puts(" CR1 ");
58+
putui(TIM5->CR1);
59+
puts(" ARR ");
60+
putui(TIM5->ARR);
61+
puts(" DIER ");
62+
putui(TIM5->DIER);
63+
puts(" SR ");
64+
putui(TIM5->SR);
65+
puts(" CNT ");
66+
putui(TIM5->CNT);
67+
puts("\n");
68+
#endif
69+
}
70+
71+
void lline_relay_release (void) {
72+
set_lline_output(0);
73+
relay_control = 0;
74+
puts("RELEASE LLINE\n");
75+
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
76+
NVIC_DisableIRQ(TIM5_IRQn);
77+
}
78+
79+
void set_lline_output(int to_set) {
80+
timeout_cycles = LLINE_TIMEOUT_CYCLES;
81+
turn_on_relay = to_set;
82+
}
83+
84+
int get_lline_status() {
85+
return turn_on_relay;
86+
}
87+
88+
#endif

board/gpio.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ void periph_init() {
120120
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
121121
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
122122
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
123+
RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;
124+
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
123125
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
124126
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
125127
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
@@ -390,7 +392,9 @@ void gpio_init() {
390392
set_gpio_output(GPIOA, 14, 1);
391393

392394
// C10,C11: L-Line setup on USART 3
393-
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
395+
// LLine now used for relay output
396+
set_gpio_output(GPIOC, 10, 1);
397+
//set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
394398
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
395399
set_gpio_pullup(GPIOC, 11, PULL_UP);
396400
#endif
@@ -475,4 +479,3 @@ void early() {
475479
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
476480
}
477481
}
478-

0 commit comments

Comments
 (0)