Skip to content

Commit ad4d423

Browse files
committed
add gmlan fail count
1 parent bb41ff7 commit ad4d423

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

board/drivers/canbitbang.h

+14-7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ char pkt_stuffed[MAX_BITS_CAN_PACKET];
119119
int gmlan_sending = -1;
120120
int gmlan_sendmax = -1;
121121
int gmlan_silent_count = -1;
122+
int gmlan_fail_count = 0;
123+
#define MAX_FAIL_COUNT 10
122124

123125
void TIM4_IRQHandler(void) {
124126
if (TIM4->SR & TIM_SR_UIF && gmlan_sendmax != -1) {
@@ -141,17 +143,21 @@ void TIM4_IRQHandler(void) {
141143
set_bitbanged_gmlan(1); // recessive
142144
gmlan_silent_count = 0;
143145
gmlan_sending = 0;
146+
gmlan_fail_count++;
147+
if (gmlan_fail_count == MAX_FAIL_COUNT) {
148+
puts("giving up GMLAN send\n");
149+
}
144150
} else {
145151
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);
146152
gmlan_sending++;
147153
}
148-
if (gmlan_sending == gmlan_sendmax) {
149-
set_bitbanged_gmlan(1); // recessive
150-
set_gpio_mode(GPIOB, 13, MODE_INPUT);
151-
TIM4->DIER = 0; // no update interrupt
152-
TIM4->CR1 = 0; // disable timer
153-
gmlan_sendmax = -1; // exit
154-
}
154+
}
155+
if (gmlan_sending == gmlan_sendmax || gmlan_fail_count == MAX_FAIL_COUNT) {
156+
set_bitbanged_gmlan(1); // recessive
157+
set_gpio_mode(GPIOB, 13, MODE_INPUT);
158+
TIM4->DIER = 0; // no update interrupt
159+
TIM4->CR1 = 0; // disable timer
160+
gmlan_sendmax = -1; // exit
155161
}
156162
}
157163
TIM4->SR = 0;
@@ -162,6 +168,7 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
162168
if (gmlan_sendmax != -1) return;
163169

164170
int len = get_bit_message(pkt_stuffed, to_bang);
171+
gmlan_fail_count = 0;
165172
gmlan_silent_count = 0;
166173
gmlan_sending = 0;
167174
gmlan_sendmax = len;

0 commit comments

Comments
 (0)