4 * \brief Chip-specific oscillator management functions.
\r
6 * Copyright (c) 2015 Atmel Corporation. All rights reserved.
\r
12 * Redistribution and use in source and binary forms, with or without
\r
13 * modification, are permitted provided that the following conditions are met:
\r
15 * 1. Redistributions of source code must retain the above copyright notice,
\r
16 * this list of conditions and the following disclaimer.
\r
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
19 * this list of conditions and the following disclaimer in the documentation
\r
20 * and/or other materials provided with the distribution.
\r
22 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
23 * from this software without specific prior written permission.
\r
25 * 4. This software may only be redistributed and used in connection with an
\r
26 * Atmel microcontroller product.
\r
28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
\r
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
38 * POSSIBILITY OF SUCH DAMAGE.
\r
44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
\r
47 #ifndef CHIP_OSC_H_INCLUDED
\r
48 #define CHIP_OSC_H_INCLUDED
\r
62 * Below BOARD_XXX macros are related to the specific board, and
\r
63 * should be defined by the board code, otherwise default value are used.
\r
65 #if !defined(BOARD_FREQ_SLCK_XTAL)
\r
66 # warning The board slow clock xtal frequency has not been defined.
\r
67 # define BOARD_FREQ_SLCK_XTAL (32768UL)
\r
70 #if !defined(BOARD_FREQ_SLCK_BYPASS)
\r
71 # warning The board slow clock bypass frequency has not been defined.
\r
72 # define BOARD_FREQ_SLCK_BYPASS (32768UL)
\r
75 #if !defined(BOARD_FREQ_MAINCK_XTAL)
\r
76 # warning The board main clock xtal frequency has not been defined.
\r
77 # define BOARD_FREQ_MAINCK_XTAL (12000000UL)
\r
80 #if !defined(BOARD_FREQ_MAINCK_BYPASS)
\r
81 # warning The board main clock bypass frequency has not been defined.
\r
82 # define BOARD_FREQ_MAINCK_BYPASS (12000000UL)
\r
85 #if !defined(BOARD_OSC_STARTUP_US)
\r
86 # warning The board main clock xtal startup time has not been defined.
\r
87 # define BOARD_OSC_STARTUP_US (15625UL)
\r
91 * \weakgroup osc_group
\r
95 //! \name Oscillator identifiers
\r
97 #define OSC_SLCK_32K_RC 0 //!< Internal 32kHz RC oscillator.
\r
98 #define OSC_SLCK_32K_XTAL 1 //!< External 32kHz crystal oscillator.
\r
99 #define OSC_SLCK_32K_BYPASS 2 //!< External 32kHz bypass oscillator.
\r
100 #define OSC_MAINCK_4M_RC 3 //!< Internal 4MHz RC oscillator.
\r
101 #define OSC_MAINCK_8M_RC 4 //!< Internal 8MHz RC oscillator.
\r
102 #define OSC_MAINCK_12M_RC 5 //!< Internal 12MHz RC oscillator.
\r
103 #define OSC_MAINCK_XTAL 6 //!< External crystal oscillator.
\r
104 #define OSC_MAINCK_BYPASS 7 //!< External bypass oscillator.
\r
107 //! \name Oscillator clock speed in hertz
\r
109 #define OSC_SLCK_32K_RC_HZ CHIP_FREQ_SLCK_RC //!< Internal 32kHz RC oscillator.
\r
110 #define OSC_SLCK_32K_XTAL_HZ BOARD_FREQ_SLCK_XTAL //!< External 32kHz crystal oscillator.
\r
111 #define OSC_SLCK_32K_BYPASS_HZ BOARD_FREQ_SLCK_BYPASS //!< External 32kHz bypass oscillator.
\r
112 #define OSC_MAINCK_4M_RC_HZ CHIP_FREQ_MAINCK_RC_4MHZ //!< Internal 4MHz RC oscillator.
\r
113 #define OSC_MAINCK_8M_RC_HZ CHIP_FREQ_MAINCK_RC_8MHZ //!< Internal 8MHz RC oscillator.
\r
114 #define OSC_MAINCK_12M_RC_HZ CHIP_FREQ_MAINCK_RC_12MHZ //!< Internal 12MHz RC oscillator.
\r
115 #define OSC_MAINCK_XTAL_HZ BOARD_FREQ_MAINCK_XTAL //!< External crystal oscillator.
\r
116 #define OSC_MAINCK_BYPASS_HZ BOARD_FREQ_MAINCK_BYPASS //!< External bypass oscillator.
\r
119 static inline void osc_enable(uint32_t ul_id)
\r
122 case OSC_SLCK_32K_RC:
\r
125 case OSC_SLCK_32K_XTAL:
\r
126 pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
\r
129 case OSC_SLCK_32K_BYPASS:
\r
130 pmc_switch_sclk_to_32kxtal(PMC_OSC_BYPASS);
\r
134 case OSC_MAINCK_4M_RC:
\r
135 pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_4_MHz);
\r
138 case OSC_MAINCK_8M_RC:
\r
139 pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_8_MHz);
\r
142 case OSC_MAINCK_12M_RC:
\r
143 pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_12_MHz);
\r
147 case OSC_MAINCK_XTAL:
\r
148 pmc_switch_mainck_to_xtal(PMC_OSC_XTAL,
\r
149 pmc_us_to_moscxtst(BOARD_OSC_STARTUP_US,
\r
150 OSC_SLCK_32K_RC_HZ));
\r
153 case OSC_MAINCK_BYPASS:
\r
154 pmc_switch_mainck_to_xtal(PMC_OSC_BYPASS,
\r
155 pmc_us_to_moscxtst(BOARD_OSC_STARTUP_US,
\r
156 OSC_SLCK_32K_RC_HZ));
\r
161 static inline void osc_disable(uint32_t ul_id)
\r
164 case OSC_SLCK_32K_RC:
\r
165 case OSC_SLCK_32K_XTAL:
\r
166 case OSC_SLCK_32K_BYPASS:
\r
169 case OSC_MAINCK_4M_RC:
\r
170 case OSC_MAINCK_8M_RC:
\r
171 case OSC_MAINCK_12M_RC:
\r
172 pmc_osc_disable_fastrc();
\r
175 case OSC_MAINCK_XTAL:
\r
176 pmc_osc_disable_xtal(PMC_OSC_XTAL);
\r
179 case OSC_MAINCK_BYPASS:
\r
180 pmc_osc_disable_xtal(PMC_OSC_BYPASS);
\r
185 static inline bool osc_is_ready(uint32_t ul_id)
\r
188 case OSC_SLCK_32K_RC:
\r
191 case OSC_SLCK_32K_XTAL:
\r
192 case OSC_SLCK_32K_BYPASS:
\r
193 return pmc_osc_is_ready_32kxtal();
\r
195 case OSC_MAINCK_4M_RC:
\r
196 case OSC_MAINCK_8M_RC:
\r
197 case OSC_MAINCK_12M_RC:
\r
198 case OSC_MAINCK_XTAL:
\r
199 case OSC_MAINCK_BYPASS:
\r
200 return pmc_osc_is_ready_mainck();
\r
206 static inline uint32_t osc_get_rate(uint32_t ul_id)
\r
209 case OSC_SLCK_32K_RC:
\r
210 return OSC_SLCK_32K_RC_HZ;
\r
212 case OSC_SLCK_32K_XTAL:
\r
213 return BOARD_FREQ_SLCK_XTAL;
\r
215 case OSC_SLCK_32K_BYPASS:
\r
216 return BOARD_FREQ_SLCK_BYPASS;
\r
218 case OSC_MAINCK_4M_RC:
\r
219 return OSC_MAINCK_4M_RC_HZ;
\r
221 case OSC_MAINCK_8M_RC:
\r
222 return OSC_MAINCK_8M_RC_HZ;
\r
224 case OSC_MAINCK_12M_RC:
\r
225 return OSC_MAINCK_12M_RC_HZ;
\r
227 case OSC_MAINCK_XTAL:
\r
228 return BOARD_FREQ_MAINCK_XTAL;
\r
230 case OSC_MAINCK_BYPASS:
\r
231 return BOARD_FREQ_MAINCK_BYPASS;
\r
247 #endif /* CHIP_OSC_H_INCLUDED */
\r