46 #ifndef XMEGA_SYSCLK_H_INCLUDED 47 #define XMEGA_SYSCLK_H_INCLUDED 59 #ifdef CONFIG_OSC_AUTOCAL 60 # if CONFIG_OSC_AUTOCAL == OSC_ID_RC2MHZ 61 # define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC CONFIG_OSC_AUTOCAL_REF_OSC 62 # elif CONFIG_OSC_AUTOCAL == OSC_ID_RC32MHZ 63 # define CONFIG_OSC_AUTOCAL_RC32MHZ_REF_OSC CONFIG_OSC_AUTOCAL_REF_OSC 65 # error Bad configuration of CONFIG_OSC_AUTOCAL and/or CONFIG_OSC_AUTOCAL_REF_OSC 70 #ifndef CONFIG_SYSCLK_SOURCE 71 # define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_RC2MHZ 74 #ifndef CONFIG_SYSCLK_PSADIV 75 # define CONFIG_SYSCLK_PSADIV SYSCLK_PSADIV_1 78 #ifndef CONFIG_SYSCLK_PSBCDIV 79 # define CONFIG_SYSCLK_PSBCDIV SYSCLK_PSBCDIV_1_1 85 #define SYSCLK_SRC_RC2MHZ CLK_SCLKSEL_RC2M_gc 87 #define SYSCLK_SRC_RC32MHZ CLK_SCLKSEL_RC32M_gc 89 #define SYSCLK_SRC_RC32KHZ CLK_SCLKSEL_RC32K_gc 91 #define SYSCLK_SRC_XOSC CLK_SCLKSEL_XOSC_gc 93 #define SYSCLK_SRC_PLL CLK_SCLKSEL_PLL_gc 99 #define SYSCLK_PSADIV_1 CLK_PSADIV_1_gc 100 #define SYSCLK_PSADIV_2 CLK_PSADIV_2_gc 101 #define SYSCLK_PSADIV_4 CLK_PSADIV_4_gc 102 #define SYSCLK_PSADIV_8 CLK_PSADIV_8_gc 103 #define SYSCLK_PSADIV_16 CLK_PSADIV_16_gc 104 #define SYSCLK_PSADIV_32 CLK_PSADIV_32_gc 105 #define SYSCLK_PSADIV_64 CLK_PSADIV_64_gc 106 #define SYSCLK_PSADIV_128 CLK_PSADIV_128_gc 107 #define SYSCLK_PSADIV_256 CLK_PSADIV_256_gc 108 #define SYSCLK_PSADIV_512 CLK_PSADIV_512_gc 114 #define SYSCLK_PSBCDIV_1_1 CLK_PSBCDIV_1_1_gc 116 #define SYSCLK_PSBCDIV_1_2 CLK_PSBCDIV_1_2_gc 118 #define SYSCLK_PSBCDIV_4_1 CLK_PSBCDIV_4_1_gc 120 #define SYSCLK_PSBCDIV_2_2 CLK_PSBCDIV_2_2_gc 140 #define SYSCLK_DMA PR_DMA_bm 141 #define SYSCLK_EDMA PR_EDMA_bm 142 #define SYSCLK_EVSYS PR_EVSYS_bm 143 #define SYSCLK_RTC PR_RTC_bm 144 #define SYSCLK_EBI PR_EBI_bm 145 #define SYSCLK_AES PR_AES_bm 146 #define SYSCLK_USB PR_USB_bm 147 #define SYSCLK_XCL PR_XCL_bm 155 #define SYSCLK_AC PR_AC_bm 156 #define SYSCLK_ADC PR_ADC_bm 157 #define SYSCLK_DAC PR_DAC_bm 165 #define SYSCLK_TC0 PR_TC0_bm 166 #define SYSCLK_TC1 PR_TC1_bm 167 #define SYSCLK_TC4 PR_TC4_bm 168 #define SYSCLK_TC5 PR_TC5_bm 169 #define SYSCLK_HIRES PR_HIRES_bm 170 #define SYSCLK_SPI PR_SPI_bm 171 #define SYSCLK_USART0 PR_USART0_bm 172 #define SYSCLK_USART1 PR_USART1_bm 173 #define SYSCLK_TWI PR_TWI_bm 183 #define SYSCLK_RTCSRC_ULP CLK_RTCSRC_ULP_gc 185 #define SYSCLK_RTCSRC_TOSC CLK_RTCSRC_TOSC_gc 187 #define SYSCLK_RTCSRC_RCOSC CLK_RTCSRC_RCOSC_gc 189 #define SYSCLK_RTCSRC_TOSC32 CLK_RTCSRC_TOSC32_gc 191 #define SYSCLK_RTCSRC_RCOSC32 CLK_RTCSRC_RCOSC32_gc 193 #define SYSCLK_RTCSRC_EXTCLK CLK_RTCSRC_EXTCLK_gc 197 #if XMEGA_AU || XMEGA_B || XMEGA_C 200 #define USBCLK_SRC_RCOSC 0 202 #define USBCLK_SRC_PLL 1 218 # define CONFIG_USBCLK_SOURCE 221 #endif // XMEGA_AU || XMEGA_B || XMEGA_C 243 switch (CONFIG_SYSCLK_SOURCE) {
247 #ifdef CONFIG_OSC_RC32_CAL 248 return CONFIG_OSC_RC32_CAL;
258 return BOARD_XOSC_HZ;
261 #ifdef CONFIG_PLL0_SOURCE 263 return pll_get_default_rate(0);
285 switch (CONFIG_SYSCLK_PSADIV) {
286 case SYSCLK_PSADIV_6:
288 case SYSCLK_PSADIV_10:
290 case SYSCLK_PSADIV_12:
292 case SYSCLK_PSADIV_24:
294 case SYSCLK_PSADIV_48:
302 if (CONFIG_SYSCLK_PSADIV & (1U << CLK_PSADIV_gp)) {
303 shift = (CONFIG_SYSCLK_PSADIV >> (1 + CLK_PSADIV_gp)) + 1;
318 switch (CONFIG_SYSCLK_PSBCDIV) {
345 if (CONFIG_SYSCLK_PSBCDIV & (1U << CLK_PSBCDIV_gp))
371 if (module == NULL) {
376 else if (module == &AES) {
381 else if (module == &EBI) {
386 else if (module == &RTC) {
391 else if (module == &EVSYS) {
396 else if (module == &DMA) {
401 else if (module == &EDMA) {
406 else if (module == &ACA) {
411 else if (module == &ACB) {
416 else if (module == &ADCA) {
421 else if (module == &ADCB) {
426 else if (module == &DACA) {
433 else if (module == &DACB) {
437 #endif // Workaround end 439 else if (module == &FAULTC0) {
444 else if (module == &FAULTC1) {
449 else if (module == &TCC0) {
454 else if (module == &TCD0) {
459 else if (module == &TCE0) {
464 else if (module == &TCF0) {
469 else if (module == &TCC1) {
474 else if (module == &TCD1) {
479 else if (module == &TCE1) {
484 else if (module == &TCF1) {
489 else if (module == &TCC4) {
494 else if (module == &TCC5) {
499 else if (module == &TCD4) {
504 else if (module == &TCD5) {
509 else if (module == &HIRESC) {
514 else if (module == &HIRESD) {
519 else if (module == &HIRESE) {
524 else if (module == &HIRESF) {
529 else if (module == &SPIC) {
534 else if (module == &SPID) {
539 else if (module == &SPIE) {
544 else if (module == &SPIF) {
549 else if (module == &USARTC0) {
554 else if (module == &USARTD0) {
559 else if (module == &USARTE0) {
564 else if (module == &USARTF0) {
569 else if (module == &USARTC1) {
574 else if (module == &USARTD1) {
579 else if (module == &USARTE1) {
584 else if (module == &USARTF1) {
589 else if (module == &TWIC) {
594 else if (module == &TWID) {
599 else if (module == &TWIE) {
604 else if (module == &TWIF) {
609 else if (module == &XCL) {
652 if (module == NULL) {
656 else if (module == &AES) {
661 else if (module == &EBI) {
666 else if (module == &RTC) {
671 else if (module == &EVSYS) {
676 else if (module == &DMA) {
681 else if (module == &EDMA) {
686 else if (module == &ACA) {
691 else if (module == &ACB) {
696 else if (module == &ADCA) {
701 else if (module == &ADCB) {
706 else if (module == &DACA) {
713 else if (module == &DACB) {
717 #endif // Workaround end 719 else if (module == &TCC0) {
724 else if (module == &TCD0) {
729 else if (module == &TCE0) {
734 else if (module == &TCF0) {
739 else if (module == &TCC1) {
744 else if (module == &TCD1) {
749 else if (module == &TCE1) {
754 else if (module == &TCF1) {
759 else if (module == &TCC4) {
764 else if (module == &TCC5) {
769 else if (module == &TCD4) {
774 else if (module == &TCD5) {
779 else if (module == &HIRESC) {
784 else if (module == &HIRESD) {
789 else if (module == &HIRESE) {
794 else if (module == &HIRESF) {
799 else if (module == &SPIC) {
804 else if (module == &SPID) {
809 else if (module == &SPIE) {
814 else if (module == &SPIF) {
819 else if (module == &USARTC0) {
824 else if (module == &USARTD0) {
829 else if (module == &USARTE0) {
834 else if (module == &USARTF0) {
839 else if (module == &USARTC1) {
844 else if (module == &USARTD1) {
849 else if (module == &USARTE1) {
854 else if (module == &USARTF1) {
859 else if (module == &TWIC) {
864 else if (module == &TWID) {
869 else if (module == &TWIE) {
874 else if (module == &TWIF) {
879 else if (module == &XCL) {
898 if (module == NULL) {
902 else if (module == &AES) {
907 else if (module == &EBI) {
912 else if (module == &RTC) {
917 else if (module == &EVSYS) {
922 else if (module == &DMA) {
927 else if (module == &EDMA) {
932 else if (module == &ACA) {
937 else if (module == &ACB) {
942 else if (module == &ADCA) {
947 else if (module == &ADCB) {
952 else if (module == &DACA) {
959 else if (module == &DACB) {
963 #endif // Workaround end 965 else if (module == &TCC0) {
970 else if (module == &TCD0) {
975 else if (module == &TCE0) {
980 else if (module == &TCF0) {
985 else if (module == &TCC1) {
990 else if (module == &TCD1) {
995 else if (module == &TCE1) {
1000 else if (module == &TCF1) {
1005 else if (module == &TCC4) {
1010 else if (module == &TCC5) {
1015 else if (module == &TCD4) {
1020 else if (module == &TCD5) {
1025 else if (module == &HIRESC) {
1030 else if (module == &HIRESD) {
1035 else if (module == &HIRESE) {
1040 else if (module == &HIRESF) {
1045 else if (module == &SPIC) {
1050 else if (module == &SPID) {
1055 else if (module == &SPIE) {
1060 else if (module == &SPIF) {
1065 else if (module == &USARTC0) {
1070 else if (module == &USARTD0) {
1075 else if (module == &USARTE0) {
1080 else if (module == &USARTF0) {
1085 else if (module == &USARTC1) {
1090 else if (module == &USARTD1) {
1095 else if (module == &USARTE1) {
1100 else if (module == &USARTF1) {
1105 else if (module == &TWIC) {
1110 else if (module == &TWID) {
1115 else if (module == &TWIE) {
1120 else if (module == &TWIF) {
1125 else if (module == &XCL) {
1148 uint8_t mask = *((uint8_t *)&PR.PRGEN + port);
1149 return (mask &
id) == 0;
1152 #if XMEGA_AU || XMEGA_B || XMEGA_C || defined(__DOXYGEN__) 1153 # if defined(CONFIG_USBCLK_SOURCE) || defined(__DOXYGEN__) 1154 # if (CONFIG_USBCLK_SOURCE == USBCLK_SRC_RCOSC) 1155 # define USBCLK_STARTUP_TIMEOUT 1 1156 # elif (CONFIG_USBCLK_SOURCE == USBCLK_SRC_PLL) 1157 # if (CONFIG_PLL0_SOURCE == PLL_SRC_XOSC) 1158 # define USBCLK_STARTUP_TIMEOUT XOSC_STARTUP_TIMEOUT 1159 # elif (CONFIG_PLL0_SOURCE == PLL_SRC_RC32MHZ) 1160 # define USBCLK_STARTUP_TIMEOUT 1 1161 # elif (CONFIG_PLL0_SOURCE == PLL_SRC_RC2MHZ) 1162 # define USBCLK_STARTUP_TIMEOUT 1 1164 # error Unknow value for CONFIG_PLL0_SOURCE, see conf_clock.h. 1168 # define CONFIG_USBCLK_SOURCE USBCLK_SRC_RCOSC 1169 # define USBCLK_STARTUP_TIMEOUT 1 1171 void sysclk_enable_usb(uint8_t frequency);
1172 void sysclk_disable_usb(
void);
1195 CLK.PSCTRL = (psadiv | psbcdiv);
1219 CLK.LOCK = CLK_LOCK_bm;
1238 Assert((
id & ~CLK_RTCSRC_gm) == 0);
1242 #if !XMEGA_A && !XMEGA_D 1250 #if !XMEGA_A && !XMEGA_D 1258 CLK.RTCCTRL =
id | CLK_RTCEN_bm;
1274 extern void sysclk_init(
void);
#define SYSCLK_TC4
Timer/Counter 0.
#define SYSCLK_AC
Analog Comparator.
static uint32_t sysclk_get_cpu_hz(void)
Return the current rate in Hz of the CPU clock.
#define SYSCLK_RTC
Real-Time Counter.
#define SYSCLK_EDMA
EDMA Controller.
static void sysclk_lock(void)
Lock the system clock configuration.
#define SYSCLK_SRC_XOSC
External oscillator.
Standard board header file. Diese Datei enthält die Standardparameter und Pinbelegungen für das BMS B...
#define SYSCLK_USART0
USART 0.
#define SYSCLK_RTCSRC_RCOSC32
#define SYSCLK_TC5
Timer/Counter 1.
#define SYSCLK_EBI
Ext Bus Interface.
Commonly used includes, types and macros.
#define Assert(expr)
This macro is used to test fatal errors.
#define SYSCLK_USART1
USART 1.
static void sysclk_rtcsrc_disable(void)
Disable RTC clock.
static void sysclk_set_source(uint8_t src)
Change the source of the main system clock.
#define SYSCLK_TC1
Timer/Counter 1.
static uint32_t sysclk_get_peripheral_bus_hz(const volatile void *module)
Retrieves the current rate in Hz of the Peripheral Bus clock attached to the specified peripheral...
void sysclk_enable_module(enum sysclk_port_id port, uint8_t id)
Enable the clock to peripheral id on port port.
#define SYSCLK_PSBCDIV_4_1
Prescale CLKper2, CLKper and CLKcpu by 4.
#define SYSCLK_DAC
D/A Converter.
#define SYSCLK_DMA
DMA Controller.
Chip-specific PLL management functions.
#define SYSCLK_EVSYS
Event System.
#define SYSCLK_XCL
USB Module.
#define OSC_ID_XOSC
External Oscillator.
static void sysclk_enable_peripheral_clock(const volatile void *module)
Enable a peripheral's clock from its base address.
#define SYSCLK_TC0
Timer/Counter 0.
static void sysclk_rtcsrc_enable(uint8_t id)
Enable RTC clock with specified clock source.
static uint32_t sysclk_get_per2_hz(void)
Return the current rate in Hz of clk_PER2.
#define SYSCLK_ADC
A/D Converter.
#define SYSCLK_SPI
SPI controller.
#define SYSCLK_SRC_RC32KHZ
Internal 32 KHz RC oscillator.
Chip-specific oscillator management functions.
#define SYSCLK_TWI
TWI controller.
static uint32_t sysclk_get_per4_hz(void)
Return the current rate in Hz of clk_PER4.
#define SYSCLK_PSBCDIV_1_2
Prescale CLKper and CLKcpu by 2.
static uint32_t sysclk_get_per_hz(void)
Return the current rate in Hz of clk_PER.
#define SYSCLK_RTCSRC_RCOSC
static uint32_t sysclk_get_main_hz(void)
Return the current rate in Hz of the main system clock.
#define OSC_ID_RC32KHZ
32 KHz Internal RC Oscillator
#define SYSCLK_AES
AES Module.
Devices not associated with a specific port.
#define SYSCLK_HIRES
Hi-Res Extension.
#define SYSCLK_RTCSRC_TOSC32
#define SYSCLK_PSADIV_512
Prescale CLKper4 by 512.
#define SYSCLK_SRC_RC2MHZ
Internal 2 MHz RC oscillator.
#define SYSCLK_PSBCDIV_1_1
Do not prescale.
static void sysclk_disable_peripheral_clock(const volatile void *module)
Disable a peripheral's clock from its base address.
#define SYSCLK_SRC_RC32MHZ
Internal 32 MHz RC oscillator.
#define SYSCLK_PSBCDIV_2_2
Prescale CLKper2 by 2, CLKper and CLKcpu by 4.
#define SYSCLK_SRC_PLL
Phase-Locked Loop.
#define SYSCLK_RTCSRC_EXTCLK
void sysclk_disable_module(enum sysclk_port_id port, uint8_t id)
Disable the clock to peripheral id on port port.
Chip-specific system clock manager configuration.
#define SYSCLK_RTCSRC_TOSC
static bool sysclk_module_is_enabled(enum sysclk_port_id port, uint8_t id)
Check if the synchronous clock is enabled for a module.
static void sysclk_set_prescalers(uint8_t psadiv, uint8_t psbcdiv)
Set system clock prescaler configuration.