scif_uc3l.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  1. /*This file has been prepared for Doxygen automatic documentation generation.*/
  2. /*! \file *********************************************************************
  3. *
  4. * \brief System Control InterFace(SCIF) driver interface.
  5. *
  6. *
  7. * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
  8. * - Supported devices: All AVR32 UC3L devices.
  9. * - AppNote:
  10. *
  11. * \author Atmel Corporation: http://www.atmel.com \n
  12. * Support and FAQ: http://support.atmel.no/
  13. *
  14. *****************************************************************************/
  15. /* Copyright (C) 2009 - 2011 Atmel Corporation. All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions are met:
  19. *
  20. * 1. Redistributions of source code must retain the above copyright notice, this
  21. * list of conditions and the following disclaimer.
  22. *
  23. * 2. Redistributions in binary form must reproduce the above copyright notice,
  24. * this list of conditions and the following disclaimer in the documentation
  25. * and/or other materials provided with the distribution.
  26. *
  27. * 3. The name of Atmel may not be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * 4. This software may only be redistributed and used in connection with an Atmel
  31. * AVR product.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  34. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  35. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  36. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  37. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  38. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  39. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  40. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  41. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  42. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  43. *
  44. */
  45. #ifndef _SCIF_UC3L_H_
  46. #define _SCIF_UC3L_H_
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. #include "compiler.h"
  51. // These defines are missing from or wrong in the toolchain header file ip_xxx.h or part.h
  52. #if defined(AVR32_SCIF_100_H_INCLUDED) || defined(AVR32_SCIF_102_H_INCLUDED)
  53. // Optionnal #undef AVR32_SCIF_GC_NO_DIV_CLOCK if the define values is wrong.
  54. #define AVR32_SCIF_GC_NO_DIV_CLOCK AVR32_GC_NO_DIV_CLOCK
  55. #endif
  56. #define AVR32_SCIF_OSCCTRL0_OSCEN_ENABLE 0x00000001 //! Enable value for OSCCTRL0.OSCEN
  57. #define AVR32_SCIF_OSCCTRL0_OSCEN_DISABLE 0x00000000 //! Disable value for OSCCTRL0.OSCEN
  58. #define AVR32_SCIF_OSCCTRL32_OSC32EN_ENABLE 0x00000001 //! Enable value for OSCCTRL32.OSC32EN
  59. #define AVR32_SCIF_OSCCTRL32_OSC32EN_DISABLE 0x00000000 //! Disable value for OSCCTRL32.OSC32EN
  60. //! Device-specific data
  61. //!< External crystal/clock min frequency (in Herz)
  62. #define SCIF_EXT_CRYSTAL_MIN_FREQ_HZ 4000000UL
  63. //!< External crystal/clock max frequency (in Herz)
  64. #define SCIF_EXT_CRYSTAL_MAX_FREQ_HZ 20000000UL
  65. //! The different clock source for the generic clocks
  66. typedef enum
  67. {
  68. SCIF_GCCTRL_SLOWCLOCK = AVR32_SCIF_GC_USES_CLK_SLOW,
  69. SCIF_GCCTRL_OSC32K = AVR32_SCIF_GC_USES_CLK_32,
  70. SCIF_GCCTRL_DFLL0 = AVR32_SCIF_GC_USES_DFLL0,
  71. SCIF_GCCTRL_OSC0 = AVR32_SCIF_GC_USES_OSC0,
  72. SCIF_GCCTRL_RC120M = AVR32_SCIF_GC_USES_RC120M,
  73. SCIF_GCCTRL_CPUCLOCK = AVR32_SCIF_GC_USES_CLK_CPU,
  74. SCIF_GCCTRL_HSBCLOCK = AVR32_SCIF_GC_USES_CLK_HSB,
  75. SCIF_GCCTRL_PBACLOCK = AVR32_SCIF_GC_USES_CLK_PBA,
  76. SCIF_GCCTRL_PBBCLOCK = AVR32_SCIF_GC_USES_CLK_PBB,
  77. SCIF_GCCTRL_RC32K = AVR32_SCIF_GC_USES_RC32K,
  78. SCIF_GCCTRL_CLK1K = AVR32_SCIF_GC_USES_CLK_1K,
  79. #if (UC3L0128 || UC3L0256)
  80. SCIF_GCCTRL_PLL0 = AVR32_SCIF_GC_USES_PLL0,
  81. #endif
  82. SCIF_GCCTRL_OSCSEL_INVALID
  83. } scif_gcctrl_oscsel_t;
  84. //! The min DFLL output frequency
  85. #if (UC3L0128 || UC3L0256)
  86. #define SCIF_DFLL_MINFREQ_KHZ 20000
  87. #define SCIF_DFLL_MINFREQ_HZ 20000000UL
  88. #else
  89. #define SCIF_DFLL_MINFREQ_KHZ 40000
  90. #define SCIF_DFLL_MINFREQ_HZ 40000000UL
  91. #endif
  92. //! The max DFLL output frequency
  93. #define SCIF_DFLL_MAXFREQ_KHZ 150000
  94. #define SCIF_DFLL_MAXFREQ_HZ 150000000UL
  95. //! The RCSYS slow clock frequency
  96. #define SCIF_SLOWCLOCK_FREQ_HZ AVR32_SCIF_RCOSC_FREQUENCY
  97. #define SCIF_SLOWCLOCK_FREQ_KHZ (SCIF_SLOWCLOCK_FREQ_HZ/1000)
  98. //! The RC32K slow clock frequency
  99. #define SCIF_RC32K_FREQ_HZ 32768
  100. #define SCIF_RC32K_FREQ_KHZ (SCIF_RC32K_FREQ_HZ/1000)
  101. //! The RC120M frequency
  102. #define SCIF_RC120M_FREQ_HZ 120000000UL
  103. #define SCIF_RC120M_FREQ_KHZ 120000
  104. //! The OSC32 frequency
  105. #define SCIF_OSC32_FREQ_HZ 32768
  106. //! The timeguard used for polling in ticks.
  107. #define SCIF_POLL_TIMEOUT 100000
  108. //! Define "not supported" for the chosen implementation.
  109. #define SCIF_NOT_SUPPORTED (-10000)
  110. //! The different oscillators
  111. typedef enum
  112. {
  113. SCIF_OSC0 = 0,
  114. SCIF_OSC1 = 1
  115. } scif_osc_t;
  116. //! The different oscillator modes
  117. typedef enum
  118. {
  119. SCIF_OSC_MODE_EXT_CLK = 0, // For both OSC0 & OSC32
  120. SCIF_OSC_MODE_2PIN_CRYSTAL = 1, // For both OSC0 and OSC32
  121. SCIF_OSC_MODE_NOT_SUPPORTED_1 = 2,
  122. SCIF_OSC_MODE_NOT_SUPPORTED_2 = 3,
  123. SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR = 4, // For OSC32 only
  124. SCIF_OSC_MODE_NOT_SUPPORTED_3 = 5,
  125. SCIF_OSC_MODE_NOT_SUPPORTED_4 = 6,
  126. SCIF_OSC_MODE_NOT_SUPPORTED_5 = 7
  127. } scif_osc_mode_t;
  128. //! OSC0/OSC1 startup options.
  129. typedef struct
  130. {
  131. //! The input frequency (from the external clock or the crystal).
  132. unsigned long freq_hz;
  133. //! Set the oscillator mode.
  134. scif_osc_mode_t mode;
  135. //! Specify the oscillator startup time.
  136. unsigned char startup;
  137. //! Gain for the oscillator
  138. unsigned char gain;
  139. } scif_osc_opt_t;
  140. #if (UC3L0128 || UC3L0256)
  141. //! PLL0 startup options.
  142. typedef struct
  143. {
  144. //! Set to 1 for VCO frequency range 80-180MHz, set to 0 for VCO frequency range 160-240Mhz.
  145. unsigned char pll_freq;
  146. //! 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.
  147. unsigned char pll_wbwdisable;
  148. //! Divide the PLL output frequency by 2. (this settings does not change the FVCO value)
  149. unsigned char pll_div2;
  150. //! PLL MUL in the PLL formula
  151. unsigned int mul;
  152. //! PLL DIV in the PLL formula
  153. unsigned int div;
  154. //! PLL lockount
  155. unsigned int lockcount;
  156. //! Specify the scillator input.
  157. unsigned char osc;
  158. } scif_pll_opt_t;
  159. #endif
  160. //! OSC32 startup options.
  161. typedef struct
  162. {
  163. //! Set the oscillator mode.
  164. scif_osc_mode_t mode;
  165. //! Specify the oscillator startup time.
  166. unsigned char startup;
  167. //! Select pins used for the 32kHz Crystal
  168. bool pinsel;
  169. //! 1kHz output enable/disable
  170. bool en1k;
  171. //! 32kHz output enable/disable
  172. bool en32k;
  173. } scif_osc32_opt_t;
  174. //! Generic clock generation settings.
  175. typedef struct
  176. {
  177. //! The input clock source to use for the generic clock
  178. scif_gcctrl_oscsel_t clock_source;
  179. //! The division factor to apply to the clock src.
  180. unsigned int divider;
  181. //! Enable/disable the generic clock divisor
  182. unsigned int diven;
  183. //! Oscillator external crystal(or external clock) frequency (board dependant)
  184. // (to fill-in if the clock_source is set to OSCn).
  185. unsigned long extosc_f;
  186. } scif_gclk_opt_t;
  187. //! DFLL open-loop mode settings.
  188. typedef struct
  189. {
  190. unsigned int fine;
  191. unsigned int coarse;
  192. } scif_dfll_openloop_conf_t;
  193. //! DFLL closed-loop mode settings.
  194. typedef struct
  195. {
  196. //! The coarse value (= (fDFLL - SCIF_DFLL_MINFREQ_KHZ)*255/(SCIF_DFLL_MAXFREQ_KHZ - SCIF_DFLL_MINFREQ_KHZ))
  197. unsigned int coarse;
  198. //! The fmul value (= (fDFLL*2^16)/fref) - imul*2^16)
  199. unsigned int fmul;
  200. //! The imul value (= (fDFLL)/fref)
  201. unsigned int imul;
  202. //! Fine maximum step size during fine adjustment
  203. unsigned int finemaxstep;
  204. //! Coarse maximum step size during coarse adjustment
  205. unsigned int coarsemaxstep;
  206. } scif_dfll_closedloop_conf_t;
  207. //! DFLL SSG settings.
  208. typedef struct
  209. {
  210. //! Enable/disable the pseudo random
  211. unsigned int use_random;
  212. //! SSG amplitude
  213. unsigned int amplitude;
  214. //! SSG step size
  215. unsigned int step_size;
  216. } scif_dfll_ssg_conf_t;
  217. //! Unlock SCIF register macro
  218. #define SCIF_UNLOCK(reg) (AVR32_SCIF.unlock = (AVR32_SCIF_UNLOCK_KEY_VALUE << AVR32_SCIF_UNLOCK_KEY_OFFSET)|(reg))
  219. /*! \name Interrupt Functions
  220. */
  221. //! @{
  222. /*! \brief Enable SCIF interrupts.
  223. *
  224. * \param mask the interrupts to enable.
  225. */
  226. #ifdef __GNUC__
  227. NUT_FORCE_INLINE
  228. #endif
  229. static inline void scif_enable_interrupts(unsigned long mask)
  230. {
  231. AVR32_SCIF.ier = mask;
  232. }
  233. /*! \brief Disable SCIF interrupts.
  234. *
  235. * \param mask the interrupts to disable.
  236. */
  237. #ifdef __GNUC__
  238. NUT_FORCE_INLINE
  239. #endif
  240. static inline void scif_disable_interrupts(unsigned long mask)
  241. {
  242. AVR32_SCIF.idr = mask;
  243. }
  244. /*! \brief Read the SCIF currently enabled interrupts.
  245. *
  246. * \return The enabled interrupts.
  247. */
  248. #ifdef __GNUC__
  249. NUT_FORCE_INLINE
  250. #endif
  251. static inline unsigned long scif_get_enabled_interrupts(void)
  252. {
  253. return(AVR32_SCIF.imr);
  254. }
  255. /*! \brief Read the interrupt status of the SCIF.
  256. *
  257. * \return The interrupts which have been triggered.
  258. */
  259. #ifdef __GNUC__
  260. NUT_FORCE_INLINE
  261. #endif
  262. static inline unsigned long scif_get_interrupts_status(void)
  263. {
  264. return(AVR32_SCIF.isr);
  265. }
  266. /*! \brief Clear raised interrupts from the SCIF.
  267. *
  268. * \param mask The interrupts to clear.
  269. */
  270. #ifdef __GNUC__
  271. NUT_FORCE_INLINE
  272. #endif
  273. static inline void scif_clear_interrupts_status(unsigned long mask)
  274. {
  275. AVR32_SCIF.icr = mask;
  276. }
  277. //! @}
  278. /*! \name Power and Clocks Status Functions
  279. */
  280. //! @{
  281. /*! \brief Read the Power and Clocks Status of the SCIF.
  282. *
  283. * \return The content of the PCLKSR register
  284. */
  285. #ifdef __GNUC__
  286. NUT_FORCE_INLINE
  287. #endif
  288. static inline unsigned long scif_get_pclk_status(void)
  289. {
  290. return(AVR32_SCIF.pclksr);
  291. }
  292. //! @}
  293. /*! \name OSC0/OSC1 Functions
  294. */
  295. //! @{
  296. /*! \brief Configure and start an OSC0/OSC1 oscillator.
  297. *
  298. * \param osc The oscillator to start [INPUT]
  299. * \param opt The configuration of the oscillator [INPUT]
  300. * \param wait_for_ready Wait for the oscillator to be stable before return [INPUT]
  301. *
  302. * \note To avoid an infinite loop, this function checks the osc0 ready flag
  303. * SCIF_POLL_TIMEOUT times.
  304. *
  305. * \return Status.
  306. * \retval 0 Oscillator start successfull.
  307. * \retval <0 Error starting the oscillator.
  308. */
  309. extern long int scif_start_osc(scif_osc_t osc, const scif_osc_opt_t *opt, bool wait_for_ready);
  310. /*! \brief Is an oscillator stable and ready to be used as clock source?
  311. *
  312. * \param osc The oscillator [INPUT]
  313. *
  314. * \return Status.
  315. * \retval true oscillator stable and ready
  316. * \retval false oscillator not enabled or not ready.
  317. */
  318. extern bool scif_is_osc_ready(scif_osc_t osc);
  319. /*! \brief Stop an oscillator.
  320. *
  321. * \param osc The oscillator to stop
  322. *
  323. * \return Status.
  324. * \retval 0 Oscillator successfully stopped.
  325. * \retval <0 An error occured when stopping the oscillator.
  326. */
  327. extern long int scif_stop_osc(scif_osc_t osc);
  328. /*! \brief Configure an oscillator in crystal mode
  329. *
  330. * \param osc The oscillator to configure [INPUT]
  331. * \param fcrystal Crystal frequency (Hz) [INPUT]
  332. *
  333. * \return Status.
  334. * \retval 0 Oscillator successfully configured.
  335. * \retval <0 Error configuring the oscillator.
  336. */
  337. extern long int scif_configure_osc_crystalmode(scif_osc_t osc, unsigned int fcrystal);
  338. /*! \brief Configure an external clock as input clock
  339. *
  340. * \param osc The external clock to configure [INPUT]
  341. *
  342. * \return Status.
  343. * \retval 0 External clock successfully configured.
  344. * \retval <0 Error configuring the external clock.
  345. */
  346. extern long int scif_configure_osc_extmode(scif_osc_t osc);
  347. /*! \brief Enable an oscillator with a given startup time.
  348. *
  349. * \param osc The oscillator to configure [INPUT]
  350. * \param startup Oscillator startup time (one of AVR32_SCIF_OSCCTRLx_STARTUP_x_RCOSC) [INPUT]
  351. * \param wait_for_ready Wait for the oscillator to be stable before return [INPUT]
  352. *
  353. * \return Status.
  354. * \retval 0 Oscillator successfully started
  355. * \retval <0 Error starting the oscillator.
  356. */
  357. extern long int scif_enable_osc(scif_osc_t osc, unsigned int startup, bool wait_for_ready);
  358. #if (UC3L0128 || UC3L0256)
  359. //! @}
  360. /*! \name PLL0 Functions
  361. */
  362. //! @{
  363. /*!
  364. * \brief This function will setup PLL0.
  365. * \param opt The configuration of the PLL [INPUT]
  366. * \return Status.
  367. * \retval 0 PLL successfully configured
  368. * \retval <0 Error.
  369. */
  370. extern long int scif_pll0_setup(const scif_pll_opt_t *opt);
  371. /*!
  372. * \brief This function will enable PLL0.
  373. * \return Status.
  374. * \retval 0 PLL successfully enabled
  375. * \retval <0 Error starting the PLL.
  376. */
  377. extern long int scif_pll0_enable(void);
  378. /*!
  379. * \brief This function will disable PLL0.
  380. * \return Status.
  381. * \retval 0 PLL successfully disabled
  382. * \retval <0 Error disabling the PLL.
  383. */
  384. extern long int scif_pll0_disable(void);
  385. /*!
  386. * \brief This function will wait until the PLL0 is locked
  387. * \return Status.
  388. * \retval 0 OK
  389. * \retval <0 Error
  390. */
  391. extern long int scif_wait_for_pll0_locked(void);
  392. //! @}
  393. #endif
  394. /*! \name OSC32 Functions
  395. */
  396. //! @{
  397. /*! \brief Configure and start the OSC32 oscillator.
  398. *
  399. * \param opt The configuration of the oscillator [INPUT]
  400. * \param wait_for_ready Wait for the oscillator to be stable before return [INPUT]
  401. *
  402. * \note To avoid an infinite loop, this function checks the osc32 ready flag
  403. * SCIF_POLL_TIMEOUT times.
  404. *
  405. * \return Status.
  406. * \retval 0 Oscillator start successfull.
  407. * \retval <0 Error starting the oscillator.
  408. */
  409. extern long int scif_start_osc32(const scif_osc32_opt_t *opt, bool wait_for_ready);
  410. /*! \brief Is OSC32 stable and ready to be used as clock source?
  411. *
  412. * \return Status.
  413. * \retval true oscillator stable and ready
  414. * \retval false oscillator not enabled or not ready.
  415. */
  416. #ifdef __GNUC__
  417. NUT_FORCE_INLINE
  418. #endif
  419. static inline bool scif_is_osc32_ready(void)
  420. {
  421. return((AVR32_SCIF.pclksr & AVR32_SCIF_PCLKSR_OSC32RDY_MASK)>>AVR32_SCIF_PCLKSR_OSC32RDY_OFFSET);
  422. }
  423. /*! \brief Enable the 1kHz output of the OSC32 oscillator
  424. *
  425. */
  426. #ifdef __GNUC__
  427. NUT_FORCE_INLINE
  428. #endif
  429. static inline void scif_osc32_1kout_ena(void)
  430. {
  431. AVR32_SCIF.oscctrl32 |= AVR32_SCIF_EN1K_MASK;
  432. }
  433. /*! \brief Disable the 1kHz output of the OSC32 oscillator
  434. *
  435. */
  436. #ifdef __GNUC__
  437. NUT_FORCE_INLINE
  438. #endif
  439. static inline void scif_osc32_1kout_dis(void)
  440. {
  441. AVR32_SCIF.oscctrl32 &= ~AVR32_SCIF_EN1K_MASK;
  442. }
  443. /*! \brief Enable the 32kHz output of the OSC32 oscillator
  444. *
  445. */
  446. #ifdef __GNUC__
  447. NUT_FORCE_INLINE
  448. #endif
  449. static inline void scif_osc32_32kout_ena(void)
  450. {
  451. AVR32_SCIF.oscctrl32 |= AVR32_SCIF_EN32K_MASK;
  452. }
  453. /*! \brief Disable the 32kHz output of the OSC32 oscillator
  454. *
  455. */
  456. #ifdef __GNUC__
  457. NUT_FORCE_INLINE
  458. #endif
  459. static inline void scif_osc32_32kout_dis(void)
  460. {
  461. AVR32_SCIF.oscctrl32 &= ~AVR32_SCIF_EN32K_MASK;
  462. }
  463. /*! \brief Stop the OSC32 oscillator.
  464. *
  465. * \return Status.
  466. * \retval 0 Oscillator successfully stopped.
  467. * \retval <0 An error occured when stopping the oscillator.
  468. */
  469. extern long int scif_stop_osc32(void);
  470. //! @}
  471. /*! \name DFLL Control Functions
  472. */
  473. //! @{
  474. /*! \brief Configure and start the DFLL0 in open loop mode.
  475. *
  476. * \param pdfllconfig The DFLL parameters in open loop mode [INPUT]
  477. *
  478. * \return Status.
  479. * \retval 0 DFLL0 configured and started successfully.
  480. * \retval <0 Error.
  481. */
  482. extern long int scif_dfll0_openloop_start(const scif_dfll_openloop_conf_t *pdfllconfig);
  483. /*! \brief Automatic configuration and start of the DFLL0 in open loop mode
  484. *
  485. * \param TargetFreqkHz The DFLL target frequency (in kHz) [INPUT]
  486. *
  487. * \return Status.
  488. * \retval 0 DFLL0 configured and started successfully.
  489. * \retval <0 Error.
  490. */
  491. extern long int scif_dfll0_openloop_start_auto(unsigned long TargetFreqkHz);
  492. /*! \brief Update the frequency of the DFLL0 in open loop mode.
  493. *
  494. * \param pdfllconfig The DFLL parameters in open loop mode [INPUT]
  495. *
  496. * \return Status.
  497. * \retval 0 DFLL0 frequency updated successfully.
  498. * \retval <0 Error.
  499. */
  500. extern long int scif_dfll0_openloop_updatefreq(const scif_dfll_openloop_conf_t *pdfllconfig);
  501. /*! \brief Automatic configuration to update the frequency of the DFLL0 in open loop mode.
  502. *
  503. * \param TargetFreq The DFLL target frequency (in kHz) [INPUT]
  504. *
  505. * \return Status.
  506. * \retval 0 DFLL0 frequency updated successfully.
  507. * \retval <0 Error.
  508. */
  509. extern long int scif_dfll0_openloop_updatefreq_auto(unsigned long TargetFreq);
  510. /*! \brief Stop the DFLL0 in open loop mode.
  511. *
  512. * \return Status.
  513. * \retval 0 DFLL0 successfully stopped.
  514. * \retval <0 Error.
  515. */
  516. extern long int scif_dfll0_openloop_stop(void);
  517. /*! \brief Configure and enable the SSG reference generic clock
  518. *
  519. * \note The frequency of the SSG reference clock should be higher than the CLK_DFLLIF_REF
  520. * to ensure that the DFLLIF can lock.
  521. *
  522. * \param pgc_conf The settings for the generic clock [INPUT]
  523. *
  524. * \return Status.
  525. * \retval 0 SSG Generic clock configured and started successfully.
  526. * \retval <0 Error.
  527. */
  528. #define scif_dfll0_ssg_gc_enable(pgc_conf) scif_start_gclk(AVR32_SCIF_GCLK_DFLL0_SSG, pgc_conf)
  529. /*! \brief Configure and enable the SSG
  530. *
  531. * \note The SSG reference generic clock must have previously been enabled.
  532. *
  533. * \param pssg_conf The settings for the SCIF.DFLL0SSG register [INPUT]
  534. *
  535. * \return Status.
  536. * \retval 0 SSG Generic clock configured and started successfully.
  537. * \retval <0 Error.
  538. */
  539. extern long int scif_dfll0_ssg_enable(scif_dfll_ssg_conf_t *pssg_conf);
  540. /*! \brief Configure and enable the closed-loop mode main reference generic clock
  541. *
  542. * \param pgc_conf The settings for the generic clock [INPUT]
  543. *
  544. * \return Status.
  545. * \retval 0 Main reference generic clock configured and started successfully.
  546. * \retval <0 Error.
  547. */
  548. #define scif_dfll0_closedloop_mainref_gc_enable(pgc_conf) scif_start_gclk(AVR32_SCIF_GCLK_DFLL0_REF, pgc_conf)
  549. /*! \brief Configure and start the DFLL0 in closed loop mode.
  550. *
  551. * \note The main reference generic clock must have previously been started.
  552. *
  553. * \param pdfllconfig The DFLL parameters in closed loop mode [INPUT]
  554. *
  555. * \return Status.
  556. * \retval 0 DFLL0 configured and started successfully.
  557. * \retval <0 Error.
  558. */
  559. extern long int scif_dfll0_closedloop_start(const scif_dfll_closedloop_conf_t *pdfllconfig);
  560. /*! \brief Depending on the target frequency, compute the DFLL configuration parameters
  561. * and start the DFLL0 in closed loop mode.
  562. *
  563. * \note Configures and enables the generic clock CLK_DFLLIF_REF to serve as the main reference.
  564. *
  565. * \note This function only supports the following source clocks for the CLK_DFLLIF_REF generic clock:
  566. * SCIF_GCCTRL_SLOWCLOCK (aka RCSYS), SCIF_GCCTRL_OSC32K, SCIF_GCCTRL_RC32K,
  567. * SCIF_GCCTRL_OSC0, SCIF_GCCTRL_RC120M, SCIF_GCCTRL_CLK1K.
  568. *
  569. * \param gc_dfllif_ref_opt The settings for the CLK_DFLLIF_REF generic clock [INPUT]
  570. * \param target_freq_hz The target frequency (in Hz) [INPUT]
  571. * \param enable_ssg Enable/disable the SSG feature [INPUT]
  572. *
  573. * \return Status.
  574. * \retval 0 DFLL0 configured and started successfully.
  575. * \retval <0 Error.
  576. */
  577. extern long int scif_dfll0_closedloop_configure_and_start( const scif_gclk_opt_t *gc_dfllif_ref_opt,
  578. unsigned long long target_freq_hz,
  579. bool enable_ssg);
  580. /*! \brief Configure and enable the generic clock used by the closed-loop mode dithering stage and by the SSG.
  581. *
  582. * \param pgc_conf The settings for the generic clock [INPUT]
  583. *
  584. * \return Status.
  585. * \retval 0 Dithering & SSG reference generic clock configured and started successfully.
  586. * \retval <0 Error.
  587. */
  588. #define scif_dfll0_closedloop_dither_gc_enable(pgc_conf) scif_dfll0_ssg_gc_enable(pgc_conf)
  589. //! @}
  590. /*! \name Calibration Functions
  591. */
  592. //! @{
  593. //! @}
  594. /*! \name 120MHz RCosc Functions
  595. */
  596. //! @{
  597. /*! \brief Start the 120MHz internal RCosc (RC120M) clock
  598. */
  599. extern void scif_start_rc120M(void);
  600. /*! \brief Stop the 120MHz internal RCosc (RC120M) clock
  601. */
  602. extern void scif_stop_rc120M(void);
  603. //! @}
  604. /*! \name 32kHz internal RCosc (RC32K) Functions
  605. */
  606. //! @{
  607. /*! \brief Start the 32kHz internal RCosc (RC32K) clock
  608. */
  609. extern void scif_start_rc32k(void);
  610. /*! \brief Stop the 32kHz internal RCosc (RC32K) clock
  611. */
  612. extern void scif_stop_rc32k(void);
  613. /*! \brief Unforce the RC32 signal from being output on the dedicated pin (PA20)
  614. */
  615. extern void scif_disable_rc32out(void);
  616. //! @}
  617. /*! \name Generic Clock Functions
  618. */
  619. //! @{
  620. /*! \brief Setup and start a generic clock.
  621. *
  622. * \param gclk The generic clock number to setup and start (cf. datasheet)
  623. * \param opt The settings for the generic clock.
  624. *
  625. * \return Status.
  626. * \retval 0 Success.
  627. * \retval <0 An error occured.
  628. */
  629. extern long int scif_start_gclk(unsigned int gclk, const scif_gclk_opt_t *opt);
  630. /*! \brief Stop a generic clock.
  631. *
  632. * \param gclk The generic clock number to stop.
  633. *
  634. * \note To avoid an infinite loop, this function checks the Clock enable flag
  635. * SCIF_POLL_TIMEOUT times.
  636. *
  637. * \return Status.
  638. * \retval 0 Success.
  639. * \retval <0 Unable to stop generic clock.
  640. */
  641. extern long int scif_stop_gclk(unsigned int gclk);
  642. /*! \brief Setup a generic clock.
  643. *
  644. * \param gclk generic clock number (0 for gc0...)
  645. * \param clk_src The input clock source to use for the generic clock
  646. * \param diven Generic clock divisor enable
  647. * \param divfactor Generic clock divisor
  648. *
  649. * \note If the generic clock is already enabled, this function will disable it,
  650. * apply the configuration then restart the generic clock.
  651. *
  652. * \return Status.
  653. * \retval 0 Success.
  654. * \retval <0 An error occured.
  655. */
  656. extern long int scif_gc_setup(unsigned int gclk, scif_gcctrl_oscsel_t clk_src, unsigned int diven, unsigned int divfactor);
  657. /*! \brief Enable a generic clock.
  658. *
  659. * \param gclk generic clock number (0 for gc0...)
  660. *
  661. * \return Status.
  662. * \retval 0 Success.
  663. * \retval <0 An error occured.
  664. */
  665. extern long int scif_gc_enable(unsigned int gclk);
  666. //! @}
  667. /*! \name Backup Registers Functions
  668. */
  669. //! @{
  670. //! @}
  671. /*! \name Miscellaneous Functions
  672. */
  673. //! @{
  674. /*! \brief Wait for a status high in the Power and Clocks status register.
  675. *
  676. * \param statusMask Mask field of the status to poll [INPUT]
  677. *
  678. * \return Status.
  679. * \retval 0 Status is high.
  680. * \retval <0 SCIF_POLL_TIMEOUT Timeout expired before the status was high.
  681. */
  682. long int scif_pclksr_statushigh_wait(unsigned long statusMask);
  683. //! @}
  684. #ifdef __cplusplus
  685. }
  686. #endif
  687. #endif // _SCIF_UC3L_H_