1 /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 08/09/2003
\r
5 * Description : This file contains all the functions prototypes for the
\r
6 * TIM software library.
\r
7 ********************************************************************************
\r
12 *******************************************************************************
\r
13 THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
\r
14 CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
15 AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
\r
16 OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
\r
17 OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
\r
18 CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
19 *******************************************************************************/
\r
24 #include "71x_map.h"
\r
26 typedef enum { TIM_EXTERNAL,
\r
30 typedef enum { TIM_RISING,
\r
34 typedef enum { TIM_CHANNEL_A,
\r
38 typedef enum { TIM_WITH_IT,
\r
42 typedef enum { TIM_TIMING,
\r
46 typedef enum { TIM_HIGH,
\r
50 typedef enum { TIM_START,
\r
53 } TIM_CounterOperations;
\r
55 typedef enum { TIM_ICFA = 0x8000,
\r
62 typedef struct { u16 Pulse;
\r
66 #define TIM_ECKEN_Mask 0x0001
\r
67 #define TIM_EXEDG_Mask 0x0002
\r
69 #define TIM_IEDGA_Mask 0x0004
\r
70 #define TIM_IEDGB_Mask 0x0008
\r
72 #define TIM_PWM_Mask 0x0010
\r
74 #define TIM_OMP_Mask 0x0020
\r
76 #define TIM_OCAE_Mask 0x0040
\r
77 #define TIM_OCBE_Mask 0x0080
\r
79 #define TIM_OLVLA_Mask 0x0100
\r
80 #define TIM_OLVLB_Mask 0x0200
\r
82 #define TIM_FOLVA_Mask 0x0400
\r
83 #define TIM_FOLVB_Mask 0x0800
\r
85 #define TIM_PWMI_Mask 0x4000
\r
87 #define TIM_EN_Mask 0x8000
\r
89 #define TIM_OCBIE_mask 0x0800
\r
90 #define TIM_ICBIE_Mask 0x1000
\r
91 #define TIM_TOE_Mask 0x2000
\r
92 #define TIM_ICAIE_Mask 0x8000
\r
93 #define TIM_OCAIE_mask 0x4000
\r
95 #define TIM_ICA_IT 0x8000 // Input Capture Channel A
\r
96 #define TIM_OCA_IT 0x4000 // Output Compare Channel A
\r
97 #define TIM_TO_IT 0x2000 // Timer OverFlow
\r
98 #define TIM_ICB_IT 0x1000 // Input Capture Channel B
\r
99 #define TIM_OCB_IT 0x0800 // Input Capture Channel A
\r
102 /*******************************************************************************
\r
103 * Function Name : TIM_Init
\r
104 * Description : This routine is used to Initialize the TIM peripheral
\r
105 * Input : TIM Timer to Initialize
\r
107 *******************************************************************************/
\r
108 void TIM_Init( TIM_TypeDef *TIMx );
\r
110 /*******************************************************************************
\r
111 * Function Name : TIM_ClockSourceConfig
\r
112 * Description : This routine is used to configure the TIM clock source
\r
113 * Input : (1) TIM Timer
\r
114 * : (2) TIM_Clocks : Specifies the TIM source clock
\r
115 * - TIM_INTERNAL : The TIM is clocked by the APB2 frequency
\r
116 * divided by the prescaler value.
\r
117 * - TIM_EXTERNAL : The TIM is clocked by an external Clock
\r
119 *******************************************************************************/
\r
120 inline void TIM_ClockSourceConfig ( TIM_TypeDef *TIMx, TIM_Clocks Xclock )
\r
122 if (Xclock==TIM_EXTERNAL) TIMx->CR1|=TIM_ECKEN_Mask; else TIMx->CR1&=~TIM_ECKEN_Mask;
\r
125 /*******************************************************************************
\r
126 * Function Name : TIM_ClockSourceValue
\r
127 * Description : This routine is used to get the TIM clock source
\r
128 * Input : TIM Timer
\r
129 * Return : TIM_Clocks : Specifies the TIM source clock
\r
130 * - TIM_INTERNAL : The TIM is clocked by the APB2 frequency
\r
131 * divided by the prescaler value.
\r
132 * - TIM_EXTERNAL : The TIM is clocked by an external Clock
\r
133 *******************************************************************************/
\r
134 inline TIM_Clocks TIM_ClockSourceValue ( TIM_TypeDef *TIMx )
\r
136 return ( TIMx->CR1 & TIM_ECKEN_Mask) == 0 ? TIM_INTERNAL : TIM_EXTERNAL;
\r
139 /*******************************************************************************
\r
140 * Function Name : TIM_PrescalerConfig
\r
141 * Description : This routine is used to configure the TIM prescaler value
\r
142 * ( using an internal clock )
\r
143 * Input : (1) TIM Timer
\r
144 * : (2) Prescaler ( u8 )
\r
146 *******************************************************************************/
\r
147 inline void TIM_PrescalerConfig ( TIM_TypeDef *TIMx, u8 Xprescaler )
\r
149 TIMx->CR2 = ( TIMx->CR2 & 0xFF00 ) | Xprescaler;
\r
152 /*******************************************************************************
\r
153 * Function Name : TIM_PrescalerValue
\r
154 * Description : This routine is used to get the TIM prescaler value
\r
155 * ( when using using an internal clock )
\r
156 * Input : TIM Timer
\r
157 * Return : Prescaler ( u8 )
\r
158 *******************************************************************************/
\r
159 inline u8 TIM_PrescalerValue ( TIM_TypeDef *TIMx )
\r
161 return TIMx->CR2 & 0x00FF;
\r
164 /*******************************************************************************
\r
165 * Function Name : TIM_ClockLevelConfig
\r
166 * Description : This routine is used to configure the TIM clock level
\r
167 * ( using an external clock )
\r
168 * Input : TIM Timer
\r
169 * : TIM_Clock_Edges : Specifies the active adge of the external clock
\r
170 * - TIM_RISING : The rising edge
\r
171 * - TIM_FALLING : The falling edge
\r
173 *******************************************************************************/
\r
174 inline void TIM_ClockLevelConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge )
\r
176 if (Xedge == TIM_RISING) TIMx->CR1 |= TIM_EXEDG_Mask; else TIMx->CR1 &= ~TIM_EXEDG_Mask;
\r
179 /*******************************************************************************
\r
180 * Function Name : TIM_ClockLevelValue
\r
181 * Description : This routine is used to get the TIM clock level
\r
182 * Input : TIM Timer
\r
183 * Output : TIM_Clock_Edges : Specifies the active adge of the external clock
\r
184 * - TIM_RISING : The rising edge
\r
185 * - TIM_FALLING : The falling edge
\r
186 *******************************************************************************/
\r
187 inline TIM_Clock_Edges TIM_ClockLevelValue ( TIM_TypeDef *TIMx )
\r
189 return ( TIMx->CR1 & TIM_EXEDG_Mask ) == 0 ? TIM_FALLING : TIM_RISING;
\r
192 /*******************************************************************************
\r
193 * Function Name : TIM_ICAPModeConfig
\r
194 * Description : This routine is used to configure the input capture feature
\r
195 * Input : (1) TIM Timer
\r
196 * : (2) Input Capture Channel ( Channel_A or Channel_B )
\r
197 * : (3) Active Edge : Rising edge or Falling edge.
\r
199 *******************************************************************************/
\r
200 void TIM_ICAPModeConfig ( TIM_TypeDef *TIMx,
\r
201 TIM_Channels Xchannel,
\r
202 TIM_Clock_Edges Xedge );
\r
204 /*******************************************************************************
\r
205 * Function Name : TIM_ICAPValue
\r
206 * Description : This routine is used to get the Input Capture value
\r
207 * Input : (1) TIM Timer
\r
208 * : (2) Input Capture Channel ( Channel_A or Channel_B )
\r
210 *******************************************************************************/
\r
211 inline u16 TIM_ICAPValue ( TIM_TypeDef *TIMx, TIM_Channels Xchannel )
\r
213 return Xchannel == TIM_CHANNEL_A ? TIMx->ICAR : TIMx->ICBR;
\r
216 /*******************************************************************************
\r
217 * Function Name : TIM_OCMPModeConfig
\r
218 * Description : This routine is used to configure the output compare feature
\r
219 * Input : (1) TIM Timer
\r
220 * : (2) OCMP Channel ( Channel_A or Channel_B )
\r
221 * : (3) Pulse Length
\r
222 * : (4) OC_Mode : output wave, or only timing.
\r
223 * : (5) Level : Rising edge or Falling edge after the ==
\r
225 *******************************************************************************/
\r
226 void TIM_OCMPModeConfig ( TIM_TypeDef *TIMx,
\r
227 TIM_Channels Xchannel,
\r
229 TIM_OC_Modes Xmode,
\r
230 TIM_Logic_Levels Xlevel );
\r
232 /*******************************************************************************
\r
233 * Function Name : TIM_OPModeConfig
\r
234 * Description : This routine is used to configure the one pulse mode
\r
235 * Input : (1) TIM Timer
\r
236 * : (3) XpulseLength : Length of the pulse
\r
237 * : (4) Level1 : Level during the pulse
\r
238 * : (5) Level2 : Level after the pulse
\r
239 * : (6) Activation Edge : High or Low on ICAP A
\r
241 *******************************************************************************/
\r
242 void TIM_OPModeConfig ( TIM_TypeDef *TIMx,
\r
244 TIM_Logic_Levels XLevel1,
\r
245 TIM_Logic_Levels XLevel2,
\r
246 TIM_Clock_Edges Xedge );
\r
248 /*******************************************************************************
\r
249 * Function Name : TIM_PWMOModeConfig
\r
250 * Description : This routine is used to configure the PWM in output mode
\r
251 * Input : (1) TIM Timer
\r
252 * : (2) DutyCycle : u16
\r
253 * : (3) Level 1 : During the Duty Cycle
\r
254 * : (4) Level 2 : During the after the pulse
\r
255 * : (5) Full period : u16
\r
257 *******************************************************************************/
\r
258 void TIM_PWMOModeConfig ( TIM_TypeDef *TIMx,
\r
260 TIM_Logic_Levels XLevel1,
\r
262 TIM_Logic_Levels XLevel2
\r
265 /*******************************************************************************
\r
266 * Function Name : TIM_PWMInputConfig
\r
267 * Description : This routine is used to configure the PWM in input mode
\r
268 * Input : (1) TIM Timer
\r
269 * : (2) First Activation Edge
\r
271 *******************************************************************************/
\r
272 void TIM_PWMIModeConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge );
\r
274 /*******************************************************************************
\r
275 * Function Name : TIM_PWMIValue
\r
276 * Description : This routine is used to get the PWMI values
\r
277 * Input : (1) TIM Timer
\r
278 * Output : PWMI_parameters : - u16 Dyty cycle
\r
280 *******************************************************************************/
\r
281 PWMI_parameters TIM_PWMIValue (TIM_TypeDef *TIMx );
\r
283 /*******************************************************************************
\r
284 * Function Name : TIM_CounterConfig
\r
285 * Description : This routine is used to start/stop and clear the selected
\r
287 * Input : (1) TIM Timer
\r
288 * : (2) TIM_CounterOperations
\r
289 TIM_START Enables or resumes the counter
\r
290 * TIM_STOP Stops the TIM counter
\r
291 * TIM_CLEAR Set the TIM counter value to FFFCh
\r
293 *******************************************************************************/
\r
294 void TIM_CounterConfig ( TIM_TypeDef *TIMx, TIM_CounterOperations Xoperation );
\r
296 /*******************************************************************************
\r
297 * Function Name : TIM_ITConfig
\r
298 * Description : This routine is used to configure the TIM IT
\r
299 * Input : (1) TIM Timer
\r
300 * : (2) TIM interrupt
\r
301 * : (2) ENABLE / DISABLE
\r
303 *******************************************************************************/
\r
304 inline void TIM_ITConfig ( TIM_TypeDef *TIMx, u16 New_IT, FunctionalState NewState )
\r
306 if (NewState == ENABLE) TIMx->CR2 |= New_IT; else TIMx->CR2 &= ~New_IT;
\r
309 /*******************************************************************************
\r
310 * Function Name : TIM_FlagStatus
\r
311 * Description : This routine is used to check whether a Flag is Set.
\r
312 * Input : (1) TIM Timer
\r
313 * : (2) The TIM FLag
\r
314 * Output : Flag NewState
\r
315 *******************************************************************************/
\r
316 inline FlagStatus TIM_FlagStatus ( TIM_TypeDef *TIMx, TIM_Flags Xflag )
\r
318 return (TIMx->SR & Xflag) == 0 ? RESET : SET;
\r
321 /*******************************************************************************
\r
322 * Function Name : TIM_FlagClear
\r
323 * Description : This routine is used to clear Flags.
\r
324 * Input : (1) TIM Timer
\r
325 * : (2) The TIM FLag
\r
327 *******************************************************************************/
\r
328 inline void TIM_FlagClear ( TIM_TypeDef *TIMx, TIM_Flags Xflag )
\r
330 TIMx->SR &= ~Xflag;
\r
333 /*******************************************************************************
\r
334 * Function Name : TIM_CounterValue
\r
335 * Description : This routine returns the timer counter value.
\r
336 * Input : TIM Timer
\r
337 * Output : The counter value
\r
338 *******************************************************************************/
\r
339 inline u16 TIM_CounterValue(TIM_TypeDef *TIMx)
\r
345 /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/
\r