Skip to content

Commit

Permalink
add gmlan fail count
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jun 15, 2018
1 parent bb41ff7 commit ad4d423
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions board/drivers/canbitbang.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ char pkt_stuffed[MAX_BITS_CAN_PACKET];
int gmlan_sending = -1;
int gmlan_sendmax = -1;
int gmlan_silent_count = -1;
int gmlan_fail_count = 0;
#define MAX_FAIL_COUNT 10

void TIM4_IRQHandler(void) {
if (TIM4->SR & TIM_SR_UIF && gmlan_sendmax != -1) {
Expand All @@ -141,17 +143,21 @@ void TIM4_IRQHandler(void) {
set_bitbanged_gmlan(1); // recessive
gmlan_silent_count = 0;
gmlan_sending = 0;
gmlan_fail_count++;
if (gmlan_fail_count == MAX_FAIL_COUNT) {
puts("giving up GMLAN send\n");
}
} else {
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);
gmlan_sending++;
}
if (gmlan_sending == gmlan_sendmax) {
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
}
}
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;
Expand All @@ -162,6 +168,7 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
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;
Expand Down

0 comments on commit ad4d423

Please sign in to comment.