45 #ifndef XMEGA_OSC_H_INCLUDED 46 #define XMEGA_OSC_H_INCLUDED 63 #define OSC_ID_RC2MHZ OSC_RC2MEN_bm 65 #define OSC_ID_RC32MHZ OSC_RC32MEN_bm 67 #define OSC_ID_RC32KHZ OSC_RC32KEN_bm 69 #define OSC_ID_XOSC OSC_XOSCEN_bm 72 # define OSC_ID_RC8MHZ OSC_RC8MEN_bm 81 #define OSC_ID_USBSOF 0xff 86 #define XOSC_TYPE_EXTERNAL 0 87 #define XOSC_TYPE_32KHZ 2 88 #define XOSC_TYPE_XTAL 3 96 # define CONFIG_XOSC_32KHZ_LPM 111 #define XOSC_STARTUP_256 0 112 #define XOSC_STARTUP_1024 1 113 #define XOSC_STARTUP_16384 2 127 #define XOSC_RANGE_04TO2 OSC_FRQRANGE_04TO2_gc 129 #define XOSC_RANGE_2TO9 OSC_FRQRANGE_2TO9_gc 131 #define XOSC_RANGE_9TO12 OSC_FRQRANGE_9TO12_gc 133 #define XOSC_RANGE_12TO16 OSC_FRQRANGE_12TO16_gc 150 # ifndef CONFIG_XOSC_STARTUP 151 # ifndef BOARD_XOSC_STARTUP_US 152 # error BOARD_XOSC_STARTUP_US must be configured. 154 # define BOARD_XOSC_STARTUP_CYCLES \ 156 (BOARD_XOSC_HZ / 1000000 * BOARD_XOSC_STARTUP_US) 158 # if (BOARD_XOSC_TYPE == XOSC_TYPE_XTAL) 159 # if (BOARD_XOSC_STARTUP_CYCLES > 16384) 160 # error BOARD_XOSC_STARTUP_US is too high for current BOARD_XOSC_HZ. 162 # elif (BOARD_XOSC_STARTUP_CYCLES > 1024) 163 # define CONFIG_XOSC_STARTUP XOSC_STARTUP_16384 164 # define XOSC_STARTUP_TIMEOUT (16384*(1000000/BOARD_XOSC_HZ)) 166 # elif (BOARD_XOSC_STARTUP_CYCLES > 256) 167 # define CONFIG_XOSC_STARTUP XOSC_STARTUP_1024 168 # define XOSC_STARTUP_TIMEOUT (1024*(1000000/BOARD_XOSC_HZ)) 171 # define CONFIG_XOSC_STARTUP XOSC_STARTUP_256 172 # define XOSC_STARTUP_TIMEOUT (256*(1000000/BOARD_XOSC_HZ)) 175 # define CONFIG_XOSC_STARTUP 0 181 # ifndef CONFIG_XOSC_RANGE 182 # if (BOARD_XOSC_TYPE == XOSC_TYPE_XTAL) 183 # if (BOARD_XOSC_HZ < 400000) 184 # error BOARD_XOSC_HZ is below minimum frequency of 400 kHz. 186 # elif (BOARD_XOSC_HZ < 2000000) 187 # define CONFIG_XOSC_RANGE XOSC_RANGE_04TO2 189 # elif (BOARD_XOSC_HZ < 9000000) 190 # define CONFIG_XOSC_RANGE XOSC_RANGE_2TO9 192 # elif (BOARD_XOSC_HZ < 12000000) 193 # define CONFIG_XOSC_RANGE XOSC_RANGE_9TO12 195 # elif (BOARD_XOSC_HZ <= 16000000) 196 # define CONFIG_XOSC_RANGE XOSC_RANGE_12TO16 199 # error BOARD_XOSC_HZ is above maximum frequency of 16 MHz. 202 # define CONFIG_XOSC_RANGE 0 221 flags = cpu_irq_save();
223 #if (XMEGA_E && CONFIG_SYSCLK_RC8MHZ_LPM) 224 if(
id == OSC_ID_RC8MHZ) {
225 OSC.CTRL |= OSC_RC8MLPM_bm;
228 cpu_irq_restore(flags);
231 #if defined(BOARD_XOSC_HZ) || defined(__DOXYGEN__) 241 static inline void osc_enable_external(uint8_t
id)
247 #ifndef CONFIG_XOSC_32KHZ_LPM 248 # if (XMEGA_E && (BOARD_XOSC_TYPE == XOSC_TYPE_EXTERNAL) && defined(CONFIG_XOSC_EXTERNAL_PC4)) 249 OSC.XOSCCTRL = OSC_XOSCSEL4_bm;
251 OSC.XOSCCTRL = BOARD_XOSC_TYPE | (CONFIG_XOSC_STARTUP << 2) |
255 OSC.XOSCCTRL = BOARD_XOSC_TYPE | (CONFIG_XOSC_STARTUP << 2) |
256 CONFIG_XOSC_RANGE | OSC_X32KLPM_bm;
259 flags = cpu_irq_save();
261 cpu_irq_restore(flags);
265 static inline void osc_enable_external(uint8_t
id)
271 static inline void osc_disable(uint8_t
id)
277 flags = cpu_irq_save();
279 cpu_irq_restore(flags);
282 static inline void osc_enable(uint8_t
id)
287 osc_enable_external(
id);
291 static inline bool osc_is_ready(uint8_t
id)
295 return OSC.STATUS & id;
329 flags = cpu_irq_save();
336 OSC.DFLLCTRL |= OSC_RC2MCREF_bm;
338 OSC.DFLLCTRL &= ~(OSC_RC2MCREF_bm);
340 DFLLRC2M.CTRL |= DFLL_ENABLE_bm;
345 #if XMEGA_AU || XMEGA_B || XMEGA_C || XMEGA_E 353 OSC.DFLLCTRL &= ~(OSC_RC32MCREF_gm);
357 OSC.DFLLCTRL |= OSC_RC32MCREF_XOSC32K_gc;
360 OSC.DFLLCTRL |= OSC_RC32MCREF_RC32K_gc;
368 DFLLRC32M.COMP1 = 0x80;
369 DFLLRC32M.COMP2 = 0xBB;
370 OSC.DFLLCTRL |= OSC_RC32MCREF_USBSOF_gc;
377 # if defined(OSC_RC32MCREF_gm) 378 OSC.DFLLCTRL &= ~(OSC_RC32MCREF_gm);
383 # if defined(OSC_RC32MCREF_gm) 384 OSC.DFLLCTRL |= OSC_RC32MCREF_XOSC32K_gc;
386 OSC.DFLLCTRL |= OSC_RC32MCREF_bm;
390 # if defined(OSC_RC32MCREF_gm) 391 OSC.DFLLCTRL |= OSC_RC32MCREF_RC32K_gc;
393 OSC.DFLLCTRL &= ~(OSC_RC32MCREF_bm);
398 DFLLRC32M.CTRL |= DFLL_ENABLE_bm;
405 cpu_irq_restore(flags);
451 DFLLRC2M.CALA=LSB(calib);
452 DFLLRC2M.CALB=MSB(calib);
457 DFLLRC32M.CALA=LSB(calib);
458 DFLLRC32M.CALB=MSB(calib);
463 OSC.RC8MCAL=LSB(calib);
474 static inline uint32_t osc_get_rate(uint8_t
id)
483 #ifdef CONFIG_OSC_RC32_CAL 484 return CONFIG_OSC_RC32_CAL;
494 return BOARD_XOSC_HZ;
503 static inline void osc_wait_ready(uint8_t
id)
505 while (!osc_is_ready(
id)) {
#define OSC_ID_RC32MHZ
32 MHz Internal RC Oscillator
Standard board header file. Diese Datei enthält die Standardparameter und Pinbelegungen für das BMS B...
Commonly used includes, types and macros.
#define Assert(expr)
This macro is used to test fatal errors.
#define OSC_ID_RC2MHZ
2 MHz Internal RC Oscillator
static void osc_disable_autocalibration(uint8_t id)
Disable DFLL-based automatic calibration of an internal 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 OSC_ID_RC32KHZ
32 KHz Internal RC Oscillator
#define OSC_ID_USBSOF
Reference from USB Start Of Frame.
static void osc_enable_internal(uint8_t id)
Enable internal oscillator id.