Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
2 | * File Name : 91x_scu.c |
||
3 | * Author : MCD Application Team |
||
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
||
5 | * Description : This file provides the SCU library software 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 | ******************************************************************************** |
||
12 | * 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 |
||
14 | * 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 |
||
16 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
||
17 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
||
18 | *******************************************************************************/ |
||
19 | |||
20 | /* Includes ------------------------------------------------------------------*/ |
||
21 | #include "91x_scu.h" |
||
22 | |||
23 | /* Include of other module interface headers ---------------------------------*/ |
||
24 | /* Local includes ------------------------------------------------------------*/ |
||
25 | /* Private typedef -----------------------------------------------------------*/ |
||
26 | /* Private define ------------------------------------------------------------*/ |
||
27 | #define SCU_PLLEN 0x80000 |
||
28 | /* Private macro -------------------------------------------------------------*/ |
||
29 | /* Private variables ---------------------------------------------------------*/ |
||
30 | /* Private function prototypes -----------------------------------------------*/ |
||
31 | /* Interface functions -------------------------------------------------------*/ |
||
32 | /* Private functions ---------------------------------------------------------*/ |
||
33 | |||
34 | /******************************************************************************* |
||
35 | * Function Name : SCU_MCLKSourceConfig |
||
36 | * Description : Configures the MCLK source clock |
||
37 | * Input : MCLK_Source = SCU_MCLK_OSC, SCU_MCLK_PLL or SCU_MCLK_RTC |
||
38 | * Output : None |
||
39 | * Return : ErrorStatus: SUCCESS or ERROR |
||
40 | * Note : this function returns ERROR if trying to select the PLL as |
||
41 | * clock source while the PLL is disabled or not locked. |
||
42 | *******************************************************************************/ |
||
43 | ErrorStatus SCU_MCLKSourceConfig(u32 MCLK_Source) |
||
44 | { |
||
45 | u32 CLKCNTR_Value; |
||
46 | |||
47 | CLKCNTR_Value = SCU->CLKCNTR; /*get CLKCNTR register value*/ |
||
48 | CLKCNTR_Value &=~0x3; /*clear field MCLKSEL*/ |
||
49 | if (MCLK_Source == SCU_MCLK_PLL) /*PLL selected as clock source*/ |
||
50 | { |
||
51 | /*check if PLL enabled & locked*/ |
||
52 | if (!((SCU->PLLCONF&SCU_PLLEN)&&(SCU->SYSSTATUS&SCU_FLAG_LOCK))) |
||
53 | return ERROR; |
||
54 | } |
||
55 | else CLKCNTR_Value |=MCLK_Source; /*OSC or RTC selected as clock source*/ |
||
56 | SCU->CLKCNTR = CLKCNTR_Value; /*Update CLKCNTR register value*/ |
||
57 | return SUCCESS; |
||
58 | } |
||
59 | |||
60 | /******************************************************************************* |
||
61 | * Function Name : SCU_PLLFactorsConfig |
||
62 | * Description : Sets the PLL factors |
||
63 | * Input : PLLN, PLLM and PLLP |
||
64 | * Output : None |
||
65 | * Return : ErrorStatus: ERROR or SUCCESS |
||
66 | * Notes : -The PLL factors must respect the PLL specification requirements |
||
67 | * -The function returns ERROR if trying to change PLL |
||
68 | * factors while PLL is selected as Main Clock source (MCLK) |
||
69 | * -This function disables the PLL, to enable the PLL use |
||
70 | * function" SCU_PLLCmd(ENABLE)" after setting the PLL factors |
||
71 | ******************************************************************************/ |
||
72 | ErrorStatus SCU_PLLFactorsConfig(u8 PLLN, u8 PLLM, u8 PLLP) |
||
73 | { |
||
74 | if (SCU_PLLCmd(DISABLE)==SUCCESS) /*Disable PLL*/ |
||
75 | { |
||
76 | SCU->PLLCONF =0; /*clear PLLCONF register*/ |
||
77 | SCU->PLLCONF |=(PLLN<<8); /*update PLLN field*/ |
||
78 | SCU->PLLCONF |=PLLM; /*update PLLM field*/ |
||
79 | SCU->PLLCONF |=PLLP<<16; /*update PLLP field*/ |
||
80 | return SUCCESS; |
||
81 | } |
||
82 | return ERROR; |
||
83 | } |
||
84 | |||
85 | /******************************************************************************* |
||
86 | * Function Name : SCU_PLLCmd |
||
87 | * Description : Enable or Disable the PLL |
||
88 | * Input : NewState = ENABLE or DISABLE |
||
89 | * Output : None |
||
90 | * Return : ErrorStatus: SUCCESS or ERROR |
||
91 | * Note : -The function returns ERROR if: |
||
92 | * *trying to disable the PLL while it is selected as the MCLK |
||
93 | * *trying to enable the PLL while it is already enabled and |
||
94 | * locked |
||
95 | *******************************************************************************/ |
||
96 | ErrorStatus SCU_PLLCmd(FunctionalState NewState) |
||
97 | { |
||
98 | vu32 i; |
||
99 | if (NewState==ENABLE) |
||
100 | { |
||
101 | if (!((SCU->PLLCONF&SCU_PLLEN)&&(SCU->SYSSTATUS&SCU_FLAG_LOCK))) |
||
102 | { |
||
103 | SCU->SYSSTATUS|=SCU_FLAG_LOCK; /*clear LOCK bit*/ |
||
104 | SCU->PLLCONF |=SCU_PLLEN; /*PLL Enable*/ |
||
105 | while(!SCU->SYSSTATUS&SCU_FLAG_LOCK); /*Wait PLL to lock*/ |
||
106 | return SUCCESS; |
||
107 | } |
||
108 | else return ERROR; |
||
109 | } |
||
110 | else /*NewState = DISABLE*/ |
||
111 | { |
||
112 | if(SCU->CLKCNTR&0x3) /*check if PLL not sys CLK*/ |
||
113 | { |
||
114 | for(i=10;i>0;i--); /*delay before PLL disabling*/ |
||
115 | SCU->PLLCONF &=~SCU_PLLEN; /*PLL Disable*/ |
||
116 | return SUCCESS; |
||
117 | } |
||
118 | else return ERROR; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | /******************************************************************************* |
||
123 | * Function Name : SCU_RCLKDivisorConfig |
||
124 | * Description : Sets the RCLK divisor value |
||
125 | * Input : RCLK_Divisor |
||
126 | * Output : None |
||
127 | * Return : None |
||
128 | *******************************************************************************/ |
||
129 | void SCU_RCLKDivisorConfig(u32 RCLK_Divisor) |
||
130 | { |
||
131 | SCU->CLKCNTR &=SCU_RCLK_Div1; /*clear RCLKDIV[2:0] field*/ |
||
132 | if (RCLK_Divisor!=SCU_RCLK_Div1) |
||
133 | SCU->CLKCNTR |= RCLK_Divisor; /*update field with RCLK divisor*/ |
||
134 | } |
||
135 | |||
136 | /******************************************************************************* |
||
137 | * Function Name : SCU_HCLKDivisorConfig |
||
138 | * Description : Sets the HCLK divisor value |
||
139 | * Input : HCLK_Divisor |
||
140 | * Output : None |
||
141 | * Return : None |
||
142 | *******************************************************************************/ |
||
143 | void SCU_HCLKDivisorConfig(u32 HCLK_Divisor) |
||
144 | { |
||
145 | SCU->CLKCNTR &=SCU_HCLK_Div1; /*clear AHBDIV[1:0] field*/ |
||
146 | if (HCLK_Divisor!=SCU_HCLK_Div1) |
||
147 | SCU->CLKCNTR |= HCLK_Divisor; /*update field with HCLK divisor*/ |
||
148 | } |
||
149 | |||
150 | /******************************************************************************* |
||
151 | * Function Name : SCU_PCLKDivisorConfig |
||
152 | * Description : Sets the PCLK divisor value |
||
153 | * Input : PCLK_Divisor |
||
154 | * Output : None |
||
155 | * Return : None |
||
156 | *******************************************************************************/ |
||
157 | void SCU_PCLKDivisorConfig(u32 PCLK_Divisor) |
||
158 | { |
||
159 | SCU->CLKCNTR &=SCU_PCLK_Div1; /*clear APBDIV[1:0] field*/ |
||
160 | if (PCLK_Divisor!=SCU_PCLK_Div1) |
||
161 | SCU->CLKCNTR |= PCLK_Divisor; /*update field with PCLK Divisor*/ |
||
162 | } |
||
163 | |||
164 | /******************************************************************************* |
||
165 | * Function Name : SCU_APBPeriphClockConfig |
||
166 | * Description : Enable the clock for an APB peripheral |
||
167 | * Input : -APBPerip : APB peripherals(__RTC, __ADC ,...) |
||
168 | * -NewState : ENABLE or DISABLE |
||
169 | * Output : None |
||
170 | * Return : None |
||
171 | *******************************************************************************/ |
||
172 | void SCU_APBPeriphClockConfig(u32 APBPeriph, FunctionalState NewState) |
||
173 | { |
||
174 | if (NewState==ENABLE) /*Enable clock for APB peripheral*/ |
||
175 | SCU->PCGR1 |=APBPeriph; |
||
176 | else |
||
177 | SCU->PCGR1 &=~APBPeriph; /*Disable clock for APB peripheral*/ |
||
178 | } |
||
179 | |||
180 | /******************************************************************************* |
||
181 | * Function Name : SCU_AHBPeriphClockConfig |
||
182 | * Description : Enable the clock for an AHB peripheral |
||
183 | * Input : -AHBPerip: AHB peripherals(__USB, __DMA,...) |
||
184 | * -NewState : ENABLE or DISABLE |
||
185 | * Output : None |
||
186 | * Return : None |
||
187 | *******************************************************************************/ |
||
188 | void SCU_AHBPeriphClockConfig(u32 AHBPeriph, FunctionalState NewState) |
||
189 | { |
||
190 | if (NewState==ENABLE) /*Enable clock for AHB peripheral*/ |
||
191 | SCU->PCGRO |=AHBPeriph; |
||
192 | else |
||
193 | SCU->PCGRO &=~AHBPeriph; /*Disable clock for AHB peripheral*/ |
||
194 | } |
||
195 | |||
196 | /******************************************************************************* |
||
197 | * Function Name : SCU_APBPeriphReset |
||
198 | * Description : Assert or deassert Reset on APB peripheral |
||
199 | * Input : -APBPeriph: APB peripherals(__RTC, __ADC,...) |
||
200 | -NewState : ENABLE or DISABLE |
||
201 | * Output : None |
||
202 | * Return : None |
||
203 | *******************************************************************************/ |
||
204 | void SCU_APBPeriphReset(u32 APBPeriph, FunctionalState NewState) |
||
205 | { |
||
206 | if (NewState==DISABLE) /*APB peripheral not held in Reset*/ |
||
207 | SCU->PRR1 |=APBPeriph; |
||
208 | else |
||
209 | SCU->PRR1 &=~APBPeriph; /*APB peripheral held in Reset*/ |
||
210 | } |
||
211 | |||
212 | /******************************************************************************* |
||
213 | * Function Name : SCU_AHBPeriphReset |
||
214 | * Description : Assert or deassert Reset on AHB peripheral |
||
215 | * Input : -AHBPeriph: AHB peripherals(__USB, __DMA,...) |
||
216 | -NewState : ENABLE or DISABLE |
||
217 | * Output : None |
||
218 | * Return : None |
||
219 | *******************************************************************************/ |
||
220 | void SCU_AHBPeriphReset(u32 AHBPeriph, FunctionalState NewState) |
||
221 | { |
||
222 | if (NewState==DISABLE) |
||
223 | SCU->PRR0 |=AHBPeriph; /*AHB peripheral not held in Reset*/ |
||
224 | else |
||
225 | SCU->PRR0 &=~AHBPeriph; /*AHB peripheral held in Reset*/ |
||
226 | } |
||
227 | |||
228 | /******************************************************************************* |
||
229 | * Function Name : SCU_APBPeriphIdleConfig |
||
230 | * Description : Enable or Disable Periph Clock during Idle mode |
||
231 | * Input : -APBPeriph: APB peripherals(__RTC, __ADC,...) |
||
232 | -NewState : ENABLE or DISABLE |
||
233 | * Output : None |
||
234 | * Return : None |
||
235 | *******************************************************************************/ |
||
236 | void SCU_APBPeriphIdleConfig(u32 APBPeriph, FunctionalState NewState) |
||
237 | { |
||
238 | if (NewState==ENABLE) |
||
239 | SCU->MGR1 |=APBPeriph; /*APB peripheral clock enabled during Idle mode*/ |
||
240 | else |
||
241 | SCU->MGR1 &=~APBPeriph; /*APB peripheral clock disabled during Idle mode*/ |
||
242 | } |
||
243 | |||
244 | /******************************************************************************* |
||
245 | * Function Name : SCU_AHBPeriphIdleConfig |
||
246 | * Description : Enable or Disable Periph Clock during Idle mode |
||
247 | * Input : -AHBPeriph: AHB peripherals(__USB, __DMA,...) |
||
248 | -NewState : ENABLE or DISABLE |
||
249 | * Output : None |
||
250 | * Return : None |
||
251 | *******************************************************************************/ |
||
252 | void SCU_AHBPeriphIdleConfig(u32 AHBPeriph, FunctionalState NewState) |
||
253 | { |
||
254 | if (NewState==ENABLE) |
||
255 | SCU->MGR0 |=AHBPeriph; /*AHB peripheral clock enabled during Idle mode*/ |
||
256 | else |
||
257 | SCU->MGR0 &=~AHBPeriph; /*AHB peripheral clock disabled during Idle mode*/ |
||
258 | } |
||
259 | |||
260 | /******************************************************************************* |
||
261 | * Function Name : SCU_APBPeriphDebugConfig |
||
262 | * Description : Enable or Disable Periph Clock during ARM debug state |
||
263 | * Input : -APBPeriph: APB peripherals(__RTC, __ADC,...) |
||
264 | -NewState : ENABLE or DISABLE |
||
265 | * Output : None |
||
266 | * Return : None |
||
267 | *******************************************************************************/ |
||
268 | void SCU_APBPeriphDebugConfig(u32 APBPeriph, FunctionalState NewState) |
||
269 | { |
||
270 | if (NewState==ENABLE) |
||
271 | SCU->PECGR1 |=APBPeriph; /*APB peripheral clock enabled during ARM debug state*/ |
||
272 | else |
||
273 | SCU->PECGR1 &=~APBPeriph; /*APB peripheral clock disabled during ARM debug state*/ |
||
274 | } |
||
275 | |||
276 | /******************************************************************************* |
||
277 | * Function Name : SCU_AHBPeriphDebugConfig |
||
278 | * Description : Enable or Disable Periph Clock during ARM debug state |
||
279 | * Input : -AHBPeriph: AHB peripherals(__USB, __DMA,...) |
||
280 | -NewState : ENABLE or DISABLE |
||
281 | * Output : None |
||
282 | * Return : None |
||
283 | *******************************************************************************/ |
||
284 | void SCU_AHBPeriphDebugConfig(u32 AHBPeriph, FunctionalState NewState) |
||
285 | { |
||
286 | if (NewState==ENABLE) |
||
287 | SCU->PECGR0 |=AHBPeriph; /*AHB peripheral clock enabled during ARM debug state*/ |
||
288 | else |
||
289 | SCU->PECGR0 &=~AHBPeriph; /*AHB peripheral clock disabled during ARM debug state*/ |
||
290 | } |
||
291 | /******************************************************************************* |
||
292 | * Function Name : SCU_BRCLKDivisorConfig |
||
293 | * Description : Sets the BRCLK divisor value |
||
294 | * Input : BRCLK_Divisor |
||
295 | * Output : None |
||
296 | * Return : None |
||
297 | *******************************************************************************/ |
||
298 | void SCU_BRCLKDivisorConfig(u32 BRCLK_Divisor) |
||
299 | { |
||
300 | SCU->CLKCNTR &=SCU_BRCLK_Div2; /*Clear BRSEL bit*/ |
||
301 | if (BRCLK_Divisor==SCU_BRCLK_Div1) |
||
302 | SCU->CLKCNTR |= SCU_BRCLK_Div1; /*set bit BRSEL*/ |
||
303 | } |
||
304 | |||
305 | /******************************************************************************* |
||
306 | * Function Name : SCU_TIMCLKSourceConfig |
||
307 | * Description : Sets the TIMx clock source |
||
308 | * Input : - TIMx : SCU_TIM01 or SCU_TIM23 |
||
309 | * - TIMCLK_Source = SCU_TIMCLK_EXT or SCU_TIMCLK_INT |
||
310 | * Output : None |
||
311 | * Return : None |
||
312 | *******************************************************************************/ |
||
313 | void SCU_TIMCLKSourceConfig(u8 TIMx, u32 TIMCLK_Source) |
||
314 | { |
||
315 | if (TIMx== SCU_TIM01) /*TIM01 clock source configuration*/ |
||
316 | { |
||
317 | SCU->CLKCNTR &=0xFFFFDFFF; |
||
318 | if (TIMCLK_Source == SCU_TIMCLK_EXT) |
||
319 | SCU->CLKCNTR |=0x2000; |
||
320 | } |
||
321 | else |
||
322 | { |
||
323 | SCU->CLKCNTR &=0xFFFFBFFF; /*TIM23 clock source configuration*/ |
||
324 | if (TIMCLK_Source == SCU_TIMCLK_EXT) |
||
325 | SCU->CLKCNTR |=0x4000; |
||
326 | } |
||
327 | } |
||
328 | |||
329 | /******************************************************************************* |
||
330 | * Function Name : SCU_TIMPresConfig |
||
331 | * Description : Sets the TIMx Prescaler Value |
||
332 | * Input : - TIMx : SCU_TIM01 or SCU_TIM23 |
||
333 | * - Prescaler (16 bit value) |
||
334 | * Output : None |
||
335 | * Return : None |
||
336 | *******************************************************************************/ |
||
337 | void SCU_TIMPresConfig(u8 TIMx, u16 Prescaler) |
||
338 | { |
||
339 | if (TIMx==SCU_TIM01) /*TIM01 Prescaler configuration*/ |
||
340 | SCU->SCR1 = Prescaler&0xFFFF; |
||
341 | else |
||
342 | SCU->SCR2 = Prescaler&0xFFFF; /*TIM23 Prescaler configuration*/ |
||
343 | } |
||
344 | |||
345 | /******************************************************************************* |
||
346 | * Function Name : SCU_USBCLKConfig |
||
347 | * Description : Configures the clock source for the 48MHz USBCLK |
||
348 | * Input : USBCLK_Source: SCU_USBCLK_MCLK,SCU_USBCLK_MCLK2 or SCU_USBCLK_EXT |
||
349 | * Output : None |
||
350 | * Return : None |
||
351 | *******************************************************************************/ |
||
352 | void SCU_USBCLKConfig(u32 USBCLK_Source) |
||
353 | { |
||
354 | SCU->CLKCNTR &=SCU_USBCLK_MCLK; /*clear USBSEL[1:0] field*/ |
||
355 | if (USBCLK_Source!=SCU_USBCLK_MCLK) |
||
356 | SCU->CLKCNTR |= USBCLK_Source; /*update field with USBCLK_Source*/ |
||
357 | } |
||
358 | |||
359 | /******************************************************************************* |
||
360 | * Function Name : SCU_PHYCLKConfig |
||
361 | * Description : Enable or Disable PHY clock output |
||
362 | * Input : NewState : ENABLE or DISABLE |
||
363 | * Output : None |
||
364 | * Return : None |
||
365 | *******************************************************************************/ |
||
366 | void SCU_PHYCLKConfig(FunctionalState NewState) |
||
367 | { |
||
368 | if (NewState==ENABLE) |
||
369 | SCU->CLKCNTR |= 0x1000; /*enable MIIPHY clock*/ |
||
370 | else |
||
371 | SCU->CLKCNTR &=~0x1000; /*disable MIIPHY clock*/ |
||
372 | } |
||
373 | |||
374 | /******************************************************************************* |
||
375 | * Function Name : SCU_FMICLKDivisorConfig |
||
376 | * Description : Set the FMI clock divisor |
||
377 | * Input : FMICLK_Divisor: SCU_FMICLK_Div1 or SCU_FMICLK_DIV2 |
||
378 | * Output : None |
||
379 | * Return : None |
||
380 | *******************************************************************************/ |
||
381 | void SCU_FMICLKDivisorConfig(u32 FMICLK_Divisor) |
||
382 | { |
||
383 | SCU->CLKCNTR &=SCU_FMICLK_Div1; /*FMICLK = RCLK*/ |
||
384 | if (FMICLK_Divisor!=SCU_FMICLK_Div1) |
||
385 | SCU->CLKCNTR |=SCU_FMICLK_Div2; /*FMICLK = RCLK/2 */ |
||
386 | } |
||
387 | |||
388 | /******************************************************************************* |
||
389 | * Function Name : SCU_EMIBCLKDivisorConfig |
||
390 | * Description : Set the EMI Bus clock divisor: EMIBCLK = HCLK or HCLK/2 |
||
391 | * Input : SCU_EMICLK: SCU_EMIBCLK_Div1 , SCU_EMIBCLK_Div2 |
||
392 | * Output : None |
||
393 | * Return : None |
||
394 | *******************************************************************************/ |
||
395 | void SCU_EMIBCLKDivisorConfig(u32 SCU_EMIBCLK) |
||
396 | { |
||
397 | SCU->CLKCNTR &=SCU_EMIBCLK_Div1; /*EMIBCLK = HCLK */ |
||
398 | if (SCU_EMIBCLK!=SCU_EMIBCLK_Div1) |
||
399 | SCU->CLKCNTR |= SCU_EMIBCLK_Div2; /*EMIBCLK = HCLK/2 */ |
||
400 | } |
||
401 | |||
402 | /******************************************************************************* |
||
403 | * Function Name : SCU_EMIModeConfig |
||
404 | * Description : Configure the EMI as Multiplexed or Demultiplexed |
||
405 | * Input : SCU_EMIMODE : SCU_EMI_MUX or SCU_EMI_DEMUX |
||
406 | * Output : None |
||
407 | * Return : None |
||
408 | *******************************************************************************/ |
||
409 | void SCU_EMIModeConfig(u32 SCU_EMIMODE) |
||
410 | { |
||
411 | SCU->SCR0 &=SCU_EMI_MUX; /*EMI mode = Multiplexed*/ |
||
412 | if (SCU_EMIMODE!=SCU_EMI_MUX) |
||
413 | SCU->SCR0 |= SCU_EMI_DEMUX; /*EMI mode = Demultiplexed*/ |
||
414 | } |
||
415 | |||
416 | /******************************************************************************* |
||
417 | * Function Name : SCU_EMIALEConfig |
||
418 | * Description : Configure the ALE signal (length & polarity) |
||
419 | * Input : -SCU_EMIALE_LEN : SCU_EMIALE_LEN1 or SCU_EMIALE_LEN2 |
||
420 | * -SCU_EMIALE_POL : SCU_EMIALE_POLLow or SCU_EMI_POLHigh |
||
421 | * Output : None |
||
422 | * Return : None |
||
423 | *******************************************************************************/ |
||
424 | void SCU_EMIALEConfig(u32 SCU_EMIALE_LEN, u32 SCU_EMIALE_POL) |
||
425 | { |
||
426 | /*Configure EMI ALE Length*/ |
||
427 | SCU->SCR0 &=SCU_EMIALE_LEN1; |
||
428 | if (SCU_EMIALE_LEN!=SCU_EMIALE_LEN1) |
||
429 | SCU->SCR0 |= SCU_EMIALE_LEN2; |
||
430 | |||
431 | /*Configure EMI ALE POL*/ |
||
432 | SCU->SCR0 &=SCU_EMIALE_POLLow; |
||
433 | if (SCU_EMIALE_POL!=SCU_EMIALE_POLLow) |
||
434 | SCU->SCR0 |= SCU_EMIALE_POLHigh; |
||
435 | } |
||
436 | |||
437 | /******************************************************************************* |
||
438 | * Function Name : SCU_ITConfig |
||
439 | * Description : ENBALE or DISABLE an SCU interrupt |
||
440 | * Input : -SCU_IT: interrupt mask |
||
441 | * -NewState: ENABLE or DISABLE |
||
442 | * Output : None |
||
443 | * Return : None |
||
444 | *******************************************************************************/ |
||
445 | void SCU_ITConfig(u32 SCU_IT, FunctionalState NewState) |
||
446 | { |
||
447 | if (NewState==ENABLE) |
||
448 | SCU->ITCMSK&=~SCU_IT; /*IT enable */ |
||
449 | else |
||
450 | SCU->ITCMSK|=SCU_IT; /*IT disable( mask)*/ |
||
451 | } |
||
452 | |||
453 | /******************************************************************************* |
||
454 | * Function Name : SCU_GetFlagStatus |
||
455 | * Description : Returns flag status |
||
456 | * Input : SCU_Flag |
||
457 | * Output : NONE |
||
458 | * Return : SET or RESET |
||
459 | *******************************************************************************/ |
||
460 | FlagStatus SCU_GetFlagStatus(u32 SCU_Flag) |
||
461 | { |
||
462 | if (SCU->SYSSTATUS&SCU_Flag) |
||
463 | return SET; |
||
464 | else return RESET; |
||
465 | } |
||
466 | |||
467 | /******************************************************************************* |
||
468 | * Function Name : SCU_ClearFlag |
||
469 | * Description : Clears a SYSTATUS Flag |
||
470 | * Input : SCU_Flag |
||
471 | * Output : None |
||
472 | * Return : None |
||
473 | *******************************************************************************/ |
||
474 | void SCU_ClearFlag(u32 SCU_Flag) |
||
475 | { |
||
476 | SCU->SYSSTATUS = SCU_Flag; |
||
477 | } |
||
478 | /******************************************************************************* |
||
479 | * Function Name : SCU_GetPLLfreqValue |
||
480 | * Description : Gets the current PLL frequency |
||
481 | * Input : None |
||
482 | * Output : None |
||
483 | * Return : PLL frequency (KHz) |
||
484 | *******************************************************************************/ |
||
485 | u32 SCU_GetPLLFreqValue(void) |
||
486 | { |
||
487 | u8 PLL_M; |
||
488 | u8 PLL_N; |
||
489 | u8 PLL_P; |
||
490 | |||
491 | PLL_M = SCU->PLLCONF&0xFF; |
||
492 | PLL_N = (SCU->PLLCONF&0xFF00)>>8; |
||
493 | PLL_P = (SCU->PLLCONF&0x70000)>>16; |
||
494 | |||
495 | if ((PLL_M>0)&&(PLL_N>0)) |
||
496 | return (u32)(((_Main_Crystal*2)*PLL_N)/(PLL_M<<PLL_P)); |
||
497 | |||
498 | else return 0; |
||
499 | } |
||
500 | /******************************************************************************* |
||
501 | * Function Name : SCU_GetMCLKFreqValue |
||
502 | * Description : Gets the current MCLK frequency |
||
503 | * Input : None |
||
504 | * Output : None |
||
505 | * Return : MCLK frequency (KHz) |
||
506 | *******************************************************************************/ |
||
507 | u32 SCU_GetMCLKFreqValue(void) |
||
508 | { |
||
509 | if ((SCU->CLKCNTR&0x3) == 0x2) return (u32)(_Main_Crystal); |
||
510 | if ((SCU->CLKCNTR&0x3) == 0x1) return (u32)(32); |
||
511 | else return (SCU_GetPLLFreqValue()); |
||
512 | } |
||
513 | |||
514 | /******************************************************************************* |
||
515 | * Function Name : SCU_GetRCLKFreqValue |
||
516 | * Description : Gets the current RCLK frequency |
||
517 | * Input : None |
||
518 | * Output : None |
||
519 | * Return : RCLK frequency (KHz) |
||
520 | *******************************************************************************/ |
||
521 | u32 SCU_GetRCLKFreqValue(void) |
||
522 | { |
||
523 | u8 RCLK_Div; |
||
524 | RCLK_Div = (SCU->CLKCNTR&0x1C)>>2; |
||
525 | if (RCLK_Div==0x5) RCLK_Div=10; |
||
526 | return (u32)(SCU_GetMCLKFreqValue() >>RCLK_Div); |
||
527 | } |
||
528 | |||
529 | /******************************************************************************* |
||
530 | * Function Name : SCU_GetHCLKFreqValue |
||
531 | * Description : Gets the current PCLK frequency |
||
532 | * Input : None |
||
533 | * Output : None |
||
534 | * Return : HCLK frequency (KHz) |
||
535 | *******************************************************************************/ |
||
536 | u32 SCU_GetHCLKFreqValue(void) |
||
537 | { |
||
538 | u8 HCLK_Div; |
||
539 | HCLK_Div = (SCU->CLKCNTR&0x60)>>5; |
||
540 | return (u32)(SCU_GetRCLKFreqValue() >>HCLK_Div); |
||
541 | } |
||
542 | |||
543 | /******************************************************************************* |
||
544 | * Function Name : SCU_GetPCLKFreqValue |
||
545 | * Description : Gets the current HCLK frequency |
||
546 | * Input : None |
||
547 | * Output : None |
||
548 | * Return : PCLK frequency (KHz) |
||
549 | *******************************************************************************/ |
||
550 | u32 SCU_GetPCLKFreqValue(void) |
||
551 | { |
||
552 | u8 PCLK_Div; |
||
553 | PCLK_Div = (SCU->CLKCNTR&0x180)>>7; |
||
554 | return (u32)(SCU_GetRCLKFreqValue() >>PCLK_Div); |
||
555 | } |
||
556 | |||
557 | /******************************************************************************* |
||
558 | * Function Name : SCU_WakeUpLineConfig |
||
559 | * Description : Configures an External interrupt as WakeUp line |
||
560 | * Input : EXTint : 0 -> 31 |
||
561 | * Output : None |
||
562 | * Return : None |
||
563 | *******************************************************************************/ |
||
564 | void SCU_WakeUpLineConfig(u8 EXTint) |
||
565 | { |
||
566 | if (EXTint < 8) |
||
567 | { |
||
568 | SCU->WKUPSEL&=~0x7; |
||
569 | SCU->WKUPSEL|=EXTint; |
||
570 | } |
||
571 | else if (EXTint<16) |
||
572 | { |
||
573 | SCU->WKUPSEL&=~0x38; |
||
574 | SCU->WKUPSEL|=(EXTint-8)<<3; |
||
575 | } |
||
576 | else if (EXTint<24) |
||
577 | { |
||
578 | SCU->WKUPSEL&=~0x1C0; |
||
579 | SCU->WKUPSEL|=(EXTint-16)<<6; |
||
580 | } |
||
581 | else |
||
582 | { |
||
583 | SCU->WKUPSEL&=~0xE00; |
||
584 | SCU->WKUPSEL|=(EXTint-24)<<9; |
||
585 | } |
||
586 | } |
||
587 | |||
588 | /******************************************************************************* |
||
589 | * Function Name : SCU_SpecIntRunModeConfig |
||
590 | * Description : Enables or Disables the Special Run mode |
||
591 | * Input : newstate = ENABLE or DISABLE |
||
592 | * Output : None |
||
593 | * Return : None |
||
594 | *******************************************************************************/ |
||
595 | void SCU_SpecIntRunModeConfig(FunctionalState NewState) |
||
596 | { |
||
597 | if (NewState == ENABLE) |
||
598 | SCU->PWRMNG |=0x8; |
||
599 | else |
||
600 | SCU->PWRMNG &=~0x8; |
||
601 | } |
||
602 | /******************************************************************************* |
||
603 | * Function Name : SCU_EnterIdleMode |
||
604 | * Description : Enters in Idle mode |
||
605 | * Input : None |
||
606 | * Output : None |
||
607 | * Return : None |
||
608 | *******************************************************************************/ |
||
609 | void SCU_EnterIdleMode(void) |
||
610 | { |
||
611 | SCU->PWRMNG |=0x1; |
||
612 | } |
||
613 | /******************************************************************************* |
||
614 | * Function Name : SCU_EnterSleepMode |
||
615 | * Description : Enters in Sleep mode |
||
616 | * Input : None |
||
617 | * Output : None |
||
618 | * Return : None |
||
619 | *******************************************************************************/ |
||
620 | void SCU_EnterSleepMode(void) |
||
621 | { |
||
622 | SCU->PWRMNG |=0x2; |
||
623 | } |
||
624 | |||
625 | /******************************************************************************* |
||
626 | * Function Name : SCU_UARTIrDAConfig |
||
627 | * Description : Enable or Disable the Irda mode for UARTx |
||
628 | * Input : - SCU_UARTx :x=0,1 or 2 |
||
629 | * - UART_IrDA_Mode : SCU_UARTMode_IrDA or SCU_UARTMode_UART |
||
630 | * Output : None |
||
631 | * Return : None |
||
632 | *******************************************************************************/ |
||
633 | void SCU_UARTIrDASelect(u8 SCU_UARTx, u8 UART_IrDA_Mode) |
||
634 | { |
||
635 | if (UART_IrDA_Mode == SCU_UARTMode_IrDA) |
||
636 | { |
||
637 | if (SCU_UARTx== SCU_UART0) SCU->SCR0 |=0x400; |
||
638 | else if (SCU_UARTx== SCU_UART1) SCU->SCR0 |=0x800; |
||
639 | else SCU->SCR0 |=0x1000; |
||
640 | } |
||
641 | else |
||
642 | { |
||
643 | if (SCU_UARTx== SCU_UART0) SCU->SCR0 &=~0x400; |
||
644 | else if (SCU_UARTx== SCU_UART1) SCU->SCR0 &=~0x800; |
||
645 | else SCU->SCR0 &=~0x1000; |
||
646 | } |
||
647 | } |
||
648 | /******************************************************************************* |
||
649 | * Function Name : SCU_PFQBCCmd |
||
650 | * Description : Enable or Disable PFQBC |
||
651 | * Input : NewState : ENABLE or DISABLE |
||
652 | * Output : None |
||
653 | * Return : None |
||
654 | *******************************************************************************/ |
||
655 | void SCU_PFQBCCmd(FunctionalState NewState) |
||
656 | { |
||
657 | if (NewState==ENABLE) |
||
658 | SCU->SCR0 |=0x1; |
||
659 | else SCU->SCR0 &=~0x1; |
||
660 | } |
||
661 | |||
662 | /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/ |