53 #if XMEGA_AU || XMEGA_B || XMEGA_C 58 void sysclk_init(
void)
60 uint8_t *reg = (uint8_t *)&PR.PRGEN;
62 #ifdef CONFIG_OSC_RC32_CAL
68 bool need_rc2mhz =
false;
79 CONFIG_SYSCLK_PSBCDIV);
81 #if (CONFIG_OSC_RC32_CAL==48000000UL) 82 NVM.CMD = NVM_CMD_READ_CALIB_ROW_gc;
83 MSB(cal) = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSC));
84 LSB(cal) = pgm_read_byte(offsetof(NVM_PROD_SIGNATURES_t, USBRCOSCA));
85 NVM.CMD = NVM_CMD_NO_OPERATION_gc;
111 switch (CONFIG_SYSCLK_SOURCE) {
115 #ifdef CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC 116 if (CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC
118 osc_enable(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
119 osc_wait_ready(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
122 CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
136 #ifdef CONFIG_PLL0_SOURCE 141 pll_enable_config_defaults(0);
145 case SYSCLK_SRC_RC8MHZ:
146 osc_enable(OSC_ID_RC8MHZ);
147 osc_wait_ready(OSC_ID_RC8MHZ);
156 CLK.CTRL = CONFIG_SYSCLK_SOURCE;
157 Assert(CLK.CTRL == CONFIG_SYSCLK_SOURCE);
161 #ifdef CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC 162 osc_enable(CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC);
163 osc_wait_ready(CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC);
165 CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC);
171 #ifdef CONFIG_RTC_SOURCE 178 irqflags_t flags = cpu_irq_save();
180 *((uint8_t *)&PR.PRGEN + port) &= ~id;
182 cpu_irq_restore(flags);
187 irqflags_t flags = cpu_irq_save();
189 *((uint8_t *)&PR.PRGEN + port) |= id;
191 cpu_irq_restore(flags);
194 #if XMEGA_AU || XMEGA_B || XMEGA_C || defined(__DOXYGEN__) 205 void sysclk_enable_usb(uint8_t frequency)
209 Assert((frequency == 6) || (frequency == 48));
215 if (frequency == 6) {
216 prescaler = CLK_USBPSDIV_8_gc;
226 case USBCLK_SRC_RCOSC:
230 #ifdef CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC 231 if (CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC
233 osc_enable(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
234 osc_wait_ready(CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
237 CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC);
241 CLK.USBCTRL = ((prescaler) | CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm);
245 #ifdef CONFIG_PLL0_SOURCE 247 pll_enable_config_defaults(0);
248 ccp_write_io((uint8_t *)&CLK.USBCTRL, (prescaler)
265 void sysclk_disable_usb(
void)
271 #endif // XMEGA_AU || XMEGA_B || XMEGA_C #define OSC_ID_RC32MHZ
32 MHz Internal RC Oscillator
void sysclk_disable_module(enum sysclk_port_id port, uint8_t id)
Disable the clock to peripheral id on port port.
#define SYSCLK_SRC_XOSC
External oscillator.
Commonly used includes, types and macros.
#define Assert(expr)
This macro is used to test fatal errors.
#define SYSCLK_USB
USB Module.
#define CONFIG_USBCLK_SOURCE
Chip-specific PLL management functions.
#define OSC_ID_RC2MHZ
2 MHz Internal RC Oscillator
#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.
static void osc_user_calibration(uint8_t id, uint16_t calib)
Load a specific calibration value for the specified oscillator.
#define SYSCLK_PSADIV_1
Do not prescale.
static void sysclk_rtcsrc_enable(uint8_t id)
Enable RTC clock with specified clock source.
#define SYSCLK_SRC_RC32KHZ
Internal 32 KHz RC oscillator.
2 MHz Internal RC Oscillator
Chip-specific oscillator management functions.
#define OSC_ID_RC32KHZ
32 KHz Internal RC Oscillator
Devices not associated with a specific port.
#define SYSCLK_SRC_RC2MHZ
Internal 2 MHz RC oscillator.
#define OSC_ID_USBSOF
Reference from USB Start Of Frame.
#define SYSCLK_PSBCDIV_1_1
Do not prescale.
#define SYSCLK_SRC_RC32MHZ
Internal 32 MHz RC oscillator.
void sysclk_enable_module(enum sysclk_port_id port, uint8_t id)
Enable the clock to peripheral id on port port.
Chip-specific system clock management functions.
#define SYSCLK_SRC_PLL
Phase-Locked Loop.
static void sysclk_set_prescalers(uint8_t psadiv, uint8_t psbcdiv)
Set system clock prescaler configuration.