Nut/OS  5.0.5
API Reference
scif_uc3l.h
Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00016 /* Copyright (C) 2009 - 2011 Atmel Corporation. All rights reserved.
00017  *
00018  * Redistribution and use in source and binary forms, with or without
00019  * modification, are permitted provided that the following conditions are met:
00020  *
00021  * 1. Redistributions of source code must retain the above copyright notice, this
00022  * list of conditions and the following disclaimer.
00023  *
00024  * 2. Redistributions in binary form must reproduce the above copyright notice,
00025  * this list of conditions and the following disclaimer in the documentation
00026  * and/or other materials provided with the distribution.
00027  *
00028  * 3. The name of Atmel may not be used to endorse or promote products derived
00029  * from this software without specific prior written permission.
00030  *
00031  * 4. This software may only be redistributed and used in connection with an Atmel
00032  * AVR product.
00033  *
00034  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00035  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00036  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00037  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
00038  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00039  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00040  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00041  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00042  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00043  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00044  *
00045  */
00046 #ifndef _SCIF_UC3L_H_
00047 #define _SCIF_UC3L_H_
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #include "compiler.h"
00054 
00055 //  These defines are missing from or wrong in the toolchain header file ip_xxx.h or part.h
00056 #if defined(AVR32_SCIF_100_H_INCLUDED) || defined(AVR32_SCIF_102_H_INCLUDED)
00057 // Optionnal #undef AVR32_SCIF_GC_NO_DIV_CLOCK if the define values is wrong.
00058 #define AVR32_SCIF_GC_NO_DIV_CLOCK       AVR32_GC_NO_DIV_CLOCK
00059 #endif
00060 
00061 #define AVR32_SCIF_OSCCTRL0_OSCEN_ENABLE      0x00000001  //! Enable value for OSCCTRL0.OSCEN
00062 #define AVR32_SCIF_OSCCTRL0_OSCEN_DISABLE     0x00000000  //! Disable value for OSCCTRL0.OSCEN
00063 #define AVR32_SCIF_OSCCTRL32_OSC32EN_ENABLE   0x00000001  //! Enable value for OSCCTRL32.OSC32EN
00064 #define AVR32_SCIF_OSCCTRL32_OSC32EN_DISABLE  0x00000000  //! Disable value for OSCCTRL32.OSC32EN
00065 
00066 
00068 
00070 #define SCIF_EXT_CRYSTAL_MIN_FREQ_HZ  4000000UL
00071 
00072 #define SCIF_EXT_CRYSTAL_MAX_FREQ_HZ  20000000UL
00073 
00075 typedef enum
00076 {
00077   SCIF_GCCTRL_SLOWCLOCK  = AVR32_SCIF_GC_USES_CLK_SLOW,
00078   SCIF_GCCTRL_OSC32K  = AVR32_SCIF_GC_USES_CLK_32,
00079   SCIF_GCCTRL_DFLL0  = AVR32_SCIF_GC_USES_DFLL0,
00080   SCIF_GCCTRL_OSC0  = AVR32_SCIF_GC_USES_OSC0,
00081   SCIF_GCCTRL_RC120M  = AVR32_SCIF_GC_USES_RC120M,
00082   SCIF_GCCTRL_CPUCLOCK  = AVR32_SCIF_GC_USES_CLK_CPU,
00083   SCIF_GCCTRL_HSBCLOCK  = AVR32_SCIF_GC_USES_CLK_HSB,
00084   SCIF_GCCTRL_PBACLOCK  = AVR32_SCIF_GC_USES_CLK_PBA,
00085   SCIF_GCCTRL_PBBCLOCK  = AVR32_SCIF_GC_USES_CLK_PBB,
00086   SCIF_GCCTRL_RC32K  = AVR32_SCIF_GC_USES_RC32K,
00087   SCIF_GCCTRL_CLK1K  = AVR32_SCIF_GC_USES_CLK_1K,
00088 #if (UC3L0128 || UC3L0256)
00089   SCIF_GCCTRL_PLL0  = AVR32_SCIF_GC_USES_PLL0,
00090 #endif
00091   SCIF_GCCTRL_OSCSEL_INVALID
00092 } scif_gcctrl_oscsel_t;
00093 
00095 #if (UC3L0128 || UC3L0256)
00096 #define SCIF_DFLL_MINFREQ_KHZ         20000
00097 #define SCIF_DFLL_MINFREQ_HZ          20000000UL
00098 #else
00099 #define SCIF_DFLL_MINFREQ_KHZ         40000
00100 #define SCIF_DFLL_MINFREQ_HZ          40000000UL
00101 #endif
00102 
00104 #define SCIF_DFLL_MAXFREQ_KHZ         150000
00105 #define SCIF_DFLL_MAXFREQ_HZ          150000000UL
00106 
00108 #define SCIF_SLOWCLOCK_FREQ_HZ        AVR32_SCIF_RCOSC_FREQUENCY
00109 #define SCIF_SLOWCLOCK_FREQ_KHZ       (SCIF_SLOWCLOCK_FREQ_HZ/1000)
00110 
00112 #define SCIF_RC32K_FREQ_HZ            32768
00113 #define SCIF_RC32K_FREQ_KHZ           (SCIF_RC32K_FREQ_HZ/1000)
00114 
00116 #define SCIF_RC120M_FREQ_HZ           120000000UL
00117 #define SCIF_RC120M_FREQ_KHZ          120000
00118 
00120 #define SCIF_OSC32_FREQ_HZ            32768
00121 
00123 #define SCIF_POLL_TIMEOUT             100000
00124 
00126 #define SCIF_NOT_SUPPORTED            (-10000)
00127 
00128 
00130 typedef enum
00131 {
00132   SCIF_OSC0  = 0,
00133   SCIF_OSC1  = 1
00134 } scif_osc_t;
00135 
00137 typedef enum
00138 {
00139   SCIF_OSC_MODE_EXT_CLK = 0,            // For both OSC0 & OSC32
00140   SCIF_OSC_MODE_2PIN_CRYSTAL = 1,       // For both OSC0 and OSC32
00141   SCIF_OSC_MODE_NOT_SUPPORTED_1 = 2,
00142   SCIF_OSC_MODE_NOT_SUPPORTED_2 = 3,
00143   SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR = 4, // For OSC32 only
00144   SCIF_OSC_MODE_NOT_SUPPORTED_3 = 5,
00145   SCIF_OSC_MODE_NOT_SUPPORTED_4 = 6,
00146   SCIF_OSC_MODE_NOT_SUPPORTED_5 = 7
00147 } scif_osc_mode_t;
00148 
00150 typedef struct
00151 {
00153   unsigned long   freq_hz;
00155   scif_osc_mode_t mode;
00157   unsigned char   startup;
00159   unsigned char   gain;
00160 } scif_osc_opt_t;
00161 
00162 #if (UC3L0128 || UC3L0256)
00163 
00164 typedef struct
00165 {
00167   unsigned char   pll_freq;
00169   unsigned char   pll_wbwdisable;
00171   unsigned char   pll_div2;
00173   unsigned int    mul;
00175   unsigned int    div;
00177   unsigned int    lockcount;
00179   unsigned char   osc;
00180 } scif_pll_opt_t;
00181 #endif
00182 
00184 typedef struct
00185 {
00187   scif_osc_mode_t mode;
00189   unsigned char   startup;
00191   bool            pinsel;
00193   bool            en1k;
00195   bool            en32k;
00196 } scif_osc32_opt_t;
00197 
00198 
00200 typedef struct
00201 {
00203   scif_gcctrl_oscsel_t clock_source;
00205   unsigned int divider;
00207   unsigned int diven;
00209   // (to fill-in if the clock_source is set to OSCn).
00210   unsigned long extosc_f;
00211 } scif_gclk_opt_t;
00212 
00213 
00215 typedef struct
00216 {
00217   unsigned int  fine;
00218   unsigned int  coarse;
00219 } scif_dfll_openloop_conf_t;
00220 
00222 typedef struct
00223 {
00225   unsigned int    coarse;
00227   unsigned int    fmul;
00229   unsigned int    imul;
00231   unsigned int    finemaxstep;
00233   unsigned int    coarsemaxstep;
00234 } scif_dfll_closedloop_conf_t;
00235 
00237 typedef struct
00238 {
00240   unsigned int    use_random;
00242   unsigned int    amplitude;
00244   unsigned int    step_size;
00245 } scif_dfll_ssg_conf_t;
00246 
00247 
00249 #define SCIF_UNLOCK(reg)  (AVR32_SCIF.unlock = (AVR32_SCIF_UNLOCK_KEY_VALUE << AVR32_SCIF_UNLOCK_KEY_OFFSET)|(reg))
00250 
00253 
00254 
00259 #ifdef __GNUC__
00260 __attribute__((__always_inline__))
00261 #endif
00262 static inline void scif_enable_interrupts(unsigned long mask)
00263 {
00264   AVR32_SCIF.ier = mask;
00265 }
00266 
00271 #ifdef __GNUC__
00272 __attribute__((__always_inline__))
00273 #endif
00274 static inline void scif_disable_interrupts(unsigned long mask)
00275 {
00276   AVR32_SCIF.idr = mask;
00277 }
00278 
00283 #ifdef __GNUC__
00284 __attribute__((__always_inline__))
00285 #endif
00286 static inline unsigned long scif_get_enabled_interrupts(void)
00287 {
00288   return(AVR32_SCIF.imr);
00289 }
00290 
00295 #ifdef __GNUC__
00296 __attribute__((__always_inline__))
00297 #endif
00298 static inline unsigned long scif_get_interrupts_status(void)
00299 {
00300   return(AVR32_SCIF.isr);
00301 }
00302 
00307 #ifdef __GNUC__
00308 __attribute__((__always_inline__))
00309 #endif
00310 static inline void scif_clear_interrupts_status(unsigned long mask)
00311 {
00312   AVR32_SCIF.icr = mask;
00313 }
00314 
00316 
00317 
00320 
00321 
00326 #ifdef __GNUC__
00327 __attribute__((__always_inline__))
00328 #endif
00329 static inline unsigned long scif_get_pclk_status(void)
00330 {
00331   return(AVR32_SCIF.pclksr);
00332 }
00333 
00335 
00336 
00339 
00340 
00354 extern long int scif_start_osc(scif_osc_t osc, const scif_osc_opt_t *opt, bool wait_for_ready);
00355 
00364 extern bool scif_is_osc_ready(scif_osc_t osc);
00365 
00374 extern long int scif_stop_osc(scif_osc_t osc);
00375 
00385 extern long int scif_configure_osc_crystalmode(scif_osc_t osc, unsigned int fcrystal);
00386 
00395 extern long int scif_configure_osc_extmode(scif_osc_t osc);
00396 
00407 extern long int scif_enable_osc(scif_osc_t osc, unsigned int startup, bool wait_for_ready);
00408 
00409 #if (UC3L0128 || UC3L0256)
00410 
00411 
00412 
00415 
00416 
00424 extern long int scif_pll0_setup(const scif_pll_opt_t *opt);
00425 
00432 extern long int scif_pll0_enable(void);
00433 
00440 extern long int scif_pll0_disable(void);
00441 
00442 
00449 extern long int scif_wait_for_pll0_locked(void);
00450 
00452 
00453 #endif
00454 
00457 
00458 
00471 extern long int scif_start_osc32(const scif_osc32_opt_t *opt, bool wait_for_ready);
00472 
00479 #ifdef __GNUC__
00480 __attribute__((__always_inline__))
00481 #endif
00482 static inline bool scif_is_osc32_ready(void)
00483 {
00484   return((AVR32_SCIF.pclksr & AVR32_SCIF_PCLKSR_OSC32RDY_MASK)>>AVR32_SCIF_PCLKSR_OSC32RDY_OFFSET);
00485 }
00486 
00490 #ifdef __GNUC__
00491 __attribute__((__always_inline__))
00492 #endif
00493 static inline void scif_osc32_1kout_ena(void)
00494 {
00495   AVR32_SCIF.oscctrl32 |= AVR32_SCIF_EN1K_MASK;
00496 }
00497 
00501 #ifdef __GNUC__
00502 __attribute__((__always_inline__))
00503 #endif
00504 static inline void scif_osc32_1kout_dis(void)
00505 {
00506   AVR32_SCIF.oscctrl32 &= ~AVR32_SCIF_EN1K_MASK;
00507 }
00508 
00512 #ifdef __GNUC__
00513 __attribute__((__always_inline__))
00514 #endif
00515 static inline void scif_osc32_32kout_ena(void)
00516 {
00517   AVR32_SCIF.oscctrl32 |= AVR32_SCIF_EN32K_MASK;
00518 }
00519 
00523 #ifdef __GNUC__
00524 __attribute__((__always_inline__))
00525 #endif
00526 static inline void scif_osc32_32kout_dis(void)
00527 {
00528   AVR32_SCIF.oscctrl32 &= ~AVR32_SCIF_EN32K_MASK;
00529 }
00530 
00537 extern long int scif_stop_osc32(void);
00538 
00540 
00541 
00544 
00545 
00554 extern long int scif_dfll0_openloop_start(const scif_dfll_openloop_conf_t *pdfllconfig);
00555 
00564 extern long int scif_dfll0_openloop_start_auto(unsigned long TargetFreqkHz);
00565 
00574 extern long int scif_dfll0_openloop_updatefreq(const scif_dfll_openloop_conf_t *pdfllconfig);
00575 
00584 extern long int scif_dfll0_openloop_updatefreq_auto(unsigned long TargetFreq);
00585 
00592 extern long int scif_dfll0_openloop_stop(void);
00593 
00605 #define scif_dfll0_ssg_gc_enable(pgc_conf) scif_start_gclk(AVR32_SCIF_GCLK_DFLL0_SSG, pgc_conf)
00606 
00617 extern long int scif_dfll0_ssg_enable(scif_dfll_ssg_conf_t *pssg_conf);
00618 
00627 #define scif_dfll0_closedloop_mainref_gc_enable(pgc_conf) scif_start_gclk(AVR32_SCIF_GCLK_DFLL0_REF, pgc_conf)
00628 
00639 extern long int scif_dfll0_closedloop_start(const scif_dfll_closedloop_conf_t *pdfllconfig);
00640 
00658 extern long int scif_dfll0_closedloop_configure_and_start( const scif_gclk_opt_t *gc_dfllif_ref_opt,
00659                                                     unsigned long long target_freq_hz,
00660                                                     bool enable_ssg);
00661 
00670 #define scif_dfll0_closedloop_dither_gc_enable(pgc_conf)  scif_dfll0_ssg_gc_enable(pgc_conf)
00671 
00672 
00673 
00675 
00676 
00679 
00680 
00681 
00683 
00684 
00687 
00688 
00691 extern void scif_start_rc120M(void);
00692 
00695 extern void scif_stop_rc120M(void);
00696 
00698 
00699 
00702 
00703 
00706 extern void scif_start_rc32k(void);
00707 
00710 extern void scif_stop_rc32k(void);
00711 
00714 extern void scif_disable_rc32out(void);
00715 
00717 
00718 
00721 
00722 
00732 extern long int scif_start_gclk(unsigned int gclk, const scif_gclk_opt_t *opt);
00733 
00745 extern long int scif_stop_gclk(unsigned int gclk);
00746 
00761 extern long int scif_gc_setup(unsigned int gclk, scif_gcctrl_oscsel_t clk_src, unsigned int diven, unsigned int divfactor);
00762 
00771 extern long int scif_gc_enable(unsigned int gclk);
00772 
00774 
00775 
00778 
00779 
00780 
00782 
00783 
00786 
00787 
00796 long int scif_pclksr_statushigh_wait(unsigned long statusMask);
00797 
00799 
00800 #ifdef __cplusplus
00801 }
00802 #endif
00803 
00804 #endif  // _SCIF_UC3L_H_