sysclk.c
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #include <sysclk.h>
38 
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
52 #if defined(CONFIG_SYSCLK_DEFAULT_RETURNS_SLOW_OSC)
53 
56 uint32_t sysclk_initialized = 0;
57 #endif
58 
69 void sysclk_set_prescalers(uint32_t ul_pres)
70 {
71  pmc_mck_set_prescaler(ul_pres);
73 }
74 
81 void sysclk_set_source(uint32_t ul_src)
82 {
83  switch (ul_src) {
84  case SYSCLK_SRC_SLCK_RC:
88  break;
89 
96  break;
97 
98  case SYSCLK_SRC_PLLACK:
100  break;
101 
102  case SYSCLK_SRC_UPLLCK:
104  break;
105  }
106 
108 }
109 
110 #if defined(CONFIG_USBCLK_SOURCE) || defined(__DOXYGEN__)
111 
120 void sysclk_enable_usb(void)
121 {
123 
124 #ifdef CONFIG_PLL0_SOURCE
126  struct pll_config pllcfg;
127 
129  pll_config_defaults(&pllcfg, 0);
130  pll_enable(&pllcfg, 0);
132  pmc_switch_udpck_to_pllack(CONFIG_USBCLK_DIV - 1);
133  pmc_enable_udpck();
134  return;
135  }
136 #endif
137 
139 
140  pmc_enable_upll_clock();
141  pmc_switch_udpck_to_upllck(CONFIG_USBCLK_DIV - 1);
142  pmc_enable_udpck();
143  return;
144  }
145 }
146 
152 void sysclk_disable_usb(void)
153 {
154  pmc_disable_udpck();
155 }
156 #endif // CONFIG_USBCLK_SOURCE
157 
158 void sysclk_init(void)
159 {
160  struct pll_config pllcfg;
161 
162  /* Set flash wait state to max in case the below clock switching. */
164 
165  /* Config system clock setting */
169  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
171  }
172 
176  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
178  }
179 
183  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
185  }
186 
188  /* Already running from SYSCLK_SRC_MAINCK_4M_RC */
189  }
190 
194  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
196  }
197 
201  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
203  }
204 
208  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
210  }
211 
215  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
217  }
218 
219 #ifdef CONFIG_PLL0_SOURCE
222  pll_config_defaults(&pllcfg, 0);
223  pll_enable(&pllcfg, 0);
225  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
227  }
228 #endif
229 
232  pll_config_defaults(&pllcfg, 1);
233  pll_enable(&pllcfg, 1);
235  pmc_mck_set_division(CONFIG_SYSCLK_DIV);
236  pmc_switch_mck_to_upllck(CONFIG_SYSCLK_PRES);
237  }
238  /* Update the SystemFrequency variable */
240 
241  /* Set a flash wait state depending on the master clock frequency */
243 
244 #if (defined CONFIG_SYSCLK_DEFAULT_RETURNS_SLOW_OSC)
245  /* Signal that the internal frequencies are setup */
246  sysclk_initialized = 1;
247 #endif
248 }
249 
251 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 
Chip-specific system clock management functions.
static void osc_wait_ready(uint8_t id)
Wait until the oscillator identified by id is ready.
Definition: osc.h:162
#define CONFIG_PLL1_SOURCE
Definition: same70/pll.h:97
#define OSC_SLCK_32K_RC
Internal 32kHz RC oscillator.
Definition: same70/osc.h:87
#define CHIP_FREQ_CPU_MAX
Definition: same70j19.h:592
#define USBCLK_SRC_UPLL
Use UPLL.
#define PMC_MCKR_CSS_SLOW_CLK
(PMC_MCKR) Slow Clock is selected
uint32_t pmc_switch_mck_to_pllack(uint32_t ul_pres)
Switch master clock source selection to PLLA clock.
Definition: pmc.c:218
#define OSC_SLCK_32K_BYPASS
External 32kHz bypass oscillator.
Definition: same70/osc.h:89
static uint32_t sysclk_get_cpu_hz(void)
Return the current rate in Hz of the CPU clock.
#define OSC_MAINCK_12M_RC
Internal 12MHz RC oscillator.
Definition: same70/osc.h:92
#define CONFIG_SYSCLK_SOURCE
Initial/static main system clock source.
#define SYSCLK_SRC_MAINCK_12M_RC
Internal 12MHz RC oscillator as master source clock.
void pmc_mck_set_prescaler(uint32_t ul_pres)
Set the prescaler of the MCK.
Definition: pmc.c:96
uint32_t pmc_switch_mck_to_sclk(uint32_t ul_pres)
Switch master clock source selection to slow clock.
Definition: pmc.c:154
void SystemCoreClockUpdate(void)
Updates the SystemCoreClock with current core Clock retrieved from cpu registers. ...
#define SYSCLK_SRC_PLLACK
Use PLLACK as master source clock.
#define SYSCLK_SRC_MAINCK_8M_RC
Internal 8MHz RC oscillator as master source clock.
static void pll_enable_source(enum pll_source e_src)
Enable the source of the pll. The source is enabled, if the source is not already running...
Definition: same70/pll.h:197
#define SYSCLK_SRC_SLCK_XTAL
External 32kHz crystal oscillator as master source clock.
#define SYSCLK_SRC_SLCK_RC
Internal 32kHz RC oscillator as master source clock.
#define PMC_MCKR_CSS_MAIN_CLK
(PMC_MCKR) Main Clock is selected
static void pll_enable(const struct pll_config *p_cfg, uint32_t ul_pll_id)
Definition: same70/pll.h:160
void sysclk_set_prescalers(uint32_t ul_pres)
Set system clock prescaler configuration.
Definition: sysclk.c:69
static void osc_enable(uint32_t ul_id)
Definition: same70/osc.h:109
void sysclk_init(void)
Initialize the synchronous clock system.
Definition: sysclk.c:158
#define CONFIG_PLL0_SOURCE
Definition: conf_clock.h:68
void sysclk_enable_usb(void)
#define SYSCLK_SRC_SLCK_BYPASS
External 32kHz bypass oscillator as master source clock.
Hardware-specific representation of PLL configuration.
Definition: same70/pll.h:78
void system_init_flash(uint32_t ul_clk)
#define pll_config_defaults(cfg, pll_id)
Initialize PLL configuration using default parameters.
Definition: same70/pll.h:131
static int pll_wait_for_lock(unsigned int pll_id)
Wait for PLL pll_id to become locked.
Definition: pll.h:317
#define CONFIG_USBCLK_DIV
Configuration symbol for the USB generic clock divider setting.
Definition: conf_clock.h:87
#define OSC_MAINCK_BYPASS
External bypass oscillator.
Definition: same70/osc.h:94
void sysclk_disable_usb(void)
#define CONFIG_SYSCLK_PRES
Initial CPU clock divider (mck)
void pmc_mck_set_source(uint32_t ul_source)
Set the source of the MCK.
Definition: pmc.c:139
#define PMC_MCKR_CSS_PLLA_CLK
(PMC_MCKR) PLLA Clock is selected
uint32_t pmc_switch_mck_to_mainck(uint32_t ul_pres)
Switch master clock source selection to main clock.
Definition: pmc.c:186
#define OSC_MAINCK_8M_RC
Internal 8MHz RC oscillator.
Definition: same70/osc.h:91
#define PMC_MCKR_CSS_UPLL_CLK
(PMC_MCKR) Divided UPLL Clock is selected
#define CONFIG_SYSCLK_DIV
Definition: conf_clock.h:63
#define OSC_MAINCK_XTAL
External crystal oscillator.
Definition: same70/osc.h:93
#define USBCLK_SRC_PLL0
Use PLLA.
#define SYSCLK_SRC_UPLLCK
Use UPLLCK as master source clock.
#define SYSCLK_SRC_MAINCK_XTAL
External crystal oscillator as master source clock.
#define CONFIG_USBCLK_SOURCE
Configuration symbol for the USB generic clock source.
Definition: conf_clock.h:86
#define Assert(expr)
This macro is used to test fatal errors.
Definition: compiler.h:196
#define SYSCLK_SRC_MAINCK_BYPASS
External bypass oscillator as master source clock.
#define OSC_SLCK_32K_XTAL
External 32kHz crystal oscillator.
Definition: same70/osc.h:88
#define SYSCLK_SRC_MAINCK_4M_RC
Internal 4MHz RC oscillator as master source clock.
void sysclk_set_source(uint32_t ul_src)
Change the source of the main system clock.
Definition: sysclk.c:81


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58