Skip to content

Commit

Permalink
Squashed 'panda/' changes from 39c1e39..06958e4
Browse files Browse the repository at this point in the history
06958e4 Fix pedal bootstub build
f5817e6 Fix Pedal bootstub version
c00fe86 CircleCI needs to check bootstub doesn't break too
9b5b696 Subaru: remove GM leftover
20c76ad Power Saving (#169)
c6eeaad Subaru: added last engage/disengage regression test
37d46e0 Subaru: added subaru safety tests
5686dae Subaru updated driver factor
a6193a8 Dcp remove (#168)
e437b9b Subaru: fixed bug and added safety tests
176f132 Subaru: added proper safety model
0b10bb7 Subaru safety: move camera to bus 2
bce279a Pedal: only one firmware (#164)
4f73cb4 Toyota pedal: checking for no pedal being commanded when openpilot is off
0b2327e Merge pull request #160 from commaai/capture_make_failure
7b504d2 panda safety test that replays drives of saved CAN messages (#151)
d7d0889 Capture make failure so it can be logged to sentry

git-subtree-dir: panda
git-subtree-split: 06958e4
  • Loading branch information
Vehicle Researcher committed Mar 26, 2019
1 parent a25e215 commit 2a0f066
Show file tree
Hide file tree
Showing 25 changed files with 484 additions and 458 deletions.
12 changes: 8 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ jobs:
command: |
docker run panda_build /bin/bash -c "cd /panda/board; make bin"
- run:
name: Build Honda Pedal STM image
name: Build Panda STM bootstub image
command: |
docker run panda_build /bin/bash -c "cd /panda/board/pedal_honda; make obj/comma.bin"
docker run panda_build /bin/bash -c "cd /panda/board; make obj/bootstub.panda.bin"
- run:
name: Build Toyota Pedal STM image
name: Build Pedal STM image
command: |
docker run panda_build /bin/bash -c "cd /panda/board/pedal_toyota; make obj/comma.bin"
docker run panda_build /bin/bash -c "cd /panda/board/pedal; make obj/comma.bin"
- run:
name: Build Pedal STM bootstub image
command: |
docker run panda_build /bin/bash -c "cd /panda/board/pedal; make obj/bootstub.bin"
- run:
name: Build NEO STM image
command: |
Expand Down
8 changes: 8 additions & 0 deletions board/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ CFLAGS += -I inc -I ../ -nostdlib -fno-builtin -std=gnu11 -Os

CFLAGS += -Tstm32_flash.ld

# Compile fast charge (DCP) only not on EON
ifeq (,$(wildcard /EON))
BUILDER = DEV
else
CFLAGS += "-DEON"
BUILDER = EON
endif

CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
OBJDUMP = arm-none-eabi-objdump
Expand Down
1 change: 1 addition & 0 deletions board/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ void early() {
#ifdef PANDA
// enable the ESP, disable ESP boot mode
// unless we are on a giant panda, then there's no ESP
// dont disable on grey panda
if (is_giant_panda) {
set_esp_mode(ESP_DISABLED);
} else {
Expand Down
11 changes: 7 additions & 4 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ int main() {
} else {
// enable ESP uart
uart_init(USART1, 115200);
#ifdef EON
set_esp_mode(ESP_DISABLED);
#endif
}
// enable LIN
uart_init(UART5, 10400);
Expand Down Expand Up @@ -590,8 +593,6 @@ int main() {
uint64_t marker = 0;
#define CURRENT_THRESHOLD 0xF00
#define CLICKS 8
// Enough clicks to ensure that enumeration happened. Should be longer than bootup time of the device connected to EON
#define CLICKS_BOOTUP 30
#endif

for (cnt=0;;cnt++) {
Expand All @@ -618,8 +619,9 @@ int main() {
}
break;
case USB_POWER_CDP:
// been CLICKS_BOOTUP clicks since we switched to CDP
if ((cnt-marker) >= CLICKS_BOOTUP ) {
#ifndef EON
// been CLICKS clicks since we switched to CDP
if ((cnt-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");
Expand All @@ -631,6 +633,7 @@ int main() {
if (current >= CURRENT_THRESHOLD) {
marker = cnt;
}
#endif
break;
case USB_POWER_DCP:
// been at least CLICKS clicks since we switched to DCP
Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion board/pedal_honda/Makefile → board/pedal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ recover: obj/bootstub.bin obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.bin

include ../../common/version.mk

obj/cert.h: ../../crypto/getcertheader.py
../../crypto/getcertheader.py ../../certs/debug.pub ../../certs/release.pub > $@

obj/main.o: main.c ../*.h
mkdir -p obj
$(CC) $(CFLAGS) -o $@ -c $<

obj/bootstub.o: ../bootstub.c ../*.h
obj/bootstub.o: ../bootstub.c ../*.h obj/gitversion.h obj/cert.h
mkdir -p obj
mkdir -p ../obj
cp obj/gitversion.h ../obj/gitversion.h
cp obj/cert.h ../obj/cert.h
$(CC) $(CFLAGS) -o $@ -c $<

obj/$(STARTUP_FILE).o: ../$(STARTUP_FILE).s
Expand Down
File renamed without changes.
64 changes: 37 additions & 27 deletions board/pedal_honda/main.c → board/pedal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,33 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {

#endif

// ***************************** honda can checksum *****************************

int can_cksum(uint8_t *dat, int len, int addr, int idx) {
int i;
int s = 0;
for (i = 0; i < len; i++) {
s += (dat[i] >> 4);
s += dat[i] & 0xF;
// ***************************** pedal can checksum *****************************

uint8_t pedal_checksum(uint8_t *dat, int len) {
uint8_t crc = 0xFF;
uint8_t poly = 0xD5; // standard crc8
int i, j;
for (i = len - 1; i >= 0; i--) {
crc ^= dat[i];
for (j = 0; j < 8; j++) {
if ((crc & 0x80) != 0) {
crc = (uint8_t)((crc << 1) ^ poly);
}
else {
crc <<= 1;
}
}
}
s += (addr>>0)&0xF;
s += (addr>>4)&0xF;
s += (addr>>8)&0xF;
s += idx;
s = 8-s;
return s&0xF;
return crc;
}

// ***************************** can port *****************************

// addresses to be used on CAN
#define CAN_GAS_INPUT 0x200
#define CAN_GAS_OUTPUT 0x201
#define CAN_GAS_SIZE 6
#define COUNTER_CYCLE 0xF

void CAN1_TX_IRQHandler() {
// clear interrupt
Expand Down Expand Up @@ -134,14 +139,19 @@ void CAN1_RX0_IRQHandler() {
}

// normal packet
uint8_t *dat = (uint8_t *)&CAN->sFIFOMailBox[0].RDLR;
uint8_t *dat2 = (uint8_t *)&CAN->sFIFOMailBox[0].RDHR;
uint8_t dat[8];
uint8_t *rdlr = (uint8_t *)&CAN->sFIFOMailBox[0].RDLR;
uint8_t *rdhr = (uint8_t *)&CAN->sFIFOMailBox[0].RDHR;
for (int i=0; i<4; i++) {
dat[i] = rdlr[i];
dat[i+4] = rdhr[i];
}
uint16_t value_0 = (dat[0] << 8) | dat[1];
uint16_t value_1 = (dat[2] << 8) | dat[3];
uint8_t enable = (dat2[0] >> 7) & 1;
uint8_t index = (dat2[1] >> 4) & 3;
if (can_cksum(dat, 5, CAN_GAS_INPUT, index) == (dat2[1] & 0xF)) {
if (((current_index+1)&3) == index) {
uint8_t enable = (dat[4] >> 7) & 1;
uint8_t index = dat[4] & COUNTER_CYCLE;
if (pedal_checksum(dat, CAN_GAS_SIZE - 1) == dat[5]) {
if (((current_index + 1) & COUNTER_CYCLE) == index) {
#ifdef DEBUG
puts("setting gas ");
puth(value);
Expand Down Expand Up @@ -196,18 +206,18 @@ void TIM3_IRQHandler() {
// check timer for sending the user pedal and clearing the CAN
if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) {
uint8_t dat[8];
dat[0] = (pdl0>>8)&0xFF;
dat[1] = (pdl0>>0)&0xFF;
dat[2] = (pdl1>>8)&0xFF;
dat[3] = (pdl1>>0)&0xFF;
dat[4] = state;
dat[5] = can_cksum(dat, 5, CAN_GAS_OUTPUT, pkt_idx) | (pkt_idx<<4);
dat[0] = (pdl0>>8) & 0xFF;
dat[1] = (pdl0>>0) & 0xFF;
dat[2] = (pdl1>>8) & 0xFF;
dat[3] = (pdl1>>0) & 0xFF;
dat[4] = (state & 0xF) << 4 | pkt_idx;
dat[5] = pedal_checksum(dat, CAN_GAS_SIZE - 1);
CAN->sTxMailBox[0].TDLR = dat[0] | (dat[1]<<8) | (dat[2]<<16) | (dat[3]<<24);
CAN->sTxMailBox[0].TDHR = dat[4] | (dat[5]<<8);
CAN->sTxMailBox[0].TDTR = 6; // len of packet is 5
CAN->sTxMailBox[0].TIR = (CAN_GAS_OUTPUT << 21) | 1;
++pkt_idx;
pkt_idx &= 3;
pkt_idx &= COUNTER_CYCLE;
} else {
// old can packet hasn't sent!
state = FAULT_SEND;
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion board/pedal_toyota/.gitignore

This file was deleted.

58 changes: 0 additions & 58 deletions board/pedal_toyota/Makefile

This file was deleted.

30 changes: 0 additions & 30 deletions board/pedal_toyota/README

This file was deleted.

Loading

0 comments on commit 2a0f066

Please sign in to comment.