1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
\r
2 * File Name : stm32f10x_tim.c
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 09/29/2006
\r
5 * Description : This file provides all the TIM firmware functions.
\r
6 ********************************************************************************
\r
11 ********************************************************************************
\r
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
14 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
\r
15 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
\r
16 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
\r
17 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 *******************************************************************************/
\r
20 /* Includes ------------------------------------------------------------------*/
\r
21 #include "stm32f10x_tim.h"
\r
22 #include "stm32f10x_rcc.h"
\r
24 /* Private typedef -----------------------------------------------------------*/
\r
25 /* Private define ------------------------------------------------------------*/
\r
26 /* ---------------------- TIM registers bit mask ------------------------ */
\r
27 #define CR1_CEN_Set ((u16)0x0001)
\r
28 #define CR1_CEN_Reset ((u16)0x03FE)
\r
29 #define CR1_UDIS_Set ((u16)0x0002)
\r
30 #define CR1_UDIS_Reset ((u16)0x03FD)
\r
31 #define CR1_URS_Set ((u16)0x0004)
\r
32 #define CR1_URS_Reset ((u16)0x03FB)
\r
33 #define CR1_OPM_Mask ((u16)0x03F7)
\r
34 #define CR1_CounterMode_Mask ((u16)0x039F)
\r
35 #define CR1_ARPE_Set ((u16)0x0080)
\r
36 #define CR1_ARPE_Reset ((u16)0x037F)
\r
37 #define CR1_CKD_Mask ((u16)0x00FF)
\r
39 #define CR2_CCDS_Set ((u16)0x0008)
\r
40 #define CR2_CCDS_Reset ((u16)0x0007)
\r
41 #define CR2_MMS_Mask ((u16)0x0080)
\r
42 #define CR2_TI1S_Set ((u16)0x0080)
\r
43 #define CR2_TI1S_Reset ((u16)0xFF70)
\r
45 #define SMCR_SMS_Mask ((u16)0xFFF0)
\r
46 #define SMCR_ETR_Mask ((u16)0x00F7)
\r
47 #define SMCR_TS_Mask ((u16)0xFF87)
\r
48 #define SMCR_MSM_Mask ((u16)0xFF77)
\r
49 #define SMCR_ECE_Set ((u16)0x4000)
\r
51 #define CCMR_CC13S_Mask ((u16)0x7F7C)
\r
52 #define CCMR_CC24S_Mask ((u16)0x7C7F)
\r
53 #define CCMR_TI13Direct_Set ((u16)0x0001)
\r
54 #define CCMR_TI24Direct_Set ((u16)0x0100)
\r
55 #define CCMR_OC13FE_Mask ((u16)0x7F7B)
\r
56 #define CCMR_OC24FE_Mask ((u16)0x7B7F)
\r
57 #define CCMR_OC13PE_Mask ((u16)0x7F77)
\r
58 #define CCMR_OC24PE_Mask ((u16)0x777F)
\r
59 #define CCMR_OCM13_Mask ((u16)0x7F0F)
\r
60 #define CCMR_OCM24_Mask ((u16)0x0F7F)
\r
61 #define CCMR_IC13PSC_Mask ((u16)0xFFF3)
\r
62 #define CCMR_IC24PSC_Mask ((u16)0xF3FF)
\r
63 #define CCMR_IC13F_Mask ((u16)0xFF0F)
\r
64 #define CCMR_IC24F_Mask ((u16)0x0FFF)
\r
65 #define CCER_CC1P_Mask ((u16)0xFFFD)
\r
67 #define CCER_CC2P_Mask ((u16)0xFFDF)
\r
68 #define CCER_CC3P_Mask ((u16)0xFDFF)
\r
69 #define CCER_CC4P_Mask ((u16)0xDFFF)
\r
71 #define CCRE_CC1E_Set ((u16)0x0001)
\r
72 #define CCRE_CC1E_Reset ((u16)0xFFFE)
\r
73 #define CCRE_CC1E_Mask ((u16)0xFFFE)
\r
75 #define CCRE_CC2E_Set ((u16)0x0010)
\r
76 #define CCRE_CC2E_Reset ((u16)0xFFEF)
\r
77 #define CCRE_CC2E_Mask ((u16)0xFFEF)
\r
79 #define CCRE_CC3E_Set ((u16)0x0100)
\r
80 #define CCRE_CC3E_Reset ((u16)0xFEFF)
\r
82 #define CCRE_CC4E_Set ((u16)0x1000)
\r
83 #define CCRE_CC4E_Reset ((u16)0xEFFF)
\r
84 #define CCRE_CC4E_Mask ((u16)0xEFFF)
\r
86 #define DCR_DMA_Mask ((u16)0x0000)
\r
88 /* TIM private Masks */
\r
89 #define TIM_Period_Reset_Mask ((u16)0x0000)
\r
90 #define TIM_Prescaler_Reset_Mask ((u16)0x0000)
\r
91 #define TIM_Pulse_Reset_Mask ((u16)0x0000)
\r
92 #define TIM_ICFilter_Mask ((u8)0x00)
\r
94 /* Private macro -------------------------------------------------------------*/
\r
95 /* Private variables ---------------------------------------------------------*/
\r
96 static uc16 Tab_OCModeMask[4] = {0xFF00, 0x00FF, 0xFF00, 0x00FF};
\r
97 static uc16 Tab_PolarityMask[4] = {CCER_CC1P_Mask, CCER_CC2P_Mask, CCER_CC3P_Mask, CCER_CC4P_Mask};
\r
99 /* Private function prototypes -----------------------------------------------*/
\r
100 static void PWMI_Config(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct);
\r
101 static void TI1_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
103 static void TI2_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
105 static void TI3_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
107 static void TI4_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
109 static void ETR_Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler,
\r
110 u16 TIM_ExtTRGPolarity, u8 ExtTRGFilter);
\r
111 /* Private functions ---------------------------------------------------------*/
\r
113 /*******************************************************************************
\r
114 * Function Name : TIM_DeInit
\r
115 * Description : Deinitializes the TIMx peripheral registers to their default
\r
117 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
120 *******************************************************************************/
\r
121 void TIM_DeInit(TIM_TypeDef* TIMx)
\r
123 switch (*(u32*)&TIMx)
\r
126 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE);
\r
127 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
\r
131 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
\r
132 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
\r
136 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE);
\r
137 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE);
\r
145 /*******************************************************************************
\r
146 * Function Name : TIM_TimeBaseInit
\r
147 * Description : Initializes the TIMx Time Base Unit peripheral according to
\r
148 * the specified parameters in the TIM_TimeBaseInitStruct.
\r
149 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
150 * - TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
\r
151 * structure that contains the configuration information for
\r
152 * the specified TIM peripheral.
\r
155 *******************************************************************************/
\r
156 void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
\r
158 /* Check the parameters */
\r
159 assert(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
\r
160 assert(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));
\r
162 /* Set the Autoreload value */
\r
163 TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
\r
165 /* Set the Prescaler value */
\r
166 TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
\r
168 /* Select the Counter Mode and set the clock division */
\r
169 TIMx->CR1 &= CR1_CKD_Mask & CR1_CounterMode_Mask;
\r
170 TIMx->CR1 |= (u32)TIM_TimeBaseInitStruct->TIM_ClockDivision |
\r
171 TIM_TimeBaseInitStruct->TIM_CounterMode;
\r
173 /*******************************************************************************
\r
174 * Function Name : TIM_OCInit
\r
175 * Description : Initializes the TIMx peripheral according to the specified
\r
176 * parameters in the TIM_OCInitStruct.
\r
177 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
178 * - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
\r
179 * that contains the configuration information for the specified
\r
183 *******************************************************************************/
\r
184 void TIM_OCInit(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
\r
186 u32 tmpccmrx = 0, tmpccer = 0;
\r
188 /* Check the parameters */
\r
189 assert(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));
\r
190 assert(IS_TIM_CHANNEL(TIM_OCInitStruct->TIM_Channel));
\r
191 assert(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));
\r
193 tmpccer = TIMx->CCER;
\r
195 if ((TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_1) ||
\r
196 (TIM_OCInitStruct->TIM_Channel == (u16)TIM_Channel_2))
\r
198 tmpccmrx = TIMx->CCMR1;
\r
200 /* Reset the Output Compare Bits */
\r
201 tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel];
\r
203 /* Set the Output Polarity level */
\r
204 tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel];
\r
206 if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_1)
\r
208 /* Disable the Channel 1: Reset the CCE Bit */
\r
209 TIMx->CCER &= CCRE_CC1E_Reset;
\r
211 /* Select the Output Compare Mode */
\r
212 tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
\r
214 /* Set the Capture Compare Register value */
\r
215 TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse;
\r
217 /* Set the Capture Compare Enable Bit */
\r
218 tmpccer |= CCRE_CC1E_Set;
\r
220 /* Set the Capture Compare Polarity */
\r
221 tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;
\r
223 else /* TIM_Channel_2 */
\r
225 /* Disable the Channel 2: Reset the CCE Bit */
\r
226 TIMx->CCER &= CCRE_CC2E_Reset;
\r
228 /* Select the Output Compare Mode */
\r
229 tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8;
\r
231 /* Set the Capture Compare Register value */
\r
232 TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse;
\r
234 /* Set the Capture Compare Enable Bit */
\r
235 tmpccer |= CCRE_CC2E_Set;
\r
237 /* Set the Capture Compare Polarity */
\r
238 tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 4;
\r
241 TIMx->CCMR1 = (u16)tmpccmrx;
\r
245 if ((TIM_OCInitStruct->TIM_Channel == TIM_Channel_3) ||
\r
246 (TIM_OCInitStruct->TIM_Channel == TIM_Channel_4))
\r
248 tmpccmrx = TIMx->CCMR2;
\r
250 /* Reset the Output Compare Bits */
\r
251 tmpccmrx &= Tab_OCModeMask[TIM_OCInitStruct->TIM_Channel];
\r
253 /* Set the Output Polarity level */
\r
254 tmpccer &= Tab_PolarityMask[TIM_OCInitStruct->TIM_Channel];
\r
256 if (TIM_OCInitStruct->TIM_Channel == TIM_Channel_3)
\r
258 /* Disable the Channel 3: Reset the CCE Bit */
\r
259 TIMx->CCER &= CCRE_CC3E_Reset;
\r
261 /* Select the Output Compare Mode */
\r
262 tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;
\r
264 /* Set the Capture Compare Register value */
\r
265 TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse;
\r
267 /* Set the Capture Compare Enable Bit */
\r
268 tmpccer |= CCRE_CC3E_Set;
\r
270 /* Set the Capture Compare Polarity */
\r
271 tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 8;
\r
273 else /* TIM_Channel_4 */
\r
275 /* Disable the Channel 4: Reset the CCE Bit */
\r
276 TIMx->CCER &= CCRE_CC4E_Reset;
\r
278 /* Select the Output Compare Mode */
\r
279 tmpccmrx |= (u32)TIM_OCInitStruct->TIM_OCMode << 8;
\r
281 /* Set the Capture Compare Register value */
\r
282 TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse;
\r
284 /* Set the Capture Compare Enable Bit */
\r
285 tmpccer |= CCRE_CC4E_Set;
\r
287 /* Set the Capture Compare Polarity */
\r
288 tmpccer |= (u32)TIM_OCInitStruct->TIM_OCPolarity << 12;
\r
291 TIMx->CCMR2 = (u16)tmpccmrx;
\r
295 TIMx->CCER = (u16)tmpccer;
\r
298 /*******************************************************************************
\r
299 * Function Name : TIM_ICInit
\r
300 * Description : Initializes the TIMx peripheral according to the specified
\r
301 * parameters in the TIM_ICInitStruct.
\r
302 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
303 * - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
\r
304 * that contains the configuration information for the specified
\r
308 *******************************************************************************/
\r
309 void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
\r
311 /* Check the parameters */
\r
312 assert(IS_TIM_IC_MODE(TIM_ICInitStruct->TIM_ICMode));
\r
313 assert(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel));
\r
314 assert(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity));
\r
315 assert(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection));
\r
316 assert(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler));
\r
317 assert(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter));
\r
319 if (TIM_ICInitStruct->TIM_ICMode == TIM_ICMode_ICAP)
\r
321 if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
\r
323 /* TI1 Configuration */
\r
324 TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
\r
325 TIM_ICInitStruct->TIM_ICSelection,
\r
326 TIM_ICInitStruct->TIM_ICFilter);
\r
328 /* Set the Input Capture Prescaler value */
\r
329 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
331 else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2)
\r
333 /* TI2 Configuration */
\r
334 TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
\r
335 TIM_ICInitStruct->TIM_ICSelection,
\r
336 TIM_ICInitStruct->TIM_ICFilter);
\r
338 /* Set the Input Capture Prescaler value */
\r
339 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
341 else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3)
\r
343 /* TI3 Configuration */
\r
344 TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
\r
345 TIM_ICInitStruct->TIM_ICSelection,
\r
346 TIM_ICInitStruct->TIM_ICFilter);
\r
348 /* Set the Input Capture Prescaler value */
\r
349 TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
351 else /* TIM_Channel_4 */
\r
353 /* TI4 Configuration */
\r
354 TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,
\r
355 TIM_ICInitStruct->TIM_ICSelection,
\r
356 TIM_ICInitStruct->TIM_ICFilter);
\r
358 /* Set the Input Capture Prescaler value */
\r
359 TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
364 PWMI_Config(TIMx, TIM_ICInitStruct);
\r
368 /*******************************************************************************
\r
369 * Function Name : TIM_TimeBaseStructInit
\r
370 * Description : Fills each TIM_TimeBaseInitStruct member with its default value.
\r
371 * Input : - TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef
\r
372 * structure which will be initialized.
\r
375 *******************************************************************************/
\r
376 void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)
\r
378 /* Set the default configuration */
\r
379 TIM_TimeBaseInitStruct->TIM_Period = TIM_Period_Reset_Mask;
\r
380 TIM_TimeBaseInitStruct->TIM_Prescaler = TIM_Prescaler_Reset_Mask;
\r
381 TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1;
\r
382 TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up;
\r
385 /*******************************************************************************
\r
386 * Function Name : TIM_OCStructInit
\r
387 * Description : Fills each TIM_OCInitStruct member with its default value.
\r
388 * Input : - TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure
\r
389 * which will be initialized.
\r
392 *******************************************************************************/
\r
393 void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)
\r
395 /* Set the default configuration */
\r
396 TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;
\r
397 TIM_OCInitStruct->TIM_Channel = TIM_Channel_1;
\r
398 TIM_OCInitStruct->TIM_Pulse = TIM_Pulse_Reset_Mask;
\r
399 TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;
\r
402 /*******************************************************************************
\r
403 * Function Name : TIM_ICStructInit
\r
404 * Description : Fills each TIM_InitStruct member with its default value.
\r
405 * Input : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
\r
406 * which will be initialized.
\r
409 *******************************************************************************/
\r
410 void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)
\r
412 /* Set the default configuration */
\r
413 TIM_ICInitStruct->TIM_ICMode = TIM_ICMode_ICAP;
\r
414 TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;
\r
415 TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;
\r
416 TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;
\r
417 TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;
\r
418 TIM_ICInitStruct->TIM_ICFilter = TIM_ICFilter_Mask;
\r
421 /*******************************************************************************
\r
422 * Function Name : TIM_Cmd
\r
423 * Description : Enables or disables the specified TIM peripheral.
\r
424 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIMx peripheral.
\r
425 * - Newstate: new state of the TIMx peripheral.
\r
426 * This parameter can be: ENABLE or DISABLE.
\r
429 *******************************************************************************/
\r
430 void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
\r
432 /* Check the parameters */
\r
433 assert(IS_FUNCTIONAL_STATE(NewState));
\r
435 if (NewState != DISABLE)
\r
437 /* Enable the TIM Counter */
\r
438 TIMx->CR1 |= CR1_CEN_Set;
\r
442 /* Disable the TIM Counter */
\r
443 TIMx->CR1 &= CR1_CEN_Reset;
\r
447 /*******************************************************************************
\r
448 * Function Name : TIM_ITConfig
\r
449 * Description : Enables or disables the TIMx interrupts.
\r
450 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
451 * - TIM_IT: specifies the TIM interrupts sources to be enabled
\r
453 * This parameter can be any combination of the following values:
\r
454 * - TIM_IT_Update: Timer update Interrupt
\r
455 * - TIM_IT_CC1: Capture Compare 1 Interrupt
\r
456 * - TIM_IT_CC2: Capture Compare 2 Interrupt
\r
457 * - TIM_IT_CC3: Capture Compare 3 Interrupt
\r
458 * - TIM_IT_CC4: Capture Compare 4 Interrupt
\r
459 * - TIM_IT_Trigger: Trigger Interrupt
\r
460 * - Newstate: new state of the specified TIMx interrupts.
\r
461 * This parameter can be: ENABLE or DISABLE.
\r
464 *******************************************************************************/
\r
465 void TIM_ITConfig(TIM_TypeDef* TIMx, u16 TIM_IT, FunctionalState NewState)
\r
467 /* Check the parameters */
\r
468 assert(IS_TIM_IT(TIM_IT));
\r
469 assert(IS_FUNCTIONAL_STATE(NewState));
\r
471 if (NewState != DISABLE)
\r
473 /* Enable the Interrupt sources */
\r
474 TIMx->DIER |= TIM_IT;
\r
478 /* Disable the Interrupt sources */
\r
479 TIMx->DIER &= (u16)(~TIM_IT);
\r
483 /*******************************************************************************
\r
484 * Function Name : TIM_DMAConfig
\r
485 * Description : Configures the TIMx
\92s DMA interface.
\r
486 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
487 * - TIM_DMABase: DMA Base address.
\r
488 * This parameter can be one of the following values:
\r
489 * - TIM_DMABase_CR1, TIM_DMABase_CR2, TIM_DMABase_SMCR,
\r
490 * TIM_DMABase_DIER, TIM_DMABase_SR, TIM_DMABase_EGR,
\r
491 * TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER,
\r
492 * TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR,
\r
493 * TIM_DMABase_CCR1, TIM_DMABase_CCR2, TIM_DMABase_CCR3,
\r
494 * TIM_DMABase_CCR4, TIM_DMABase_DCR.
\r
495 * - TIM_DMABurstLength: DMA Burst length.
\r
496 * This parameter can be one value between:
\r
497 * TIM_DMABurstLength_1Byte and TIM_DMABurstLength_18Bytes.
\r
500 *******************************************************************************/
\r
501 void TIM_DMAConfig(TIM_TypeDef* TIMx, u16 TIM_DMABase, u16 TIM_DMABurstLength)
\r
505 /* Check the parameters */
\r
506 assert(IS_TIM_DMA_BASE(TIM_DMABase));
\r
507 assert(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));
\r
509 tmpdcr = TIMx->DCR;
\r
511 /* Reset the DBA and the DBL Bits */
\r
512 tmpdcr &= DCR_DMA_Mask;
\r
514 /* Set the DMA Base and the DMA Burst Length */
\r
515 tmpdcr |= TIM_DMABase | TIM_DMABurstLength;
\r
517 TIMx->DCR = (u16)tmpdcr;
\r
520 /*******************************************************************************
\r
521 * Function Name : TIM_DMACmd
\r
522 * Description : Enables or disables the TIMx
\92s DMA Requests.
\r
523 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
524 * - TIM_DMASources: specifies the DMA Request sources.
\r
525 * This parameter can be any combination of the following values:
\r
526 * - TIM_DMA_CC1: Capture Compare 1 DMA source
\r
527 * - TIM_DMA_CC2: Capture Compare 2 DMA source
\r
528 * - TIM_DMA_CC3: Capture Compare 3 DMA source
\r
529 * - TIM_DMA_CC4: Capture Compare 4 DMA source
\r
530 * - TIM_DMA_Trigger: Trigger DMA source
\r
531 * - Newstate: new state of the DMA Request sources.
\r
532 * This parameter can be: ENABLE or DISABLE.
\r
535 *******************************************************************************/
\r
536 void TIM_DMACmd(TIM_TypeDef* TIMx, u16 TIM_DMASource, FunctionalState Newstate)
\r
540 /* Check the parameters */
\r
541 assert(IS_TIM_DMA_SOURCE(TIM_DMASource));
\r
542 assert(IS_FUNCTIONAL_STATE(Newstate));
\r
544 tmpdier = TIMx->DIER;
\r
546 if (Newstate != DISABLE)
\r
548 /* Enable the DMA sources */
\r
549 tmpdier |= TIM_DMASource;
\r
553 /* Disable the DMA sources */
\r
554 tmpdier &= (u16)(~TIM_DMASource);
\r
556 TIMx->DIER = (u16)tmpdier;
\r
559 /*******************************************************************************
\r
560 * Function Name : TIM_InternalClockConfig
\r
561 * Description : Configures the TIMx interrnal Clock
\r
562 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
565 *******************************************************************************/
\r
566 void TIM_InternalClockConfig(TIM_TypeDef* TIMx)
\r
568 /* Disable slave mode to clock the prescaler directly with the internal clock */
\r
569 TIMx->SMCR &= SMCR_SMS_Mask;
\r
571 /*******************************************************************************
\r
572 * Function Name : TIM_ITRxExternalClockConfig
\r
573 * Description : Configures the TIMx Internal Trigger as External Clock
\r
574 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
575 * - TIM_ITRSource: Trigger source.
\r
576 * This parameter can be one of the following values:
\r
577 * - TIM_TS_ITR0: Internal Trigger 0
\r
578 * - TIM_TS_ITR1: Internal Trigger 1
\r
579 * - TIM_TS_ITR2: Internal Trigger 2
\r
580 * - TIM_TS_ITR3: Internal Trigger 3
\r
583 *******************************************************************************/
\r
584 void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
\r
586 /* Check the parameters */
\r
587 assert(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));
\r
589 /* Select the Internal Trigger */
\r
590 TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);
\r
592 /* Select the External clock mode1 */
\r
593 TIMx->SMCR |= TIM_SlaveMode_External1;
\r
595 /*******************************************************************************
\r
596 * Function Name : TIM_TIxExternalClockConfig
\r
597 * Description : Configures the TIMx Trigger as External Clock
\r
598 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
599 * - TIM_TIxExternalCLKSource: Trigger source.
\r
600 * This parameter can be one of the following values:
\r
601 * - TIM_TS_TI1F_ED: TI1 Edge Detector
\r
602 * - TIM_TS_TI1FP1: Filtered Timer Input 1
\r
603 * - TIM_TS_TI2FP2: Filtered Timer Input 2
\r
604 * - TIM_ICPolarity: specifies the TIx Polarity.
\r
605 * This parameter can be:
\r
606 * - TIM_ICPolarity_Rising
\r
607 * - TIM_ICPolarity_Falling
\r
608 * - ICFilter : specifies the filter value.
\r
609 * This parameter must be a value between 0x0 and 0xF.
\r
612 *******************************************************************************/
\r
613 void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_TIxExternalCLKSource,
\r
614 u16 TIM_ICPolarity, u8 ICFilter)
\r
616 /* Check the parameters */
\r
617 assert(IS_TIM_TIX_TRIGGER_SELECTION(TIM_TIxExternalCLKSource));
\r
618 assert(IS_TIM_IC_POLARITY(TIM_ICPolarity));
\r
619 assert(IS_TIM_IC_FILTER(ICFilter));
\r
621 /* Configure the Timer Input Clock Source */
\r
622 if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2)
\r
624 TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
\r
628 TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);
\r
631 /* Select the Trigger source */
\r
632 TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource);
\r
634 /* Select the External clock mode1 */
\r
635 TIMx->SMCR |= TIM_SlaveMode_External1;
\r
638 /*******************************************************************************
\r
639 * Function Name : TIM_ETRClockMode1Config
\r
640 * Description : Configures the External clock Mode1
\r
641 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
642 * - TIM_ExtTRGPrescaler: The external Trigger Prescaler.
\r
643 * It can be one of the following values:
\r
644 * - TIM_ExtTRGPSC_OFF
\r
645 * - TIM_ExtTRGPSC_DIV2
\r
646 * - TIM_ExtTRGPSC_DIV4
\r
647 * - TIM_ExtTRGPSC_DIV8.
\r
648 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
\r
649 * It can be one of the following values:
\r
650 * - TIM_ExtTRGPolarity_Inverted
\r
651 * - TIM_ExtTRGPolarity_NonInverted
\r
652 * - ExtTRGFilter: External Trigger Filter.
\r
653 * This parameter must be a value between 0x00 and 0x0F
\r
656 *******************************************************************************/
\r
657 void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity,
\r
660 /* Check the parameters */
\r
661 assert(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
\r
662 assert(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
\r
664 /* Configure the ETR Clock source */
\r
665 ETR_Config(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
\r
667 /* Select the External clock mode1 */
\r
668 TIMx->SMCR &= SMCR_SMS_Mask;
\r
669 TIMx->SMCR |= TIM_SlaveMode_External1;
\r
671 /* Select the Trigger selection : ETRF */
\r
672 TIMx->SMCR &= SMCR_TS_Mask;
\r
673 TIMx->SMCR |= TIM_TS_ETRF;
\r
676 /*******************************************************************************
\r
677 * Function Name : TIM_ETRClockMode2Config
\r
678 * Description : Configures the External clock Mode2
\r
679 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
680 * - TIM_ExtTRGPrescaler: The external Trigger Prescaler.
\r
681 * It can be one of the following values:
\r
682 * - TIM_ExtTRGPSC_OFF
\r
683 * - TIM_ExtTRGPSC_DIV2
\r
684 * - TIM_ExtTRGPSC_DIV4
\r
685 * - TIM_ExtTRGPSC_DIV8
\r
686 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
\r
687 * It can be one of the following values:
\r
688 * - TIM_ExtTRGPolarity_Inverted
\r
689 * - TIM_ExtTRGPolarity_NonInverted
\r
690 * - ExtTRGFilter: External Trigger Filter.
\r
691 * This parameter must be a value between 0x00 and 0x0F
\r
694 *******************************************************************************/
\r
695 void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler,
\r
696 u16 TIM_ExtTRGPolarity, u8 ExtTRGFilter)
\r
698 /* Check the parameters */
\r
699 assert(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
\r
700 assert(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
\r
702 /* Configure the ETR Clock source */
\r
703 ETR_Config(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
\r
705 /* Enable the External clock mode2 */
\r
706 TIMx->SMCR |= SMCR_ECE_Set;
\r
708 /*******************************************************************************
\r
709 * Function Name : TIM_SelectInputTrigger
\r
710 * Description : Selects the Input Trigger source
\r
711 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
712 * - TIM_InputTriggerSource: The Input Trigger source.
\r
713 * This parameter can be one of the following values:
\r
714 * - TIM_TS_ITR0: Internal Trigger 0
\r
715 * - TIM_TS_ITR1: Internal Trigger 1
\r
716 * - TIM_TS_ITR2: Internal Trigger 2
\r
717 * - TIM_TS_ITR3: Internal Trigger 3
\r
718 * - TIM_TS_TI1F_ED: TI1 Edge Detector
\r
719 * - TIM_TS_TI1FP1: Filtered Timer Input 1
\r
720 * - TIM_TS_TI2FP2: Filtered Timer Input 2
\r
721 * - TIM_TS_ETRF: External Trigger input
\r
724 *******************************************************************************/
\r
725 void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
\r
729 /* Check the parameters */
\r
730 assert(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));
\r
732 tmpsmcr = TIMx->SMCR;
\r
734 /* Select the Tgigger Source */
\r
735 tmpsmcr &= SMCR_TS_Mask;
\r
736 tmpsmcr |= TIM_InputTriggerSource;
\r
738 TIMx->SMCR = (u16)tmpsmcr;
\r
741 /*******************************************************************************
\r
742 * Function Name : TIM_PrescalerConfig
\r
743 * Description : Configures the TIMx Prescaler.
\r
744 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
745 * - Prescaler: specifies the Prescaler Register value
\r
746 * - TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
\r
747 * This parameter can be one of the following values:
\r
748 * - TIM_PSCReloadMode_Update: The Prescaler is loaded at
\r
749 * the update event.
\r
750 * - TIM_PSCReloadMode_Immediate: The Prescaler is loaded
\r
754 *******************************************************************************/
\r
755 void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode)
\r
757 /* Check the parameters */
\r
758 assert(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));
\r
760 /* Set the Prescaler value */
\r
761 TIMx->PSC = Prescaler;
\r
763 /* Set or reset the UG Bit */
\r
764 if (TIM_PSCReloadMode == TIM_PSCReloadMode_Immediate)
\r
766 TIMx->EGR |= TIM_EventSource_Update;
\r
770 TIMx->EGR &= TIM_EventSource_Update;
\r
774 /*******************************************************************************
\r
775 * Function Name : TIM_CounterModeConfig
\r
776 * Description : Specifies the TIMx Counter Mode to be used.
\r
777 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
778 * - TIM_CounterMode: specifies the Counter Mode to be used
\r
779 * This parameter can be one of the following values:
\r
780 * - TIM_CounterMode_Up: TIM Up Counting Mode
\r
781 * - TIM_CounterMode_Down: TIM Down Counting Mode
\r
782 * - TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
\r
783 * - TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
\r
784 * - TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
\r
787 *******************************************************************************/
\r
788 void TIM_CounterModeConfig(TIM_TypeDef* TIMx, u16 TIM_CounterMode)
\r
792 /* Check the parameters */
\r
793 assert(IS_TIM_COUNTER_MODE(TIM_CounterMode));
\r
795 tmpcr1 = TIMx->CR1;
\r
797 /* Reset the CMS and DIR Bits */
\r
798 tmpcr1 &= CR1_CounterMode_Mask;
\r
800 /* Set the Counter Mode */
\r
801 tmpcr1 |= TIM_CounterMode;
\r
803 TIMx->CR1 = (u16)tmpcr1;
\r
806 /*******************************************************************************
\r
807 * Function Name : TIM_ForcedOC1Config
\r
808 * Description : Forces the TIMx output 1 waveform to active or inactive level.
\r
809 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
810 * - TIM_ForcedAction: specifies the forced Action to be set to
\r
811 * the output waveform.
\r
812 * This parameter can be one of the following values:
\r
813 * - TIM_ForcedAction_Active: Force active level on OC1REF
\r
814 * - TIM_ForcedAction_InActive: Force inactive level on
\r
818 *******************************************************************************/
\r
819 void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
\r
823 /* Check the parameters */
\r
824 assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
\r
826 tmpccmr1 = TIMx->CCMR1;
\r
828 /* Reset the OCM Bits */
\r
829 tmpccmr1 &= CCMR_OCM13_Mask;
\r
831 /* Configure The Forced output Mode */
\r
832 tmpccmr1 |= TIM_ForcedAction;
\r
834 TIMx->CCMR1 = (u16)tmpccmr1;
\r
837 /*******************************************************************************
\r
838 * Function Name : TIM_ForcedOC2Config
\r
839 * Description : Forces the TIMx output 2 waveform to active or inactive level.
\r
840 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
841 * - TIM_ForcedAction: specifies the forced Action to be set to
\r
842 * the output waveform.
\r
843 * This parameter can be one of the following values:
\r
844 * - TIM_ForcedAction_Active: Force active level on OC2REF
\r
845 * - TIM_ForcedAction_InActive: Force inactive level on
\r
849 *******************************************************************************/
\r
850 void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
\r
854 /* Check the parameters */
\r
855 assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
\r
857 tmpccmr1 = TIMx->CCMR1;
\r
859 /* Reset the OCM Bits */
\r
860 tmpccmr1 &= CCMR_OCM24_Mask;
\r
862 /* Configure The Forced output Mode */
\r
863 tmpccmr1 |= (u16)(TIM_ForcedAction << 8);
\r
865 TIMx->CCMR1 = (u16)tmpccmr1;
\r
868 /*******************************************************************************
\r
869 * Function Name : TIM_ForcedOC3Config
\r
870 * Description : Forces the TIMx output 3 waveform to active or inactive level.
\r
871 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
872 * - TIM_ForcedAction: specifies the forced Action to be set to
\r
873 * the output waveform.
\r
874 * This parameter can be one of the following values:
\r
875 * - TIM_ForcedAction_Active: Force active level on OC3REF
\r
876 * - TIM_ForcedAction_InActive: Force inactive level on
\r
880 *******************************************************************************/
\r
881 void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
\r
885 /* Check the parameters */
\r
886 assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
\r
888 tmpccmr2 = TIMx->CCMR2;
\r
890 /* Reset the OCM Bits */
\r
891 tmpccmr2 &= CCMR_OCM13_Mask;
\r
893 /* Configure The Forced output Mode */
\r
894 tmpccmr2 |= TIM_ForcedAction;
\r
896 TIMx->CCMR2 = (u16)tmpccmr2;
\r
899 /*******************************************************************************
\r
900 * Function Name : TIM_ForcedOC4Config
\r
901 * Description : Forces the TIMx output 4 waveform to active or inactive level.
\r
902 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
903 * - TIM_ForcedAction: specifies the forced Action to be set to
\r
904 * the output waveform.
\r
905 * This parameter can be one of the following values:
\r
906 * - TIM_ForcedAction_Active: Force active level on OC4REF
\r
907 * - TIM_ForcedAction_InActive: Force inactive level on
\r
911 *******************************************************************************/
\r
912 void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
\r
916 /* Check the parameters */
\r
917 assert(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
\r
919 tmpccmr2 = TIMx->CCMR2;
\r
921 /* Reset the OCM Bits */
\r
922 tmpccmr2 &= CCMR_OCM24_Mask;
\r
924 /* Configure The Forced output Mode */
\r
925 tmpccmr2 |= (u16)(TIM_ForcedAction << 8);
\r
927 TIMx->CCMR2 = (u16)tmpccmr2;
\r
930 /*******************************************************************************
\r
931 * Function Name : TIM_ARRPreloadConfig
\r
932 * Description : Enables or disables TIMx peripheral Preload register on ARR.
\r
933 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
934 * - Newstate: new state of the TIMx peripheral Preload register
\r
935 * This parameter can be: ENABLE or DISABLE.
\r
938 *******************************************************************************/
\r
939 void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState Newstate)
\r
943 /* Check the parameters */
\r
944 assert(IS_FUNCTIONAL_STATE(Newstate));
\r
946 tmpcr1 = TIMx->CR1;
\r
948 if (Newstate != DISABLE)
\r
950 /* Set the ARR Preload Bit */
\r
951 tmpcr1 |= CR1_ARPE_Set;
\r
955 /* Reset the ARR Preload Bit */
\r
956 tmpcr1 &= CR1_ARPE_Reset;
\r
959 TIMx->CR1 = (u16)tmpcr1;
\r
962 /*******************************************************************************
\r
963 * Function Name : TIM_SelectCCDMA
\r
964 * Description : Selects the TIMx peripheral Capture Compare DMA source.
\r
965 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
966 * - Newstate: new state of the Capture Compare DMA source
\r
967 * This parameter can be: ENABLE or DISABLE.
\r
970 *******************************************************************************/
\r
971 void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState Newstate)
\r
975 /* Check the parameters */
\r
976 assert(IS_FUNCTIONAL_STATE(Newstate));
\r
978 tmpcr2 = TIMx->CR2;
\r
980 if (Newstate != DISABLE)
\r
982 /* Set the CCDS Bit */
\r
983 tmpcr2 |= CR2_CCDS_Set;
\r
987 /* Reset the CCDS Bit */
\r
988 tmpcr2 &= CR2_CCDS_Reset;
\r
991 TIMx->CR2 = (u16)tmpcr2;
\r
994 /*******************************************************************************
\r
995 * Function Name : TIM_OC1PreloadConfig
\r
996 * Description : Enables or disables the TIMx peripheral Preload register on CCR1.
\r
997 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
998 * - TIM_OCPreload: new state of the TIMx peripheral Preload
\r
1000 * This parameter can be one of the following values:
\r
1001 * - TIM_OCPreload_Enable
\r
1002 * - TIM_OCPreload_Disable
\r
1005 *******************************************************************************/
\r
1006 void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
\r
1010 /* Check the parameters */
\r
1011 assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
\r
1013 tmpccmr1 = TIMx->CCMR1;
\r
1015 /* Reset the OCPE Bit */
\r
1016 tmpccmr1 &= CCMR_OC13PE_Mask;
\r
1018 /* Enable or Disable the Output Compare Preload feature */
\r
1019 tmpccmr1 |= TIM_OCPreload;
\r
1021 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1024 /*******************************************************************************
\r
1025 * Function Name : TIM_OC2PreloadConfig
\r
1026 * Description : Enables or disables the TIMx peripheral Preload register on CCR2.
\r
1027 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1028 * - TIM_OCPreload: new state of the TIMx peripheral Preload
\r
1030 * This parameter can be one of the following values:
\r
1031 * - TIM_OCPreload_Enable
\r
1032 * - TIM_OCPreload_Disable
\r
1035 *******************************************************************************/
\r
1036 void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
\r
1040 /* Check the parameters */
\r
1041 assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
\r
1043 tmpccmr1 = TIMx->CCMR1;
\r
1045 /* Reset the OCPE Bit */
\r
1046 tmpccmr1 &= CCMR_OC24PE_Mask;
\r
1048 /* Enable or Disable the Output Compare Preload feature */
\r
1049 tmpccmr1 |= (u16)(TIM_OCPreload << 8);
\r
1051 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1054 /*******************************************************************************
\r
1055 * Function Name : TIM_OC3PreloadConfig
\r
1056 * Description : Enables or disables the TIMx peripheral Preload register on CCR3.
\r
1057 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1058 * - TIM_OCPreload: new state of the TIMx peripheral Preload
\r
1060 * This parameter can be one of the following values:
\r
1061 * - TIM_OCPreload_Enable
\r
1062 * - TIM_OCPreload_Disable
\r
1065 *******************************************************************************/
\r
1066 void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
\r
1070 /* Check the parameters */
\r
1071 assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
\r
1073 tmpccmr2 = TIMx->CCMR2;
\r
1075 /* Reset the OCPE Bit */
\r
1076 tmpccmr2 &= CCMR_OC13PE_Mask;
\r
1078 /* Enable or Disable the Output Compare Preload feature */
\r
1079 tmpccmr2 |= TIM_OCPreload;
\r
1081 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1084 /*******************************************************************************
\r
1085 * Function Name : TIM_OC4PreloadConfig
\r
1086 * Description : Enables or disables the TIMx peripheral Preload register on CCR4.
\r
1087 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1088 * - TIM_OCPreload: new state of the TIMx peripheral Preload
\r
1090 * This parameter can be one of the following values:
\r
1091 * - TIM_OCPreload_Enable
\r
1092 * - TIM_OCPreload_Disable
\r
1095 *******************************************************************************/
\r
1096 void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
\r
1100 /* Check the parameters */
\r
1101 assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
\r
1103 tmpccmr2 = TIMx->CCMR2;
\r
1105 /* Reset the OCPE Bit */
\r
1106 tmpccmr2 &= CCMR_OC24PE_Mask;
\r
1108 /* Enable or Disable the Output Compare Preload feature */
\r
1109 tmpccmr2 |= (u16)(TIM_OCPreload << 8);
\r
1111 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1114 /*******************************************************************************
\r
1115 * Function Name : TIM_OC1FastConfig
\r
1116 * Description : Configures the TIMx Output Compare 1 Fast feature.
\r
1117 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1118 * - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
\r
1119 * This parameter can be one of the following values:
\r
1120 * - TIM_OCFast_Enable
\r
1121 * - TIM_OCFast_Disable
\r
1124 *******************************************************************************/
\r
1125 void TIM_OC1FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
\r
1129 /* Check the parameters */
\r
1130 assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
\r
1132 tmpccmr1 = TIMx->CCMR1;
\r
1134 /* Reset the OCFE Bit */
\r
1135 tmpccmr1 &= CCMR_OC13FE_Mask;
\r
1137 /* Enable or Disable the Output Compare Fast Bit */
\r
1138 tmpccmr1 |= TIM_OCFast;
\r
1140 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1143 /*******************************************************************************
\r
1144 * Function Name : TIM_OC2FastConfig
\r
1145 * Description : Configures the TIMx Output Compare 2 Fast feature.
\r
1146 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1147 * - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
\r
1148 * This parameter can be one of the following values:
\r
1149 * - TIM_OCFast_Enable
\r
1150 * - TIM_OCFast_Disable
\r
1153 *******************************************************************************/
\r
1154 void TIM_OC2FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
\r
1158 /* Check the parameters */
\r
1159 assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
\r
1161 tmpccmr1 = TIMx->CCMR1;
\r
1163 /* Reset the OCFE Bit */
\r
1164 tmpccmr1 &= CCMR_OC24FE_Mask;
\r
1166 /* Enable or Disable the Output Compare Fast Bit */
\r
1167 tmpccmr1 |= (u16)(TIM_OCFast << 8);
\r
1169 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1172 /*******************************************************************************
\r
1173 * Function Name : TIM_OC3FastConfig
\r
1174 * Description : Configures the TIMx Output Compare 3 Fast feature.
\r
1175 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1176 * - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
\r
1177 * This parameter can be one of the following values:
\r
1178 * - TIM_OCFast_Enable
\r
1179 * - TIM_OCFast_Disable
\r
1182 *******************************************************************************/
\r
1183 void TIM_OC3FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
\r
1187 /* Check the parameters */
\r
1188 assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
\r
1190 tmpccmr2 = TIMx->CCMR2;
\r
1192 /* Reset the OCFE Bit */
\r
1193 tmpccmr2 &= CCMR_OC13FE_Mask;
\r
1195 /* Enable or Disable the Output Compare Fast Bit */
\r
1196 tmpccmr2 |= TIM_OCFast;
\r
1198 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1201 /*******************************************************************************
\r
1202 * Function Name : TIM_OC4FastConfig
\r
1203 * Description : Configures the TIMx Output Compare 4 Fast feature.
\r
1204 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1205 * - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
\r
1206 * This parameter can be one of the following values:
\r
1207 * - TIM_OCFast_Enable
\r
1208 * - TIM_OCFast_Disable
\r
1211 *******************************************************************************/
\r
1212 void TIM_OC4FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
\r
1216 /* Check the parameters */
\r
1217 assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
\r
1219 tmpccmr2 = TIMx->CCMR2;
\r
1221 /* Reset the OCFE Bit */
\r
1222 tmpccmr2 &= CCMR_OC24FE_Mask;
\r
1224 /* Enable or Disable the Output Compare Fast Bit */
\r
1225 tmpccmr2 |= (u16)(TIM_OCFast << 8);
\r
1227 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1230 /*******************************************************************************
\r
1231 * Function Name : TIM_UpdateDisableConfig
\r
1232 * Description : Enables or Disables the TIMx Update event.
\r
1233 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1234 * - Newstate: new state of the TIMx peripheral Preload register
\r
1235 * This parameter can be: ENABLE or DISABLE.
\r
1238 *******************************************************************************/
\r
1239 void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState Newstate)
\r
1243 /* Check the parameters */
\r
1244 assert(IS_FUNCTIONAL_STATE(Newstate));
\r
1246 tmpcr1 = TIMx->CR1;
\r
1248 if (Newstate != DISABLE)
\r
1250 /* Set the Update Disable Bit */
\r
1251 tmpcr1 |= CR1_UDIS_Set;
\r
1255 /* Reset the Update Disable Bit */
\r
1256 tmpcr1 &= CR1_UDIS_Reset;
\r
1259 TIMx->CR1 = (u16)tmpcr1;
\r
1262 /*******************************************************************************
\r
1263 * Function Name : TIM_EncoderInterfaceConfig
\r
1264 * Description : Configures the TIMx Encoder Interface.
\r
1265 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1266 * - TIM_EncoderMode: specifies the TIMx Encoder Mode.
\r
1267 * This parameter can be one of the following values:
\r
1268 * - TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge
\r
1269 * depending on TI2FP2 level.
\r
1270 * - TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge
\r
1271 * depending on TI1FP1 level.
\r
1272 * - TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and
\r
1273 * TI2FP2 edges depending on the level of the other input.
\r
1274 * - TIM_IC1Polarity: specifies the IC1 Polarity
\r
1275 * This parmeter can be one of the following values:
\r
1276 * - TIM_ICPolarity_Falling
\r
1277 * - TIM_ICPolarity_Rising
\r
1278 * - TIM_IC2Polarity: specifies the IC2 Polarity
\r
1279 * This parmeter can be one of the following values:
\r
1280 * - TIM_ICPolarity_Falling
\r
1281 * - TIM_ICPolarity_Rising
\r
1284 *******************************************************************************/
\r
1285 void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, u16 TIM_EncoderMode,
\r
1286 u16 TIM_IC1Polarity, u16 TIM_IC2Polarity)
\r
1292 /* Check the parameters */
\r
1293 assert(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
\r
1294 assert(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
\r
1295 assert(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
\r
1297 tmpsmcr = TIMx->SMCR;
\r
1298 tmpccmr1 = TIMx->CCMR1;
\r
1299 tmpccer = TIMx->CCER;
\r
1301 /* Set the encoder Mode */
\r
1302 tmpsmcr &= SMCR_SMS_Mask;
\r
1303 tmpsmcr |= TIM_EncoderMode;
\r
1305 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
\r
1306 tmpccmr1 &= CCMR_CC13S_Mask & CCMR_CC24S_Mask;
\r
1307 tmpccmr1 |= CCMR_TI13Direct_Set | CCMR_TI24Direct_Set;
\r
1309 /* Set the TI1 and the TI2 Polarities */
\r
1310 tmpccer &= CCER_CC1P_Mask & CCER_CC2P_Mask;
\r
1311 tmpccer |= (TIM_IC1Polarity | (u16)((u16)TIM_IC2Polarity << 4));
\r
1313 TIMx->SMCR = (u16)tmpsmcr;
\r
1315 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1317 TIMx->CCER = (u16)tmpccer;
\r
1320 /*******************************************************************************
\r
1321 * Function Name : TIM_GenerateEvent
\r
1322 * Description : Configures the TIMx event to be generate by software.
\r
1323 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1324 * - TIM_EventSource: specifies the event source.
\r
1325 * This parameter can be one or more of the following values:
\r
1326 * - TIM_EventSource_Update: Timer update Event source
\r
1327 * - TIM_EventSource_CC1: Timer Capture Compare 1 Event source
\r
1328 * - TIM_EventSource_CC2: Timer Capture Compare 2 Event source
\r
1329 * - TIM_EventSource_CC3: Timer Capture Compare 3 Event source
\r
1330 * - TIM_EventSource_CC4: Timer Capture Compare 4 Event source
\r
1331 * - TIM_EventSource_Trigger: Timer Trigger Event source
\r
1334 *******************************************************************************/
\r
1335 void TIM_GenerateEvent(TIM_TypeDef* TIMx, u16 TIM_EventSource)
\r
1337 /* Check the parameters */
\r
1338 assert(IS_TIM_EVENT_SOURCE(TIM_EventSource));
\r
1340 /* Set the event sources */
\r
1341 TIMx->EGR |= TIM_EventSource;
\r
1344 /*******************************************************************************
\r
1345 * Function Name : TIM_OC1PolarityConfig
\r
1346 * Description : Configures the TIMx channel 1 polarity.
\r
1347 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1348 * - TIM_OCPolarity: specifies the OC1 Polarity
\r
1349 * This parmeter can be one of the following values:
\r
1350 * - TIM_OCPolarity_High: Output Compare active high
\r
1351 * - TIM_OCPolarity_Low: Output Compare active low
\r
1354 *******************************************************************************/
\r
1355 void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
\r
1359 /* Check the parameters */
\r
1360 assert(IS_TIM_OC_POLARITY(TIM_OCPolarity));
\r
1362 tmpccer = TIMx->CCER;
\r
1364 /* Set or Reset the CC1P Bit */
\r
1365 tmpccer &= CCER_CC1P_Mask;
\r
1366 tmpccer |= TIM_OCPolarity;
\r
1368 TIMx->CCER = (u16)tmpccer;
\r
1371 /*******************************************************************************
\r
1372 * Function Name : TIM_OC2PolarityConfig
\r
1373 * Description : Configures the TIMx channel 2 polarity.
\r
1374 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1375 * - TIM_OCPolarity: specifies the OC2 Polarity
\r
1376 * This parmeter can be one of the following values:
\r
1377 * - TIM_OCPolarity_High: Output Compare active high
\r
1378 * - TIM_OCPolarity_Low: Output Compare active low
\r
1381 *******************************************************************************/
\r
1382 void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
\r
1386 /* Check the parameters */
\r
1387 assert(IS_TIM_OC_POLARITY(TIM_OCPolarity));
\r
1389 tmpccer = TIMx->CCER;
\r
1391 /* Set or Reset the CC2P Bit */
\r
1392 tmpccer &= CCER_CC2P_Mask;
\r
1393 tmpccer |= (u16)((u16)TIM_OCPolarity << 4);
\r
1395 TIMx->CCER = (u16)tmpccer;
\r
1398 /*******************************************************************************
\r
1399 * Function Name : TIM_OC3PolarityConfig
\r
1400 * Description : Configures the TIMx channel 3 polarity.
\r
1401 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1402 * - TIM_OCPolarity: specifies the OC3 Polarity
\r
1403 * This parmeter can be one of the following values:
\r
1404 * - TIM_OCPolarity_High: Output Compare active high
\r
1405 * - TIM_OCPolarity_Low: Output Compare active low
\r
1408 *******************************************************************************/
\r
1409 void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
\r
1413 /* Check the parameters */
\r
1414 assert(IS_TIM_OC_POLARITY(TIM_OCPolarity));
\r
1416 tmpccer = TIMx->CCER;
\r
1418 /* Set or Reset the CC3P Bit */
\r
1419 tmpccer &= CCER_CC3P_Mask;
\r
1420 tmpccer |= (u16)((u16)TIM_OCPolarity << 8);
\r
1422 TIMx->CCER = (u16)tmpccer;
\r
1425 /*******************************************************************************
\r
1426 * Function Name : TIM_OC4PolarityConfig
\r
1427 * Description : Configures the TIMx channel 4 polarity.
\r
1428 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1429 * - TIM_OCPolarity: specifies the OC4 Polarity
\r
1430 * This parmeter can be one of the following values:
\r
1431 * - TIM_OCPolarity_High: Output Compare active high
\r
1432 * - TIM_OCPolarity_Low: Output Compare active low
\r
1435 *******************************************************************************/
\r
1436 void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
\r
1440 /* Check the parameters */
\r
1441 assert(IS_TIM_OC_POLARITY(TIM_OCPolarity));
\r
1443 tmpccer = TIMx->CCER;
\r
1445 /* Set or Reset the CC4P Bit */
\r
1446 tmpccer &= CCER_CC4P_Mask;
\r
1447 tmpccer |= (u16)((u16)TIM_OCPolarity << 12);
\r
1449 TIMx->CCER = (u16)tmpccer;
\r
1452 /*******************************************************************************
\r
1453 * Function Name : TIM_UpdateRequestConfig
\r
1454 * Description : Configures the TIMx Update Request Interrupt source.
\r
1455 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1456 * - TIM_UpdateSource: specifies the Update source.
\r
1457 * This parameter can be one of the following values:
\r
1458 * - TIM_UpdateSource_Regular
\r
1459 * - TIM_UpdateSource_Global
\r
1462 *******************************************************************************/
\r
1463 void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, u16 TIM_UpdateSource)
\r
1467 /* Check the parameters */
\r
1468 assert(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource));
\r
1470 tmpcr1 = TIMx->CR1;
\r
1472 if (TIM_UpdateSource == TIM_UpdateSource_Regular)
\r
1474 /* Set the URS Bit */
\r
1475 tmpcr1 |= CR1_URS_Set;
\r
1479 /* Reset the URS Bit */
\r
1480 tmpcr1 &= CR1_URS_Reset;
\r
1482 TIMx->CR1 = (u16)tmpcr1;
\r
1485 /*******************************************************************************
\r
1486 * Function Name : TIM_SelectHallSensor
\r
1487 * Description : Enables or disables the TIMx
\92s Hall sensor interface.
\r
1488 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1489 * - Newstate: new state of the TIMx Hall sensor interface.
\r
1490 * This parameter can be: ENABLE or DISABLE.
\r
1493 *******************************************************************************/
\r
1494 void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState Newstate)
\r
1496 /* Check the parameters */
\r
1497 assert(IS_FUNCTIONAL_STATE(Newstate));
\r
1499 if (Newstate != DISABLE)
\r
1501 /* Set the TI1S Bit */
\r
1502 TIMx->CR2 |= CR2_TI1S_Set;
\r
1506 /* Reset the TI1S Bit */
\r
1507 TIMx->CR2 &= CR2_TI1S_Reset;
\r
1511 /*******************************************************************************
\r
1512 * Function Name : TIM_SelectOnePulseMode
\r
1513 * Description : Selects the TIMx
\92s One Pulse Mode.
\r
1514 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1515 * - TIM_OPMode: specifies the OPM Mode to be used.
\r
1516 * This parameter can be one of the following values:
\r
1517 * - TIM_OPMode_Single
\r
1518 * - TIM_OPMode_Repetitive
\r
1521 *******************************************************************************/
\r
1522 void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, u16 TIM_OPMode)
\r
1526 /* Check the parameters */
\r
1527 assert(IS_TIM_OPM_MODE(TIM_OPMode));
\r
1529 tmpcr1 = TIMx->CR1;
\r
1531 /* Reset the OPM Bit */
\r
1532 tmpcr1 &= CR1_OPM_Mask;
\r
1534 /* Configure the OPM Mode */
\r
1535 tmpcr1 |= TIM_OPMode;
\r
1537 TIMx->CR1 = (u16)tmpcr1;
\r
1540 /*******************************************************************************
\r
1541 * Function Name : TIM_SelectOutputTrigger
\r
1542 * Description : Selects the TIMx Trigger Output Mode.
\r
1543 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1544 * - TIM_TRGOSource: specifies the Trigger Output source.
\r
1545 * This paramter can be one of the following values:
\r
1546 * - TIM_TRGOSource_Reset
\r
1547 * - TIM_TRGOSource_Enable
\r
1548 * - TIM_TRGOSource_Update
\r
1549 * - TIM_TRGOSource_OC1
\r
1550 * - TIM_TRGOSource_OC1Ref
\r
1551 * - TIM_TRGOSource_OC2Ref
\r
1552 * - TIM_TRGOSource_OC3Ref
\r
1553 * - TIM_TRGOSource_OC4Ref
\r
1556 *******************************************************************************/
\r
1557 void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, u16 TIM_TRGOSource)
\r
1561 /* Check the parameters */
\r
1562 assert(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));
\r
1564 tmpcr2 = TIMx->CR2;
\r
1565 /* Reset the MMS Bits */
\r
1566 tmpcr2 &= CR2_MMS_Mask;
\r
1568 /* Select the TRGO source */
\r
1569 tmpcr2 |= TIM_TRGOSource;
\r
1571 TIMx->CR2 = (u16)tmpcr2;
\r
1574 /*******************************************************************************
\r
1575 * Function Name : TIM_SelectSlaveMode
\r
1576 * Description : Selects the TIMx Slave Mode.
\r
1577 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1578 * - TIM_SlaveMode: specifies the Timer Slave Mode.
\r
1579 * This paramter can be one of the following values:
\r
1580 * - TIM_SlaveMode_Reset
\r
1581 * - TIM_SlaveMode_Gated
\r
1582 * - TIM_SlaveMode_Trigger
\r
1583 * - TIM_SlaveMode_External1
\r
1586 *******************************************************************************/
\r
1587 void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, u16 TIM_SlaveMode)
\r
1591 /* Check the parameters */
\r
1592 assert(IS_TIM_SLAVE_MODE(TIM_SlaveMode));
\r
1594 tmpsmcr = TIMx->SMCR;
\r
1596 /* Reset the SMS Bits */
\r
1597 tmpsmcr &= SMCR_SMS_Mask;
\r
1599 /* Select the Slave Mode */
\r
1600 tmpsmcr |= TIM_SlaveMode;
\r
1602 TIMx->SMCR = (u16)tmpsmcr;
\r
1605 /*******************************************************************************
\r
1606 * Function Name : TIM_SelectMasterSlaveMode
\r
1607 * Description : Sets or Resets the TIMx Master/Slave Mode.
\r
1608 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1609 * - TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.
\r
1610 * This paramter can be one of the following values:
\r
1611 * - TIM_MasterSlaveMode_Enable: synchronization between the
\r
1612 * current timer and its slaves (through TRGO).
\r
1613 * - TIM_MasterSlaveMode_Disable: No action
\r
1616 *******************************************************************************/
\r
1617 void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, u16 TIM_MasterSlaveMode)
\r
1621 /* Check the parameters */
\r
1622 assert(IS_TIM_MSM_STATE(TIM_MasterSlaveMode));
\r
1624 tmpsmcr = TIMx->SMCR;
\r
1626 /* Set or Reset the MSM Bit */
\r
1627 tmpsmcr &= SMCR_MSM_Mask;
\r
1628 tmpsmcr |= TIM_MasterSlaveMode;
\r
1630 TIMx->SMCR = (u16)tmpsmcr;
\r
1633 /*******************************************************************************
\r
1634 * Function Name : TIM_SetAutoreload
\r
1635 * Description : Sets the TIMx Autoreload Register value
\r
1636 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1637 * - Autoreload: specifies the Autoreload register new value.
\r
1640 *******************************************************************************/
\r
1641 void TIM_SetAutoreload(TIM_TypeDef* TIMx, u16 Autoreload)
\r
1643 /* Set the Autoreload Register value */
\r
1644 TIMx->ARR = Autoreload;
\r
1647 /*******************************************************************************
\r
1648 * Function Name : TIM_SetCompare1
\r
1649 * Description : Sets the TIMx Capture Compare1 Register value
\r
1650 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1651 * - Compare1: specifies the Capture Compare1 register new value.
\r
1654 *******************************************************************************/
\r
1655 void TIM_SetCompare1(TIM_TypeDef* TIMx, u16 Compare1)
\r
1657 /* Set the Capture Compare1 Register value */
\r
1658 TIMx->CCR1 = Compare1;
\r
1661 /*******************************************************************************
\r
1662 * Function Name : TIM_SetCompare2
\r
1663 * Description : Sets the TIMx Capture Compare2 Register value
\r
1664 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1665 * - Compare2: specifies the Capture Compare2 register new value.
\r
1668 *******************************************************************************/
\r
1669 void TIM_SetCompare2(TIM_TypeDef* TIMx, u16 Compare2)
\r
1671 /* Set the Capture Compare2 Register value */
\r
1672 TIMx->CCR2 = Compare2;
\r
1675 /*******************************************************************************
\r
1676 * Function Name : TIM_SetCompare3
\r
1677 * Description : Sets the TIMx Capture Compare3 Register value
\r
1678 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1679 * - Compare3: specifies the Capture Compare3 register new value.
\r
1682 *******************************************************************************/
\r
1683 void TIM_SetCompare3(TIM_TypeDef* TIMx, u16 Compare3)
\r
1685 /* Set the Capture Compare3 Register value */
\r
1686 TIMx->CCR3 = Compare3;
\r
1689 /*******************************************************************************
\r
1690 * Function Name : TIM_SetCompare4
\r
1691 * Description : Sets the TIMx Capture Compare4 Register value
\r
1692 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1693 * - Compare4: specifies the Capture Compare4 register new value.
\r
1696 *******************************************************************************/
\r
1697 void TIM_SetCompare4(TIM_TypeDef* TIMx, u16 Compare4)
\r
1699 /* Set the Capture Compare4 Register value */
\r
1700 TIMx->CCR4 = Compare4;
\r
1703 /*******************************************************************************
\r
1704 * Function Name : TIM_SetIC1Prescaler
\r
1705 * Description : Sets the TIMx Input Capture 1 prescaler.
\r
1706 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1707 * - TIM_IC1Prescaler: specifies the Input Capture1 prescaler
\r
1709 * This parameter can be one of the following values:
\r
1710 * - TIM_ICPSC_DIV1: no prescaler
\r
1711 * - TIM_ICPSC_DIV2: capture is done once every 2 events
\r
1712 * - TIM_ICPSC_DIV4: capture is done once every 4 events
\r
1713 * - TIM_ICPSC_DIV8: capture is done once every 8 events
\r
1716 *******************************************************************************/
\r
1717 void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC1Prescaler)
\r
1721 /* Check the parameters */
\r
1722 assert(IS_TIM_IC_PRESCALER(TIM_IC1Prescaler));
\r
1724 tmpccmr1 = TIMx->CCMR1;
\r
1726 /* Reset the IC1PSC Bits */
\r
1727 tmpccmr1 &= CCMR_IC13PSC_Mask;
\r
1729 /* Set the IC1PSC value */
\r
1730 tmpccmr1 |= TIM_IC1Prescaler;
\r
1732 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1735 /*******************************************************************************
\r
1736 * Function Name : TIM_SetIC2Prescaler
\r
1737 * Description : Sets the TIMx Input Capture 2 prescaler.
\r
1738 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1739 * - TIM_IC2Prescaler: specifies the Input Capture2 prescaler
\r
1741 * This parameter can be one of the following values:
\r
1742 * - TIM_ICPSC_DIV1: no prescaler
\r
1743 * - TIM_ICPSC_DIV2: capture is done once every 2 events
\r
1744 * - TIM_ICPSC_DIV4: capture is done once every 4 events
\r
1745 * - TIM_ICPSC_DIV8: capture is done once every 8 events
\r
1748 *******************************************************************************/
\r
1749 void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC2Prescaler)
\r
1753 /* Check the parameters */
\r
1754 assert(IS_TIM_IC_PRESCALER(TIM_IC2Prescaler));
\r
1756 tmpccmr1 = TIMx->CCMR1;
\r
1758 /* Reset the IC2PSC Bits */
\r
1759 tmpccmr1 &= CCMR_IC24PSC_Mask;
\r
1761 /* Set the IC2PSC value */
\r
1762 tmpccmr1 |= (u16)((u16)TIM_IC2Prescaler << 8);
\r
1764 TIMx->CCMR1 = (u16)tmpccmr1;
\r
1767 /*******************************************************************************
\r
1768 * Function Name : TIM_SetIC3Prescaler
\r
1769 * Description : Sets the TIMx Input Capture 3 prescaler.
\r
1770 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1771 * - TIM_IC3Prescaler: specifies the Input Capture3 prescaler
\r
1773 * This parameter can be one of the following values:
\r
1774 * - TIM_ICPSC_DIV1: no prescaler
\r
1775 * - TIM_ICPSC_DIV2: capture is done once every 2 events
\r
1776 * - TIM_ICPSC_DIV4: capture is done once every 4 events
\r
1777 * - TIM_ICPSC_DIV8: capture is done once every 8 events
\r
1780 *******************************************************************************/
\r
1781 void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC3Prescaler)
\r
1785 /* Check the parameters */
\r
1786 assert(IS_TIM_IC_PRESCALER(TIM_IC3Prescaler));
\r
1788 tmpccmr2 = TIMx->CCMR2;
\r
1790 /* Reset the IC3PSC Bits */
\r
1791 tmpccmr2 &= CCMR_IC13PSC_Mask;
\r
1793 /* Set the IC3PSC value */
\r
1794 tmpccmr2 |= TIM_IC3Prescaler;
\r
1796 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1799 /*******************************************************************************
\r
1800 * Function Name : TIM_SetIC4Prescaler
\r
1801 * Description : Sets the TIMx Input Capture 4 prescaler.
\r
1802 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1803 * - TIM_IC4Prescaler: specifies the Input Capture4 prescaler
\r
1805 * This parameter can be one of the following values:
\r
1806 * - TIM_ICPSC_DIV1: no prescaler
\r
1807 * - TIM_ICPSC_DIV2: capture is done once every 2 events
\r
1808 * - TIM_ICPSC_DIV4: capture is done once every 4 events
\r
1809 * - TIM_ICPSC_DIV8: capture is done once every 8 events
\r
1812 *******************************************************************************/
\r
1813 void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, u16 TIM_IC4Prescaler)
\r
1817 /* Check the parameters */
\r
1818 assert(IS_TIM_IC_PRESCALER(TIM_IC4Prescaler));
\r
1820 tmpccmr2 = TIMx->CCMR2;
\r
1822 /* Reset the IC4PSC Bits */
\r
1823 tmpccmr2 &= CCMR_IC24PSC_Mask;
\r
1825 /* Set the IC4PSC value */
\r
1826 tmpccmr2 |= (u16)((u16)TIM_IC4Prescaler << 8);
\r
1828 TIMx->CCMR2 = (u16)tmpccmr2;
\r
1831 /*******************************************************************************
\r
1832 * Function Name : TIM_SetClockDivision
\r
1833 * Description : Sets the TIMx Clock Division value.
\r
1834 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1835 * - TIM_CKD: specifies the clock division value.
\r
1836 * This parameter can be one of the following value:
\r
1837 * - TIM_CKD_DIV1: TDTS = Tck_tim
\r
1838 * - TIM_CKD_DIV2: TDTS = 2*Tck_tim
\r
1839 * - TIM_CKD_DIV4: TDTS = 4*Tck_tim
\r
1842 *******************************************************************************/
\r
1843 void TIM_SetClockDivision(TIM_TypeDef* TIMx, u16 TIM_CKD)
\r
1847 /* Check the parameters */
\r
1848 assert(IS_TIM_CKD_DIV(TIM_CKD));
\r
1850 tmpcr1 = TIMx->CR1;
\r
1852 /* Reset the CKD Bits */
\r
1853 tmpcr1 &= CR1_CKD_Mask;
\r
1855 /* Set the CKD value */
\r
1856 tmpcr1 |= TIM_CKD;
\r
1858 TIMx->CR1 = (u16)tmpcr1;
\r
1861 /*******************************************************************************
\r
1862 * Function Name : TIM_GetCapture1
\r
1863 * Description : Gets the TIMx Input Capture 1 value.
\r
1864 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1866 * Return : Capture Compare 1 Register value.
\r
1867 *******************************************************************************/
\r
1868 u16 TIM_GetCapture1(TIM_TypeDef* TIMx)
\r
1870 /* Get the Capture 1 Register value */
\r
1871 return TIMx->CCR1;
\r
1874 /*******************************************************************************
\r
1875 * Function Name : TIM_GetCapture2
\r
1876 * Description : Gets the TIMx Input Capture 2 value.
\r
1877 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1879 * Return : Capture Compare 2 Register value.
\r
1880 *******************************************************************************/
\r
1881 u16 TIM_GetCapture2(TIM_TypeDef* TIMx)
\r
1883 /* Get the Capture 2 Register value */
\r
1884 return TIMx->CCR2;
\r
1887 /*******************************************************************************
\r
1888 * Function Name : TIM_GetCapture3
\r
1889 * Description : Gets the TIMx Input Capture 3 value.
\r
1890 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1892 * Return : Capture Compare 3 Register value.
\r
1893 *******************************************************************************/
\r
1894 u16 TIM_GetCapture3(TIM_TypeDef* TIMx)
\r
1896 /* Get the Capture 3 Register value */
\r
1897 return TIMx->CCR3;
\r
1900 /*******************************************************************************
\r
1901 * Function Name : TIM_GetCapture4
\r
1902 * Description : Gets the TIMx Input Capture 4 value.
\r
1903 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1905 * Return : Capture Compare 4 Register value.
\r
1906 *******************************************************************************/
\r
1907 u16 TIM_GetCapture4(TIM_TypeDef* TIMx)
\r
1909 /* Get the Capture 4 Register value */
\r
1910 return TIMx->CCR4;
\r
1913 /*******************************************************************************
\r
1914 * Function Name : TIM_GetCounter
\r
1915 * Description : Gets the TIMx Counter value.
\r
1916 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1918 * Return : Counter Register value.
\r
1919 *******************************************************************************/
\r
1920 u16 TIM_GetCounter(TIM_TypeDef* TIMx)
\r
1922 /* Get the Counter Register value */
\r
1926 /*******************************************************************************
\r
1927 * Function Name : TIM_GetPrescaler
\r
1928 * Description : Gets the TIMx Prescaler value.
\r
1929 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1931 * Return : Prescaler Register value.
\r
1932 *******************************************************************************/
\r
1933 u16 TIM_GetPrescaler(TIM_TypeDef* TIMx)
\r
1935 /* Get the Prescaler Register value */
\r
1939 /*******************************************************************************
\r
1940 * Function Name : TIM_GetFlagStatus
\r
1941 * Description : Checks whether the specified TIMx flag is set or not.
\r
1942 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1943 * - TIM_FLAG: specifies the flag to check.
\r
1944 * This parameter can be one of the following values:
\r
1945 * - TIM_FLAG_Update: Timer update Flag
\r
1946 * - TIM_FLAG_CC1: Timer Capture Compare 1 Flag
\r
1947 * - TIM_FLAG_CC2: Timer Capture Compare 2 Flag
\r
1948 * - TIM_FLAG_CC3: Timer Capture Compare 3 Flag
\r
1949 * - TIM_FLAG_CC4: Timer Capture Compare 4 Flag
\r
1950 * - TIM_FLAG_Trigger: Timer Trigger Flag
\r
1951 * - TIM_FLAG_CC1OF: Timer Capture Compare 1 overcapture Flag
\r
1952 * - TIM_FLAG_CC2OF: Timer Capture Compare 2 overcapture Flag
\r
1953 * - TIM_FLAG_CC3OF: Timer Capture Compare 3 overcapture Flag
\r
1954 * - TIM_FLAG_CC4OF: Timer Capture Compare 4 overcapture Flag
\r
1956 * Return : The new state of TIM_FLAG (SET or RESET).
\r
1957 *******************************************************************************/
\r
1958 FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, u16 TIM_FLAG)
\r
1960 FlagStatus bitstatus = RESET;
\r
1962 /* Check the parameters */
\r
1963 assert(IS_TIM_GET_FLAG(TIM_FLAG));
\r
1965 if ((TIMx->SR & TIM_FLAG) != (u16)RESET )
\r
1971 bitstatus = RESET;
\r
1976 /*******************************************************************************
\r
1977 * Function Name : TIM_ClearFlag
\r
1978 * Description : Clears the TIMx's pending flags.
\r
1979 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
1980 * - TIM_FLAG: specifies the flag bit to clear.
\r
1981 * This parameter can be any combination of the following values:
\r
1982 * - TIM_FLAG_Update: Timer update Flag
\r
1983 * - TIM_FLAG_CC1: Timer Capture Compare 1 Flag
\r
1984 * - TIM_FLAG_CC2: Timer Capture Compare 2 Flag
\r
1985 * - TIM_FLAG_CC3: Timer Capture Compare 3 Flag
\r
1986 * - TIM_FLAG_CC4: Timer Capture Compare 4 Flag
\r
1987 * - TIM_FLAG_Trigger: Timer Trigger Flag
\r
1988 * - TIM_FLAG_CC1OF: Timer Capture Compare 1 overcapture Flag
\r
1989 * - TIM_FLAG_CC2OF: Timer Capture Compare 2 overcapture Flag
\r
1990 * - TIM_FLAG_CC3OF: Timer Capture Compare 3 overcapture Flag
\r
1991 * - TIM_FLAG_CC4OF: Timer Capture Compare 4 overcapture Flag
\r
1994 *******************************************************************************/
\r
1995 void TIM_ClearFlag(TIM_TypeDef* TIMx, u16 TIM_FLAG)
\r
1997 /* Check the parameters */
\r
1998 assert(IS_TIM_CLEAR_FLAG(TIM_FLAG));
\r
2000 /* Clear the flags */
\r
2001 TIMx->SR &= (u16)~TIM_FLAG;
\r
2004 /*******************************************************************************
\r
2005 * Function Name : TIM_GetITStatus
\r
2006 * Description : Checks whether the TIMx interrupt has occurred or not.
\r
2007 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2008 * - TIM_IT: specifies the TIM interrupt source to check.
\r
2009 * This parameter can be one of the following values:
\r
2010 * - TIM_IT_Update: Timer update Interrupt source
\r
2011 * - TIM_IT_CC1: Timer Capture Compare 1 Interrupt source
\r
2012 * - TIM_IT_CC2: Timer Capture Compare 2 Interrupt source
\r
2013 * - TIM_IT_CC3: Timer Capture Compare 3 Interrupt source
\r
2014 * - TIM_IT_CC4: Timer Capture Compare 4 Interrupt source
\r
2015 * - TIM_IT_Trigger: Timer Trigger Interrupt source
\r
2017 * Return : The new state of the TIM_IT(SET or RESET).
\r
2018 *******************************************************************************/
\r
2019 ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, u16 TIM_IT)
\r
2021 ITStatus bitstatus = RESET;
\r
2023 u16 itstatus = 0x0, itenable = 0x0;
\r
2025 /* Check the parameters */
\r
2026 assert(IS_TIM_GET_IT(TIM_IT));
\r
2028 itstatus = TIMx->SR & TIM_IT;
\r
2030 itenable = TIMx->DIER & TIM_IT;
\r
2032 if ((itstatus != (u16)RESET) && (itenable != (u16)RESET))
\r
2038 bitstatus = RESET;
\r
2043 /*******************************************************************************
\r
2044 * Function Name : TIM_ClearITPendingBit
\r
2045 * Description : Clears the TIMx's interrupt pending bits.
\r
2046 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2047 * - TIM_IT: specifies the pending bit to clear.
\r
2048 * This parameter can be any combination of the following values:
\r
2049 * - TIM_IT_Update: Timer update Interrupt source
\r
2050 * - TIM_IT_CC1: Timer Capture Compare 1 Interrupt source
\r
2051 * - TIM_IT_CC2: Timer Capture Compare 2 Interrupt source
\r
2052 * - TIM_IT_CC3: Timer Capture Compare 3 Interrupt source
\r
2053 * - TIM_IT_CC4: Timer Capture Compare 4 Interrupt source
\r
2054 * - TIM_IT_Trigger: Timer Trigger Interrupt source
\r
2057 *******************************************************************************/
\r
2058 void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, u16 TIM_IT)
\r
2060 /* Check the parameters */
\r
2061 assert(IS_TIM_IT(TIM_IT));
\r
2063 /* Clear the IT pending Bit */
\r
2064 TIMx->SR &= (u16)~TIM_IT;
\r
2067 /*******************************************************************************
\r
2068 * Function Name : PWMInput_Config
\r
2069 * Description : Configures the TIM peripheral according to the specified
\r
2070 * parameters in the TIM_ICInitStruct to measure an external PWM
\r
2072 * Input : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
\r
2073 * that contains the configuration information for the specified
\r
2077 *******************************************************************************/
\r
2078 static void PWMI_Config(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)
\r
2080 u8 ICPolarity = TIM_ICPolarity_Rising;
\r
2081 u8 ICSelection = TIM_ICSelection_DirectTI;
\r
2083 /* Select the Opposite Input Polarity */
\r
2084 if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)
\r
2086 ICPolarity = TIM_ICPolarity_Falling;
\r
2090 ICPolarity = TIM_ICPolarity_Rising;
\r
2093 /* Select the Opposite Input */
\r
2094 if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)
\r
2096 ICSelection = TIM_ICSelection_IndirectTI;
\r
2100 ICSelection = TIM_ICSelection_DirectTI;
\r
2103 if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)
\r
2105 /* TI1 Configuration */
\r
2106 TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
\r
2107 TIM_ICInitStruct->TIM_ICFilter);
\r
2109 /* Set the Input Capture Prescaler value */
\r
2110 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
2112 /* TI2 Configuration */
\r
2113 TI2_Config(TIMx, ICPolarity, ICSelection, TIM_ICInitStruct->TIM_ICFilter);
\r
2115 /* Set the Input Capture Prescaler value */
\r
2116 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
2120 /* TI1 Configuration */
\r
2121 TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,
\r
2122 TIM_ICInitStruct->TIM_ICFilter);
\r
2124 /* Set the Input Capture Prescaler value */
\r
2125 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
2127 /* TI2 Configuration */
\r
2128 TI1_Config(TIMx, ICPolarity, ICSelection, TIM_ICInitStruct->TIM_ICFilter);
\r
2130 /* Set the Input Capture Prescaler value */
\r
2131 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);
\r
2135 /*******************************************************************************
\r
2136 * Function Name : TI1_Config
\r
2137 * Description : Configure the TI1 as Input.
\r
2138 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2139 * - TIM_ICPolarity : The Input Polarity.
\r
2140 * This parameter can be one of the following values:
\r
2141 * - TIM_ICPolarity_Rising
\r
2142 * - TIM_ICPolarity_Falling
\r
2143 * - TIM_ICSelection: specifies the input to be used.
\r
2144 * This parameter can be one of the following values:
\r
2145 * - TIM_ICSelection_DirectTI: TIM Input 1 is selected to
\r
2146 * be connected to IC1.
\r
2147 * - TIM_ICSelection_IndirectTI: TIM Input 1 is selected to
\r
2148 * be connected to IC2.
\r
2149 * - TIM_ICSelection_TRGI: TIM Input 1 is selected to be
\r
2150 * connected to TRGI.
\r
2151 * - TIM_ICFilter: Specifies the Input Capture Filter.
\r
2152 * This parameter must be a value between 0x00 and 0x0F.
\r
2155 *******************************************************************************/
\r
2156 static void TI1_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
2159 u32 tmpccmr1 = 0, tmpccer = 0;
\r
2161 tmpccmr1 = TIMx->CCMR1;
\r
2162 tmpccer = TIMx->CCER;
\r
2164 /* Disable the Channel 1: Reset the CCE Bit */
\r
2165 TIMx->CCER &= CCRE_CC1E_Reset;
\r
2167 /* Select the Input and set the filter */
\r
2168 tmpccmr1 &= CCMR_CC13S_Mask & CCMR_IC13F_Mask;
\r
2169 tmpccmr1 |= TIM_ICSelection | (u16)((u16)TIM_ICFilter << 4);
\r
2171 /* Select the Polarity and set the CCE Bit */
\r
2172 tmpccer &= CCER_CC1P_Mask & CCRE_CC1E_Mask;
\r
2173 tmpccer |= TIM_ICPolarity | CCRE_CC1E_Set;
\r
2175 TIMx->CCMR1 = 0x0000;
\r
2176 TIMx->CCMR1 = (u16)tmpccmr1;
\r
2177 TIMx->CCER = (u16)tmpccer;
\r
2180 /*******************************************************************************
\r
2181 * Function Name : TI2_Config
\r
2182 * Description : Configure the TI2 as Input.
\r
2183 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2184 * - TIM_ICPolarity : The Input Polarity.
\r
2185 * This parameter can be one of the following values:
\r
2186 * - TIM_ICPolarity_Rising
\r
2187 * - TIM_ICPolarity_Falling
\r
2188 * - TIM_ICSelection: specifies the input to be used.
\r
2189 * This parameter can be one of the following values:
\r
2190 * - TIM_ICSelection_DirectTI: TIM Input 2 is selected to
\r
2191 * be connected to IC2.
\r
2192 * - TIM_ICSelection_IndirectTI: TIM Input 2 is selected to
\r
2193 * be connected to IC1.
\r
2194 * - TIM_ICSelection_TRGI: TIM Input 2 is selected to be
\r
2195 * connected to TRGI.
\r
2196 * - TIM_ICFilter: Specifies the Input Capture Filter.
\r
2197 * This parameter must be a value between 0x00 and 0x0F.
\r
2200 *******************************************************************************/
\r
2201 static void TI2_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
2204 u32 tmpccmr1 = 0, tmpccer = 0, tmp = 0;
\r
2206 tmpccmr1 = TIMx->CCMR1;
\r
2207 tmpccer = TIMx->CCER;
\r
2208 tmp = (u16)((u16)TIM_ICPolarity << 4);
\r
2210 /* Disable the Channel 2: Reset the CCE Bit */
\r
2211 TIMx->CCER &= CCRE_CC2E_Reset;
\r
2213 /* Select the Input and set the filter */
\r
2214 tmpccmr1 &= CCMR_CC24S_Mask & CCMR_IC24F_Mask;
\r
2215 tmpccmr1 |= (u16)((u16)TIM_ICFilter << 12);
\r
2216 tmpccmr1 |= (u16)((u16)TIM_ICSelection << 8);
\r
2218 /* Select the Polarity and set the CCE Bit */
\r
2219 tmpccer &= CCER_CC2P_Mask & CCRE_CC2E_Mask;
\r
2220 tmpccer |= tmp | CCRE_CC2E_Set;
\r
2222 TIMx->CCMR1 = (u16)tmpccmr1 ;
\r
2223 TIMx->CCER = (u16)tmpccer;
\r
2226 /*******************************************************************************
\r
2227 * Function Name : TI3_Config
\r
2228 * Description : Configure the TI3 as Input.
\r
2229 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2230 * - TIM_ICPolarity : The Input Polarity.
\r
2231 * This parameter can be one of the following values:
\r
2232 * - TIM_ICPolarity_Rising
\r
2233 * - TIM_ICPolarity_Falling
\r
2234 * - TIM_ICSelection: specifies the input to be used.
\r
2235 * This parameter can be one of the following values:
\r
2236 * - TIM_ICSelection_DirectTI: TIM Input 3 is selected to
\r
2237 * be connected to IC3.
\r
2238 * - TIM_ICSelection_IndirectTI: TIM Input 3 is selected to
\r
2239 * be connected to IC4.
\r
2240 * - TIM_ICSelection_TRGI: TIM Input 3 is selected to be
\r
2241 * connected to TRGI.
\r
2242 * - TIM_ICFilter: Specifies the Input Capture Filter.
\r
2243 * This parameter must be a value between 0x00 and 0x0F.
\r
2246 *******************************************************************************/
\r
2247 static void TI3_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
2250 u32 tmpccmr2 = 0, tmpccer = 0, tmp = 0;
\r
2252 tmpccmr2 = TIMx->CCMR2;
\r
2253 tmpccer = TIMx->CCER;
\r
2254 tmp = (u16)((u16)TIM_ICPolarity << 8);
\r
2256 /* Disable the Channel 3: Reset the CCE Bit */
\r
2257 TIMx->CCER &= CCRE_CC3E_Reset;
\r
2259 /* Select the Input and set the filter */
\r
2260 tmpccmr2 &= CCMR_CC13S_Mask & CCMR_IC13F_Mask;
\r
2261 tmpccmr2 |= TIM_ICSelection | (u16)((u16)TIM_ICFilter << 4);
\r
2263 /* Select the Polarity and set the CCE Bit */
\r
2264 tmpccer &= CCER_CC1P_Mask & CCRE_CC1E_Mask;
\r
2265 tmpccer |= tmp | CCRE_CC3E_Set;
\r
2267 TIMx->CCMR2 = (u16)tmpccmr2;
\r
2268 TIMx->CCER = (u16)tmpccer;
\r
2271 /*******************************************************************************
\r
2272 * Function Name : TI4_Config
\r
2273 * Description : Configure the TI1 as Input.
\r
2274 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2275 * - TIM_ICPolarity : The Input Polarity.
\r
2276 * This parameter can be one of the following values:
\r
2277 * - TIM_ICPolarity_Rising
\r
2278 * - TIM_ICPolarity_Falling
\r
2279 * - TIM_ICSelection: specifies the input to be used.
\r
2280 * This parameter can be one of the following values:
\r
2281 * - TIM_ICSelection_DirectTI: TIM Input 4 is selected to
\r
2282 * be connected to IC4.
\r
2283 * - TIM_ICSelection_IndirectTI: TIM Input 4 is selected to
\r
2284 * be connected to IC3.
\r
2285 * - TIM_ICSelection_TRGI: TIM Input 4 is selected to be
\r
2286 * connected to TRGI.
\r
2287 * - TIM_ICFilter: Specifies the Input Capture Filter.
\r
2288 * This parameter must be a value between 0x00 and 0x0F.
\r
2291 *******************************************************************************/
\r
2292 static void TI4_Config(TIM_TypeDef* TIMx, u16 TIM_ICPolarity, u16 TIM_ICSelection,
\r
2295 u32 tmpccmr2 = 0, tmpccer = 0, tmp = 0;
\r
2297 tmpccmr2 = TIMx->CCMR2;
\r
2298 tmpccer = TIMx->CCER;
\r
2299 tmp = (u16)((u16)TIM_ICPolarity << 12);
\r
2301 /* Disable the Channel 4: Reset the CCE Bit */
\r
2302 TIMx->CCER &= CCRE_CC4E_Reset;
\r
2304 /* Select the Input and set the filter */
\r
2305 tmpccmr2 &= CCMR_CC24S_Mask & CCMR_IC24F_Mask;
\r
2306 tmpccmr2 |= (u16)((u16)TIM_ICSelection << 8) | (u16)((u16)TIM_ICFilter << 12);
\r
2308 /* Select the Polarity and set the CCE Bit */
\r
2309 tmpccer &= CCER_CC4P_Mask & CCRE_CC4E_Mask;
\r
2310 tmpccer |= tmp | CCRE_CC4E_Set;
\r
2312 TIMx->CCMR2 = (u16)tmpccmr2;
\r
2313 TIMx->CCER = (u16)tmpccer ;
\r
2316 /*******************************************************************************
\r
2317 * Function Name : ETR_Config
\r
2318 * Description : Configure the External Trigger
\r
2319 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
\r
2320 * - TIM_ExtTRGPrescaler: The external Trigger Prescaler.
\r
2321 * This parameter can be one of the following values:
\r
2322 * - TIM_ExtTRGPSC_OFF
\r
2323 * - TIM_ExtTRGPSC_DIV2
\r
2324 * - TIM_ExtTRGPSC_DIV4
\r
2325 * - TIM_ExtTRGPSC_DIV8
\r
2326 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
\r
2327 * This parameter can be one of the following values:
\r
2328 * - TIM_ExtTRGPolarity_Inverted
\r
2329 * - TIM_ExtTRGPolarity_NonInverted
\r
2330 * - ExtTRGFilter: External Trigger Filter.
\r
2331 * This parameter must be a value between 0x00 and 0x0F.
\r
2334 *******************************************************************************/
\r
2335 static void ETR_Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity,
\r
2340 tmpsmcr = TIMx->SMCR;
\r
2342 /* Set the Prescaler, the Filter value and the Polarity */
\r
2343 tmpsmcr &= SMCR_ETR_Mask;
\r
2344 tmpsmcr |= TIM_ExtTRGPrescaler | TIM_ExtTRGPolarity | (u16)((u16)ExtTRGFilter << 8);
\r
2346 TIMx->SMCR = (u16)tmpsmcr;
\r
2348 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
\r