@@ -119,6 +119,8 @@ char pkt_stuffed[MAX_BITS_CAN_PACKET];
119
119
int gmlan_sending = -1 ;
120
120
int gmlan_sendmax = -1 ;
121
121
int gmlan_silent_count = -1 ;
122
+ int gmlan_fail_count = 0 ;
123
+ #define MAX_FAIL_COUNT 10
122
124
123
125
void TIM4_IRQHandler (void ) {
124
126
if (TIM4 -> SR & TIM_SR_UIF && gmlan_sendmax != -1 ) {
@@ -141,17 +143,21 @@ void TIM4_IRQHandler(void) {
141
143
set_bitbanged_gmlan (1 ); // recessive
142
144
gmlan_silent_count = 0 ;
143
145
gmlan_sending = 0 ;
146
+ gmlan_fail_count ++ ;
147
+ if (gmlan_fail_count == MAX_FAIL_COUNT ) {
148
+ puts ("giving up GMLAN send\n" );
149
+ }
144
150
} else {
145
151
set_bitbanged_gmlan (pkt_stuffed [gmlan_sending ]);
146
152
gmlan_sending ++ ;
147
153
}
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
155
161
}
156
162
}
157
163
TIM4 -> SR = 0 ;
@@ -162,6 +168,7 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
162
168
if (gmlan_sendmax != -1 ) return ;
163
169
164
170
int len = get_bit_message (pkt_stuffed , to_bang );
171
+ gmlan_fail_count = 0 ;
165
172
gmlan_silent_count = 0 ;
166
173
gmlan_sending = 0 ;
167
174
gmlan_sendmax = len ;
0 commit comments