PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
usbethernetclock.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
63 #include "usbethernetclock.h"
64 
70 
71 /*****************************************************************************/
72 /* Static variable declarations ('static', definition in C source) */
73 /*****************************************************************************/
74 
76 
77 /*****************************************************************************/
78 /* Global function ('extern', definition in C source) */
79 /*****************************************************************************/
80 
87 {
89  {
90  return;
91  }
92  /* Initialize default settings */
93  #if defined(FM_USBCLK)
94  /* Clear USB/Ethernet Clock Setting Register */
95  FM_USBCLK->UCCR = 0;
96 
97  /* Disable USB Clock */
98  bFM_USBCLK_USBEN_USBEN = 0;
99 
100  /* PLL Disable */
101  FM_USBCLK->UPCR1 = 0x00;
102 
103  #elif defined(FM_USBETHERNETCLK)
104  /* Clear USB/Ethernet Clock Setting Register */
105  FM_USBETHERNETCLK->UCCR = 0;
106 
107  /* Disable Ethernet PLL */
108  bFM_USBETHERNETCLK_UPCR7_EPLLEN = 0;
109 
110  /* Disable USB PLL */
111  bFM_USBETHERNETCLK_UPCR1_UPLLEN = 0;
112 
113  /* Disable USB Clock 0 */
114  #if defined(bFM_USBCLK_USBEN0_USBEN)
115  bFM_USBCLK_USBEN0_USBEN = 0;
116  #elif defined(bFM_USBETHERNETCLK_UCCR_UCEN0)
117  bFM_USBETHERNETCLK_UCCR_UCEN0 = 0;
118  #else
119  #error No bit definition for UCCR -> UCEN0
120  #endif
121 
122  /* Disable USB Clock 1 */
123  #if defined(bFM_USBCLK_USBEN1_USBEN)
124  bFM_USBCLK_USBEN1_USBEN = 0;
125  #elif defined(bFM_USBETHERNETCLK_UCCR_UCEN1)
126  bFM_USBETHERNETCLK_UCCR_UCEN0 = 0;
127  #else
128  #error No bit definition for UCCR -> UCEN1
129  #endif
130 
131 
132  /* PLL Disable */
133  FM_USBETHERNETCLK->UPCR1 = 0x00;
134  #else
135  #error Incorrect USB/Ethernet clock module
136  #endif
137  /* End of Initialize default settings */
138 
139  #ifndef USBETHERNETCLOCK_UCSEL
140  #define USBETHERNETCLOCK_UCSEL 0x00
141  #endif
142 
143  #ifndef USBETHERNETCLOCK_ECSEL
144  #define USBETHERNETCLOCK_ECSEL 0x00
145  #endif
146 
147  /* Check Clock Settings */
148  #if USBETHERNETCLOCK_PLL_K > 63
149  #error USB ETHERNET CLOCK: (K - 1) must be < 64
150  #endif
151 
152  #if ((FM3MCUTYPE == FM3MCUTYPE_TYPE6) || (FM3MCUTYPE == FM3MCUTYPE_TYPE0))
153  #if USBETHERNETCLOCK_PLL_N == 0
154  #error USB ETHERNET CLOCK: (N - 1) can't be 0
155  #endif
156  #if USBETHERNETCLOCK_PLL_N > 63
157  #error USB ETHERNET CLOCK: (N - 1) can't be > 63
158  #endif
159  #endif
160  #if ((FM3MCUTYPE == FM3MCUTYPE_TYPE1) || (FM3MCUTYPE == FM3MCUTYPE_TYPE4) || (FM3MCUTYPE == FM3MCUTYPE_TYPE5))
161  #if USBETHERNETCLOCK_PLL_N < 13
162  #error USB ETHERNET CLOCK: (N - 1) must be > 12
163  #endif
164  #if USBETHERNETCLOCK_PLL_N > 99
165  #error USB ETHERNET CLOCK: (N - 1) can't be > 99
166  #endif
167  #endif
168 
169  #if ((FM3MCUTYPE == FM3MCUTYPE_TYPE1) || (FM3MCUTYPE == FM3MCUTYPE_TYPE4) || (FM3MCUTYPE == FM3MCUTYPE_TYPE5))
170  #if USBETHERNETCLOCK_PLL_M > 15
171  #error USB ETHERNET CLOCK: (M - 1) can't be > 15
172  #endif
173  #endif
174 
175  #if ((FM3MCUTYPE == FM3MCUTYPE_TYPE6))
176  #if USBETHERNETCLOCK_PLL_M > 15
177  #error USB ETHERNET CLOCK: (M - 1) can't be > 15
178  #endif
179  #endif
180  /* End Check Clock Settings */
181 
182 
183  /* Setup PLL */
184  #if defined(FM_USBETHERNETCLK)
185  /* PLL Disable */
186  FM3_USBETHERNETCLK->UPCR1 = 0x00;
187 
188  /* wait 1ms */
189  FM3_USBETHERNETCLK->UPCR2 = 0x03;
190 
191  #ifdef USBETHERNETCLOCK_PLL_K
192  FM3_USBETHERNETCLK->UPCR3 = USBETHERNETCLOCK_PLL_K - 1;
193  #endif
194  #ifdef USBETHERNETCLOCK_PLL_K
195  FM3_USBETHERNETCLK->UPCR4 = USBETHERNETCLOCK_PLL_N - 1;
196  #endif
197  #ifdef USBETHERNETCLOCK_PLL_M
198  FM3_USBETHERNETCLK->UPCR5 = USBETHERNETCLOCK_PLL_M - 1;
199  #endif
200  #elif defined(FM_USBCLK)
201  /* PLL Disable */
202  FM_USBCLK->UPCR1 = 0x00;
203  /* wait 1ms */
204  FM_USBCLK->UPCR2 = 0x03;
205  #ifdef USBETHERNETCLOCK_PLL_K
206  FM_USBCLK->UPCR3 = USBETHERNETCLOCK_PLL_K - 1;
207  #endif
208  #ifdef USBETHERNETCLOCK_PLL_K
209  FM_USBCLK->UPCR4 = USBETHERNETCLOCK_PLL_N - 1;
210  #endif
211  #ifdef USBETHERNETCLOCK_PLL_M
212  FM_USBCLK->UPCR5 = USBETHERNETCLOCK_PLL_M - 1;
213  #endif
214  #else
215  #error Incorrect USB/Ethernet clock module
216  #endif
217  /* End Setup PLL */
218 
219 
220  /* Enable PLL and wait PLL gets ready */
221  #if defined(FM_USBCLK)
222  /* Enable USB Part of PLL */
223  bFM_USBCLK_UPCR1_UPLLEN = 1;
224 
225  /* Wait PLL gets ready */
226  while(bFM_USBCLK_UP_STR_UPRDY == 0);
227 
228  /* Select USB clock source */
229  FM_USBCLK->UCCR = 0x01 | (USBETHERNETCLOCK_UCSEL << 1);
230 
231  /* Enable USB */
232  bFM_USBCLK_USBEN_USBEN = 1;
233  #elif defined(FM_USBETHERNETCLK)
234  #if defined(USBETHERNETCLOCK_UBSR)
235  FM_USBETHERNETCLK->UPCR6 = (USBETHERNETCLOCK_UBSR & 0x0F);
236  #endif
237 
238 
239  /* Enable USB Part of PLL */
240  bFM_USBETHERNETCLK_UPCR1_UPLLEN = 1;
241 
242  /* Enable Ethernet Part of PLL */
243  bFM_USBETHERNETCLK_UPCR7_EPLLEN = 1;
244 
245 
246  /* Wait PLL gets ready */
247  while(bFM_USBETHERNETCLK_UP_STR_UPRDY == 0);
248 
249  #if ((L3_PERIPHERAL_ENABLE_EMAC0 == L3_ON) || (L3_PERIPHERAL_ENABLE_EMAC1 == L3_ON))
250  FM_USBETHERNETCLK->UCCR |= (USBETHERNETCLOCK_UCSEL << 1) | (USBETHERNETCLOCK_ECSEL << 5);
251 
252 
253  bFM_USBETHERNETCLK_UCCR_ECEN = 1;
254  #endif
255 
256  #if ((FM_PERIPHERAL_ENABLE_USB0 == ON) && (defined(USB0)))
257  FM_USBETHERNETCLK->UCCR |= (USBETHERNETCLOCK_UCSEL << 1) | (USBETHERNETCLOCK_ECSEL << 5);
258 
259  #ifdef bFM_USBETHERNETCLK_UCCR_UCEN0
260  bFM_USBETHERNETCLK_UCCR_UCEN0 = 1;
261  #endif
262 
263 
264  #ifdef bFM_USBCLK_USBEN0_USBEN
265  bFM_USBCLK_USBEN0_USBEN = 1;
266  #endif
267  #ifdef bFM_USBETHERNETCLK_USBEN0_USBEN0
268  bFM_USBETHERNETCLK_USBEN0_USBEN0 = 1;
269  #endif
270  #endif
271  #if ((FM_PERIPHERAL_ENABLE_USB1 == ON) && (defined(USB1)))
272  FM_USBETHERNETCLK->UCCR |= (USBETHERNETCLOCK_UCSEL << 1) | (USBETHERNETCLOCK_ECSEL << 5);
273 
274  #ifdef bFM_USBETHERNETCLK_UCCR_UCEN1
275  bFM_USBETHERNETCLK_UCCR_UCEN1 = 1;
276  #endif
277 
278 
279  #ifdef bFM_USBCLK_USBEN1_USBEN
280  bFM_USBCLK_USBEN1_USBEN = 1;
281  #endif
282  #ifdef bFM_USBETHERNETCLK_USBEN1_USBEN1
283  bFM_USBETHERNETCLK_USBEN1_USBEN1 = 1;
284  #endif
285  #endif
286  #else
287  #error Incorrect USB/Ethernet clock module
288  #endif
289  /* End Enable PLL and wait PLL gets ready */
290 
291  __NOP();
292  __NOP();
293  __NOP();
294  __NOP();
295  __NOP();
296 
298 }
299 
306 {
307  #if defined(FM_USBCLK)
308  FM_USBCLK->UCCR = 0;
309  bFM_USBCLK_USBEN_USBEN = 0;
310  FM_USBCLK->UPCR1 = 0x00; /* PLL Disable */
311  #elif defined(FM3_USBETHERNETCLK)
312 
313  /* Disable Ethernet PLL */
314  bFM3_USBETHERNETCLK_UPCR7_EPLLEN = 0;
315 
316  /* Disable USB PLL */
317  bFM3_USBETHERNETCLK_UPCR1_UPLLEN = 0;
318 
319  FM3_USBETHERNETCLK->UCCR = 0;
320  #ifdef bFM3_USBCLK_USBEN0_USBEN
321  bFM3_USBCLK_USBEN0_USBEN = 0;
322  #endif
323  #ifdef bFM3_USBETHERNETCLK_UCCR_UCEN0
324  bFM3_USBETHERNETCLK_UCCR_UCEN0 = 0;
325  #endif
326 
327  #ifdef bFM3_USBCLK_USBEN1_USBEN
328  bFM3_USBCLK_USBEN1_USBEN = 0;
329  #endif
330  #ifdef bFM3_USBETHERNETCLK_UCCR_UCEN1
331  bFM3_USBETHERNETCLK_UCCR_UCEN1 = 0;
332  #endif
333  FM3_USBETHERNETCLK->UPCR1 = 0x00; /* PLL Disable */
334  #else
335  #error Incorrect USB/Ethernet clock module
336  #endif
337 
338  #if defined(FM3_USBETHERNETCLK)
339  FM3_USBETHERNETCLK->UPCR1 = 0x00; /* PLL Disable */
340  #elif defined(FM_USBCLK)
341  FM_USBCLK->UPCR1 = 0x00; /* PLL Disable */
342  #else
343  #error Incorrect USB/Ethernet clock module
344  #endif
346 }
348 
349