same70/osc.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_OSC_H_INCLUDED
38 #define CHIP_OSC_H_INCLUDED
39 
40 #include "board.h"
41 #include "pmc.h"
42 
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 
51 /*
52  * Below BOARD_XXX macros are related to the specific board, and
53  * should be defined by the board code, otherwise default value are used.
54  */
55 #if !defined(BOARD_FREQ_SLCK_XTAL)
56 # warning The board slow clock xtal frequency has not been defined.
57 # define BOARD_FREQ_SLCK_XTAL (32768UL)
58 #endif
59 
60 #if !defined(BOARD_FREQ_SLCK_BYPASS)
61 # warning The board slow clock bypass frequency has not been defined.
62 # define BOARD_FREQ_SLCK_BYPASS (32768UL)
63 #endif
64 
65 #if !defined(BOARD_FREQ_MAINCK_XTAL)
66 # warning The board main clock xtal frequency has not been defined.
67 # define BOARD_FREQ_MAINCK_XTAL (12000000UL)
68 #endif
69 
70 #if !defined(BOARD_FREQ_MAINCK_BYPASS)
71 # warning The board main clock bypass frequency has not been defined.
72 # define BOARD_FREQ_MAINCK_BYPASS (12000000UL)
73 #endif
74 
75 #if !defined(BOARD_OSC_STARTUP_US)
76 # warning The board main clock xtal startup time has not been defined.
77 # define BOARD_OSC_STARTUP_US (15625UL)
78 #endif
79 
85 
87 #define OSC_SLCK_32K_RC 0
88 #define OSC_SLCK_32K_XTAL 1
89 #define OSC_SLCK_32K_BYPASS 2
90 #define OSC_MAINCK_4M_RC 3
91 #define OSC_MAINCK_8M_RC 4
92 #define OSC_MAINCK_12M_RC 5
93 #define OSC_MAINCK_XTAL 6
94 #define OSC_MAINCK_BYPASS 7
95 
96 
97 
99 #define OSC_SLCK_32K_RC_HZ CHIP_FREQ_SLCK_RC
100 #define OSC_SLCK_32K_XTAL_HZ BOARD_FREQ_SLCK_XTAL
101 #define OSC_SLCK_32K_BYPASS_HZ BOARD_FREQ_SLCK_BYPASS
102 #define OSC_MAINCK_4M_RC_HZ CHIP_FREQ_MAINCK_RC_4MHZ
103 #define OSC_MAINCK_8M_RC_HZ CHIP_FREQ_MAINCK_RC_8MHZ
104 #define OSC_MAINCK_12M_RC_HZ CHIP_FREQ_MAINCK_RC_12MHZ
105 #define OSC_MAINCK_XTAL_HZ BOARD_FREQ_MAINCK_XTAL
106 #define OSC_MAINCK_BYPASS_HZ BOARD_FREQ_MAINCK_BYPASS
107 
108 
109 static inline void osc_enable(uint32_t ul_id)
110 {
111  switch (ul_id) {
112  case OSC_SLCK_32K_RC:
113  break;
114 
115  case OSC_SLCK_32K_XTAL:
117  break;
118 
119  case OSC_SLCK_32K_BYPASS:
121  break;
122 
123 
124  case OSC_MAINCK_4M_RC:
126  break;
127 
128  case OSC_MAINCK_8M_RC:
130  break;
131 
132  case OSC_MAINCK_12M_RC:
134  break;
135 
136 
137  case OSC_MAINCK_XTAL:
141  break;
142 
143  case OSC_MAINCK_BYPASS:
147  break;
148  }
149 }
150 
151 static inline void osc_disable(uint32_t ul_id)
152 {
153  switch (ul_id) {
154  case OSC_SLCK_32K_RC:
155  case OSC_SLCK_32K_XTAL:
156  case OSC_SLCK_32K_BYPASS:
157  break;
158 
159  case OSC_MAINCK_4M_RC:
160  case OSC_MAINCK_8M_RC:
161  case OSC_MAINCK_12M_RC:
163  break;
164 
165  case OSC_MAINCK_XTAL:
167  break;
168 
169  case OSC_MAINCK_BYPASS:
171  break;
172  }
173 }
174 
175 static inline bool osc_is_ready(uint32_t ul_id)
176 {
177  switch (ul_id) {
178  case OSC_SLCK_32K_RC:
179  return 1;
180 
181  case OSC_SLCK_32K_XTAL:
182  case OSC_SLCK_32K_BYPASS:
183  return pmc_osc_is_ready_32kxtal();
184 
185  case OSC_MAINCK_4M_RC:
186  case OSC_MAINCK_8M_RC:
187  case OSC_MAINCK_12M_RC:
188  case OSC_MAINCK_XTAL:
189  case OSC_MAINCK_BYPASS:
190  return pmc_osc_is_ready_mainck();
191  }
192 
193  return 0;
194 }
195 
196 static inline uint32_t osc_get_rate(uint32_t ul_id)
197 {
198  switch (ul_id) {
199  case OSC_SLCK_32K_RC:
200  return OSC_SLCK_32K_RC_HZ;
201 
202  case OSC_SLCK_32K_XTAL:
203  return BOARD_FREQ_SLCK_XTAL;
204 
205  case OSC_SLCK_32K_BYPASS:
206  return BOARD_FREQ_SLCK_BYPASS;
207 
208  case OSC_MAINCK_4M_RC:
209  return OSC_MAINCK_4M_RC_HZ;
210 
211  case OSC_MAINCK_8M_RC:
212  return OSC_MAINCK_8M_RC_HZ;
213 
214  case OSC_MAINCK_12M_RC:
215  return OSC_MAINCK_12M_RC_HZ;
216 
217  case OSC_MAINCK_XTAL:
218  return BOARD_FREQ_MAINCK_XTAL;
219 
220  case OSC_MAINCK_BYPASS:
222  }
223 
224  return 0;
225 }
226 
228 
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 
237 #endif /* CHIP_OSC_H_INCLUDED */
void pmc_switch_mainck_to_xtal(uint32_t ul_bypass, uint32_t ul_xtal_startup_time)
Switch main clock source selection to external Xtal/Bypass.
Definition: pmc.c:485
static void osc_disable(uint32_t ul_id)
Definition: same70/osc.h:151
#define CKGR_MOR_MOSCRCF_4_MHz
(CKGR_MOR) Fast RC oscillator frequency is at 4 MHz (default)
#define OSC_SLCK_32K_RC
Internal 32kHz RC oscillator.
Definition: same70/osc.h:87
uint32_t pmc_osc_is_ready_32kxtal(void)
Check if the external 32k Xtal is ready.
Definition: pmc.c:336
static uint32_t osc_get_rate(uint32_t ul_id)
Definition: same70/osc.h:196
#define BOARD_OSC_STARTUP_US
Definition: same70/osc.h:77
#define OSC_SLCK_32K_BYPASS
External 32kHz bypass oscillator.
Definition: same70/osc.h:89
#define OSC_MAINCK_12M_RC
Internal 12MHz RC oscillator.
Definition: same70/osc.h:92
void pmc_switch_sclk_to_32kxtal(uint32_t ul_bypass)
Switch slow clock source selection to external 32k (Xtal or Bypass).
Definition: pmc.c:319
#define OSC_MAINCK_12M_RC_HZ
Internal 12MHz RC oscillator.
Definition: same70/osc.h:104
uint32_t pmc_osc_is_ready_mainck(void)
Check if the MAINCK is ready. Depending on MOSCEL, MAINCK can be one of Xtal, bypass or internal RC...
Definition: pmc.c:528
#define OSC_MAINCK_8M_RC_HZ
Internal 8MHz RC oscillator.
Definition: same70/osc.h:103
static void osc_enable(uint32_t ul_id)
Definition: same70/osc.h:109
#define BOARD_FREQ_MAINCK_XTAL
Definition: same70/osc.h:67
#define CKGR_MOR_MOSCRCF_12_MHz
(CKGR_MOR) Fast RC oscillator frequency is at 12 MHz
#define BOARD_FREQ_MAINCK_BYPASS
Definition: same70/osc.h:72
#define OSC_SLCK_32K_RC_HZ
Internal 32kHz RC oscillator.
Definition: same70/osc.h:99
void pmc_switch_mainck_to_fastrc(uint32_t ul_moscrcf)
Switch main clock source selection to internal fast RC.
Definition: pmc.c:351
#define OSC_MAINCK_BYPASS
External bypass oscillator.
Definition: same70/osc.h:94
void pmc_osc_disable_xtal(uint32_t ul_bypass)
Disable the external Xtal.
Definition: pmc.c:509
#define PMC_OSC_XTAL
#define OSC_MAINCK_4M_RC_HZ
Internal 4MHz RC oscillator.
Definition: same70/osc.h:102
#define PMC_OSC_BYPASS
#define OSC_MAINCK_8M_RC
Internal 8MHz RC oscillator.
Definition: same70/osc.h:91
#define OSC_MAINCK_4M_RC
Internal 4MHz RC oscillator.
Definition: same70/osc.h:90
#define pmc_us_to_moscxtst(startup_us, slowck_freq)
#define OSC_MAINCK_XTAL
External crystal oscillator.
Definition: same70/osc.h:93
void pmc_osc_disable_fastrc(void)
Disable the internal fast RC.
Definition: pmc.c:393
#define BOARD_FREQ_SLCK_BYPASS
Definition: same70/osc.h:62
#define CKGR_MOR_MOSCRCF_8_MHz
(CKGR_MOR) Fast RC oscillator frequency is at 8 MHz
static bool osc_is_ready(uint32_t ul_id)
Definition: same70/osc.h:175
Standard board header file.
#define BOARD_FREQ_SLCK_XTAL
Definition: same70/osc.h:57
#define OSC_SLCK_32K_XTAL
External 32kHz crystal oscillator.
Definition: same70/osc.h:88


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