power_clocks_lib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
  2. /*This file has been prepared for Doxygen automatic documentation generation.*/
  3. /*! \file *********************************************************************
  4. *
  5. * \brief High-level library abstracting features such as oscillators/pll/dfll
  6. * configuration, clock configuration, System-sensible parameters
  7. * configuration, buses clocks configuration, sleep mode, reset.
  8. *
  9. *
  10. * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
  11. * - Supported devices: All AVR32 devices.
  12. * - AppNote:
  13. *
  14. * \author Atmel Corporation: http://www.atmel.com \n
  15. * Support and FAQ: http://support.atmel.no/
  16. *
  17. *****************************************************************************/
  18. /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. *
  23. * 1. Redistributions of source code must retain the above copyright notice, this
  24. * list of conditions and the following disclaimer.
  25. *
  26. * 2. Redistributions in binary form must reproduce the above copyright notice,
  27. * this list of conditions and the following disclaimer in the documentation
  28. * and/or other materials provided with the distribution.
  29. *
  30. * 3. The name of Atmel may not be used to endorse or promote products derived
  31. * from this software without specific prior written permission.
  32. *
  33. * 4. This software may only be redistributed and used in connection with an Atmel
  34. * AVR product.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  38. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  39. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  40. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  41. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  45. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  46. *
  47. */
  48. #include "power_clocks_lib.h"
  49. //! Device-specific data
  50. #if UC3L
  51. static long int pcl_configure_clocks_uc3l(pcl_freq_param_t *param); // FORWARD declaration
  52. #endif
  53. #if UC3C
  54. static long int pcl_configure_clocks_uc3c(pcl_freq_param_t *param); // FORWARD declaration
  55. #endif
  56. long int pcl_configure_clocks(pcl_freq_param_t *param)
  57. {
  58. #ifndef AVR32_PM_VERSION_RESETVALUE
  59. // Implementation for UC3A, UC3A3, UC3B parts.
  60. return(pm_configure_clocks(param));
  61. #else
  62. #ifdef AVR32_PM_410_H_INCLUDED
  63. // Implementation for UC3C parts.
  64. return(pcl_configure_clocks_uc3c(param));
  65. #else
  66. // Implementation for UC3L parts.
  67. return(pcl_configure_clocks_uc3l(param));
  68. #endif
  69. #endif
  70. }
  71. //! Device-specific implementation
  72. #if UC3L
  73. // FORWARD declaration
  74. static long int pcl_configure_synchronous_clocks( pm_clk_src_t main_clk_src,
  75. unsigned long main_clock_freq_hz,
  76. pcl_freq_param_t *param);
  77. long int pcl_configure_clocks_rcsys(pcl_freq_param_t *param)
  78. {
  79. // Supported main clock sources: PCL_MC_RCSYS
  80. // Supported synchronous clocks frequencies if RCSYS is the main clock source:
  81. // 115200Hz, 57600Hz, 28800Hz, 14400Hz, 7200Hz, 3600Hz, 1800Hz, 900Hz, 450Hz.
  82. // NOTE: by default, this implementation doesn't perform thorough checks on the
  83. // input parameters. To enable the checks, define AVR32SFW_INPUT_CHECK.
  84. #ifdef AVR32SFW_INPUT_CHECK
  85. // Verify that fCPU >= fPBx
  86. if((param->cpu_f < param->pba_f) || (param->cpu_f < param->pbb_f))
  87. return(-1);
  88. #endif
  89. #ifdef AVR32SFW_INPUT_CHECK
  90. // Verify that the target frequencies are reachable.
  91. if((param->cpu_f > SCIF_SLOWCLOCK_FREQ_HZ) || (param->pba_f > SCIF_SLOWCLOCK_FREQ_HZ)
  92. || (param->pbb_f > SCIF_SLOWCLOCK_FREQ_HZ))
  93. return(-1);
  94. #endif
  95. return(pcl_configure_synchronous_clocks(PM_CLK_SRC_SLOW, SCIF_SLOWCLOCK_FREQ_HZ, param));
  96. }
  97. long int pcl_configure_clocks_rc120m(pcl_freq_param_t *param)
  98. {
  99. // Supported main clock sources: PCL_MC_RC120M
  100. // Supported synchronous clocks frequencies if RC120M is the main clock source:
  101. // 30MHz, 15MHz, 7.5MHz, 3.75MHz, 1.875MHz, 937.5kHz, 468.75kHz.
  102. // NOTE: by default, this implementation doesn't perform thorough checks on the
  103. // input parameters. To enable the checks, define AVR32SFW_INPUT_CHECK.
  104. #ifdef AVR32SFW_INPUT_CHECK
  105. // Verify that fCPU >= fPBx
  106. if((param->cpu_f < param->pba_f) || (param->cpu_f < param->pbb_f))
  107. return(-1);
  108. #endif
  109. #ifdef AVR32SFW_INPUT_CHECK
  110. // Verify that the target frequencies are reachable.
  111. if((param->cpu_f > SCIF_RC120M_FREQ_HZ) || (param->pba_f > SCIF_RC120M_FREQ_HZ)
  112. || (param->pbb_f > SCIF_RC120M_FREQ_HZ))
  113. return(-1);
  114. #endif
  115. // Start the 120MHz internal RCosc (RC120M) clock
  116. scif_start_rc120M();
  117. return(pcl_configure_synchronous_clocks(PM_CLK_SRC_RC120M, SCIF_RC120M_FREQ_HZ, param));
  118. }
  119. long int pcl_configure_clocks_osc0(pcl_freq_param_t *param)
  120. {
  121. // Supported main clock sources: PCL_MC_OSC0
  122. // Supported synchronous clocks frequencies if OSC0 is the main clock source:
  123. // (these obviously depend on the OSC0 frequency; we'll take 16MHz as an example)
  124. // 16MHz, 8MHz, 4MHz, 2MHz, 1MHz, 500kHz, 250kHz, 125kHz, 62.5kHz.
  125. // NOTE: by default, this implementation doesn't perform thorough checks on the
  126. // input parameters. To enable the checks, define AVR32SFW_INPUT_CHECK.
  127. unsigned long main_clock_freq;
  128. #ifdef AVR32SFW_INPUT_CHECK
  129. // Verify that fCPU >= fPBx
  130. if((param->cpu_f < param->pba_f) || (param->cpu_f < param->pbb_f))
  131. return(-1);
  132. #endif
  133. main_clock_freq = param->osc0_f;
  134. #ifdef AVR32SFW_INPUT_CHECK
  135. // Verify that the target frequencies are reachable.
  136. if((param->cpu_f > main_clock_freq) || (param->pba_f > main_clock_freq)
  137. || (param->pbb_f > main_clock_freq))
  138. return(-1);
  139. #endif
  140. // Configure OSC0 in crystal mode, external crystal with a fcrystal Hz frequency.
  141. scif_configure_osc_crystalmode(SCIF_OSC0, main_clock_freq);
  142. // Enable the OSC0
  143. scif_enable_osc(SCIF_OSC0, param->osc0_startup, true);
  144. return(pcl_configure_synchronous_clocks(PM_CLK_SRC_OSC0, main_clock_freq, param));
  145. }
  146. long int pcl_configure_clocks_dfll0(pcl_freq_param_t *param)
  147. {
  148. // Supported main clock sources: PCL_MC_DFLL
  149. // Supported synchronous clocks frequencies if DFLL is the main clock source:
  150. // (these obviously depend on the DFLL target frequency; we'll take 100MHz as an example)
  151. // 50MHz, 25MHz, 12.5MHz, 6.25MHz, 3.125MHz, 1562.5kHz, 781.25kHz, 390.625kHz.
  152. // NOTE: by default, this implementation doesn't perform thorough checks on the
  153. // input parameters. To enable the checks, define AVR32SFW_INPUT_CHECK.
  154. unsigned long main_clock_freq;
  155. scif_gclk_opt_t *pgc_dfllif_ref_opt;
  156. #ifdef AVR32SFW_INPUT_CHECK
  157. // Verify that fCPU >= fPBx
  158. if((param->cpu_f < param->pba_f) || (param->cpu_f < param->pbb_f))
  159. return(-1);
  160. #endif
  161. main_clock_freq = param->dfll_f;
  162. #ifdef AVR32SFW_INPUT_CHECK
  163. // Verify that the target DFLL output frequency is in the correct range.
  164. if((main_clock_freq > SCIF_DFLL_MAXFREQ_HZ) || (main_clock_freq < SCIF_DFLL_MINFREQ_HZ))
  165. return(-1);
  166. // Verify that the target frequencies are reachable.
  167. if((param->cpu_f > main_clock_freq) || (param->pba_f > main_clock_freq)
  168. || (param->pbb_f > main_clock_freq))
  169. return(-1);
  170. #endif
  171. pgc_dfllif_ref_opt = (scif_gclk_opt_t *)param->pextra_params;
  172. // Implementation note: this implementation configures the DFLL in closed-loop
  173. // mode (because it gives the best accuracy) which enables the generic clock CLK_DFLLIF_REF
  174. // as a reference (RCSYS being used as the generic clock source, undivided).
  175. scif_dfll0_closedloop_configure_and_start(pgc_dfllif_ref_opt, main_clock_freq, TRUE);
  176. return(pcl_configure_synchronous_clocks(PM_CLK_SRC_DFLL0, main_clock_freq, param));
  177. }
  178. static long int pcl_configure_clocks_uc3l(pcl_freq_param_t *param)
  179. {
  180. // Supported main clock sources: PCL_MC_RCSYS, PCL_MC_OSC0, PCL_MC_DFLL0, PCL_MC_RC120M
  181. // Supported synchronous clocks frequencies if RCSYS is the main clock source:
  182. // 115200Hz, 57600Hz, 28800Hz, 14400Hz, 7200Hz, 3600Hz, 1800Hz, 900Hz, 450Hz.
  183. // Supported synchronous clocks frequencies if RC120M is the main clock source:
  184. // 30MHz, 15MHz, 7.5MHz, 3.75MHz, 1.875MHz, 937.5kHz, 468.75kHz.
  185. // Supported synchronous clocks frequencies if OSC0 is the main clock source:
  186. // (these obviously depend on the OSC0 frequency; we'll take 16MHz as an example)
  187. // 16MHz, 8MHz, 4MHz, 2MHz, 1MHz, 500kHz, 250kHz, 125kHz, 62.5kHz.
  188. // Supported synchronous clocks frequencies if DFLL is the main clock source:
  189. // (these obviously depend on the DFLL target frequency; we'll take 100MHz as an example)
  190. // 50MHz, 25MHz, 12.5MHz, 6.25MHz, 3.125MHz, 1562.5kHz, 781.25kHz, 390.625kHz.
  191. // NOTE: by default, this implementation doesn't perform thorough checks on the
  192. // input parameters. To enable the checks, define AVR32SFW_INPUT_CHECK.
  193. #ifdef AVR32SFW_INPUT_CHECK
  194. // Verify that fCPU >= fPBx
  195. if((param->cpu_f < param->pba_f) || (param->cpu_f < param->pbb_f))
  196. return(-1);
  197. #endif
  198. if(PCL_MC_RCSYS == param->main_clk_src)
  199. {
  200. return(pcl_configure_clocks_rcsys(param));
  201. }
  202. else if(PCL_MC_RC120M == param->main_clk_src)
  203. {
  204. return(pcl_configure_clocks_rc120m(param));
  205. }
  206. else if(PCL_MC_OSC0 == param->main_clk_src)
  207. {
  208. return(pcl_configure_clocks_osc0(param));
  209. }
  210. else // PCL_MC_DFLL0 == param->main_clk_src
  211. {
  212. return(pcl_configure_clocks_dfll0(param));
  213. }
  214. }
  215. static long int pcl_configure_synchronous_clocks(pm_clk_src_t main_clk_src, unsigned long main_clock_freq_hz, pcl_freq_param_t *param)
  216. {
  217. //#
  218. //# Set the Synchronous clock division ratio for each clock domain
  219. //#
  220. pm_set_all_cksel(main_clock_freq_hz, param->cpu_f, param->pba_f, param->pbb_f);
  221. //#
  222. //# Set the Flash wait state and the speed read mode (depending on the target CPU frequency).
  223. //#
  224. #if UC3L
  225. flashcdw_set_flash_waitstate_and_readmode(param->cpu_f);
  226. #elif UC3C
  227. flashc_set_flash_waitstate_and_readmode(param->cpu_f);
  228. #endif
  229. //#
  230. //# Switch the main clock source to the selected clock.
  231. //#
  232. pm_set_mclk_source(main_clk_src);
  233. return PASS;
  234. }
  235. #endif // UC3L device-specific implementation
  236. //! UC3C Device-specific implementation
  237. #if UC3C
  238. static long int pcl_configure_clocks_uc3c(pcl_freq_param_t *param)
  239. {
  240. #define PM_MAX_MUL ((1 << AVR32_SCIF_PLLMUL_SIZE) - 1)
  241. #define AVR32_PM_PBA_MAX_FREQ 66000000
  242. #define AVR32_PM_PLL_VCO_RANGE0_MAX_FREQ 240000000
  243. #define AVR32_PM_PLL_VCO_RANGE0_MIN_FREQ 160000000
  244. // Implementation for UC3C parts.
  245. // Supported frequencies:
  246. // Fosc0 mul div PLL div2_en cpu_f pba_f Comment
  247. // 12 15 1 192 1 12 12
  248. // 12 9 3 40 1 20 20 PLL out of spec
  249. // 12 15 1 192 1 24 12
  250. // 12 9 1 120 1 30 15
  251. // 12 9 3 40 0 40 20 PLL out of spec
  252. // 12 15 1 192 1 48 12
  253. // 12 15 1 192 1 48 24
  254. // 12 8 1 108 1 54 27
  255. // 12 9 1 120 1 60 15
  256. // 12 9 1 120 1 60 30
  257. // 12 10 1 132 1 66 16.5
  258. //
  259. unsigned long in_cpu_f = param->cpu_f;
  260. unsigned long in_osc0_f = param->osc0_f;
  261. unsigned long mul, div, div2_en = 0, div2_cpu = 0, div2_pba = 0;
  262. unsigned long pll_freq, rest;
  263. Bool b_div2_pba, b_div2_cpu;
  264. // Configure OSC0 in crystal mode, external crystal with a FOSC0 Hz frequency.
  265. scif_configure_osc_crystalmode(SCIF_OSC0, in_osc0_f);
  266. // Enable the OSC0
  267. scif_enable_osc(SCIF_OSC0, param->osc0_startup, true);
  268. // Set the main clock source as being OSC0.
  269. pm_set_mclk_source(PM_CLK_SRC_OSC0);
  270. // Start with CPU freq config
  271. if (in_cpu_f == in_osc0_f)
  272. {
  273. param->cpu_f = in_osc0_f;
  274. param->pba_f = in_osc0_f;
  275. return PASS;
  276. }
  277. else if (in_cpu_f < in_osc0_f)
  278. {
  279. // TBD
  280. }
  281. rest = in_cpu_f % in_osc0_f;
  282. for (div = 1; div < 32; div++)
  283. {
  284. if ((div * rest) % in_osc0_f == 0)
  285. break;
  286. }
  287. if (div == 32)
  288. return FAIL;
  289. mul = (in_cpu_f * div) / in_osc0_f;
  290. if (mul > PM_MAX_MUL)
  291. return FAIL;
  292. // export 2power from PLL div to div2_cpu
  293. while (!(div % 2))
  294. {
  295. div /= 2;
  296. div2_cpu++;
  297. }
  298. // Here we know the mul and div parameter of the PLL config.
  299. // . Check out if the PLL has a valid in_cpu_f.
  300. // . Try to have for the PLL frequency (VCO output) the highest possible value
  301. // to reduce jitter.
  302. while (in_osc0_f * 2 * mul / div < AVR32_PM_PLL_VCO_RANGE0_MAX_FREQ)
  303. {
  304. if (2 * mul > PM_MAX_MUL)
  305. break;
  306. mul *= 2;
  307. div2_cpu++;
  308. }
  309. if (div2_cpu != 0)
  310. {
  311. div2_cpu--;
  312. div2_en = 1;
  313. }
  314. pll_freq = in_osc0_f * mul / (div * (1 << div2_en));
  315. // Update real CPU Frequency
  316. param->cpu_f = pll_freq / (1 << div2_cpu);
  317. mul--;
  318. scif_pll_opt_t opt;
  319. opt.osc = SCIF_OSC0, // Sel Osc0 or Osc1
  320. opt.lockcount = 16, // lockcount in main clock for the PLL wait lock
  321. opt.div = div, // DIV=1 in the formula
  322. opt.mul = mul, // MUL=7 in the formula
  323. opt.pll_div2 = div2_en, // pll_div2 Divide the PLL output frequency by 2 (this settings does not change the FVCO value)
  324. opt.pll_wbwdisable = 0, //pll_wbwdisable 1 Disable the Wide-Bandith Mode (Wide-Bandwith mode allow a faster startup time and out-of-lock time). 0 to enable the Wide-Bandith Mode.
  325. opt.pll_freq = (pll_freq < AVR32_PM_PLL_VCO_RANGE0_MIN_FREQ) ? 1 : 0, // Set to 1 for VCO frequency range 80-180MHz, set to 0 for VCO frequency range 160-240Mhz.
  326. scif_pll_setup(SCIF_PLL0, opt); // lockcount in main clock for the PLL wait lock
  327. /* Enable PLL0 */
  328. scif_pll_enable(SCIF_PLL0);
  329. /* Wait for PLL0 locked */
  330. scif_wait_for_pll_locked(SCIF_PLL0) ;
  331. rest = pll_freq;
  332. while (rest > AVR32_PM_PBA_MAX_FREQ ||
  333. rest != param->pba_f)
  334. {
  335. div2_pba++;
  336. rest = pll_freq / (1 << div2_pba);
  337. if (rest < param->pba_f)
  338. break;
  339. }
  340. // Update real PBA Frequency
  341. param->pba_f = pll_freq / (1 << div2_pba);
  342. if (div2_cpu)
  343. {
  344. b_div2_cpu = TRUE;
  345. div2_cpu--;
  346. }
  347. else
  348. b_div2_cpu = FALSE;
  349. if (div2_pba)
  350. {
  351. b_div2_pba = TRUE;
  352. div2_pba--;
  353. }
  354. else
  355. b_div2_pba = FALSE;
  356. if (b_div2_cpu == TRUE )
  357. {
  358. pm_set_clk_domain_div(PM_CLK_DOMAIN_0, (pm_divratio_t) div2_cpu); // CPU
  359. pm_set_clk_domain_div(PM_CLK_DOMAIN_1, (pm_divratio_t) div2_cpu); // HSB
  360. pm_set_clk_domain_div(PM_CLK_DOMAIN_3, (pm_divratio_t) div2_cpu); // PBB
  361. }
  362. if (b_div2_pba == TRUE )
  363. {
  364. pm_set_clk_domain_div(PM_CLK_DOMAIN_2, (pm_divratio_t) div2_pba); // PBA
  365. pm_set_clk_domain_div(PM_CLK_DOMAIN_4, (pm_divratio_t) div2_pba); // PBC
  366. }
  367. // Set Flashc Wait State
  368. flashc_set_flash_waitstate_and_readmode(param->cpu_f);
  369. // Set the main clock source as being PLL0.
  370. pm_set_mclk_source(PM_CLK_SRC_PLL0);
  371. return PASS;
  372. }
  373. #endif // UC3C device-specific implementation
  374. long int pcl_switch_to_osc(pcl_osc_t osc, unsigned int fcrystal, unsigned int startup)
  375. {
  376. #ifndef AVR32_PM_VERSION_RESETVALUE
  377. // Implementation for UC3A, UC3A3, UC3B parts.
  378. if(PCL_OSC0 == osc)
  379. {
  380. // Configure OSC0 in crystal mode, external crystal with a FOSC0 Hz frequency,
  381. // enable the OSC0, set the main clock source as being OSC0.
  382. pm_switch_to_osc0(&AVR32_PM, fcrystal, startup);
  383. }
  384. else
  385. {
  386. return PCL_NOT_SUPPORTED;
  387. }
  388. #else
  389. // Implementation for UC3C, UC3L parts.
  390. #if AVR32_PM_VERSION_RESETVALUE < 0x400
  391. return PCL_NOT_SUPPORTED;
  392. #else
  393. if(PCL_OSC0 == osc)
  394. {
  395. // Configure OSC0 in crystal mode, external crystal with a fcrystal Hz frequency.
  396. scif_configure_osc_crystalmode(SCIF_OSC0, fcrystal);
  397. // Enable the OSC0
  398. scif_enable_osc(SCIF_OSC0, startup, true);
  399. // Set the Flash wait state and the speed read mode (depending on the target CPU frequency).
  400. #if UC3L
  401. flashcdw_set_flash_waitstate_and_readmode(fcrystal);
  402. #elif UC3C
  403. flashc_set_flash_waitstate_and_readmode(fcrystal);
  404. #endif
  405. // Set the main clock source as being OSC0.
  406. pm_set_mclk_source(PM_CLK_SRC_OSC0);
  407. }
  408. else
  409. {
  410. return PCL_NOT_SUPPORTED;
  411. }
  412. #endif
  413. #endif
  414. return PASS;
  415. }
  416. long int pcl_configure_usb_clock(void)
  417. {
  418. #ifndef AVR32_PM_VERSION_RESETVALUE
  419. // Implementation for UC3A, UC3A3, UC3B parts.
  420. pm_configure_usb_clock();
  421. return PASS;
  422. #else
  423. #ifdef AVR32_PM_410_H_INCLUDED
  424. const scif_pll_opt_t opt = {
  425. .osc = SCIF_OSC0, // Sel Osc0 or Osc1
  426. .lockcount = 16, // lockcount in main clock for the PLL wait lock
  427. .div = 1, // DIV=1 in the formula
  428. .mul = 5, // MUL=7 in the formula
  429. .pll_div2 = 1, // pll_div2 Divide the PLL output frequency by 2 (this settings does not change the FVCO value)
  430. .pll_wbwdisable = 0, //pll_wbwdisable 1 Disable the Wide-Bandith Mode (Wide-Bandwith mode allow a faster startup time and out-of-lock time). 0 to enable the Wide-Bandith Mode.
  431. .pll_freq = 1, // Set to 1 for VCO frequency range 80-180MHz, set to 0 for VCO frequency range 160-240Mhz.
  432. };
  433. /* Setup PLL1 on Osc0, mul=7 ,no divisor, lockcount=16, ie. 16Mhzx6 = 96MHz output */
  434. scif_pll_setup(SCIF_PLL1, opt); // lockcount in main clock for the PLL wait lock
  435. /* Enable PLL1 */
  436. scif_pll_enable(SCIF_PLL1);
  437. /* Wait for PLL1 locked */
  438. scif_wait_for_pll_locked(SCIF_PLL1) ;
  439. // Implementation for UC3C parts.
  440. // Setup the generic clock for USB
  441. scif_gc_setup(AVR32_SCIF_GCLK_USB,
  442. SCIF_GCCTRL_PLL1,
  443. AVR32_SCIF_GC_NO_DIV_CLOCK,
  444. 0);
  445. // Now enable the generic clock
  446. scif_gc_enable(AVR32_SCIF_GCLK_USB);
  447. return PASS;
  448. #else
  449. return PCL_NOT_SUPPORTED;
  450. #endif
  451. #endif
  452. }
  453. #if UC3L
  454. #else
  455. void pcl_write_gplp(unsigned long gplp, unsigned long value)
  456. {
  457. #ifndef AVR32_PM_VERSION_RESETVALUE
  458. // Implementation for UC3A, UC3A3, UC3B parts.
  459. pm_write_gplp(&AVR32_PM,gplp,value);
  460. #else
  461. scif_write_gplp(gplp,value);
  462. #endif
  463. }
  464. unsigned long pcl_read_gplp(unsigned long gplp)
  465. {
  466. #ifndef AVR32_PM_VERSION_RESETVALUE
  467. // Implementation for UC3A, UC3A3, UC3B parts.
  468. return pm_read_gplp(&AVR32_PM,gplp);
  469. #else
  470. return scif_read_gplp(gplp);
  471. #endif
  472. }
  473. #endif