Rev 1 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_tim.c |
2 | * File Name : 91x_tim.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V2.1 |
|
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
5 | * Date : 12/22/2008 |
5 | * Description : This file provides all the TIM software functions. |
6 | * Description : This file provides all the TIM firmware functions. |
6 | ******************************************************************************** |
- | |
7 | * History: |
- | |
8 | * 05/22/2007 : Version 1.2 |
- | |
9 | * 05/24/2006 : Version 1.1 |
- | |
10 | * 05/18/2006 : Version 1.0 |
- | |
11 | ******************************************************************************** |
7 | ******************************************************************************** |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
13 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
9 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
14 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
10 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
15 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
11 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
16 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
12 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
17 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
13 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
18 | *******************************************************************************/ |
14 | *******************************************************************************/ |
19 | 15 | ||
20 | /* Includes ------------------------------------------------------------------*/ |
16 | /* Includes ------------------------------------------------------------------*/ |
21 | #include "91x_tim.h" |
17 | #include "91x_tim.h" |
22 | 18 | ||
23 | /* Include of other module interface headers ---------------------------------*/ |
19 | /* Include of other module interface headers ---------------------------------*/ |
24 | /* Local includes ------------------------------------------------------------*/ |
20 | /* Local includes ------------------------------------------------------------*/ |
25 | /* Private typedef -----------------------------------------------------------*/ |
21 | /* Private typedef -----------------------------------------------------------*/ |
26 | /* Private define ------------------------------------------------------------*/ |
22 | /* Private define ------------------------------------------------------------*/ |
27 | 23 | ||
28 | /* TIM Bits Masks */ |
24 | /* TIM Bits Masks */ |
29 | 25 | ||
30 | #define TIM_PWM_MASK 0x0010 |
26 | #define TIM_PWM_MASK 0x0010 |
31 | #define TIM_OPM_MASK 0x0020 |
27 | #define TIM_OPM_MASK 0x0020 |
32 | #define TIM_OC1_ENABLE_MASK 0x0040 |
28 | #define TIM_OC1_ENABLE_MASK 0x0040 |
33 | #define TIM_OC1_DISABLE_MASK 0xFFBF |
29 | #define TIM_OC1_DISABLE_MASK 0xFFBF |
34 | #define TIM_OC2_ENABLE_MASK 0x0080 |
30 | #define TIM_OC2_ENABLE_MASK 0x0080 |
35 | #define TIM_OC2_DISABLE_MASK 0xFF7F |
31 | #define TIM_OC2_DISABLE_MASK 0xFF7F |
36 | 32 | ||
37 | #define TIM_OLVL1_SET_MASK 0x0100 |
33 | #define TIM_OLVL1_SET_MASK 0x0100 |
38 | #define TIM_OLVL1_RESET_MASK 0xFEFF |
34 | #define TIM_OLVL1_RESET_MASK 0xFEFF |
39 | 35 | ||
40 | #define TIM_OLVL2_SET_MASK 0x0200 |
36 | #define TIM_OLVL2_SET_MASK 0x0200 |
41 | #define TIM_OLVL2_RESET_MASK 0xFDFF |
37 | #define TIM_OLVL2_RESET_MASK 0xFDFF |
42 | 38 | ||
43 | #define TIM_ENABLE_MASK 0x8000 |
39 | #define TIM_ENABLE_MASK 0x8000 |
44 | #define TIM_DISABLE_MASK 0x7FFF |
40 | #define TIM_DISABLE_MASK 0x7FFF |
45 | 41 | ||
46 | #define TIM_DMA_CLEAR_MASK 0xCFFF |
42 | #define TIM_DMA_CLEAR_MASK 0xCFFF |
47 | 43 | ||
48 | /* Private macro -------------------------------------------------------------*/ |
44 | /* Private macro -------------------------------------------------------------*/ |
49 | /* Private variables ---------------------------------------------------------*/ |
45 | /* Private variables ---------------------------------------------------------*/ |
50 | /* Private function prototypes -----------------------------------------------*/ |
46 | /* Private function prototypes -----------------------------------------------*/ |
51 | /* Interface functions -------------------------------------------------------*/ |
47 | /* Interface functions -------------------------------------------------------*/ |
52 | /* Private functions ---------------------------------------------------------*/ |
48 | /* Private functions ---------------------------------------------------------*/ |
53 | /******************************************************************************* |
49 | /******************************************************************************* |
54 | * Function Name : TIM_DeInit |
50 | * Function Name : TIM_DeInit |
55 | * Description : Initializes TIM peripheral control and registers to their |
51 | * Description : Initializes TIM peripheral control and registers to their |
56 | * : default reset values. |
52 | * : default reset values. |
57 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
53 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
58 | * peripheral. |
54 | * peripheral. |
59 | * Output : None |
55 | * Output : None |
60 | * Return : None |
56 | * Return : None |
61 | *******************************************************************************/ |
57 | *******************************************************************************/ |
62 | void TIM_DeInit(TIM_TypeDef *TIMx) |
58 | void TIM_DeInit(TIM_TypeDef *TIMx) |
63 | { |
59 | { |
64 | if((TIMx == TIM0)||(TIMx == TIM1)) |
60 | if((TIMx == TIM0)||(TIMx == TIM1)) |
65 | { |
61 | { |
66 | SCU_APBPeriphReset(__TIM01, DISABLE); /* TIM0 & TIM1 Reset's off */ |
62 | SCU_APBPeriphReset(__TIM01, DISABLE); /* TIM0 & TIM1 Reset's off */ |
67 | } |
63 | } |
68 | else |
64 | else |
69 | { |
65 | { |
70 | SCU_APBPeriphReset(__TIM23, DISABLE); /* TIM2 & TIM3 Reset's off */ |
66 | SCU_APBPeriphReset(__TIM23, DISABLE); /* TIM2 & TIM3 Reset's off */ |
71 | } |
67 | } |
72 | 68 | ||
73 | /* Set all the TIMx registers to thier default values */ |
69 | /* Set all the TIMx registers to thier default values */ |
74 | TIMx->OC1R = 0x8000; |
70 | TIMx->OC1R = 0x8000; |
75 | TIMx->OC2R = 0x8000; |
71 | TIMx->OC2R = 0x8000; |
76 | TIMx->CR1 = 0x0; |
72 | TIMx->CR1 = 0x0; |
77 | TIMx->CR2 = 0x1; |
73 | TIMx->CR2 = 0x1; |
78 | TIMx->CNTR = 0x1234; |
74 | TIMx->CNTR = 0x1234; |
79 | TIMx->SR = 0x0; |
75 | TIMx->SR = 0x0; |
80 | } |
76 | } |
81 | 77 | ||
82 | /******************************************************************************* |
78 | /******************************************************************************* |
83 | * Function Name : TIM_StructInit |
79 | * Function Name : TIM_StructInit |
84 | * Description : Fills in a TIM_InitTypeDef structure with the reset value of |
80 | * Description : Fills in a TIM_InitTypeDef structure with the reset value of |
85 | * each parameter. |
81 | * each parameter. |
86 | * Input : TIM_InitStruct : pointer to a TIM_InitTypeDef structure |
82 | * Input : TIM_InitStruct : pointer to a TIM_InitTypeDef structure |
87 | which will be initialized. |
83 | which will be initialized. |
88 | * Output : None |
84 | * Output : None |
89 | * Return : None. |
85 | * Return : None. |
90 | *******************************************************************************/ |
86 | *******************************************************************************/ |
91 | void TIM_StructInit(TIM_InitTypeDef *TIM_InitStruct) |
87 | void TIM_StructInit(TIM_InitTypeDef *TIM_InitStruct) |
92 | { |
88 | { |
93 | TIM_InitStruct->TIM_Mode = 0x0000; |
89 | TIM_InitStruct->TIM_Mode = 0x0000; |
94 | TIM_InitStruct->TIM_OC1_Modes = 0x0000; |
90 | TIM_InitStruct->TIM_OC1_Modes = 0x0000; |
95 | TIM_InitStruct->TIM_OC2_Modes = 0x0000; |
91 | TIM_InitStruct->TIM_OC2_Modes = 0x0000; |
96 | TIM_InitStruct->TIM_Clock_Source = 0x0000; |
92 | TIM_InitStruct->TIM_Clock_Source = 0x0000; |
97 | TIM_InitStruct->TIM_Clock_Edge = 0x0000; |
93 | TIM_InitStruct->TIM_Clock_Edge = 0x0000; |
98 | TIM_InitStruct->TIM_OPM_INPUT_Edge = 0x0000; |
94 | TIM_InitStruct->TIM_OPM_INPUT_Edge = 0x0000; |
99 | TIM_InitStruct->TIM_ICAP1_Edge = 0x0000; |
95 | TIM_InitStruct->TIM_ICAP1_Edge = 0x0000; |
100 | TIM_InitStruct->TIM_ICAP2_Edge = 0x0000; |
96 | TIM_InitStruct->TIM_ICAP2_Edge = 0x0000; |
101 | TIM_InitStruct->TIM_Prescaler = 0x0000; |
97 | TIM_InitStruct->TIM_Prescaler = 0x0000; |
102 | TIM_InitStruct->TIM_Pulse_Level_1 = 0x0000; |
98 | TIM_InitStruct->TIM_Pulse_Level_1 = 0x0000; |
103 | TIM_InitStruct->TIM_Pulse_Level_2 = 0x0000; |
99 | TIM_InitStruct->TIM_Pulse_Level_2 = 0x0000; |
104 | TIM_InitStruct->TIM_Period_Level = 0x0000; |
100 | TIM_InitStruct->TIM_Period_Level = 0x0000; |
105 | TIM_InitStruct->TIM_Pulse_Length_1 = 0x0000; |
101 | TIM_InitStruct->TIM_Pulse_Length_1 = 0x0000; |
106 | TIM_InitStruct->TIM_Pulse_Length_2 = 0x0000; |
102 | TIM_InitStruct->TIM_Pulse_Length_2 = 0x0000; |
107 | TIM_InitStruct->TIM_Full_Period = 0x0000; |
103 | TIM_InitStruct->TIM_Full_Period = 0x0000; |
108 | } |
104 | } |
109 | 105 | ||
110 | /******************************************************************************* |
106 | /******************************************************************************* |
111 | * Function Name : TIM_Init |
107 | * Function Name : TIM_Init |
112 | * Description : Initializes TIM peripheral according to the specified |
108 | * Description : Initializes TIM peripheral according to the specified |
113 | * parameters in the TIM_InitTypeDef structure. |
109 | * parameters in the TIM_InitTypeDef structure. |
114 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
110 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
115 | * peripheral. |
111 | * peripheral. |
116 | * Input2 : TIM_InitStruct: pointer to a TIM_InitTypeDef structure that |
112 | * Input2 : TIM_InitStruct: pointer to a TIM_InitTypeDef structure that |
117 | * contains the configuration information for the specified |
113 | * contains the configuration information for the specified |
118 | * TIM peripheral. |
114 | * TIM peripheral. |
119 | * Output : None |
115 | * Output : None |
120 | * Return : None |
116 | * Return : None |
121 | *******************************************************************************/ |
117 | *******************************************************************************/ |
122 | 118 | ||
123 | void TIM_Init(TIM_TypeDef *TIMx, TIM_InitTypeDef *TIM_InitStruct) |
119 | void TIM_Init(TIM_TypeDef *TIMx, TIM_InitTypeDef *TIM_InitStruct) |
124 | { |
120 | { |
125 | /***************************** Clock configuration ****************************/ |
121 | /***************************** Clock configuration ****************************/ |
126 | 122 | ||
127 | if (TIM_InitStruct->TIM_Clock_Source == TIM_CLK_APB) |
123 | if (TIM_InitStruct->TIM_Clock_Source == TIM_CLK_APB) |
128 | { |
124 | { |
129 | /* APB clock */ |
125 | /* APB clock */ |
130 | TIMx->CR1 &= TIM_CLK_APB; |
126 | TIMx->CR1 &= TIM_CLK_APB; |
131 | } |
127 | } |
132 | else |
128 | else |
133 | { |
129 | { |
134 | /* External/SCU clock */ |
130 | /* External clock */ |
135 | TIMx->CR1 |= TIM_CLK_EXTERNAL; |
131 | TIMx->CR1 |= TIM_CLK_EXTERNAL; |
136 | if (TIM_InitStruct->TIM_Clock_Edge == TIM_CLK_EDGE_RISING) |
132 | if (TIM_InitStruct->TIM_Clock_Edge == TIM_CLK_EDGE_RISING) |
137 | { |
133 | { |
138 | /* Clock rising edge */ |
134 | /* Clock rising edge */ |
139 | TIMx->CR1 |= TIM_CLK_EDGE_RISING; |
135 | TIMx->CR1 |= TIM_CLK_EDGE_RISING; |
140 | } |
136 | } |
141 | else |
137 | else |
142 | { |
138 | { |
143 | /* Clock falling edge */ |
139 | /* Clock falling edge */ |
144 | TIMx->CR1 &= TIM_CLK_EDGE_FALLING; |
140 | TIMx->CR1 &= TIM_CLK_EDGE_FALLING; |
145 | } |
141 | } |
146 | } |
142 | } |
147 | 143 | ||
148 | /************************** Prescaler configuration ***************************/ |
144 | /************************** Prescaler configuration ***************************/ |
149 | 145 | ||
150 | TIMx->CR2 =( TIMx->CR2 & 0xFF00 )|TIM_InitStruct->TIM_Prescaler ; |
146 | TIMx->CR2 =( TIMx->CR2 & 0xFF00 )|TIM_InitStruct->TIM_Prescaler ; |
151 | 147 | ||
152 | /********************************** TIM Modes *********************************/ |
148 | /********************************** TIM Modes *********************************/ |
153 | 149 | ||
154 | switch ( TIM_InitStruct->TIM_Mode) |
150 | switch ( TIM_InitStruct->TIM_Mode) |
155 | { |
151 | { |
156 | /******************************* PWM Input mode *******************************/ |
152 | /******************************* PWM Input mode *******************************/ |
157 | 153 | ||
158 | case TIM_PWMI: |
154 | case TIM_PWMI: |
159 | 155 | ||
160 | /* Set the PWMI Bit */ |
156 | /* Set the PWMI Bit */ |
161 | TIMx->CR1 |= TIM_PWMI; |
157 | TIMx->CR1 |= TIM_PWMI; |
162 | 158 | ||
163 | /* Set the first edge Level */ |
159 | /* Set the first edge Level */ |
164 | if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
160 | if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
165 | { |
161 | { |
166 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
162 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
167 | } |
163 | } |
168 | else |
164 | else |
169 | { |
165 | { |
170 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
166 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
171 | } |
167 | } |
172 | 168 | ||
173 | /* Set the Second edge Level ( Opposite of the first level ) */ |
169 | /* Set the Second edge Level ( Opposite of the first level ) */ |
174 | if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
170 | if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
175 | { |
171 | { |
176 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
172 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
177 | } |
173 | } |
178 | else |
174 | else |
179 | { |
175 | { |
180 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
176 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
181 | } |
177 | } |
182 | 178 | ||
183 | break; |
179 | break; |
184 | 180 | ||
185 | /************************** Output compare channel 1 **************************/ |
181 | /************************** Output compare channel 1 **************************/ |
186 | 182 | ||
187 | case TIM_OCM_CHANNEL_1: |
183 | case TIM_OCM_CHANNEL_1: |
188 | 184 | ||
189 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
185 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
190 | { |
186 | { |
191 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
187 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
192 | } |
188 | } |
193 | else |
189 | else |
194 | { |
190 | { |
195 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
191 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
196 | } |
192 | } |
197 | 193 | ||
198 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
194 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
199 | 195 | ||
200 | if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING) |
196 | if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING) |
201 | { |
197 | { |
202 | TIMx->CR1 &= TIM_OC1_DISABLE_MASK; |
198 | TIMx->CR1 &= TIM_OC1_DISABLE_MASK; |
203 | } |
199 | } |
204 | else |
200 | else |
205 | { |
201 | { |
206 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
202 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
207 | } |
203 | } |
208 | 204 | ||
209 | break; |
205 | break; |
210 | 206 | ||
211 | /************************** Output compare channel 2 **************************/ |
207 | /************************** Output compare channel 2 **************************/ |
212 | 208 | ||
213 | case TIM_OCM_CHANNEL_2: |
209 | case TIM_OCM_CHANNEL_2: |
214 | 210 | ||
215 | if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH) |
211 | if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH) |
216 | { |
212 | { |
217 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
213 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
218 | } |
214 | } |
219 | else |
215 | else |
220 | { |
216 | { |
221 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
217 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
222 | } |
218 | } |
223 | 219 | ||
224 | TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2; |
220 | TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2; |
225 | 221 | ||
226 | if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING) |
222 | if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING) |
227 | { |
223 | { |
228 | TIMx->CR1 &= TIM_OC2_DISABLE_MASK; |
224 | TIMx->CR1 &= TIM_OC2_DISABLE_MASK; |
229 | } |
225 | } |
230 | else |
226 | else |
231 | { |
227 | { |
232 | TIMx->CR1 |= TIM_OC2_ENABLE_MASK; |
228 | TIMx->CR1 |= TIM_OC2_ENABLE_MASK; |
233 | } |
229 | } |
234 | 230 | ||
235 | break; |
231 | break; |
236 | 232 | ||
237 | /************************ Output compare channel 1 & 2 ************************/ |
233 | /************************ Output compare channel 1 & 2 ************************/ |
238 | 234 | ||
239 | case TIM_OCM_CHANNEL_12: |
235 | case TIM_OCM_CHANNEL_12: |
240 | 236 | ||
241 | TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2; |
237 | TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2; |
242 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
238 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
243 | 239 | ||
244 | if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING) |
240 | if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING) |
245 | { |
241 | { |
246 | TIMx->CR1 &= TIM_OC2_DISABLE_MASK; |
242 | TIMx->CR1 &= TIM_OC2_DISABLE_MASK; |
247 | } |
243 | } |
248 | else |
244 | else |
249 | { |
245 | { |
250 | TIMx->CR1 |= TIM_OC2_ENABLE_MASK; |
246 | TIMx->CR1 |= TIM_OC2_ENABLE_MASK; |
251 | } |
247 | } |
252 | 248 | ||
253 | if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING) |
249 | if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING) |
254 | { |
250 | { |
255 | TIMx->CR1 &= TIM_OC1_DISABLE_MASK; |
251 | TIMx->CR1 &= TIM_OC1_DISABLE_MASK; |
256 | } |
252 | } |
257 | else |
253 | else |
258 | { |
254 | { |
259 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
255 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
260 | } |
256 | } |
261 | 257 | ||
262 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
258 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
263 | { |
259 | { |
264 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
260 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
265 | } |
261 | } |
266 | else |
262 | else |
267 | { |
263 | { |
268 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
264 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
269 | } |
265 | } |
270 | 266 | ||
271 | if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH) |
267 | if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH) |
272 | { |
268 | { |
273 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
269 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
274 | } |
270 | } |
275 | else |
271 | else |
276 | { |
272 | { |
277 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
273 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
278 | } |
274 | } |
279 | 275 | ||
280 | break; |
276 | break; |
281 | 277 | ||
282 | /********************************** PWM mode **********************************/ |
278 | /********************************** PWM mode **********************************/ |
283 | 279 | ||
284 | case TIM_PWM: |
280 | case TIM_PWM: |
285 | 281 | ||
286 | /* Set the Level During the pulse */ |
282 | /* Set the Level During the pulse */ |
287 | if ( TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
283 | if ( TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
288 | { |
284 | { |
289 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
285 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
290 | } |
286 | } |
291 | else |
287 | else |
292 | { |
288 | { |
293 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
289 | TIMx->CR1 &= TIM_OLVL2_RESET_MASK; |
294 | } |
290 | } |
295 | 291 | ||
296 | /* Set the Level after the pulse */ |
292 | /* Set the Level after the pulse */ |
297 | if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH) |
293 | if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH) |
298 | { |
294 | { |
299 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
295 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
300 | } |
296 | } |
301 | else |
297 | else |
302 | { |
298 | { |
303 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
299 | TIMx->CR1 &= TIM_OLVL1_RESET_MASK; |
304 | } |
300 | } |
305 | 301 | ||
306 | /* Set the OCAE */ |
302 | /* Set the OCAE */ |
307 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
303 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
308 | 304 | ||
309 | /* Set the PWM Bit */ |
305 | /* Set the PWM Bit */ |
310 | TIMx->CR1 |= TIM_PWM_MASK; |
306 | TIMx->CR1 |= TIM_PWM_MASK; |
311 | 307 | ||
312 | /* Set the Duty Cycle value */ |
308 | /* Set the Duty Cycle value */ |
313 | 309 | ||
314 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1 ; |
310 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1 ; |
315 | 311 | ||
316 | /* Set the Full Period */ |
312 | /* Set the Full Period */ |
317 | 313 | ||
318 | TIMx->OC2R = TIM_InitStruct->TIM_Full_Period ; |
314 | TIMx->OC2R = TIM_InitStruct->TIM_Full_Period ; |
319 | 315 | ||
320 | break; |
316 | break; |
321 | 317 | ||
322 | /******************************* One pulse mode *******************************/ |
318 | /******************************* One pulse mode *******************************/ |
323 | 319 | ||
324 | case TIM_OPM: |
320 | case TIM_OPM: |
325 | 321 | ||
326 | /* Set the Level During the pulse */ |
322 | /* Set the Level During the pulse */ |
327 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
323 | if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH) |
328 | { |
324 | { |
329 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
325 | TIMx->CR1 |= TIM_OLVL2_SET_MASK; |
330 | } |
326 | } |
331 | 327 | ||
332 | /* Set the Level after the pulse */ |
328 | /* Set the Level after the pulse */ |
333 | if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH) |
329 | if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH) |
334 | { |
330 | { |
335 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
331 | TIMx->CR1 |= TIM_OLVL1_SET_MASK; |
336 | } |
332 | } |
337 | 333 | ||
338 | /* Set the Activation Edge on the ICAP 1 */ |
334 | /* Set the Activation Edge on the ICAP 1 */ |
339 | if (TIM_InitStruct->TIM_OPM_INPUT_Edge == TIM_OPM_EDGE_RISING) |
335 | if (TIM_InitStruct->TIM_OPM_INPUT_Edge == TIM_OPM_EDGE_RISING) |
340 | { |
336 | { |
341 | TIMx->CR1 |= TIM_OPM_EDGE_RISING; |
337 | TIMx->CR1 |= TIM_OPM_EDGE_RISING; |
342 | } |
338 | } |
343 | 339 | ||
344 | /* Set the Output Compare Function */ |
340 | /* Set the Output Compare Function */ |
345 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
341 | TIMx->CR1 |= TIM_OC1_ENABLE_MASK; |
346 | 342 | ||
347 | /* Set the One pulse mode */ |
343 | /* Set the One pulse mode */ |
348 | TIMx->CR1 |= TIM_OPM_MASK; |
344 | TIMx->CR1 |= TIM_OPM_MASK; |
349 | 345 | ||
350 | /* Set the Pulse length */ |
346 | /* Set the Pulse length */ |
351 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
347 | TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1; |
352 | 348 | ||
353 | break; |
349 | break; |
354 | 350 | ||
355 | /*************************** Input capture channel 1 **************************/ |
351 | /*************************** Input capture channel 1 **************************/ |
356 | 352 | ||
357 | case TIM_ICAP_CHANNEL_1: |
353 | case TIM_ICAP_CHANNEL_1: |
358 | 354 | ||
359 | if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
355 | if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
360 | { |
356 | { |
361 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
357 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
362 | } |
358 | } |
363 | else |
359 | else |
364 | { |
360 | { |
365 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
361 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
366 | } |
362 | } |
367 | 363 | ||
368 | break; |
364 | break; |
369 | 365 | ||
370 | /*************************** Input capture channel 2 **************************/ |
366 | /*************************** Input capture channel 2 **************************/ |
371 | 367 | ||
372 | case TIM_ICAP_CHANNEL_2: |
368 | case TIM_ICAP_CHANNEL_2: |
373 | 369 | ||
374 | if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING) |
370 | if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING) |
375 | { |
371 | { |
376 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
372 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
377 | } |
373 | } |
378 | else |
374 | else |
379 | { |
375 | { |
380 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
376 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
381 | } |
377 | } |
382 | 378 | ||
383 | break; |
379 | break; |
384 | 380 | ||
385 | /************************* Input capture channel 1 & 2 ************************/ |
381 | /************************* Input capture channel 1 & 2 ************************/ |
386 | 382 | ||
387 | case TIM_ICAP_CHANNEL_12: |
383 | case TIM_ICAP_CHANNEL_12: |
388 | if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING) |
384 | if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING) |
389 | { |
385 | { |
390 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
386 | TIMx->CR1 |= TIM_ICAP2_EDGE_RISING; |
391 | } |
387 | } |
392 | else |
388 | else |
393 | { |
389 | { |
394 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
390 | TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING; |
395 | } |
391 | } |
396 | 392 | ||
397 | if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
393 | if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING) |
398 | { |
394 | { |
399 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
395 | TIMx->CR1 |= TIM_ICAP1_EDGE_RISING; |
400 | } |
396 | } |
401 | else |
397 | else |
402 | { |
398 | { |
403 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
399 | TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING; |
404 | } |
400 | } |
405 | 401 | ||
406 | break; |
402 | break; |
407 | 403 | ||
408 | default: |
404 | default: |
409 | break; |
405 | break; |
410 | } |
406 | } |
411 | } |
407 | } |
412 | 408 | ||
413 | /******************************************************************************* |
409 | /******************************************************************************* |
414 | * Function Name : TIM_CounterCmd |
410 | * Function Name : TIM_CounterCmd |
415 | * Description : Enables or disables TIMx Counter peripheral. |
411 | * Description : Enables or disables TIMx Counter peripheral. |
416 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
412 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
417 | * peripheral. |
413 | * peripheral. |
418 | * Input2 : TIM_operation: specifies the new state of the TIMx Counter. |
414 | * Input2 : TIM_operation: specifies the new state of the TIMx Counter. |
419 | * This parameter can be one of the following values: |
415 | * This parameter can be one of the following values: |
420 | * - TIM_START: Start the timer counter. |
416 | * - TIM_START: Start the timer counter. |
421 | * - TIM_STOP : Stop the timer counter. |
417 | * - TIM_STOP : Stop the timer counter. |
422 | * - TIM_CLEAR: Clear the timer counter. |
418 | * - TIM_CLEAR: Clear the timer counter. |
423 | * Output : None |
419 | * Output : None |
424 | * Return : None |
420 | * Return : None |
425 | *******************************************************************************/ |
421 | *******************************************************************************/ |
426 | void TIM_CounterCmd(TIM_TypeDef *TIMx, TIM_CounterOperations TIM_operation) |
422 | void TIM_CounterCmd(TIM_TypeDef *TIMx, TIM_CounterOperations TIM_operation) |
427 | { |
423 | { |
428 | switch (TIM_operation) |
424 | switch (TIM_operation) |
429 | { |
425 | { |
430 | case TIM_START: |
426 | case TIM_START: |
431 | TIMx->CR1 |= TIM_ENABLE_MASK; |
427 | TIMx->CR1 |= TIM_ENABLE_MASK; |
432 | break; |
428 | break; |
433 | 429 | ||
434 | case TIM_STOP: |
430 | case TIM_STOP: |
435 | TIMx->CR1 &= TIM_DISABLE_MASK; |
431 | TIMx->CR1 &= TIM_DISABLE_MASK; |
436 | break; |
432 | break; |
437 | 433 | ||
438 | case TIM_CLEAR: |
434 | case TIM_CLEAR: |
439 | TIMx->CNTR = 0x1234; |
435 | TIMx->CNTR = 0x1234; |
440 | break; |
436 | break; |
441 | 437 | ||
442 | default: |
438 | default: |
443 | break; |
439 | break; |
444 | } |
440 | } |
445 | } |
441 | } |
446 | 442 | ||
447 | /******************************************************************************* |
443 | /******************************************************************************* |
448 | * Function Name : TIM_PrescalerConfig |
444 | * Function Name : TIM_PrescalerConfig |
449 | * Description : This routine is used to configure the TIMx prescaler value |
445 | * Description : This routine is used to configure the TIMx prescaler value |
450 | * (when using the APB clock). |
446 | * (when using the APB clock). |
451 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
447 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
452 | * peripheral. |
448 | * peripheral. |
453 | * Input2 : TIM_Prescaler: specifies the prescaler value. This parameter |
449 | * Input2 : TIM_Prescaler: specifies the prescaler value. This parameter |
454 | * can be a value from 0x0 to 0xFF. |
450 | * can be a value from 0x0 to 0xFF. |
455 | * Output : None |
451 | * Output : None |
456 | * Return : None |
452 | * Return : None |
457 | *******************************************************************************/ |
453 | *******************************************************************************/ |
458 | void TIM_PrescalerConfig(TIM_TypeDef *TIMx, u8 TIM_Prescaler) |
454 | void TIM_PrescalerConfig(TIM_TypeDef *TIMx, u8 TIM_Prescaler) |
459 | { |
455 | { |
460 | TIMx->CR2 &= 0xFF00; |
456 | TIMx->CR2 &= 0xFF00; |
461 | TIMx->CR2 |= TIM_Prescaler; |
457 | TIMx->CR2 |= TIM_Prescaler; |
462 | 458 | ||
463 | } |
459 | } |
464 | /******************************************************************************* |
460 | /******************************************************************************* |
465 | * Function Name : TIM_GetPrescalerValue |
461 | * Function Name : TIM_GetPrescalerValue |
466 | * Description : This routine is used to get the TIMx prescaler value |
462 | * Description : This routine is used to get the TIMx prescaler value |
467 | * (when using the APB clock). |
463 | * (when using the APB clock). |
468 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
464 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
469 | * peripheral. |
465 | * peripheral. |
470 | * Output : None |
466 | * Output : None |
471 | * Return : The prescaler value. |
467 | * Return : The prescaler value. |
472 | *******************************************************************************/ |
468 | *******************************************************************************/ |
473 | u8 TIM_GetPrescalerValue(TIM_TypeDef *TIMx) |
469 | u8 TIM_GetPrescalerValue(TIM_TypeDef *TIMx) |
474 | { |
470 | { |
475 | return TIMx->CR2 & 0x00FF; |
471 | return TIMx->CR2 & 0x00FF; |
476 | } |
472 | } |
477 | 473 | ||
478 | /******************************************************************************* |
474 | /******************************************************************************* |
479 | * Function Name : TIM_GetCounterValue |
475 | * Function Name : TIM_GetCounterValue |
480 | * Description : This routine is used to get the TIMx counter value. |
476 | * Description : This routine is used to get the TIMx counter value. |
481 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
477 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
482 | * peripheral. |
478 | * peripheral. |
483 | * Output : None |
479 | * Output : None |
484 | * Return : The counter value. |
480 | * Return : The counter value. |
485 | *******************************************************************************/ |
481 | *******************************************************************************/ |
486 | u16 TIM_GetCounterValue(TIM_TypeDef *TIMx) |
482 | u16 TIM_GetCounterValue(TIM_TypeDef *TIMx) |
487 | { |
483 | { |
488 | return TIMx->CNTR; |
484 | return TIMx->CNTR; |
489 | } |
485 | } |
490 | 486 | ||
491 | /******************************************************************************* |
487 | /******************************************************************************* |
492 | * Function Name : TIM_GetICAP1Value |
488 | * Function Name : TIM_GetICAP1Value |
493 | * Description : This routine is used to get the Input Capture 1 value. |
489 | * Description : This routine is used to get the Input Capture 1 value. |
494 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
490 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
495 | * peripheral. |
491 | * peripheral. |
496 | * Output : None |
492 | * Output : None |
497 | * Return : The Input Capture 1 value. |
493 | * Return : The Input Capture 1 value. |
498 | *******************************************************************************/ |
494 | *******************************************************************************/ |
499 | u16 TIM_GetICAP1Value(TIM_TypeDef *TIMx) |
495 | u16 TIM_GetICAP1Value(TIM_TypeDef *TIMx) |
500 | { |
496 | { |
501 | return TIMx->IC1R; |
497 | return TIMx->IC1R; |
502 | } |
498 | } |
503 | 499 | ||
504 | /******************************************************************************* |
500 | /******************************************************************************* |
505 | * Function Name : TIM_GetICAP2Value |
501 | * Function Name : TIM_GetICAP2Value |
506 | * Description : This routine is used to get the Input Capture 2 value. |
502 | * Description : This routine is used to get the Input Capture 2 value. |
507 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
503 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
508 | * peripheral. |
504 | * peripheral. |
509 | * Output : None |
505 | * Output : None |
510 | * Return : The Input Capture 2 value. |
506 | * Return : The Input Capture 2 value. |
511 | *******************************************************************************/ |
507 | *******************************************************************************/ |
512 | u16 TIM_GetICAP2Value(TIM_TypeDef *TIMx) |
508 | u16 TIM_GetICAP2Value(TIM_TypeDef *TIMx) |
513 | { |
509 | { |
514 | return TIMx->IC2R; |
510 | return TIMx->IC2R; |
515 | } |
511 | } |
516 | 512 | ||
517 | /******************************************************************************* |
513 | /******************************************************************************* |
518 | * Function Name : TIM_SetPulse |
514 | * Function Name : TIM_SetPulse |
519 | * Description : This routine is used to set the pulse value. |
515 | * Description : This routine is used to set the pulse value. |
520 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
516 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
521 | * peripheral. |
517 | * peripheral. |
522 | * Input2 : TIM_Channel: specifies the needed channel. |
518 | * Input2 : TIM_Channel: specifies the needed channel. |
523 | * This parameter can be one of the following values: |
519 | * This parameter can be one of the following values: |
524 | * - TIM_PWM_OC1_Channel: PWM/Output Compare 1 Channel |
520 | * - TIM_PWM_OC1_Channel: PWM/Output Compare 1 Channel |
525 | * - TIM_OC2_Channel : Output Compare 2 Channel |
521 | * - TIM_OC2_Channel : Output Compare 2 Channel |
526 | * Input3 : TIM_Pulse: specifies the new pulse value. |
522 | * Input3 : TIM_Pulse: specifies the new pulse value. |
527 | * Output : None |
523 | * Output : None |
528 | * Return : None |
524 | * Return : None |
529 | *******************************************************************************/ |
525 | *******************************************************************************/ |
530 | void TIM_SetPulse(TIM_TypeDef *TIMx,u16 TIM_Channel ,u16 TIM_Pulse) |
526 | void TIM_SetPulse(TIM_TypeDef *TIMx,u16 TIM_Channel ,u16 TIM_Pulse) |
531 | { |
527 | { |
532 | if (TIM_Channel == TIM_PWM_OC1_Channel) |
528 | if (TIM_Channel == TIM_PWM_OC1_Channel) |
533 | { |
529 | { |
534 | TIMx->OC1R = TIM_Pulse; |
530 | TIMx->OC1R = TIM_Pulse; |
535 | } |
531 | } |
536 | else |
532 | else |
537 | { |
533 | { |
538 | TIMx->OC2R = TIM_Pulse; |
534 | TIMx->OC2R = TIM_Pulse; |
539 | } |
535 | } |
540 | } |
536 | } |
541 | /******************************************************************************* |
537 | /******************************************************************************* |
542 | * Function Name : TIM_GetFlagStatus |
538 | * Function Name : TIM_GetFlagStatus |
543 | * Description : Checks whether the specified TIMx flag is set or not. |
539 | * Description : Checks whether the specified TIMx flag is set or not. |
544 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
540 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
545 | * peripheral. |
541 | * peripheral. |
546 | * Input2 : TIM_Flag: specifies the flag to check. |
542 | * Input2 : TIM_Flag: specifies the flag to check. |
547 | * This parameter can be one of the following values: |
543 | * This parameter can be one of the following values: |
548 | * - TIM_FLAG_IC1: Input Capture Channel 1 Flag |
544 | * - TIM_FLAG_IC1: Input Capture Channel 1 Flag |
549 | * - TIM_FLAG_IC2: Input Capture Channel 2 Flag |
545 | * - TIM_FLAG_IC2: Input Capture Channel 2 Flag |
550 | * - TIM_FLAG_TO : Timer Overflow Flag |
546 | * - TIM_FLAG_TO : Timer Overflow Flag |
551 | * - TIM_FLAG_OC1: Output Compare Channel 1 Flag |
547 | * - TIM_FLAG_OC1: Output Compare Channel 1 Flag |
552 | * - TIM_FLAG_OC2: Output Compare Channel 2 Flag |
548 | * - TIM_FLAG_OC2: Output Compare Channel 2 Flag |
553 | * Output : None |
549 | * Output : None |
554 | * Return : The NewState of the TIM_Flag (SET or RESET). |
550 | * Return : The NewState of the TIM_Flag (SET or RESET). |
555 | *******************************************************************************/ |
551 | *******************************************************************************/ |
556 | FlagStatus TIM_GetFlagStatus(TIM_TypeDef *TIMx, u16 TIM_Flag) |
552 | FlagStatus TIM_GetFlagStatus(TIM_TypeDef *TIMx, u16 TIM_Flag) |
557 | { |
553 | { |
558 | if((TIMx->SR & TIM_Flag) == RESET) |
554 | if((TIMx->SR & TIM_Flag) == RESET) |
559 | { |
555 | { |
560 | return RESET; |
556 | return RESET; |
561 | } |
557 | } |
562 | else |
558 | else |
563 | { |
559 | { |
564 | return SET; |
560 | return SET; |
565 | } |
561 | } |
566 | } |
562 | } |
567 | 563 | ||
568 | /******************************************************************************* |
564 | /******************************************************************************* |
569 | * Function Name : TIM_ClearFlag |
565 | * Function Name : TIM_ClearFlag |
570 | * Description : Clears the TIM Flag passed as a parameter. |
566 | * Description : Clears the TIM Flag passed as a parameter. |
571 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
567 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
572 | * peripheral. |
568 | * peripheral. |
573 | * Input2 : TIM_Flag: specifies the flag to clear. |
569 | * Input2 : TIM_Flag: specifies the flag to clear. |
574 | * This parameter can be one of the following values: |
570 | * This parameter can be one of the following values: |
575 | * - TIM_FLAG_IC1: Input Capture Channel 1 Flag |
571 | * - TIM_FLAG_IC1: Input Capture Channel 1 Flag |
576 | * - TIM_FLAG_IC2: Input Capture Channel 2 Flag |
572 | * - TIM_FLAG_IC2: Input Capture Channel 2 Flag |
577 | * - TIM_FLAG_TO : Timer Overflow Flag |
573 | * - TIM_FLAG_TO : Timer Overflow Flag |
578 | * - TIM_FLAG_OC1: Output Compare Channel 1 Flag |
574 | * - TIM_FLAG_OC1: Output Compare Channel 1 Flag |
579 | * - TIM_FLAG_OC2: Output Compare Channel 2 Flag |
575 | * - TIM_FLAG_OC2: Output Compare Channel 2 Flag |
580 | * Output : None |
576 | * Output : None |
581 | * Return : None |
577 | * Return : None |
582 | *******************************************************************************/ |
578 | *******************************************************************************/ |
583 | void TIM_ClearFlag(TIM_TypeDef *TIMx, u16 TIM_Flag) |
579 | void TIM_ClearFlag(TIM_TypeDef *TIMx, u16 TIM_Flag) |
584 | { |
580 | { |
585 | /* Clear TIM_Flag */ |
581 | /* Clear TIM_Flag */ |
586 | TIMx->SR &= ~TIM_Flag; |
582 | TIMx->SR &= ~TIM_Flag; |
587 | } |
583 | } |
588 | 584 | ||
589 | /******************************************************************************* |
585 | /******************************************************************************* |
590 | * Function Name : TIM_GetPWMIPulse |
586 | * Function Name : TIM_GetPWMIPulse |
591 | * Description : This routine is used to get the Pulse value in PWMI Mode. |
587 | * Description : This routine is used to get the Pulse value in PWMI Mode. |
592 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
588 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
593 | * peripheral. |
589 | * peripheral. |
594 | * Output : None |
590 | * Output : None |
595 | * Return : The pulse value. |
591 | * Return : The pulse value. |
596 | *******************************************************************************/ |
592 | *******************************************************************************/ |
597 | u16 TIM_GetPWMIPulse(TIM_TypeDef *TIMx) |
593 | u16 TIM_GetPWMIPulse(TIM_TypeDef *TIMx) |
598 | { |
594 | { |
599 | return TIMx->IC2R; |
595 | return TIMx->IC2R; |
600 | } |
596 | } |
601 | 597 | ||
602 | /******************************************************************************* |
598 | /******************************************************************************* |
603 | * Function Name : TIM_GetPWMIPeriod |
599 | * Function Name : TIM_GetPWMIPeriod |
604 | * Description : This routine is used to get the Period value in PWMI Mode. |
600 | * Description : This routine is used to get the Period value in PWMI Mode. |
605 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
601 | * Input : TIMx: where x can be from 0 to 3 to select the TIM |
606 | * peripheral. |
602 | * peripheral. |
607 | * Output : None |
603 | * Output : None |
608 | * Return : The period value. |
604 | * Return : The period value. |
609 | *******************************************************************************/ |
605 | *******************************************************************************/ |
610 | u16 TIM_GetPWMIPeriod(TIM_TypeDef *TIMx) |
606 | u16 TIM_GetPWMIPeriod(TIM_TypeDef *TIMx) |
611 | { |
607 | { |
612 | return TIMx->IC1R; |
608 | return TIMx->IC1R; |
613 | } |
609 | } |
614 | 610 | ||
615 | /******************************************************************************* |
611 | /******************************************************************************* |
616 | * Function Name : TIM_ITConfig |
612 | * Function Name : TIM_ITConfig |
617 | * Description : Configures the Timer interrupt source. |
613 | * Description : Configures the Timer interrupt source. |
618 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
614 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
619 | * peripheral. |
615 | * peripheral. |
620 | * Input2 : TIM_IT: specifies the TIM interrupt source to be enabled. |
616 | * Input2 : TIM_IT: specifies the TIM interrupt source to be enabled. |
621 | * This parameter can be one of the following values: |
617 | * This parameter can be one of the following values: |
622 | * - TIM_IT_IC1: Input Capture 1 Interrupt source. |
618 | * - TIM_IT_IC1: Input Capture 1 Interrupt source. |
623 | * - TIM_IT_OC1: Output Compare 1 Interrupt source. |
619 | * - TIM_IT_OC1: Output Compare 1 Interrupt source. |
624 | * - TIM_IT_TO : Timer Overflow Interrupt source. |
620 | * - TIM_IT_TO : Timer Overflow Interrupt source. |
625 | * - TIM_IT_IC2: Input Capture 2 Interrupt source. |
621 | * - TIM_IT_IC2: Input Capture 2 Interrupt source. |
626 | * - TIM_IT_OC2: Output Compare 2 Interrupt source. |
622 | * - TIM_IT_OC2: Output Compare 2 Interrupt source. |
627 | * Input3 : TIM_Newstate: specifies the new state of the TIMx IT. |
623 | * Input3 : TIM_Newstate: specifies the new state of the TIMx IT. |
628 | * This parameter can be one of the following values: |
624 | * This parameter can be one of the following values: |
629 | * - ENABLE : Enable the needed interrupt. |
625 | * - ENABLE : Enable the needed interrupt. |
630 | * - DISABLE: Disable the needed interrupt. |
626 | * - DISABLE: Disable the needed interrupt. |
631 | * Output : None |
627 | * Output : None |
632 | * Return : None |
628 | * Return : None |
633 | *******************************************************************************/ |
629 | *******************************************************************************/ |
634 | void TIM_ITConfig(TIM_TypeDef *TIMx, u16 TIM_IT, FunctionalState TIM_Newstate) |
630 | void TIM_ITConfig(TIM_TypeDef *TIMx, u16 TIM_IT, FunctionalState TIM_Newstate) |
635 | { |
631 | { |
636 | if(TIM_Newstate == ENABLE) |
632 | if(TIM_Newstate == ENABLE) |
637 | { |
633 | { |
638 | TIMx->CR2 = (TIMx->CR2 & 0x00FF) | TIM_IT; |
634 | TIMx->CR2 = (TIMx->CR2 & 0x00FF) | TIM_IT; |
639 | } |
635 | } |
640 | else |
636 | else |
641 | { |
637 | { |
642 | TIMx->CR2 &= ~TIM_IT; |
638 | TIMx->CR2 &= ~TIM_IT; |
643 | } |
639 | } |
644 | } |
640 | } |
645 | 641 | ||
646 | /******************************************************************************* |
642 | /******************************************************************************* |
647 | * Function Name : TIM_DMAConfig |
643 | * Function Name : TIM_DMAConfig |
648 | * Description : Configures the Timer DMA source. |
644 | * Description : Configures the Timer DMA source. |
649 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
645 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
650 | * peripheral. |
646 | * peripheral. |
651 | * Input2 : TIM_DMA_Souces: specifies the TIM DMA source to be selected. |
647 | * Input2 : TIM_DMA_Souces: specifies the TIM DMA source to be selected. |
652 | * This parameter can be one of the following values: |
648 | * This parameter can be one of the following values: |
653 | * - TIM_DMA_IC1: Input Capture 1 DMA source. |
649 | * - TIM_DMA_IC1: Input Capture 1 DMA source. |
654 | * - TIM_DMA_OCA1 Output Compare 1 DMA source. |
650 | * - TIM_DMA_OCA1 Output Compare 1 DMA source. |
655 | * - TIM_DMA_TO: Timer Overflow DMA source. |
651 | * - TIM_DMA_TO: Timer Overflow DMA source. |
656 | * - TIM_DMA_IC2: Input Capture 2 DMA source. |
652 | * - TIM_DMA_IC2: Input Capture 2 DMA source. |
657 | * - TIM_DMA_OC2: Output Compare 2 DMA source. |
653 | * - TIM_DMA_OC2: Output Compare 2 DMA source. |
658 | * Output : None |
654 | * Output : None |
659 | * Return : None |
655 | * Return : None |
660 | *******************************************************************************/ |
656 | *******************************************************************************/ |
661 | void TIM_DMAConfig(TIM_TypeDef *TIMx, u16 TIM_DMA_Sources) |
657 | void TIM_DMAConfig(TIM_TypeDef *TIMx, u16 TIM_DMA_Sources) |
662 | { |
658 | { |
663 | /* Reset the DMAS[1:0] bits */ |
659 | /* Reset the DMAS[1:0] bits */ |
664 | TIMx->CR1 &= TIM_DMA_CLEAR_MASK; |
660 | TIMx->CR1 &= TIM_DMA_CLEAR_MASK; |
665 | /* Set the DMAS[1:0] bits according to TIM_DMA_Sources parameter */ |
661 | /* Set the DMAS[1:0] bits according to TIM_DMA_Sources parameter */ |
666 | TIMx->CR1 |= TIM_DMA_Sources; |
662 | TIMx->CR1 |= TIM_DMA_Sources; |
667 | } |
663 | } |
668 | 664 | ||
669 | /******************************************************************************* |
665 | /******************************************************************************* |
670 | * Function Name : TIM_DMACmd |
666 | * Function Name : TIM_DMACmd |
671 | * Description : Enables or disables TIMx DMA peripheral. |
667 | * Description : Enables or disables TIMx DMA peripheral. |
672 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
668 | * Input1 : TIMx: where x can be from 0 to 3 to select the TIM |
673 | * peripheral. |
669 | * peripheral. |
674 | * Input2 : TIM_Newstate: new state of the TIMx DMA peripheral |
670 | * Input2 : TIM_Newstate: new state of the TIMx DMA peripheral |
675 | * This parameter can be one of the following values: |
671 | * This parameter can be one of the following values: |
676 | * - ENABLE : Enable the TIMx DMA. |
672 | * - ENABLE : Enable the TIMx DMA. |
677 | * - DISABLE: Disable the TIMx DMA. |
673 | * - DISABLE: Disable the TIMx DMA. |
678 | * Output : None |
674 | * Output : None |
679 | * Return : None |
675 | * Return : None |
680 | *******************************************************************************/ |
676 | *******************************************************************************/ |
681 | void TIM_DMACmd(TIM_TypeDef *TIMx, FunctionalState TIM_Newstate) |
677 | void TIM_DMACmd(TIM_TypeDef *TIMx, FunctionalState TIM_Newstate) |
682 | { |
678 | { |
683 | if (TIM_Newstate == ENABLE) |
679 | if (TIM_Newstate == ENABLE) |
684 | { |
680 | { |
685 | TIMx->CR2 |= TIM_DMA_ENABLE; |
681 | TIMx->CR2 |= TIM_DMA_ENABLE; |
686 | } |
682 | } |
687 | else |
683 | else |
688 | { |
684 | { |
689 | TIMx->CR2 &= TIM_DMA_DISABLE; |
685 | TIMx->CR2 &= TIM_DMA_DISABLE; |
690 | } |
686 | } |
691 | } |
687 | } |
692 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |
688 | /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ |
693 | 689 |