cfg_spi_divtable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef CFG_SPI_DIVTABLE_H
20 #define CFG_SPI_DIVTABLE_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
33 #define CFG_SPIDIV_20 \
34  { /* for 20000000Hz */ \
35  7, /* -> 78125Hz */ \
36  5, /* -> 312500Hz */ \
37  3, /* -> 1250000Hz */ \
38  1, /* -> 5000000Hz */ \
39  0 /* -> 10000000Hz */ \
40  },
41 
42 #define CFG_SPIDIV_30 \
43  { /* for 30000000Hz */ \
44  7, /* -> 117187Hz */ \
45  5, /* -> 468750Hz */ \
46  4, /* -> 937500Hz */ \
47  2, /* -> 3750000Hz */ \
48  1 /* -> 7500000Hz */ \
49  },
50 
51 #define CFG_SPIDIV_32 \
52  { /* for 32000000Hz */ \
53  7, /* -> 125000Hz */ \
54  5, /* -> 500000Hz */ \
55  4, /* -> 1000000Hz */ \
56  2, /* -> 4000000Hz */ \
57  1 /* -> 8000000Hz */ \
58  },
59 
60 #define CFG_SPIDIV_36 \
61  { /* for 36000000Hz */ \
62  7, /* -> 140625Hz */ \
63  6, /* -> 281250Hz */ \
64  4, /* -> 1125000Hz */ \
65  2, /* -> 4500000Hz */ \
66  1 /* -> 9000000Hz */ \
67  },
68 
69 #define CFG_SPIDIV_40 \
70  { /* for 40000000Hz */ \
71  7, /* -> 156250Hz */ \
72  6, /* -> 312500Hz */ \
73  4, /* -> 1250000Hz */ \
74  2, /* -> 5000000Hz */ \
75  1 /* -> 10000000Hz */ \
76  },
77 
78 #define CFG_SPIDIV_42 \
79  { /* for 42000000Hz */ \
80  7, /* -> 164062Hz */ \
81  6, /* -> 328125Hz */ \
82  4, /* -> 1312500Hz */ \
83  2, /* -> 5250000Hz */ \
84  1 /* -> 10500000Hz */ \
85  },
86 
87 #define CFG_SPIDIV_45 \
88  { /* for 45000000Hz */ \
89  7, /* -> 175781Hz */ \
90  6, /* -> 351562Hz */ \
91  5, /* -> 703125Hz */ \
92  2, /* -> 5625000Hz */ \
93  1 /* -> 11250000Hz */ \
94  },
95 
96 #define CFG_SPIDIV_48 \
97  { /* for 48000000Hz */ \
98  7, /* -> 187500Hz */ \
99  6, /* -> 375000Hz */ \
100  5, /* -> 750000Hz */ \
101  2, /* -> 6000000Hz */ \
102  1 /* -> 12000000Hz */ \
103  },
104 
105 #define CFG_SPIDIV_50 \
106  { /* for 50000000Hz */ \
107  7, /* -> 195312Hz */ \
108  6, /* -> 390625Hz */ \
109  5, /* -> 781250Hz */ \
110  2, /* -> 6250000Hz */ \
111  1 /* -> 12500000Hz */ \
112  },
113 
114 #define CFG_SPIDIV_54 \
115  { /* for 54000000Hz */ \
116  7, /* -> 210937Hz */ \
117  6, /* -> 421875Hz */ \
118  5, /* -> 843750Hz */ \
119  3, /* -> 3375000Hz */ \
120  2 /* -> 6750000Hz */ \
121  },
122 
123 #define CFG_SPIDIV_60 \
124  { /* for 60000000Hz */ \
125  7, /* -> 234375Hz */ \
126  6, /* -> 468750Hz */ \
127  5, /* -> 937500Hz */ \
128  3, /* -> 3750000Hz */ \
129  2 /* -> 7500000Hz */ \
130  },
131 
132 #define CFG_SPIDIV_64 \
133  { /* for 64000000Hz */ \
134  7, /* -> 250000Hz */ \
135  6, /* -> 500000Hz */ \
136  5, /* -> 1000000Hz */ \
137  3, /* -> 4000000Hz */ \
138  2 /* -> 8000000Hz */ \
139  },
140 
141 #define CFG_SPIDIV_72 \
142  { /* for 72000000Hz */ \
143  7, /* -> 281250Hz */ \
144  7, /* -> 281250Hz */ \
145  5, /* -> 1125000Hz */ \
146  3, /* -> 4500000Hz */ \
147  2 /* -> 9000000Hz */ \
148  },
149 
150 #define CFG_SPIDIV_84 \
151  { /* for 84000000Hz */ \
152  7, /* -> 328125Hz */ \
153  7, /* -> 328125Hz */ \
154  5, /* -> 1312500Hz */ \
155  3, /* -> 5250000Hz */ \
156  2 /* -> 10500000Hz */ \
157  },
158 
159 #define CFG_SPIDIV_90 \
160  { /* for 90000000Hz */ \
161  7, /* -> 351562Hz */ \
162  7, /* -> 351562Hz */ \
163  6, /* -> 703125Hz */ \
164  3, /* -> 5625000Hz */ \
165  2 /* -> 11250000Hz */ \
166  },
167 
168 #define CFG_SPIDIV_96 \
169  { /* for 96000000Hz */ \
170  7, /* -> 375000Hz */ \
171  7, /* -> 375000Hz */ \
172  6, /* -> 750000Hz */ \
173  3, /* -> 6000000Hz */ \
174  2 /* -> 12000000Hz */ \
175  },
176 
177 #define CFG_SPIDIV_100 \
178  { /* for 100000000Hz */ \
179  7, /* -> 390625Hz */ \
180  7, /* -> 390625Hz */ \
181  6, /* -> 781250Hz */ \
182  3, /* -> 6250000Hz */ \
183  2 /* -> 12500000Hz */ \
184  },
185 
186 #define CFG_SPIDIV_108 \
187  { /* for 108000000Hz */ \
188  7, /* -> 421875Hz */ \
189  7, /* -> 421875Hz */ \
190  6, /* -> 843750Hz */ \
191  4, /* -> 3375000Hz */ \
192  3 /* -> 6750000Hz */ \
193  },
194 
205 static const uint8_t spi_divtable[2][5] = {
206 #if (CLOCK_APB1 == 20000000)
207  CFG_SPIDIV_20
208 #elif (CLOCK_APB1 == 30000000)
209  CFG_SPIDIV_30
210 #elif (CLOCK_APB1 == 32000000)
211  CFG_SPIDIV_32
212 #elif (CLOCK_APB1 == 36000000)
213  CFG_SPIDIV_36
214 #elif (CLOCK_APB1 == 40000000)
215  CFG_SPIDIV_40
216 #elif (CLOCK_APB1 == 42000000)
217  CFG_SPIDIV_42
218 #elif (CLOCK_APB1 == 45000000)
219  CFG_SPIDIV_45
220 #elif (CLOCK_APB1 == 48000000)
221  CFG_SPIDIV_48
222 #elif (CLOCK_APB1 == 50000000)
223  CFG_SPIDIV_50
224 #elif (CLOCK_APB1 == 54000000)
225  CFG_SPIDIV_54
226 #elif (CLOCK_APB1 == 72000000)
227  CFG_SPIDIV_72
228 #elif (CLOCK_APB1 == 60000000)
229  CFG_SPIDIV_60
230 #elif (CLOCK_APB1 == 64000000)
231  CFG_SPIDIV_64
232 #elif (CLOCK_APB1 == 84000000)
233  CFG_SPIDIV_84
234 #elif (CLOCK_APB1 == 90000000)
235  CFG_SPIDIV_90
236 #elif (CLOCK_APB1 == 96000000)
237  CFG_SPIDIV_96
238 #elif (CLOCK_APB1 == 100000000)
239  CFG_SPIDIV_100
240 #elif (CLOCK_APB1 == 108000000)
241  CFG_SPIDIV_108
242 #else
243 #error "CFG_SPI_DIVTABLE: no prescalers for selected APB1 bus clock defined"
244 #endif
245 
246 #if (CLOCK_APB2 == 20000000)
247  CFG_SPIDIV_20
248 #elif (CLOCK_APB2 == 30000000)
249  CFG_SPIDIV_30
250 #elif (CLOCK_APB2 == 32000000)
251  CFG_SPIDIV_32
252 #elif (CLOCK_APB2 == 36000000)
253  CFG_SPIDIV_36
254 #elif (CLOCK_APB2 == 40000000)
255  CFG_SPIDIV_40
256 #elif (CLOCK_APB2 == 42000000)
257  CFG_SPIDIV_42
258 #elif (CLOCK_APB2 == 45000000)
259  CFG_SPIDIV_45
260 #elif (CLOCK_APB2 == 48000000)
261  CFG_SPIDIV_48
262 #elif (CLOCK_APB2 == 50000000)
263  CFG_SPIDIV_50
264 #elif (CLOCK_APB2 == 54000000)
265  CFG_SPIDIV_54
266 #elif (CLOCK_APB2 == 72000000)
267  CFG_SPIDIV_72
268 #elif (CLOCK_APB2 == 60000000)
269  CFG_SPIDIV_60
270 #elif (CLOCK_APB2 == 64000000)
271  CFG_SPIDIV_64
272 #elif (CLOCK_APB2 == 84000000)
273  CFG_SPIDIV_84
274 #elif (CLOCK_APB2 == 90000000)
275  CFG_SPIDIV_90
276 #elif (CLOCK_APB2 == 96000000)
277  CFG_SPIDIV_96
278 #elif (CLOCK_APB2 == 100000000)
279  CFG_SPIDIV_100
280 #elif (CLOCK_APB2 == 108000000)
281  CFG_SPIDIV_108
282 #else
283 #error "CFG_SPI_DIVTABLE: no prescalers for selected APB2 bus clock defined"
284 #endif
285 };
286 
287 #ifdef __cplusplus
288 }
289 #endif
290 
291 #endif /* CFG_SPI_DIVTABLE_H */
292