Skip to content

Commit fa66e4b

Browse files
committed
Revert "handle rollover"
This reverts commit 2ce3a26.
1 parent 2ce3a26 commit fa66e4b

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

board/drivers/canbitbang.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
125125
silent_count = 0;
126126
}
127127
int lwait = TIM2->CNT;
128-
while (get_ts_elapsed(TIM2->CNT, lwait) < SPEEED);
128+
while ((TIM2->CNT - lwait) < SPEEED);
129129
}
130130

131131
// send my message with optional failure
132132
int last = 1;
133133
int init = TIM2->CNT;
134134
for (int i = 0; i < len; i++) {
135-
while (get_ts_elapsed(TIM2->CNT, init) < (SPEEED*i));
135+
while ((TIM2->CNT - init) < (SPEEED*i));
136136
int read = get_gpio_input(GPIOB, 12);
137137
if ((read == 0 && last == 1) && i != (len-11)) {
138138
puts("ERR: bus driven at ");

board/libc.h

-16
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,3 @@ void exit_critical_section() {
4949
}
5050
}
5151

52-
// ***** generic helpers ******
53-
54-
// compute the time elapsed (in microseconds) from 2 counter samples
55-
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
56-
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
57-
}
58-
59-
// convert a trimmed integer to signed 32 bit int
60-
int to_signed(int d, int bits) {
61-
if (d >= (1 << (bits - 1))) {
62-
d -= (1 << bits);
63-
}
64-
return d;
65-
}
66-
67-

board/safety.h

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
99
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
1010
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
1111
int safety_ignition_hook();
12+
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
13+
int to_signed(int d, int bits);
1214
void update_sample(struct sample_t *sample, int sample_new);
1315

1416
typedef void (*safety_hook_init)(int16_t param);
@@ -112,6 +114,19 @@ int safety_set_mode(uint16_t mode, int16_t param) {
112114
return -1;
113115
}
114116

117+
// compute the time elapsed (in microseconds) from 2 counter samples
118+
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
119+
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
120+
}
121+
122+
// convert a trimmed integer to signed 32 bit int
123+
int to_signed(int d, int bits) {
124+
if (d >= (1 << (bits - 1))) {
125+
d -= (1 << bits);
126+
}
127+
return d;
128+
}
129+
115130
// given a new sample, update the smaple_t struct
116131
void update_sample(struct sample_t *sample, int sample_new) {
117132
for (int i = sizeof(sample->values)/sizeof(sample->values[0]) - 1; i > 0; i--) {

0 commit comments

Comments
 (0)