Skip to content

Commit

Permalink
Revert "handle rollover"
Browse files Browse the repository at this point in the history
This reverts commit 2ce3a26.
  • Loading branch information
geohot committed Jun 11, 2018
1 parent 2ce3a26 commit fa66e4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions board/drivers/canbitbang.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
silent_count = 0;
}
int lwait = TIM2->CNT;
while (get_ts_elapsed(TIM2->CNT, lwait) < SPEEED);
while ((TIM2->CNT - lwait) < SPEEED);
}

// send my message with optional failure
int last = 1;
int init = TIM2->CNT;
for (int i = 0; i < len; i++) {
while (get_ts_elapsed(TIM2->CNT, init) < (SPEEED*i));
while ((TIM2->CNT - init) < (SPEEED*i));
int read = get_gpio_input(GPIOB, 12);
if ((read == 0 && last == 1) && i != (len-11)) {
puts("ERR: bus driven at ");
Expand Down
16 changes: 0 additions & 16 deletions board/libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,3 @@ void exit_critical_section() {
}
}

// ***** generic helpers ******

// compute the time elapsed (in microseconds) from 2 counter samples
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
}

// convert a trimmed integer to signed 32 bit int
int to_signed(int d, int bits) {
if (d >= (1 << (bits - 1))) {
d -= (1 << bits);
}
return d;
}


15 changes: 15 additions & 0 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
int safety_ignition_hook();
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last);
int to_signed(int d, int bits);
void update_sample(struct sample_t *sample, int sample_new);

typedef void (*safety_hook_init)(int16_t param);
Expand Down Expand Up @@ -112,6 +114,19 @@ int safety_set_mode(uint16_t mode, int16_t param) {
return -1;
}

// compute the time elapsed (in microseconds) from 2 counter samples
uint32_t get_ts_elapsed(uint32_t ts, uint32_t ts_last) {
return ts > ts_last ? ts - ts_last : (0xFFFFFFFF - ts_last) + 1 + ts;
}

// convert a trimmed integer to signed 32 bit int
int to_signed(int d, int bits) {
if (d >= (1 << (bits - 1))) {
d -= (1 << bits);
}
return d;
}

// given a new sample, update the smaple_t struct
void update_sample(struct sample_t *sample, int sample_new) {
for (int i = sizeof(sample->values)/sizeof(sample->values[0]) - 1; i > 0; i--) {
Expand Down

0 comments on commit fa66e4b

Please sign in to comment.