-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
0dcd84d Toyota safety: integer division bug 9a268f3 Toyota Safety: cleaner var types 8638650 bump panda version 9ab6a56 gmlan recv test a1a2d97 gmlan test 8efa389 detect ack f5fab4b nicer err ad4d423 add gmlan fail count bb41ff7 test 998f7c0 oops, set recessive 80051be autoretry on chime 813218d GM: allowing higher brakes in Volt, so decel can reach between 3 and 3.5 m/s2 74ad3d6 GM: max param definitions 38a9ea9 added gm safety for steering (#123) bf5db45 Safety: made the driver steer check common so it can be shared across multiple safety files ef079e6 Safety: made rate limit check also common dc3cc24 Safety: made common the max torque check as well dbc3568 removing extra spaces 1966bdf Safety: made real time rate limit check a shared function e214477 use timer for can bitbanging cb92733 minor bitbang refactor ed2920c support extended addressing in canbitbang 36df0996 move speed be46c7a Merge pull request #122 from commaai/gmbitbang 7edc88e put that back fa66e4b Revert "handle rollover" 2ce3a26a handle rollover 223a1fb cleanin it up 1ba7907 that space tho d917386 bitbanging works 74af441 can crc 932d727 bit stuffing support be22522 bros ok match bros 55da0b6 rigol yea, dj pauly d yea a577583 working on gmbitbang 875c2bd3 Cadillac: block OP messages if OP is on 7caba24 Addition to Bosch safety to support Hatchback (#111) 63ca46b modify before we forward bf70f51 Safety: increase buffer for sampled signals. TBD a violation feedback from board to prevent car faults b0541a8 Cadillac: monitoring the 4 torque messages independently cd1dba9 Cadillac: fixed bug in regression safety ca0b6be Cadillac: fixed typo. Need better regression tests to catch this d9f1e61 Cadillac: simplified the ignition code by removing the timeout logic and resetting controls_allowed = 0 at each init 293fd1a GM: using real ignition logic. Creedit to Jamezz 8fa507b GM: simplified max steer check logic, Cadillac: fixed can parsing bug c7e2c2d Cadillac (#119) 83bcaa3 small logic cleanup (#118) 9d92bf2 Cadillac: need to specify car name in const 79ab5af Toyota: moved common functions into safety header file 40c8dda Cadillac ignition: simplified logic 69be556 Cadillac: better ignition logic d176220 Ignition: made a default hook for GPIO bea5187 Cadillac: added max steer safety dbc11a1 Cadillac: always controls allowed for now ace232a Cadillac: ignition bug e2c89d6 Cadillac: changed ignition logic to be based on can presence 528f901 Cadillac: simpler ignition logic 4e79ecf Cadillac: added safety file placeholder git-subtree-dir: panda git-subtree-split: 0dcd84d
- Loading branch information
Vehicle Researcher
committed
Jun 17, 2018
1 parent
dcacbf6
commit d5b884f
Showing
24 changed files
with
1,291 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.1.1 | ||
v1.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
#define MAX_BITS_CAN_PACKET (200) | ||
|
||
// returns out_len | ||
int do_bitstuff(char *out, char *in, int in_len) { | ||
int last_bit = -1; | ||
int bit_cnt = 0; | ||
int j = 0; | ||
for (int i = 0; i < in_len; i++) { | ||
char bit = in[i]; | ||
out[j++] = bit; | ||
|
||
// do the stuffing | ||
if (bit == last_bit) { | ||
bit_cnt++; | ||
if (bit_cnt == 5) { | ||
// 5 in a row the same, do stuff | ||
last_bit = !bit; | ||
out[j++] = last_bit; | ||
bit_cnt = 1; | ||
} | ||
} else { | ||
// this is a new bit | ||
last_bit = bit; | ||
bit_cnt = 1; | ||
} | ||
} | ||
return j; | ||
} | ||
|
||
int append_crc(char *in, int in_len) { | ||
int crc = 0; | ||
for (int i = 0; i < in_len; i++) { | ||
crc <<= 1; | ||
if (in[i] ^ ((crc>>15)&1)) { | ||
crc = crc ^ 0x4599; | ||
} | ||
crc &= 0x7fff; | ||
} | ||
for (int i = 14; i >= 0; i--) { | ||
in[in_len++] = (crc>>i)&1; | ||
} | ||
return in_len; | ||
} | ||
|
||
int append_bits(char *in, int in_len, char *app, int app_len) { | ||
for (int i = 0; i < app_len; i++) { | ||
in[in_len++] = app[i]; | ||
} | ||
return in_len; | ||
} | ||
|
||
int append_int(char *in, int in_len, int val, int val_len) { | ||
for (int i = val_len-1; i >= 0; i--) { | ||
in[in_len++] = (val&(1<<i)) != 0; | ||
} | ||
return in_len; | ||
} | ||
|
||
int get_bit_message(char *out, CAN_FIFOMailBox_TypeDef *to_bang) { | ||
char pkt[MAX_BITS_CAN_PACKET]; | ||
char footer[] = { | ||
1, // CRC delimiter | ||
1, // ACK | ||
1, // ACK delimiter | ||
1,1,1,1,1,1,1, // EOF | ||
1,1,1, // IFS | ||
}; | ||
|
||
int len = 0; | ||
|
||
// test packet | ||
int dlc_len = to_bang->RDTR & 0xF; | ||
len = append_int(pkt, len, 0, 1); // Start-of-frame | ||
|
||
if (to_bang->RIR & 4) { | ||
// extended identifier | ||
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier | ||
len = append_int(pkt, len, 3, 2); // SRR+IDE | ||
len = append_int(pkt, len, (to_bang->RIR >> 3) & ((1<<18)-1), 18); // Identifier | ||
len = append_int(pkt, len, 0, 3); // RTR+r1+r0 | ||
} else { | ||
// standard identifier | ||
len = append_int(pkt, len, to_bang->RIR >> 21, 11); // Identifier | ||
len = append_int(pkt, len, 0, 3); // RTR+IDE+reserved | ||
} | ||
|
||
len = append_int(pkt, len, dlc_len, 4); // Data length code | ||
|
||
// append data | ||
for (int i = 0; i < dlc_len; i++) { | ||
unsigned char dat = ((unsigned char *)(&(to_bang->RDLR)))[i]; | ||
len = append_int(pkt, len, dat, 8); | ||
} | ||
|
||
// append crc | ||
len = append_crc(pkt, len); | ||
|
||
// do bitstuffing | ||
len = do_bitstuff(out, pkt, len); | ||
|
||
// append footer | ||
len = append_bits(out, len, footer, sizeof(footer)); | ||
return len; | ||
} | ||
|
||
// hardware stuff below this line | ||
|
||
#ifdef PANDA | ||
|
||
void set_bitbanged_gmlan(int val) { | ||
if (val) { | ||
GPIOB->ODR |= (1 << 13); | ||
} else { | ||
GPIOB->ODR &= ~(1 << 13); | ||
} | ||
} | ||
|
||
char pkt_stuffed[MAX_BITS_CAN_PACKET]; | ||
int gmlan_sending = -1; | ||
int gmlan_sendmax = -1; | ||
|
||
int gmlan_silent_count = 0; | ||
int gmlan_fail_count = 0; | ||
#define REQUIRED_SILENT_TIME 10 | ||
#define MAX_FAIL_COUNT 10 | ||
|
||
void TIM4_IRQHandler(void) { | ||
if (TIM4->SR & TIM_SR_UIF && gmlan_sendmax != -1) { | ||
int read = get_gpio_input(GPIOB, 12); | ||
if (gmlan_silent_count < REQUIRED_SILENT_TIME) { | ||
if (read == 0) { | ||
gmlan_silent_count = 0; | ||
} else { | ||
gmlan_silent_count++; | ||
} | ||
} else if (gmlan_silent_count == REQUIRED_SILENT_TIME) { | ||
int retry = 0; | ||
// in send loop | ||
if (gmlan_sending > 0 && // not first bit | ||
(read == 0 && pkt_stuffed[gmlan_sending-1] == 1) && // bus wrongly dominant | ||
gmlan_sending != (gmlan_sendmax-11)) { //not ack bit | ||
puts("GMLAN ERR: bus driven at "); | ||
puth(gmlan_sending); | ||
puts("\n"); | ||
retry = 1; | ||
} else if (read == 1 && gmlan_sending == (gmlan_sendmax-11)) { // recessive during ACK | ||
puts("GMLAN ERR: didn't recv ACK\n"); | ||
retry = 1; | ||
} | ||
if (retry) { | ||
// reset sender (retry after 7 silent) | ||
set_bitbanged_gmlan(1); // recessive | ||
gmlan_silent_count = 0; | ||
gmlan_sending = 0; | ||
gmlan_fail_count++; | ||
if (gmlan_fail_count == MAX_FAIL_COUNT) { | ||
puts("GMLAN ERR: giving up send\n"); | ||
} | ||
} else { | ||
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]); | ||
gmlan_sending++; | ||
} | ||
} | ||
if (gmlan_sending == gmlan_sendmax || gmlan_fail_count == MAX_FAIL_COUNT) { | ||
set_bitbanged_gmlan(1); // recessive | ||
set_gpio_mode(GPIOB, 13, MODE_INPUT); | ||
TIM4->DIER = 0; // no update interrupt | ||
TIM4->CR1 = 0; // disable timer | ||
gmlan_sendmax = -1; // exit | ||
} | ||
} | ||
TIM4->SR = 0; | ||
} | ||
|
||
void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) { | ||
// TODO: make failure less silent | ||
if (gmlan_sendmax != -1) return; | ||
|
||
int len = get_bit_message(pkt_stuffed, to_bang); | ||
gmlan_fail_count = 0; | ||
gmlan_silent_count = 0; | ||
gmlan_sending = 0; | ||
gmlan_sendmax = len; | ||
|
||
// setup for bitbang loop | ||
set_bitbanged_gmlan(1); // recessive | ||
set_gpio_mode(GPIOB, 13, MODE_OUTPUT); | ||
|
||
// setup | ||
TIM4->PSC = 48-1; // tick on 1 us | ||
TIM4->CR1 = TIM_CR1_CEN; // enable | ||
TIM4->ARR = 30-1; // 33.3 kbps | ||
|
||
// in case it's disabled | ||
NVIC_EnableIRQ(TIM4_IRQn); | ||
|
||
// run the interrupt | ||
TIM4->DIER = TIM_DIER_UIE; // update interrupt | ||
TIM4->SR = 0; | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.