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