Commit fa66e4b 1 parent 2ce3a26 commit fa66e4b Copy full SHA for fa66e4b
File tree 3 files changed +17
-18
lines changed
3 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -125,14 +125,14 @@ void bitbang_gmlan(CAN_FIFOMailBox_TypeDef *to_bang) {
125
125
silent_count = 0 ;
126
126
}
127
127
int lwait = TIM2 -> CNT ;
128
- while (get_ts_elapsed (TIM2 -> CNT , lwait ) < SPEEED );
128
+ while ((TIM2 -> CNT - lwait ) < SPEEED );
129
129
}
130
130
131
131
// send my message with optional failure
132
132
int last = 1 ;
133
133
int init = TIM2 -> CNT ;
134
134
for (int i = 0 ; i < len ; i ++ ) {
135
- while (get_ts_elapsed (TIM2 -> CNT , init ) < (SPEEED * i ));
135
+ while ((TIM2 -> CNT - init ) < (SPEEED * i ));
136
136
int read = get_gpio_input (GPIOB , 12 );
137
137
if ((read == 0 && last == 1 ) && i != (len - 11 )) {
138
138
puts ("ERR: bus driven at " );
Original file line number Diff line number Diff line change @@ -49,19 +49,3 @@ void exit_critical_section() {
49
49
}
50
50
}
51
51
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
-
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
9
9
int safety_tx_hook (CAN_FIFOMailBox_TypeDef * to_send );
10
10
int safety_tx_lin_hook (int lin_num , uint8_t * data , int len );
11
11
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 );
12
14
void update_sample (struct sample_t * sample , int sample_new );
13
15
14
16
typedef void (* safety_hook_init )(int16_t param );
@@ -112,6 +114,19 @@ int safety_set_mode(uint16_t mode, int16_t param) {
112
114
return -1 ;
113
115
}
114
116
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
+
115
130
// given a new sample, update the smaple_t struct
116
131
void update_sample (struct sample_t * sample , int sample_new ) {
117
132
for (int i = sizeof (sample -> values )/sizeof (sample -> values [0 ]) - 1 ; i > 0 ; i -- ) {
You can’t perform that action at this time.
0 commit comments