Branch data Line data Source code
1 : : #include <stdint.h>
2 : :
3 : : #include "can.h"
4 : : #include "timing_util.h"
5 : :
6 : : #if (CANLIB_BIT_TIME_US != 4)
7 : : #warning "the bit time that can.h is expecting is not what timing_util is expecting"
8 : : #endif
9 : :
10 : 0 : bool can_generate_timing_params(uint32_t system_freq, can_timing_t *timing) {
11 : : // this function is designed to create a bit time of 4 microseconds
12 [ # # # # ]: 0 : switch (system_freq) {
13 : 0 : case 48000000:
14 : 0 : timing->brp = 7;
15 : 0 : timing->sjw = 3;
16 : 0 : timing->btlmode = 1;
17 : 0 : timing->sam = 0;
18 : 0 : timing->seg1ph = 4;
19 : 0 : timing->prseg = 0;
20 : 0 : timing->seg2ph = 4;
21 : 0 : return true;
22 : 0 : case 12000000:
23 : 0 : timing->brp = 1;
24 : 0 : timing->sjw = 3;
25 : 0 : timing->btlmode = 1;
26 : 0 : timing->sam = 0;
27 : 0 : timing->seg1ph = 4;
28 : 0 : timing->prseg = 0;
29 : 0 : timing->seg2ph = 4;
30 : 0 : return true;
31 : 0 : case 6000000:
32 : 0 : timing->brp = 0;
33 : 0 : timing->sjw = 3;
34 : 0 : timing->btlmode = 1;
35 : 0 : timing->sam = 0;
36 : 0 : timing->seg1ph = 4;
37 : 0 : timing->prseg = 0;
38 : 0 : timing->seg2ph = 4;
39 : 0 : return true;
40 : : default:
41 : : // unhandled can frequency, just abort
42 : : return false;
43 : : }
44 : : }
|