Skip to content

Commit f5fab4b

Browse files
committed
nicer err
1 parent ad4d423 commit f5fab4b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

board/drivers/canbitbang.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,27 @@ void set_bitbanged_gmlan(int val) {
118118
char pkt_stuffed[MAX_BITS_CAN_PACKET];
119119
int gmlan_sending = -1;
120120
int gmlan_sendmax = -1;
121-
int gmlan_silent_count = -1;
121+
122+
int gmlan_silent_count = 0;
122123
int gmlan_fail_count = 0;
124+
#define REQUIRED_SILENT_TIME 10
123125
#define MAX_FAIL_COUNT 10
124126

125127
void TIM4_IRQHandler(void) {
126128
if (TIM4->SR & TIM_SR_UIF && gmlan_sendmax != -1) {
127129
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) {
129131
if (read == 0) {
130132
gmlan_silent_count = 0;
131133
} else {
132134
gmlan_silent_count++;
133135
}
134-
} else if (gmlan_silent_count == 7) {
136+
} else if (gmlan_silent_count == REQUIRED_SILENT_TIME) {
135137
// in send loop
136138
if (gmlan_sending > 0 && // not first bit
137139
(read == 0 && pkt_stuffed[gmlan_sending-1] == 1) && // bus wrongly dominant
138140
gmlan_sending != (gmlan_sendmax-11)) { //not ack bit
139-
puts("ERR: bus driven at ");
141+
puts("GMLAN ERR: bus driven at ");
140142
puth(gmlan_sending);
141143
puts("\n");
142144
// reset sender (retry after 7 silent)
@@ -145,7 +147,7 @@ void TIM4_IRQHandler(void) {
145147
gmlan_sending = 0;
146148
gmlan_fail_count++;
147149
if (gmlan_fail_count == MAX_FAIL_COUNT) {
148-
puts("giving up GMLAN send\n");
150+
puts("GMLAN ERR: giving up send\n");
149151
}
150152
} else {
151153
set_bitbanged_gmlan(pkt_stuffed[gmlan_sending]);

0 commit comments

Comments
 (0)