APM:Libraries
timer.h
Go to the documentation of this file.
1 /******************************************************************************
2  * The MIT License
3 
4 (c) 2017 night_ghost@ykoctpa.ru
5 
6 based on:
7 
8  * Copyright (c) 2011 LeafLabs, LLC.
9  *
10  * Permission is hereby granted, free of charge, to any person
11  * obtaining a copy of this software and associated documentation
12  * files (the "Software"), to deal in the Software without
13  * restriction, including without limitation the rights to use, copy,
14  * modify, merge, publish, distribute, sublicense, and/or sell copies
15  * of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  * SOFTWARE.
29  *****************************************************************************/
30 
38 #ifndef _TIMERS_H_
39 #define _TIMERS_H_
40 
41 #include "hal_types.h"
42 #include "bitband.h"
43 #include "dma.h"
44 
45 #define BOARD_PWM_MODE TIM_OCMode_PWM1
46 
54 typedef enum timer_type {
58 } timer_type;
59 
60 
61 typedef void (* TimerHandler)(TIM_TypeDef *tim);
62 
63 
64 
65 void TIM2_IRQHandler(void);
66 void TIM3_IRQHandler(void);
67 void TIM4_IRQHandler(void);
68 void TIM5_IRQHandler(void);
69 void TIM6_IRQHandler(void);
70 void TIM7_IRQHandler(void);
71 void TIM8_IRQHandler(void);
72 
73 /*
74  * Register bit definitions
75  */
76 
77 /* Control register 1 (CR1) */
78 
79 #define TIMER_CR1_ARPE_BIT 7
80 #define TIMER_CR1_DIR_BIT 4
81 #define TIMER_CR1_OPM_BIT 3
82 #define TIMER_CR1_URS_BIT 2
83 #define TIMER_CR1_UDIS_BIT 1
84 #define TIMER_CR1_CEN_BIT 0
85 
86 #define TIMER_CR1_CKD (0x3 << 8)
87 #define TIMER_CR1_CKD_1TCKINT (0x0 << 8)
88 #define TIMER_CR1_CKD_2TCKINT (0x1 << 8)
89 #define TIMER_CR1_CKD_4TICKINT (0x2 << 8)
90 #define TIMER_CR1_ARPE BIT(TIMER_CR1_ARPE_BIT)
91 #define TIMER_CR1_CKD_CMS (0x3 << 5)
92 #define TIMER_CR1_CKD_CMS_EDGE (0x0 << 5)
93 #define TIMER_CR1_CKD_CMS_CENTER1 (0x1 << 5)
94 #define TIMER_CR1_CKD_CMS_CENTER2 (0x2 << 5)
95 #define TIMER_CR1_CKD_CMS_CENTER3 (0x3 << 5)
96 #define TIMER_CR1_DIR BIT(TIMER_CR1_DIR_BIT)
97 #define TIMER_CR1_OPM BIT(TIMER_CR1_OPM_BIT)
98 #define TIMER_CR1_URS BIT(TIMER_CR1_URS_BIT)
99 #define TIMER_CR1_UDIS BIT(TIMER_CR1_UDIS_BIT)
100 #define TIMER_CR1_CEN BIT(TIMER_CR1_CEN_BIT)
101 
102 /* Control register 2 (CR2) */
103 
104 #define TIMER_CR2_OIS4_BIT 14
105 #define TIMER_CR2_OIS3N_BIT 13
106 #define TIMER_CR2_OIS3_BIT 12
107 #define TIMER_CR2_OIS2N_BIT 11
108 #define TIMER_CR2_OIS2_BIT 10
109 #define TIMER_CR2_OIS1N_BIT 9
110 #define TIMER_CR2_OIS1_BIT 8
111 #define TIMER_CR2_TI1S_BIT 7 /* tills? yikes */
112 #define TIMER_CR2_CCDS_BIT 3
113 #define TIMER_CR2_CCUS_BIT 2
114 #define TIMER_CR2_CCPC_BIT 0
115 
116 #define TIMER_CR2_OIS4 BIT(TIMER_CR2_OIS4_BIT)
117 #define TIMER_CR2_OIS3N BIT(TIMER_CR2_OIS3N_BIT)
118 #define TIMER_CR2_OIS3 BIT(TIMER_CR2_OIS3_BIT)
119 #define TIMER_CR2_OIS2N BIT(TIMER_CR2_OIS2N_BIT)
120 #define TIMER_CR2_OIS2 BIT(TIMER_CR2_OIS2_BIT)
121 #define TIMER_CR2_OIS1N BIT(TIMER_CR2_OIS1N_BIT)
122 #define TIMER_CR2_OIS1 BIT(TIMER_CR2_OIS1_BIT)
123 #define TIMER_CR2_TI1S BIT(TIMER_CR2_TI1S_BIT)
124 #define TIMER_CR2_MMS (0x7 << 4)
125 #define TIMER_CR2_MMS_RESET (0x0 << 4)
126 #define TIMER_CR2_MMS_ENABLE (0x1 << 4)
127 #define TIMER_CR2_MMS_UPDATE (0x2 << 4)
128 #define TIMER_CR2_MMS_COMPARE_PULSE (0x3 << 4)
129 #define TIMER_CR2_MMS_COMPARE_OC1REF (0x4 << 4)
130 #define TIMER_CR2_MMS_COMPARE_OC2REF (0x5 << 4)
131 #define TIMER_CR2_MMS_COMPARE_OC3REF (0x6 << 4)
132 #define TIMER_CR2_MMS_COMPARE_OC4REF (0x7 << 4)
133 #define TIMER_CR2_CCDS BIT(TIMER_CR2_CCDS_BIT)
134 #define TIMER_CR2_CCUS BIT(TIMER_CR2_CCUS_BIT)
135 #define TIMER_CR2_CCPC BIT(TIMER_CR2_CCPC_BIT)
136 
137 /* Slave mode control register (SMCR) */
138 
139 #define TIMER_SMCR_ETP_BIT 15
140 #define TIMER_SMCR_ECE_BIT 14
141 #define TIMER_SMCR_MSM_BIT 7
142 
143 #define TIMER_SMCR_ETP BIT(TIMER_SMCR_ETP_BIT)
144 #define TIMER_SMCR_ECE BIT(TIMER_SMCR_ECE_BIT)
145 #define TIMER_SMCR_ETPS (0x3 << 12)
146 #define TIMER_SMCR_ETPS_OFF (0x0 << 12)
147 #define TIMER_SMCR_ETPS_DIV2 (0x1 << 12)
148 #define TIMER_SMCR_ETPS_DIV4 (0x2 << 12)
149 #define TIMER_SMCR_ETPS_DIV8 (0x3 << 12)
150 #define TIMER_SMCR_ETF (0xF << 12)
151 #define TIMER_SMCR_MSM BIT(TIMER_SMCR_MSM_BIT)
152 #define TIMER_SMCR_TS (0x3 << 4)
153 #define TIMER_SMCR_TS_ITR0 (0x0 << 4)
154 #define TIMER_SMCR_TS_ITR1 (0x1 << 4)
155 #define TIMER_SMCR_TS_ITR2 (0x2 << 4)
156 #define TIMER_SMCR_TS_ITR3 (0x3 << 4)
157 #define TIMER_SMCR_TS_TI1F_ED (0x4 << 4)
158 #define TIMER_SMCR_TS_TI1FP1 (0x5 << 4)
159 #define TIMER_SMCR_TS_TI2FP2 (0x6 << 4)
160 #define TIMER_SMCR_TS_ETRF (0x7 << 4)
161 #define TIMER_SMCR_SMS 0x3
162 #define TIMER_SMCR_SMS_DISABLED 0x0
163 #define TIMER_SMCR_SMS_ENCODER1 0x1
164 #define TIMER_SMCR_SMS_ENCODER2 0x2
165 #define TIMER_SMCR_SMS_ENCODER3 0x3
166 #define TIMER_SMCR_SMS_RESET 0x4
167 #define TIMER_SMCR_SMS_GATED 0x5
168 #define TIMER_SMCR_SMS_TRIGGER 0x6
169 #define TIMER_SMCR_SMS_EXTERNAL 0x7
170 
171 /* DMA/Interrupt enable register (DIER) */
172 
173 #define TIMER_DIER_TDE_BIT 14
174 #define TIMER_DIER_CC4DE_BIT 12
175 #define TIMER_DIER_CC3DE_BIT 11
176 #define TIMER_DIER_CC2DE_BIT 10
177 #define TIMER_DIER_CC1DE_BIT 9
178 #define TIMER_DIER_UDE_BIT 8
179 #define TIMER_DIER_TIE_BIT 6
180 #define TIMER_DIER_CC4IE_BIT 4
181 #define TIMER_DIER_CC3IE_BIT 3
182 #define TIMER_DIER_CC2IE_BIT 2
183 #define TIMER_DIER_CC1IE_BIT 1
184 #define TIMER_DIER_UIE_BIT 0
185 
186 #define TIMER_DIER_TDE BIT(TIMER_DIER_TDE_BIT)
187 #define TIMER_DIER_CC4DE BIT(TIMER_DIER_CC4DE_BIT)
188 #define TIMER_DIER_CC3DE BIT(TIMER_DIER_CC3DE_BIT)
189 #define TIMER_DIER_CC2DE BIT(TIMER_DIER_CC2DE_BIT)
190 #define TIMER_DIER_CC1DE BIT(TIMER_DIER_CC1DE_BIT)
191 #define TIMER_DIER_UDE BIT(TIMER_DIER_UDE_BIT)
192 #define TIMER_DIER_TIE BIT(TIMER_DIER_TIE_BIT)
193 #define TIMER_DIER_CC4IE BIT(TIMER_DIER_CC4IE_BIT)
194 #define TIMER_DIER_CC3IE BIT(TIMER_DIER_CC3IE_BIT)
195 #define TIMER_DIER_CC2IE BIT(TIMER_DIER_CC2IE_BIT)
196 #define TIMER_DIER_CC1IE BIT(TIMER_DIER_CC1IE_BIT)
197 #define TIMER_DIER_UIE BIT(TIMER_DIER_UIE_BIT)
198 
199 /* Status register (SR) */
200 
201 #define TIMER_SR_CC4OF_BIT 12
202 #define TIMER_SR_CC3OF_BIT 11
203 #define TIMER_SR_CC2OF_BIT 10
204 #define TIMER_SR_CC1OF_BIT 9
205 #define TIMER_SR_BIF_BIT 7
206 #define TIMER_SR_TIF_BIT 6
207 #define TIMER_SR_COMIF_BIT 5
208 #define TIMER_SR_CC4IF_BIT 4
209 #define TIMER_SR_CC3IF_BIT 3
210 #define TIMER_SR_CC2IF_BIT 2
211 #define TIMER_SR_CC1IF_BIT 1
212 #define TIMER_SR_UIF_BIT 0
213 
214 #define TIMER_SR_CC4OF BIT(TIMER_SR_CC4OF_BIT)
215 #define TIMER_SR_CC3OF BIT(TIMER_SR_CC3OF_BIT)
216 #define TIMER_SR_CC2OF BIT(TIMER_SR_CC2OF_BIT)
217 #define TIMER_SR_CC1OF BIT(TIMER_SR_CC1OF_BIT)
218 #define TIMER_SR_BIF BIT(TIMER_SR_BIF_BIT)
219 #define TIMER_SR_TIF BIT(TIMER_SR_TIF_BIT)
220 #define TIMER_SR_COMIF BIT(TIMER_SR_COMIF_BIT)
221 #define TIMER_SR_CC4IF BIT(TIMER_SR_CC4IF_BIT)
222 #define TIMER_SR_CC3IF BIT(TIMER_SR_CC3IF_BIT)
223 #define TIMER_SR_CC2IF BIT(TIMER_SR_CC2IF_BIT)
224 #define TIMER_SR_CC1IF BIT(TIMER_SR_CC1IF_BIT)
225 #define TIMER_SR_UIF BIT(TIMER_SR_UIF_BIT)
226 
227 /* Event generation register (EGR) */
228 
229 #define TIMER_EGR_TG_BIT 6
230 #define TIMER_EGR_CC4G_BIT 4
231 #define TIMER_EGR_CC3G_BIT 3
232 #define TIMER_EGR_CC2G_BIT 2
233 #define TIMER_EGR_CC1G_BIT 1
234 #define TIMER_EGR_UG_BIT 0
235 
236 #define TIMER_EGR_TG BIT(TIMER_EGR_TG_BIT)
237 #define TIMER_EGR_CC4G BIT(TIMER_EGR_CC4G_BIT)
238 #define TIMER_EGR_CC3G BIT(TIMER_EGR_CC3G_BIT)
239 #define TIMER_EGR_CC2G BIT(TIMER_EGR_CC2G_BIT)
240 #define TIMER_EGR_CC1G BIT(TIMER_EGR_CC1G_BIT)
241 #define TIMER_EGR_UG BIT(TIMER_EGR_UG_BIT)
242 
243 /* Capture/compare mode registers, common values */
244 
245 #define TIMER_CCMR_CCS_OUTPUT 0x0
246 #define TIMER_CCMR_CCS_INPUT_TI1 0x1
247 #define TIMER_CCMR_CCS_INPUT_TI2 0x2
248 #define TIMER_CCMR_CCS_INPUT_TRC 0x3
249 
250 /* Capture/compare mode register 1 (CCMR1) */
251 
252 #define TIMER_CCMR1_OC2CE_BIT 15
253 #define TIMER_CCMR1_OC2PE_BIT 11
254 #define TIMER_CCMR1_OC2FE_BIT 10
255 #define TIMER_CCMR1_OC1CE_BIT 7
256 #define TIMER_CCMR1_OC1PE_BIT 3
257 #define TIMER_CCMR1_OC1FE_BIT 2
258 
259 #define TIMER_CCMR1_OC2CE BIT(TIMER_CCMR1_OC2CE_BIT)
260 #define TIMER_CCMR1_OC2M (0x3 << 12)
261 #define TIMER_CCMR1_IC2F (0xF << 12)
262 #define TIMER_CCMR1_OC2PE BIT(TIMER_CCMR1_OC2PE_BIT)
263 #define TIMER_CCMR1_OC2FE BIT(TIMER_CCMR1_OC2FE_BIT)
264 #define TIMER_CCMR1_IC2PSC (0x3 << 10)
265 #define TIMER_CCMR1_CC2S (0x3 << 8)
266 #define TIMER_CCMR1_CC2S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8)
267 #define TIMER_CCMR1_CC2S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8)
268 #define TIMER_CCMR1_CC2S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8)
269 #define TIMER_CCMR1_CC2S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8)
270 #define TIMER_CCMR1_OC1CE BIT(TIMER_CCMR1_OC1CE_BIT)
271 #define TIMER_CCMR1_OC1M (0x3 << 4)
272 #define TIMER_CCMR1_IC1F (0xF << 4)
273 #define TIMER_CCMR1_OC1PE BIT(TIMER_CCMR1_OC1PE_BIT)
274 #define TIMER_CCMR1_OC1FE BIT(TIMER_CCMR1_OC1FE_BIT)
275 #define TIMER_CCMR1_IC1PSC (0x3 << 2)
276 #define TIMER_CCMR1_CC1S 0x3
277 #define TIMER_CCMR1_CC1S_OUTPUT TIMER_CCMR_CCS_OUTPUT
278 #define TIMER_CCMR1_CC1S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1
279 #define TIMER_CCMR1_CC1S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2
280 #define TIMER_CCMR1_CC1S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC
281 
282 /* Capture/compare mode register 2 (CCMR2) */
283 
284 #define TIMER_CCMR2_OC4CE_BIT 15
285 #define TIMER_CCMR2_OC4PE_BIT 11
286 #define TIMER_CCMR2_OC4FE_BIT 10
287 #define TIMER_CCMR2_OC3CE_BIT 7
288 #define TIMER_CCMR2_OC3PE_BIT 3
289 #define TIMER_CCMR2_OC3FE_BIT 2
290 
291 #define TIMER_CCMR2_OC4CE BIT(TIMER_CCMR2_OC4CE_BIT)
292 #define TIMER_CCMR2_OC4M (0x3 << 12)
293 #define TIMER_CCMR2_IC2F (0xF << 12)
294 #define TIMER_CCMR2_OC4PE BIT(TIMER_CCMR2_OC4PE_BIT)
295 #define TIMER_CCMR2_OC4FE BIT(TIMER_CCMR2_OC4FE_BIT)
296 #define TIMER_CCMR2_IC2PSC (0x3 << 10)
297 #define TIMER_CCMR2_CC4S (0x3 << 8)
298 #define TIMER_CCMR1_CC4S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8)
299 #define TIMER_CCMR1_CC4S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8)
300 #define TIMER_CCMR1_CC4S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8)
301 #define TIMER_CCMR1_CC4S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8)
302 #define TIMER_CCMR2_OC3CE BIT(TIMER_CCMR2_OC3CE_BIT)
303 #define TIMER_CCMR2_OC3M (0x3 << 4)
304 #define TIMER_CCMR2_IC1F (0xF << 4)
305 #define TIMER_CCMR2_OC3PE BIT(TIMER_CCMR2_OC3PE_BIT)
306 #define TIMER_CCMR2_OC3FE BIT(TIMER_CCMR2_OC3FE_BIT)
307 #define TIMER_CCMR2_IC1PSC (0x3 << 2)
308 #define TIMER_CCMR2_CC3S 0x3
309 #define TIMER_CCMR1_CC3S_OUTPUT TIMER_CCMR_CCS_OUTPUT
310 #define TIMER_CCMR1_CC3S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1
311 #define TIMER_CCMR1_CC3S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2
312 #define TIMER_CCMR1_CC3S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC
313 
314 /* Capture/compare enable register (CCER) */
315 
316 #define TIMER_CCER_CC4P_BIT 13
317 #define TIMER_CCER_CC4E_BIT 12
318 #define TIMER_CCER_CC3NP_BIT 11
319 #define TIMER_CCER_CC3NE_BIT 10
320 #define TIMER_CCER_CC3P_BIT 9
321 #define TIMER_CCER_CC3E_BIT 8
322 #define TIMER_CCER_CC2NP_BIT 7
323 #define TIMER_CCER_CC2NE_BIT 6
324 #define TIMER_CCER_CC2P_BIT 5
325 #define TIMER_CCER_CC2E_BIT 4
326 #define TIMER_CCER_CC1NP_BIT 3
327 #define TIMER_CCER_CC1NE_BIT 2
328 #define TIMER_CCER_CC1P_BIT 1
329 #define TIMER_CCER_CC1E_BIT 0
330 
331 #define TIMER_CCER_CC4P BIT(TIMER_CCER_CC4P_BIT)
332 #define TIMER_CCER_CC4E BIT(TIMER_CCER_CC4E_BIT)
333 #define TIMER_CCER_CC3P BIT(TIMER_CCER_CC3P_BIT)
334 #define TIMER_CCER_CC3E BIT(TIMER_CCER_CC3E_BIT)
335 #define TIMER_CCER_CC2P BIT(TIMER_CCER_CC2P_BIT)
336 #define TIMER_CCER_CC2E BIT(TIMER_CCER_CC2E_BIT)
337 #define TIMER_CCER_CC1P BIT(TIMER_CCER_CC1P_BIT)
338 #define TIMER_CCER_CC1E BIT(TIMER_CCER_CC1E_BIT)
339 
340 #define TIMER_CCER_CC3NP BIT(TIMER_CCER_CC3NP_BIT)
341 #define TIMER_CCER_CC3NE BIT(TIMER_CCER_CC3NE_BIT)
342 #define TIMER_CCER_CC2NP BIT(TIMER_CCER_CC2NP_BIT)
343 #define TIMER_CCER_CC2NE BIT(TIMER_CCER_CC2NE_BIT)
344 #define TIMER_CCER_CC1NP BIT(TIMER_CCER_CC1NP_BIT)
345 #define TIMER_CCER_CC1NE BIT(TIMER_CCER_CC1NE_BIT)
346 
347 /* Break and dead-time register (BDTR) */
348 
349 #define TIMER_BDTR_MOE_BIT 15
350 #define TIMER_BDTR_AOE_BIT 14
351 #define TIMER_BDTR_BKP_BIT 13
352 #define TIMER_BDTR_BKE_BIT 12
353 #define TIMER_BDTR_OSSR_BIT 11
354 #define TIMER_BDTR_OSSI_BIT 10
355 
356 #define TIMER_BDTR_MOE BIT(TIMER_BDTR_MOE_BIT)
357 #define TIMER_BDTR_AOE BIT(TIMER_BDTR_AOE_BIT)
358 #define TIMER_BDTR_BKP BIT(TIMER_BDTR_BKP_BIT)
359 #define TIMER_BDTR_BKE BIT(TIMER_BDTR_BKE_BIT)
360 #define TIMER_BDTR_OSSR BIT(TIMER_BDTR_OSSR_BIT)
361 #define TIMER_BDTR_OSSI BIT(TIMER_BDTR_OSSI_BIT)
362 #define TIMER_BDTR_LOCK (0x3 << 8)
363 #define TIMER_BDTR_LOCK_OFF (0x0 << 8)
364 #define TIMER_BDTR_LOCK_LEVEL1 (0x1 << 8)
365 #define TIMER_BDTR_LOCK_LEVEL2 (0x2 << 8)
366 #define TIMER_BDTR_LOCK_LEVEL3 (0x3 << 8)
367 #define TIMER_BDTR_DTG 0xFF
368 
369 /* DMA control register (DCR) */
370 
371 #define TIMER_DCR_DBL (0x1F << 8)
372 #define TIMER_DCR_DBL_1BYTE (0x0 << 8)
373 #define TIMER_DCR_DBL_2BYTE (0x1 << 8)
374 #define TIMER_DCR_DBL_3BYTE (0x2 << 8)
375 #define TIMER_DCR_DBL_4BYTE (0x3 << 8)
376 #define TIMER_DCR_DBL_5BYTE (0x4 << 8)
377 #define TIMER_DCR_DBL_6BYTE (0x5 << 8)
378 #define TIMER_DCR_DBL_7BYTE (0x6 << 8)
379 #define TIMER_DCR_DBL_8BYTE (0x7 << 8)
380 #define TIMER_DCR_DBL_9BYTE (0x8 << 8)
381 #define TIMER_DCR_DBL_10BYTE (0x9 << 8)
382 #define TIMER_DCR_DBL_11BYTE (0xA << 8)
383 #define TIMER_DCR_DBL_12BYTE (0xB << 8)
384 #define TIMER_DCR_DBL_13BYTE (0xC << 8)
385 #define TIMER_DCR_DBL_14BYTE (0xD << 8)
386 #define TIMER_DCR_DBL_15BYTE (0xE << 8)
387 #define TIMER_DCR_DBL_16BYTE (0xF << 8)
388 #define TIMER_DCR_DBL_17BYTE (0x10 << 8)
389 #define TIMER_DCR_DBL_18BYTE (0x11 << 8)
390 #define TIMER_DCR_DBA 0x1F
391 #define TIMER_DCR_DBA_CR1 0x0
392 #define TIMER_DCR_DBA_CR2 0x1
393 #define TIMER_DCR_DBA_SMCR 0x2
394 #define TIMER_DCR_DBA_DIER 0x3
395 #define TIMER_DCR_DBA_SR 0x4
396 #define TIMER_DCR_DBA_EGR 0x5
397 #define TIMER_DCR_DBA_CCMR1 0x6
398 #define TIMER_DCR_DBA_CCMR2 0x7
399 #define TIMER_DCR_DBA_CCER 0x8
400 #define TIMER_DCR_DBA_CNT 0x9
401 #define TIMER_DCR_DBA_PSC 0xA
402 #define TIMER_DCR_DBA_ARR 0xB
403 #define TIMER_DCR_DBA_RCR 0xC
404 #define TIMER_DCR_DBA_CCR1 0xD
405 #define TIMER_DCR_DBA_CCR2 0xE
406 #define TIMER_DCR_DBA_CCR3 0xF
407 #define TIMER_DCR_DBA_CCR4 0x10
408 #define TIMER_DCR_DBA_BDTR 0x11
409 #define TIMER_DCR_DBA_DCR 0x12
410 #define TIMER_DCR_DBA_DMAR 0x13
411 
412 /*
413  * Convenience routines
414  */
415 
420 /* TODO TIMER_PWM_CENTER_ALIGNED, TIMER_INPUT_CAPTURE, TIMER_ONE_PULSE */
421 typedef enum timer_mode {
427  /* TIMER_PWM_CENTER_ALIGNED, /\**< Center-aligned PWM output mode. *\/ */
433  /* TIMER_INPUT_CAPTURE, /\**< In this mode, the timer can measure the */
434  /* pulse lengths of input signals. *\/ */
435  /* TIMER_ONE_PULSE /\**< In this mode, the timer can generate a single */
436  /* pulse on a GPIO pin for a specified amount of */
437  /* time. *\/ */
438 } timer_mode;
439 
441 typedef enum timer_Channel {
442  NO_CH = 0,
443  TIMER_CH1 = 1,
444  TIMER_CH2 = 2,
445  TIMER_CH3 = 3,
446  TIMER_CH4 = 4,
448 
450  TIMER_CH2N = 10,
451  TIMER_CH3N = 11,
453 } timer_Channel;
454 
455 #define TIMER_CH_MASK 7
456 
457 enum {
461 };
462 
463 #ifdef __cplusplus
464 #define CONSTEXPR constexpr
465  extern "C" {
466 #else
467 #define CONSTEXPR
468 #endif
469 
470 
471 
472 
479 typedef enum timer_interrupt_id {
489 
490 
491 typedef enum timer_oc_mode {
521 } timer_oc_mode;
522 
523 
524 
525 
526 
527 /*
528 01: CC1 channel is configured as input, IC1 is mapped on TI1.
529 10: CC1 channel is configured as input, IC1 is mapped on TI2.
530 11: CC1 channel is configured as input, IC1 is mapped on TRC. This mode is working only if
531 an internal trigger input is selected through TS bit (TIMx_SMCR register)
532 
533 */
534 
535 typedef enum timer_ic_mode {
536  TIMER_IC_MODE_TI1 = 1,//TIM_ICSelection_DirectTI
537  TIMER_IC_MODE_TI2 = 2,//TIM_ICSelection_IndirectTI
539 } timer_ic_mode;
540 
541 
542 typedef enum Timer_cc_Polarity {
545  //TIMER_POLARITY_BOTH =2, not supported
547 
548 
553 typedef enum timer_oc_mode_flags {
558 
559 
560 typedef struct TimerState {
561  volatile uint8_t busy;
562  bool update;
563  uint32_t freq; // real frequency that programmed to timer
564  float freq_scale; // needed/real frequencies ratio
565 } timerState;
566 
567 
568 typedef struct TIM_DMA {
570  uint8_t dma_channel;
571 } Tim_dma;
572 
574 struct Timer_dev {
575  TIM_TypeDef *regs;
576  uint32_t clk;
577  Handler *handlers; // < User IRQ handlers
579  Tim_dma ch_dma[4];
580  uint16_t af; // GPIO AF number
581  //
582  timer_type type; // < Timer's type
583  uint8_t n_handlers; // number of handlers
584  uint8_t bus; // APB1 or APB2
585  uint8_t id; // timer's number
586  //
587 };
588 
589 
590 typedef struct Timer_dev timer_dev;
591 
592 extern const timer_dev timers[];
593 
594 #define timer1 (timers[0])
595 #define timer2 (timers[1])
596 #define timer3 (timers[2])
597 #define timer4 (timers[3])
598 #define timer5 (timers[4])
599 #define timer6 (timers[5])
600 #define timer7 (timers[6])
601 #define timer8 (timers[7])
602 #define timer9 (timers[8])
603 #define timer10 (timers[9])
604 #define timer11 (timers[10])
605 #define timer12 (timers[11])
606 #define timer13 (timers[12])
607 #define timer14 (timers[13])
608 
609 #define TIMER1 (&timer1)
610 #define TIMER2 (&timer2)
611 #define TIMER3 (&timer3)
612 #define TIMER4 (&timer4)
613 #define TIMER5 (&timer5)
614 #define TIMER6 (&timer6)
615 #define TIMER7 (&timer7)
616 #define TIMER8 (&timer8)
617 #define TIMER9 (&timer9)
618 #define TIMER10 (&timer10)
619 #define TIMER11 (&timer11)
620 #define TIMER12 (&timer12)
621 #define TIMER13 (&timer13)
622 #define TIMER14 (&timer14)
623 
624 
625 /*
626  * Note: Don't require timer_channel arguments! We want to be able to say
627  *
628  * for (int channel = 1; channel <= 4; channel++) {
629  * ...
630  * }
631  *
632  * without the compiler yelling at us.
633  */
634 
635 void timer_init(const timer_dev *dev);
636 void timer_reset(const timer_dev *dev);
637 void timer_disable(const timer_dev *dev);
638 void timer_set_mode(const timer_dev *dev, timer_Channel channel, timer_mode mode);
639 void timer_foreach(void (*fn)(const timer_dev*));
640 
641 void timer_attach_interrupt(const timer_dev *dev, uint8_t interrupt, Handler handler, uint8_t priority);
642 void timer_detach_interrupt(const timer_dev *dev, uint8_t interrupt);
643 void timer_attach_all_interrupts(const timer_dev *dev, Handler handler);
644 
645 uint32_t configTimeBase(const timer_dev *dev , uint16_t period, uint16_t khz);
646 
647 void timer_enable_NVICirq(const timer_dev *dev, uint8_t interrupt, uint8_t priority);
648 void timer_disable_NVICirq(const timer_dev *dev, uint8_t interrupt);
649 
650 
651 static INLINE uint32_t get_timer_mask(const timer_dev *dev){
652  if(dev->regs == TIM2 || dev->regs == TIM5)
653  return 0xFFFFFFFF; // 32 bit
654  else
655  return 0xFFFF; // 16 bit
656 }
657 
661 static inline void timer_init_all(void) {
663 }
664 
668 static inline void timer_disable_all(void) {
670 }
671 
679 static INLINE void timer_pause(const timer_dev *dev) {
680  *bb_perip(&(dev->regs->CR1), TIMER_CR1_CEN_BIT) = 0;
681 }
682 
690 static INLINE void timer_resume(const timer_dev *dev) {
691  *bb_perip(&(dev->regs->CR1), TIMER_CR1_CEN_BIT) = 1;
692 }
693 
702 static INLINE uint16_t timer_get_count(const timer_dev *dev) {
703  return (uint16_t)(dev->regs->CNT);
704 }
705 
706 static INLINE uint32_t timer_get_count32(const timer_dev *dev) {
707  return dev->regs->CNT;
708 }
709 
715 static INLINE void timer_set_count(const timer_dev *dev, uint16_t value) {
716  dev->regs->CNT = value;
717 }
718 
731 static inline uint16_t timer_get_prescaler(const timer_dev *dev) {
732  return (uint16_t)(dev->regs->PSC);
733 }
734 
745 static inline void timer_set_prescaler(const timer_dev *dev, uint16_t psc) {
746  dev->regs->PSC = psc;
747 }
748 
753 static inline uint16_t timer_get_reload(const timer_dev *dev) {
754  return (uint16_t)(dev->regs->ARR);
755 }
756 
763 static INLINE void timer_set_reload(const timer_dev *dev, uint32_t arr) {
764  dev->regs->ARR = arr;
765 }
766 
772 static inline uint16_t timer_get_compare(const timer_dev *dev, timer_Channel channel) {
773  __IO uint32_t *ccr = &(dev->regs->CCR1) + ((channel&TIMER_CH_MASK) - 1);
774  return *ccr;
775 }
776 
783 static inline void timer_set_compare(const timer_dev *dev,
784  timer_Channel channel,
785  uint16_t value) {
786  __IO uint32_t *ccr = &(dev->regs->CCR1) + ((channel&TIMER_CH_MASK) - 1);
787  *ccr = value;
788 }
789 
790 
791 static INLINE uint16_t timer_get_capture(const timer_dev *dev, timer_Channel channel) {
792  __IO uint32_t *ccr = &(dev->regs->CCR1) + ((channel&TIMER_CH_MASK) - 1);
793  return *ccr;
794 }
795 
796 
807 static inline void timer_generate_update(const timer_dev *dev) {
808  *bb_perip(&(dev->regs->EGR), TIMER_EGR_UG_BIT) = 1;
809 }
810 
815 static inline void timer_dma_enable_trg_req(const timer_dev *dev) {
816  *bb_perip(&(dev->regs->DIER), TIMER_DIER_TDE_BIT) = 1;
817 }
818 
823 static inline void timer_dma_disable_trg_req(const timer_dev *dev) {
824  *bb_perip(&(dev->regs->DIER), TIMER_DIER_TDE_BIT) = 0;
825 }
826 
832 static inline void timer_dma_enable_req(const timer_dev *dev, timer_Channel channel) {
833  *bb_perip(&(dev->regs->DIER), (channel&TIMER_CH_MASK) + 8) = 1;
834 }
835 
841 static inline void timer_dma_disable_req(const timer_dev *dev, timer_Channel channel) {
842  *bb_perip(&(dev->regs->DIER), (channel&TIMER_CH_MASK) + 8) = 0;
843 }
844 
845 
846 
858 static inline void timer_cc_enable(const timer_dev *dev, timer_Channel channel) {
859 #if 1
860  if(channel < TIMER_CH_MAX){
861  *bb_perip(&(dev->regs->CCER), 4 * (channel - 1)) = 1;
862  } else {
863  *bb_perip(&(dev->regs->CCER), 4 * ((channel&TIMER_CH_MASK) - 1) + 2) = 1;
864  }
865 #else
866  switch(channel) {
867  case 1:
868  dev->regs->CCER |= (uint16_t)TIM_CCER_CC1E;
869  break;
870  case 2:
871  dev->regs->CCER |= (uint16_t)TIM_CCER_CC2E;
872  break;
873  case 3:
874  dev->regs->CCER |= (uint16_t)TIM_CCER_CC3E;
875  break;
876  case 4:
877  dev->regs->CCER |= (uint16_t)TIM_CCER_CC4E;
878  break;
879  default:
880  break;
881  }
882 #endif
883 }
884 
891 static inline void timer_cc_disable(const timer_dev *dev, timer_Channel channel) {
892 #if 1
893  if(channel < TIMER_CH_MAX){
894  *bb_perip(&(dev->regs->CCER), 4 * (channel - 1)) = 0;
895  } else {
896  *bb_perip(&(dev->regs->CCER), 4 * ((channel&TIMER_CH_MASK) - 1) + 2) = 0;
897  }
898 #else
899  switch(channel){
900  case 1:
901  dev->regs->CCER &= (uint16_t)~TIM_CCER_CC1E;
902  break;
903  case 2:
904  dev->regs->CCER &= (uint16_t)~TIM_CCER_CC2E;
905  break;
906  case 3:
907  dev->regs->CCER &= (uint16_t)~TIM_CCER_CC3E;
908  break;
909  case 4:
910  dev->regs->CCER &= (uint16_t)~TIM_CCER_CC4E;
911  break;
912  default:
913  break;
914  }
915 #endif
916 }
917 
926  if(channel < TIMER_CH_MAX){
927  return (timer_cc_polarity)(*bb_perip(&(dev->regs->CCER), 4 * (channel-1) + 1));
928  } else {
929  return (timer_cc_polarity)(*bb_perip(&(dev->regs->CCER), 4 * ((channel&TIMER_CH_MASK)-1) + 3));
930  }
931 }
932 
950 static inline void timer_cc_set_pol(const timer_dev *dev, timer_Channel channel, timer_cc_polarity pol) {
951  if(channel < TIMER_CH_MAX){
952  *bb_perip(&(dev->regs->CCER), 4 * (channel - 1) + 1) = pol;
953  }else {
954  *bb_perip(&(dev->regs->CCER), 4 * ((channel&TIMER_CH_MASK)- 1) + 3) = pol;
955  }
956 }
957 
958 
964 static inline uint8_t timer_dma_get_burst_len(const timer_dev *dev) {
965  uint32_t dbl = ((dev->regs->DCR) & TIMER_DCR_DBL) >> 8;
966  return dbl + 1; /* 0 means 1 byte, etc. */
967 }
968 
975 static inline void timer_dma_set_burst_len(const timer_dev *dev, uint8_t length) {
976  uint32_t tmp = dev->regs->DCR;
977  tmp &= ~TIMER_DCR_DBL;
978  tmp |= (length - 1) << 8;
979  dev->regs->DCR = tmp;
980 }
981 
987 typedef enum timer_dma_base_addr {
1024 
1031 static inline timer_dma_base_addr timer_dma_get_base_addr(const timer_dev *dev) {
1032  uint32_t dcr = dev->regs->DCR;
1033  return (timer_dma_base_addr)(dcr & TIMER_DCR_DBA);
1034 }
1035 
1042 static inline void timer_dma_set_base_addr(const timer_dev *dev,
1043  timer_dma_base_addr dma_base) {
1044  uint32_t tmp = dev->regs->DCR;
1045  tmp &= ~TIMER_DCR_DBA;
1046  tmp |= dma_base;
1047  dev->regs->DCR = tmp;
1048 }
1049 
1050 
1065 static inline void timer_oc_set_mode(const timer_dev *dev,
1066  timer_Channel _channel,
1067  timer_oc_mode mode,
1068  uint8_t flags) {
1069 
1070  uint8_t channel = _channel & TIMER_CH_MASK;
1071  uint8_t bit0 = channel & 1;
1072  uint8_t bit1 = ((channel-1) >> 1) & 1; // fixed
1073  /* channel == 1,2 -> CCMR1; channel == 3,4 -> CCMR2 */
1074  __IO uint16_t *ccmr = &(dev->regs->CCMR1) + bit1*2;
1075  /* channel == 1,3 -> shift = 0, channel == 2,4 -> shift = 8 */
1076  uint8_t shift = 8 * (1 - bit0);
1077 
1078  uint16_t tmp = *ccmr;
1079  tmp &= ~(0xFF << shift);
1080  tmp |= (mode | flags | TIMER_CCMR_CCS_OUTPUT) << shift;
1081  *ccmr = tmp;
1082 }
1083 
1084 
1085 
1096 static inline void timer_ic_set_mode(const timer_dev *dev,
1097  timer_Channel _channel,
1098  uint8_t mode,
1099  uint16_t filter) {
1100 
1101  uint8_t channel = _channel & TIMER_CH_MASK;
1102  uint8_t bit0 = channel & 1;
1103  uint8_t bit1 = ((channel-1) >> 1) & 1; // fixed
1104  /* channel == 1,2 -> CCMR1; channel == 3,4 -> CCMR2 */
1105  __IO uint16_t *ccmr = &(dev->regs->CCMR1) + bit1*2;
1106  /* channel == 1,3 -> shift = 0, channel == 2,4 -> shift = 8 */
1107  uint8_t shift = 8 * (1 - bit0);
1108 
1109  uint16_t tmp = *ccmr;
1110  tmp &= ~(0xFF << shift);
1111  tmp |= (mode | (filter << 4) ) << shift;
1112  *ccmr = tmp;
1113 }
1114 
1115 
1116 
1125 static inline void timer_enable_irq(const timer_dev *dev, timer_interrupt_id interrupt) {
1126 // *bb_perip(&(dev->regs->DIER), interrupt) = 1;
1127  dev->regs->DIER |= 1<<(interrupt & TIMER_CH_MASK);
1128 }
1129 
1138 static inline void timer_disable_irq(const timer_dev *dev, timer_interrupt_id interrupt) {
1139 // *bb_perip(&(dev->regs->DIER), interrupt) = 0;
1140  dev->regs->DIER &= ~(1<<(interrupt & TIMER_CH_MASK));
1141 }
1142 
1143 
1144 #ifdef __cplusplus
1145  }
1146 #endif
1147 
1148 #endif
uint16_t af
Definition: timer.h:580
#define TIMER_CH_MASK
Definition: timer.h:455
uint32_t clk
Definition: timer.h:576
void timer_reset(const timer_dev *dev)
Definition: timer.c:316
static void timer_dma_disable_req(const timer_dev *dev, timer_Channel channel)
Disable a timer channel&#39;s DMA request.
Definition: timer.h:841
static void timer_cc_enable(const timer_dev *dev, timer_Channel channel)
Enable a timer channel&#39;s capture/compare signal.
Definition: timer.h:858
static void timer_cc_disable(const timer_dev *dev, timer_Channel channel)
Disable a timer channel&#39;s output compare or input capture signal.
Definition: timer.h:891
void timer_enable_NVICirq(const timer_dev *dev, uint8_t interrupt, uint8_t priority)
Definition: timer.c:845
#define TIMER_DCR_DBA_RCR
Definition: timer.h:403
#define TIMER_DCR_DBA_CNT
Definition: timer.h:400
static void timer_disable_all(void)
Definition: timer.h:668
void TIM8_IRQHandler(void)
#define TIMER_DCR_DBA_DCR
Definition: timer.h:409
timer_ic_mode
Definition: timer.h:535
static void timer_cc_set_pol(const timer_dev *dev, timer_Channel channel, timer_cc_polarity pol)
Set a timer channel&#39;s capture/compare output polarity.
Definition: timer.h:950
void TIM7_IRQHandler(void)
Definition: timer.c:591
static void timer_dma_disable_trg_req(const timer_dev *dev)
Disable a timer&#39;s trigger DMA request.
Definition: timer.h:823
#define TIMER_DCR_DBA_DMAR
Definition: timer.h:410
enum Timer_cc_Polarity timer_cc_polarity
#define TIMER_DCR_DBA
Definition: timer.h:390
struct TIM_DMA Tim_dma
Timer_cc_Polarity
Definition: timer.h:542
volatile uint8_t busy
Definition: timer.h:561
static INLINE uint16_t timer_get_capture(const timer_dev *dev, timer_Channel channel)
Definition: timer.h:791
Handler * handlers
Definition: timer.h:577
void timer_disable_NVICirq(const timer_dev *dev, uint8_t interrupt)
Definition: timer.c:850
static INLINE uint32_t get_timer_mask(const timer_dev *dev)
Definition: timer.h:651
const timer_dev timers[]
Definition: timer.c:75
uint8_t n_handlers
Definition: timer.h:583
void timer_detach_interrupt(const timer_dev *dev, uint8_t interrupt)
static INLINE void timer_pause(const timer_dev *dev)
Stop a timer&#39;s counter from changing.
Definition: timer.h:679
static INLINE void timer_set_count(const timer_dev *dev, uint16_t value)
Sets the counter value for the given timer.
Definition: timer.h:715
uint32_t freq
Definition: timer.h:563
bool update
Definition: timer.h:562
void TIM2_IRQHandler(void)
Definition: timer.c:571
static INLINE uint16_t timer_get_count(const timer_dev *dev)
Returns the timer&#39;s counter value.
Definition: timer.h:702
void timer_attach_interrupt(const timer_dev *dev, uint8_t interrupt, Handler handler, uint8_t priority)
#define TIMER_DCR_DBA_DIER
Definition: timer.h:394
static void timer_dma_enable_req(const timer_dev *dev, timer_Channel channel)
Enable a timer channel&#39;s DMA request.
Definition: timer.h:832
static INLINE void timer_resume(const timer_dev *dev)
Start a timer&#39;s counter.
Definition: timer.h:690
timer_oc_mode
Definition: timer.h:491
#define TIMER_DCR_DBA_CR1
Definition: timer.h:391
static timer_dma_base_addr timer_dma_get_base_addr(const timer_dev *dev)
Get the timer&#39;s DMA base address.
Definition: timer.h:1031
uint8_t bus
Definition: timer.h:584
timer_Channel
Definition: timer.h:441
#define TIMER_DCR_DBL
Definition: timer.h:371
timer_interrupt_id
Timer interrupt number.
Definition: timer.h:479
void timer_set_mode(const timer_dev *dev, timer_Channel channel, timer_mode mode)
Definition: timer.c:442
static uint16_t timer_get_prescaler(const timer_dev *dev)
Returns the given timer&#39;s prescaler.
Definition: timer.h:731
static AP_HAL::OwnPtr< AP_HAL::Device > dev
Definition: ICM20789.cpp:16
void TIM6_IRQHandler(void)
static uint16_t timer_get_reload(const timer_dev *dev)
Returns a timer&#39;s reload value.
Definition: timer.h:753
#define TIMER_DCR_DBA_CCER
Definition: timer.h:399
#define TIMER_DCR_DBA_SMCR
Definition: timer.h:393
#define BIT(shift)
Definition: util.h:40
timer_type
Timer type.
Definition: timer.h:54
void timer_disable(const timer_dev *dev)
Disable a timer.
Definition: timer.c:340
static void timer_dma_set_burst_len(const timer_dev *dev, uint8_t length)
Set a timer&#39;s DMA burst length.
Definition: timer.h:975
#define INLINE
Definition: hal_types.h:79
#define TIMER_DCR_DBA_EGR
Definition: timer.h:396
struct TimerState timerState
static void timer_oc_set_mode(const timer_dev *dev, timer_Channel _channel, timer_oc_mode mode, uint8_t flags)
Configure a channel&#39;s output compare mode.
Definition: timer.h:1065
static void timer_init_all(void)
Definition: timer.h:661
#define TIMER_DCR_DBA_CCR4
Definition: timer.h:407
uint8_t dma_channel
Definition: timer.h:570
void TIM5_IRQHandler(void)
Definition: timer.c:583
#define TIMER_DCR_DBA_CCR3
Definition: timer.h:406
static void timer_set_compare(const timer_dev *dev, timer_Channel channel, uint16_t value)
Set the compare value for the given timer channel.
Definition: timer.h:783
float freq_scale
Definition: timer.h:564
timer_dma_base_addr
Timer DMA base address.
Definition: timer.h:987
Bit-banding utility functions.
enum Dma_stream dma_stream
#define TIMER_DCR_DBA_BDTR
Definition: timer.h:408
#define TIMER_DCR_DBA_CCMR1
Definition: timer.h:397
static void timer_enable_irq(const timer_dev *dev, timer_interrupt_id interrupt)
Enable a timer interrupt.
Definition: timer.h:1125
void NOINLINE filter(float &dst, float val, const byte k)
static void timer_disable_irq(const timer_dev *dev, timer_interrupt_id interrupt)
Disable a timer interrupt.
Definition: timer.h:1138
static void timer_dma_enable_trg_req(const timer_dev *dev)
Enable a timer&#39;s trigger DMA request.
Definition: timer.h:815
static void timer_ic_set_mode(const timer_dev *dev, timer_Channel _channel, uint8_t mode, uint16_t filter)
Configure a channel&#39;s input capture mode.
Definition: timer.h:1096
void timer_attach_all_interrupts(const timer_dev *dev, Handler handler)
Definition: timer.c:494
void(* TimerHandler)(TIM_TypeDef *tim)
Definition: timer.h:61
dma_stream dma_stream
Definition: timer.h:569
uint32_t configTimeBase(const timer_dev *dev, uint16_t period, uint16_t khz)
Definition: timer.c:357
static uint16_t timer_get_compare(const timer_dev *dev, timer_Channel channel)
Get the compare value for the given timer channel.
Definition: timer.h:772
static timer_cc_polarity timer_cc_get_pol(const timer_dev *dev, timer_Channel channel)
Get a channel&#39;s capture/compare output polarity.
Definition: timer.h:925
#define TIMER_DIER_TDE_BIT
Definition: timer.h:173
timerState * state
Definition: timer.h:578
TIM_TypeDef * regs
Definition: timer.h:575
#define TIMER_DCR_DBA_CR2
Definition: timer.h:392
uint8_t id
Definition: timer.h:585
Definition: timer.h:442
float value
void TIM4_IRQHandler(void)
Definition: timer.c:579
#define TIMER_DCR_DBA_PSC
Definition: timer.h:401
#define TIMER_CR1_CEN_BIT
Definition: timer.h:84
uint64_t Handler
Definition: hal_types.h:19
Definition: timer.h:568
static INLINE void timer_set_reload(const timer_dev *dev, uint32_t arr)
Set a timer&#39;s reload value.
Definition: timer.h:763
static void timer_dma_set_base_addr(const timer_dev *dev, timer_dma_base_addr dma_base)
Set the timer&#39;s DMA base address.
Definition: timer.h:1042
#define TIMER_DCR_DBA_CCR2
Definition: timer.h:405
void timer_foreach(void(*fn)(const timer_dev *))
Call a function on timer devices.
Definition: timer.c:468
timer_type type
Definition: timer.h:582
#define TIMER_DCR_DBA_ARR
Definition: timer.h:402
void timer_init(const timer_dev *dev)
Definition: timer.c:303
static void timer_set_prescaler(const timer_dev *dev, uint16_t psc)
Set a timer&#39;s prescale value.
Definition: timer.h:745
timer_mode
Definition: timer.h:421
static INLINE uint32_t timer_get_count32(const timer_dev *dev)
Definition: timer.h:706
#define TIMER_DCR_DBA_CCR1
Definition: timer.h:404
static uint8_t timer_dma_get_burst_len(const timer_dev *dev)
Get a timer&#39;s DMA burst length.
Definition: timer.h:964
#define TIMER_CCMR_CCS_OUTPUT
Definition: timer.h:245
#define TIMER_DCR_DBA_CCMR2
Definition: timer.h:398
void TIM3_IRQHandler(void)
Definition: timer.c:575
static volatile uint32_t * bb_perip(volatile void *address, uint32_t bit)
Obtain a pointer to the bit-band address corresponding to a bit in a peripheral address.
Definition: bitband.h:85
#define TIMER_EGR_UG_BIT
Definition: timer.h:234
#define TIMER_DCR_DBA_SR
Definition: timer.h:395
static void timer_generate_update(const timer_dev *dev)
Generate an update event for the given timer.
Definition: timer.h:807
timer_oc_mode_flags
Definition: timer.h:553