Go to the documentation of this file.00001
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
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
00056 #if defined(AVR32_SCIF_100_H_INCLUDED) || defined(AVR32_SCIF_102_H_INCLUDED)
00057
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,
00140 SCIF_OSC_MODE_2PIN_CRYSTAL = 1,
00141 SCIF_OSC_MODE_NOT_SUPPORTED_1 = 2,
00142 SCIF_OSC_MODE_NOT_SUPPORTED_2 = 3,
00143 SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR = 4,
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
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_