same70/sysclk.h
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 #ifndef CHIP_SYSCLK_H_INCLUDED
38 #define CHIP_SYSCLK_H_INCLUDED
39 
40 #include <osc.h>
41 #include <pll.h>
42 
192 
194 #ifdef __cplusplus
195 extern "C" {
196 #endif
197 
198 
205 
207 
214 #ifndef CONFIG_SYSCLK_SOURCE
215 # define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_MAINCK_4M_RC
216 #endif
217 
227 #ifndef CONFIG_SYSCLK_PRES
228 # define CONFIG_SYSCLK_PRES 0
229 #endif
230 
232 
234 
235 #define SYSCLK_SRC_SLCK_RC 0
236 #define SYSCLK_SRC_SLCK_XTAL 1
237 #define SYSCLK_SRC_SLCK_BYPASS 2
238 #define SYSCLK_SRC_MAINCK_4M_RC 3
239 #define SYSCLK_SRC_MAINCK_8M_RC 4
240 #define SYSCLK_SRC_MAINCK_12M_RC 5
241 #define SYSCLK_SRC_MAINCK_XTAL 6
242 #define SYSCLK_SRC_MAINCK_BYPASS 7
243 #define SYSCLK_SRC_PLLACK 8
244 #define SYSCLK_SRC_UPLLCK 9
245 
246 
247 
249 #define SYSCLK_PRES_1 PMC_MCKR_PRES_CLK_1
250 #define SYSCLK_PRES_2 PMC_MCKR_PRES_CLK_2
251 #define SYSCLK_PRES_4 PMC_MCKR_PRES_CLK_4
252 #define SYSCLK_PRES_8 PMC_MCKR_PRES_CLK_8
253 #define SYSCLK_PRES_16 PMC_MCKR_PRES_CLK_16
254 #define SYSCLK_PRES_32 PMC_MCKR_PRES_CLK_32
255 #define SYSCLK_PRES_64 PMC_MCKR_PRES_CLK_64
256 #define SYSCLK_PRES_3 PMC_MCKR_PRES_CLK_3
257 
258 
259 
261 #define SYSCLK_DIV_1 PMC_MCKR_MDIV_EQ_PCK
262 #define SYSCLK_DIV_2 PMC_MCKR_MDIV_PCK_DIV2
263 #define SYSCLK_DIV_4 PMC_MCKR_MDIV_PCK_DIV4
264 #define SYSCLK_DIV_3 PMC_MCKR_MDIV_PCK_DIV3
265 
266 
267 
269 #define USBCLK_SRC_PLL0 0
270 #define USBCLK_SRC_UPLL 1
271 
272 
273 
283 #ifdef __DOXYGEN__
284 # define CONFIG_USBCLK_SOURCE
285 #endif
286 
295 #ifdef __DOXYGEN__
296 # define CONFIG_USBCLK_DIV
297 #endif
298 
310 
321 #if (defined CONFIG_SYSCLK_DEFAULT_RETURNS_SLOW_OSC)
322 extern uint32_t sysclk_initialized;
323 #endif
324 static inline uint32_t sysclk_get_main_hz(void)
325 {
326 #if (defined CONFIG_SYSCLK_DEFAULT_RETURNS_SLOW_OSC)
327  if (!sysclk_initialized ) {
328  return OSC_MAINCK_4M_RC_HZ;
329  }
330 #endif
331 
332  /* Config system clock setting */
334  return OSC_SLCK_32K_RC_HZ;
336  return OSC_SLCK_32K_XTAL_HZ;
338  return OSC_SLCK_32K_BYPASS_HZ;
340  return OSC_MAINCK_4M_RC_HZ;
342  return OSC_MAINCK_8M_RC_HZ;
344  return OSC_MAINCK_12M_RC_HZ;
346  return OSC_MAINCK_XTAL_HZ;
348  return OSC_MAINCK_BYPASS_HZ;
349  }
350 #ifdef CONFIG_PLL0_SOURCE
352  return pll_get_default_rate(0);
353  }
354 #endif
355 
356 #ifdef CONFIG_PLL1_SOURCE
358  return PLL_UPLL_HZ;
359  }
360 #endif
361  else {
362  /* unhandled_case(CONFIG_SYSCLK_SOURCE); */
363  return 0;
364  }
365 }
366 
378 static inline uint32_t sysclk_get_cpu_hz(void)
379 {
380  /* CONFIG_SYSCLK_PRES is the register value for setting the expected */
381  /* prescaler, not an immediate value. */
382  return sysclk_get_main_hz() /
385 }
386 
392 static inline uint32_t sysclk_get_peripheral_hz(void)
393 {
394  /* CONFIG_SYSCLK_PRES is the register value for setting the expected */
395  /* prescaler, not an immediate value. */
396  return sysclk_get_main_hz() /
398 }
399 
408 static inline uint32_t sysclk_get_peripheral_bus_hz(const volatile void *module)
409 {
410  UNUSED(module);
411  return sysclk_get_peripheral_hz();
412 }
414 
416 
417 
423 static inline void sysclk_enable_peripheral_clock(uint32_t ul_id)
424 {
425  pmc_enable_periph_clk(ul_id);
426 }
427 
433 static inline void sysclk_disable_peripheral_clock(uint32_t ul_id)
434 {
435  pmc_disable_periph_clk(ul_id);
436 }
437 
439 
441 
442 
443 extern void sysclk_set_prescalers(uint32_t ul_pres);
444 extern void sysclk_set_source(uint32_t ul_src);
445 
447 
448 extern void sysclk_enable_usb(void);
449 extern void sysclk_disable_usb(void);
450 
451 extern void sysclk_init(void);
452 
454 
456 
457 #ifdef __cplusplus
458 }
459 #endif
460 
461 
463 #endif /* CHIP_SYSCLK_H_INCLUDED */
#define OSC_MAINCK_XTAL_HZ
External crystal oscillator.
Definition: same70/osc.h:105
#define UNUSED(v)
Marking v as a unused parameter or value.
Definition: compiler.h:86
#define pll_get_default_rate(pll_id)
Get the default rate in Hz of pll_id.
Definition: same70/pll.h:82
static uint32_t sysclk_get_cpu_hz(void)
Return the current rate in Hz of the CPU clock.
#define OSC_SLCK_32K_XTAL_HZ
External 32kHz crystal oscillator.
Definition: same70/osc.h:100
#define CONFIG_SYSCLK_SOURCE
Initial/static main system clock source.
#define SYSCLK_PRES_3
Set master clock prescaler to 3.
#define SYSCLK_SRC_MAINCK_12M_RC
Internal 12MHz RC oscillator as master source clock.
uint32_t pmc_disable_periph_clk(uint32_t ul_id)
Disable the specified peripheral clock.
Definition: pmc.c:722
uint32_t pmc_enable_periph_clk(uint32_t ul_id)
Enable the specified peripheral clock.
Definition: pmc.c:682
#define OSC_SLCK_32K_BYPASS_HZ
External 32kHz bypass oscillator.
Definition: same70/osc.h:101
#define OSC_MAINCK_12M_RC_HZ
Internal 12MHz RC oscillator.
Definition: same70/osc.h:104
#define SYSCLK_SRC_PLLACK
Use PLLACK as master source clock.
#define SYSCLK_SRC_MAINCK_8M_RC
Internal 8MHz RC oscillator as master source clock.
#define SYSCLK_SRC_SLCK_XTAL
External 32kHz crystal oscillator as master source clock.
Chip-specific PLL definitions.
#define SYSCLK_SRC_SLCK_RC
Internal 32kHz RC oscillator as master source clock.
static uint32_t sysclk_get_peripheral_hz(void)
Retrieves the current rate in Hz of the peripheral clocks.
#define OSC_MAINCK_8M_RC_HZ
Internal 8MHz RC oscillator.
Definition: same70/osc.h:103
void sysclk_set_prescalers(uint32_t ul_pres)
Set system clock prescaler configuration.
Definition: sysclk.c:69
void sysclk_init(void)
Initialize the synchronous clock system.
Definition: sysclk.c:158
static void sysclk_disable_peripheral_clock(uint32_t ul_id)
Disable a peripheral&#39;s clock.
void sysclk_enable_usb(void)
#define SYSCLK_SRC_SLCK_BYPASS
External 32kHz bypass oscillator as master source clock.
#define OSC_SLCK_32K_RC_HZ
Internal 32kHz RC oscillator.
Definition: same70/osc.h:99
void sysclk_disable_usb(void)
#define CONFIG_SYSCLK_PRES
Initial CPU clock divider (mck)
#define PLL_UPLL_HZ
Definition: same70/pll.h:65
#define OSC_MAINCK_4M_RC_HZ
Internal 4MHz RC oscillator.
Definition: same70/osc.h:102
#define CONFIG_SYSCLK_DIV
Definition: conf_clock.h:63
static void sysclk_enable_peripheral_clock(uint32_t ul_id)
Enable a peripheral&#39;s clock.
#define SYSCLK_SRC_UPLLCK
Use UPLLCK as master source clock.
#define SYSCLK_SRC_MAINCK_XTAL
External crystal oscillator as master source clock.
Chip-specific oscillator management functions.
#define OSC_MAINCK_BYPASS_HZ
External bypass oscillator.
Definition: same70/osc.h:106
#define SYSCLK_SRC_MAINCK_BYPASS
External bypass oscillator as master source clock.
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...
#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
static uint32_t sysclk_get_main_hz(void)
Return the current rate in Hz of the main system clock.


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