46 #ifndef XMEGA_PLL_H_INCLUDED 47 #define XMEGA_PLL_H_INCLUDED 57 #define PLL_MIN_HZ 10000000UL 58 #define PLL_MAX_HZ 200000000UL 59 #define PLL_NR_OPTIONS 0 70 #define pll_get_default_rate(pll_id) \ 71 pll_get_default_rate_priv(CONFIG_PLL##pll_id##_SOURCE, \ 72 CONFIG_PLL##pll_id##_MUL, \ 73 CONFIG_PLL##pll_id##_DIV) 90 unsigned int mul,
unsigned int div)
101 #ifdef CONFIG_OSC_RC32_CAL //32MHz oscillator is calibrated to another frequency 102 rate = CONFIG_OSC_RC32_CAL / 4;
122 Assert(rate >= PLL_MIN_HZ);
123 Assert(rate <= PLL_MAX_HZ);
139 unsigned int div,
unsigned int mul)
141 Assert(mul >= 1 && mul <= 31);
150 cfg->ctrl = src | (mul << OSC_PLLFAC_gp);
153 #define pll_config_defaults(cfg, pll_id) \ 154 pll_config_init(cfg, \ 155 CONFIG_PLL##pll_id##_SOURCE, \ 156 CONFIG_PLL##pll_id##_DIV, \ 157 CONFIG_PLL##pll_id##_MUL) 159 static inline void pll_config_read(
struct pll_config *cfg,
unsigned int pll_id)
163 cfg->ctrl = OSC.PLLCTRL;
166 static inline void pll_config_write(
const struct pll_config *cfg,
171 OSC.PLLCTRL = cfg->ctrl;
186 flags = cpu_irq_save();
187 pll_config_write(cfg, pll_id);
188 OSC.CTRL |= OSC_PLLEN_bm;
189 cpu_irq_restore(flags);
201 flags = cpu_irq_save();
202 OSC.CTRL &= ~OSC_PLLEN_bm;
203 cpu_irq_restore(flags);
206 static inline bool pll_is_locked(
unsigned int pll_id)
210 return OSC.STATUS & OSC_PLLRDY_bm;
213 static inline void pll_enable_source(
enum pll_source src)
223 #ifdef CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC 224 if (CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC
226 osc_enable(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
227 osc_wait_ready(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
230 CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
247 static inline void pll_enable_config_defaults(
unsigned int pll_id)
251 if (pll_is_locked(pll_id)) {
255 #ifdef CONFIG_PLL0_SOURCE 257 pll_enable_source(CONFIG_PLL0_SOURCE);
269 while (!pll_is_locked(pll_id));
272 static inline int pll_wait_for_lock(
unsigned int pll_id)
276 while (!pll_is_locked(pll_id)) {
#define OSC_ID_RC32MHZ
32 MHz Internal RC Oscillator
static void pll_disable(unsigned int pll_id)
static void pll_config_init(struct pll_config *cfg, enum pll_source src, unsigned int div, unsigned int mul)
Commonly used includes, types and macros.
#define Assert(expr)
This macro is used to test fatal errors.
static uint32_t pll_get_default_rate_priv(enum pll_source src, unsigned int mul, unsigned int div)
Return clock rate for specified PLL settings.
#define OSC_ID_XOSC
External Oscillator.
static void osc_enable_autocalibration(uint8_t id, uint8_t ref_id)
Enable DFLL-based automatic calibration of an internal oscillator.
2 MHz Internal RC Oscillator
32 MHz Internal RC Oscillator
static void pll_enable(const struct pll_config *cfg, unsigned int pll_id)
#define OSC_ID_USBSOF
Reference from USB Start Of Frame.