]> begriffs open source - freertos/blob - 20080217/Demo/ARM7_STR71x_IAR/Library/include/tim.h
Prepare Fujitsu ports for release.
[freertos] / 20080217 / Demo / ARM7_STR71x_IAR / Library / include / tim.h
1 /******************** (C) COPYRIGHT 2003 STMicroelectronics ********************\r
2 * File Name          : tim.h\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
8 * History:\r
9 *  30/11/2004 : V2.0\r
10 *  14/07/2004 : V1.3\r
11 *  01/01/2004 : V1.2\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
20 \r
21 #ifndef __TIM_H\r
22 #define __TIM_H\r
23 \r
24 #include "71x_map.h"\r
25 \r
26 typedef enum { TIM_EXTERNAL,\r
27                TIM_INTERNAL\r
28              } TIM_Clocks;\r
29 \r
30 typedef enum { TIM_RISING,\r
31                TIM_FALLING\r
32              } TIM_Clock_Edges;\r
33 \r
34 typedef enum { TIM_CHANNEL_A,\r
35                TIM_CHANNEL_B\r
36              } TIM_Channels;\r
37 \r
38 typedef enum { TIM_WITH_IT,\r
39                TIM_WITHOUT_IT\r
40              } TIM_IT_Mode;\r
41 \r
42 typedef enum { TIM_TIMING,\r
43                TIM_WAVE\r
44              } TIM_OC_Modes;\r
45 \r
46 typedef enum { TIM_HIGH,\r
47                TIM_LOW\r
48              } TIM_Logic_Levels;\r
49 \r
50 typedef enum { TIM_START,\r
51                TIM_STOP,\r
52                TIM_CLEAR\r
53              } TIM_CounterOperations;\r
54 \r
55 typedef enum { TIM_ICFA = 0x8000,\r
56                TIM_OCFA = 0x4000,\r
57                TIM_TOF  = 0x2000,\r
58                TIM_ICFB = 0x1000,\r
59                TIM_OCFB = 0x0800\r
60              } TIM_Flags;\r
61 \r
62 typedef struct { u16 Pulse;\r
63                  u16 Period;\r
64                } PWMI_parameters;\r
65 \r
66 #define TIM_ECKEN_Mask  0x0001\r
67 #define TIM_EXEDG_Mask  0x0002\r
68 \r
69 #define TIM_IEDGA_Mask  0x0004\r
70 #define TIM_IEDGB_Mask  0x0008\r
71 \r
72 #define TIM_PWM_Mask    0x0010\r
73 \r
74 #define TIM_OMP_Mask    0x0020\r
75 \r
76 #define TIM_OCAE_Mask   0x0040\r
77 #define TIM_OCBE_Mask   0x0080\r
78 \r
79 #define TIM_OLVLA_Mask  0x0100\r
80 #define TIM_OLVLB_Mask  0x0200\r
81 \r
82 #define TIM_FOLVA_Mask  0x0400\r
83 #define TIM_FOLVB_Mask  0x0800\r
84 \r
85 #define TIM_PWMI_Mask   0x4000\r
86 \r
87 #define TIM_EN_Mask     0x8000\r
88 \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
94 \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
100 \r
101 \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
106 * Return         : None\r
107 *******************************************************************************/\r
108 void TIM_Init( TIM_TypeDef *TIMx );\r
109 \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
118 * Return         : None\r
119 *******************************************************************************/\r
120 inline void TIM_ClockSourceConfig ( TIM_TypeDef *TIMx, TIM_Clocks Xclock )\r
121 {\r
122         if (Xclock==TIM_EXTERNAL) TIMx->CR1|=TIM_ECKEN_Mask; else TIMx->CR1&=~TIM_ECKEN_Mask;\r
123 }\r
124 \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
135 {\r
136         return ( TIMx->CR1 & TIM_ECKEN_Mask) == 0 ? TIM_INTERNAL : TIM_EXTERNAL;\r
137 }\r
138 \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
145 * Return         : None\r
146 *******************************************************************************/\r
147 inline void TIM_PrescalerConfig ( TIM_TypeDef *TIMx, u8 Xprescaler )\r
148 {\r
149         TIMx->CR2 = ( TIMx->CR2 & 0xFF00 ) | Xprescaler;\r
150 }\r
151 \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
160 {\r
161         return TIMx->CR2 & 0x00FF;\r
162 }\r
163 \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
172 * Return         : None\r
173 *******************************************************************************/\r
174 inline void TIM_ClockLevelConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge )\r
175 {\r
176         if (Xedge == TIM_RISING) TIMx->CR1 |= TIM_EXEDG_Mask; else TIMx->CR1 &= ~TIM_EXEDG_Mask;\r
177 }\r
178 \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
188 {\r
189         return ( TIMx->CR1 & TIM_EXEDG_Mask ) == 0 ? TIM_FALLING : TIM_RISING;\r
190 }\r
191 \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
198 * Output         : None\r
199 *******************************************************************************/\r
200 void TIM_ICAPModeConfig ( TIM_TypeDef  *TIMx,\r
201                           TIM_Channels Xchannel,\r
202                           TIM_Clock_Edges  Xedge );\r
203 \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
209 * Output         : None\r
210 *******************************************************************************/\r
211 inline u16 TIM_ICAPValue ( TIM_TypeDef *TIMx, TIM_Channels Xchannel )\r
212 {\r
213         return Xchannel == TIM_CHANNEL_A ? TIMx->ICAR : TIMx->ICBR;\r
214 }\r
215 \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
224 * Output         : None\r
225 *******************************************************************************/\r
226 void TIM_OCMPModeConfig (  TIM_TypeDef  *TIMx,\r
227                            TIM_Channels Xchannel,\r
228                            u16          XpulseLength,\r
229                            TIM_OC_Modes     Xmode,\r
230                            TIM_Logic_Levels Xlevel );\r
231 \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
240 * Output         : None\r
241 *******************************************************************************/\r
242 void TIM_OPModeConfig ( TIM_TypeDef  *TIMx,\r
243                         u16          XpulseLength,\r
244                         TIM_Logic_Levels XLevel1,\r
245                         TIM_Logic_Levels XLevel2,\r
246                         TIM_Clock_Edges  Xedge );\r
247 \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
256 * Output         : None\r
257 *******************************************************************************/\r
258 void TIM_PWMOModeConfig ( TIM_TypeDef  *TIMx,\r
259                           u16          XDutyCycle,\r
260                           TIM_Logic_Levels XLevel1,\r
261                           u16          XFullperiod,\r
262                           TIM_Logic_Levels XLevel2\r
263                         );\r
264 \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
270 * Output         : None\r
271 *******************************************************************************/\r
272 void TIM_PWMIModeConfig ( TIM_TypeDef *TIMx, TIM_Clock_Edges Xedge );\r
273 \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
279                                      - u16 Full period\r
280 *******************************************************************************/\r
281 PWMI_parameters TIM_PWMIValue (TIM_TypeDef *TIMx );\r
282 \r
283 /*******************************************************************************\r
284 * Function Name  : TIM_CounterConfig\r
285 * Description    : This routine is used to start/stop and clear the selected\r
286 *                  timer counter\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
292 * Output         : None\r
293 *******************************************************************************/\r
294 void TIM_CounterConfig ( TIM_TypeDef *TIMx, TIM_CounterOperations Xoperation );\r
295 \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
302 * Output         : None\r
303 *******************************************************************************/\r
304 inline void TIM_ITConfig ( TIM_TypeDef *TIMx, u16 New_IT, FunctionalState NewState )\r
305 {\r
306         if (NewState == ENABLE) TIMx->CR2 |= New_IT; else TIMx->CR2 &= ~New_IT;\r
307 }\r
308 \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
317 {\r
318         return (TIMx->SR & Xflag) == 0 ? RESET : SET;\r
319 }\r
320 \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
326 * Output         : None\r
327 *******************************************************************************/\r
328 inline void TIM_FlagClear ( TIM_TypeDef *TIMx, TIM_Flags Xflag )\r
329 {\r
330         TIMx->SR &= ~Xflag;\r
331 }\r
332 \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
340 {\r
341         return TIMx->CNTR;\r
342 }\r
343 #endif  // __TIM_H\r
344 \r
345 /******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/\r