@@ -118,25 +118,27 @@ void set_bitbanged_gmlan(int val) {
118
118
char pkt_stuffed [MAX_BITS_CAN_PACKET ];
119
119
int gmlan_sending = -1 ;
120
120
int gmlan_sendmax = -1 ;
121
- int gmlan_silent_count = -1 ;
121
+
122
+ int gmlan_silent_count = 0 ;
122
123
int gmlan_fail_count = 0 ;
124
+ #define REQUIRED_SILENT_TIME 10
123
125
#define MAX_FAIL_COUNT 10
124
126
125
127
void TIM4_IRQHandler (void ) {
126
128
if (TIM4 -> SR & TIM_SR_UIF && gmlan_sendmax != -1 ) {
127
129
int read = get_gpio_input (GPIOB , 12 );
128
- if (gmlan_silent_count != -1 && gmlan_silent_count < 7 ) {
130
+ if (gmlan_silent_count < REQUIRED_SILENT_TIME ) {
129
131
if (read == 0 ) {
130
132
gmlan_silent_count = 0 ;
131
133
} else {
132
134
gmlan_silent_count ++ ;
133
135
}
134
- } else if (gmlan_silent_count == 7 ) {
136
+ } else if (gmlan_silent_count == REQUIRED_SILENT_TIME ) {
135
137
// in send loop
136
138
if (gmlan_sending > 0 && // not first bit
137
139
(read == 0 && pkt_stuffed [gmlan_sending - 1 ] == 1 ) && // bus wrongly dominant
138
140
gmlan_sending != (gmlan_sendmax - 11 )) { //not ack bit
139
- puts ("ERR: bus driven at " );
141
+ puts ("GMLAN ERR: bus driven at " );
140
142
puth (gmlan_sending );
141
143
puts ("\n" );
142
144
// reset sender (retry after 7 silent)
@@ -145,7 +147,7 @@ void TIM4_IRQHandler(void) {
145
147
gmlan_sending = 0 ;
146
148
gmlan_fail_count ++ ;
147
149
if (gmlan_fail_count == MAX_FAIL_COUNT ) {
148
- puts ("giving up GMLAN send\n" );
150
+ puts ("GMLAN ERR: giving up send\n" );
149
151
}
150
152
} else {
151
153
set_bitbanged_gmlan (pkt_stuffed [gmlan_sending ]);
0 commit comments