xref: /btstack/port/samv71-xplained-atwilc3000/ASF/common/services/clock/osc.h (revision 1b2596b5303dd8caeea8565532c93cca8dab8cc4)
1*1b2596b5SMatthias Ringwald /**
2*1b2596b5SMatthias Ringwald  * \file
3*1b2596b5SMatthias Ringwald  *
4*1b2596b5SMatthias Ringwald  * \brief Oscillator management
5*1b2596b5SMatthias Ringwald  *
6*1b2596b5SMatthias Ringwald  * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved.
7*1b2596b5SMatthias Ringwald  *
8*1b2596b5SMatthias Ringwald  * \asf_license_start
9*1b2596b5SMatthias Ringwald  *
10*1b2596b5SMatthias Ringwald  * \page License
11*1b2596b5SMatthias Ringwald  *
12*1b2596b5SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
13*1b2596b5SMatthias Ringwald  * modification, are permitted provided that the following conditions are met:
14*1b2596b5SMatthias Ringwald  *
15*1b2596b5SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright notice,
16*1b2596b5SMatthias Ringwald  *    this list of conditions and the following disclaimer.
17*1b2596b5SMatthias Ringwald  *
18*1b2596b5SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright notice,
19*1b2596b5SMatthias Ringwald  *    this list of conditions and the following disclaimer in the documentation
20*1b2596b5SMatthias Ringwald  *    and/or other materials provided with the distribution.
21*1b2596b5SMatthias Ringwald  *
22*1b2596b5SMatthias Ringwald  * 3. The name of Atmel may not be used to endorse or promote products derived
23*1b2596b5SMatthias Ringwald  *    from this software without specific prior written permission.
24*1b2596b5SMatthias Ringwald  *
25*1b2596b5SMatthias Ringwald  * 4. This software may only be redistributed and used in connection with an
26*1b2596b5SMatthias Ringwald  *    Atmel microcontroller product.
27*1b2596b5SMatthias Ringwald  *
28*1b2596b5SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29*1b2596b5SMatthias Ringwald  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30*1b2596b5SMatthias Ringwald  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31*1b2596b5SMatthias Ringwald  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32*1b2596b5SMatthias Ringwald  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33*1b2596b5SMatthias Ringwald  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34*1b2596b5SMatthias Ringwald  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35*1b2596b5SMatthias Ringwald  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36*1b2596b5SMatthias Ringwald  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37*1b2596b5SMatthias Ringwald  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38*1b2596b5SMatthias Ringwald  * POSSIBILITY OF SUCH DAMAGE.
39*1b2596b5SMatthias Ringwald  *
40*1b2596b5SMatthias Ringwald  * \asf_license_stop
41*1b2596b5SMatthias Ringwald  *
42*1b2596b5SMatthias Ringwald  */
43*1b2596b5SMatthias Ringwald /*
44*1b2596b5SMatthias Ringwald  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45*1b2596b5SMatthias Ringwald  */
46*1b2596b5SMatthias Ringwald #ifndef OSC_H_INCLUDED
47*1b2596b5SMatthias Ringwald #define OSC_H_INCLUDED
48*1b2596b5SMatthias Ringwald 
49*1b2596b5SMatthias Ringwald #include "parts.h"
50*1b2596b5SMatthias Ringwald #include "conf_clock.h"
51*1b2596b5SMatthias Ringwald 
52*1b2596b5SMatthias Ringwald #if SAM3S
53*1b2596b5SMatthias Ringwald # include "sam3s/osc.h"
54*1b2596b5SMatthias Ringwald #elif SAM3XA
55*1b2596b5SMatthias Ringwald # include "sam3x/osc.h"
56*1b2596b5SMatthias Ringwald #elif SAM3U
57*1b2596b5SMatthias Ringwald # include "sam3u/osc.h"
58*1b2596b5SMatthias Ringwald #elif SAM3N
59*1b2596b5SMatthias Ringwald # include "sam3n/osc.h"
60*1b2596b5SMatthias Ringwald #elif SAM4S
61*1b2596b5SMatthias Ringwald # include "sam4s/osc.h"
62*1b2596b5SMatthias Ringwald #elif SAM4E
63*1b2596b5SMatthias Ringwald # include "sam4e/osc.h"
64*1b2596b5SMatthias Ringwald #elif SAM4C
65*1b2596b5SMatthias Ringwald # include "sam4c/osc.h"
66*1b2596b5SMatthias Ringwald #elif SAM4CM
67*1b2596b5SMatthias Ringwald # include "sam4cm/osc.h"
68*1b2596b5SMatthias Ringwald #elif SAM4CP
69*1b2596b5SMatthias Ringwald # include "sam4cp/osc.h"
70*1b2596b5SMatthias Ringwald #elif SAM4L
71*1b2596b5SMatthias Ringwald # include "sam4l/osc.h"
72*1b2596b5SMatthias Ringwald #elif SAM4N
73*1b2596b5SMatthias Ringwald # include "sam4n/osc.h"
74*1b2596b5SMatthias Ringwald #elif SAMG
75*1b2596b5SMatthias Ringwald # include "samg/osc.h"
76*1b2596b5SMatthias Ringwald #elif SAMV71
77*1b2596b5SMatthias Ringwald # include "samv71/osc.h"
78*1b2596b5SMatthias Ringwald #elif SAMV70
79*1b2596b5SMatthias Ringwald # include "samv70/osc.h"
80*1b2596b5SMatthias Ringwald #elif SAME70
81*1b2596b5SMatthias Ringwald # include "same70/osc.h"
82*1b2596b5SMatthias Ringwald #elif SAMS70
83*1b2596b5SMatthias Ringwald # include "sams70/osc.h"
84*1b2596b5SMatthias Ringwald #elif (UC3A0 || UC3A1)
85*1b2596b5SMatthias Ringwald # include "uc3a0_a1/osc.h"
86*1b2596b5SMatthias Ringwald #elif UC3A3
87*1b2596b5SMatthias Ringwald # include "uc3a3_a4/osc.h"
88*1b2596b5SMatthias Ringwald #elif UC3B
89*1b2596b5SMatthias Ringwald # include "uc3b0_b1/osc.h"
90*1b2596b5SMatthias Ringwald #elif UC3C
91*1b2596b5SMatthias Ringwald # include "uc3c/osc.h"
92*1b2596b5SMatthias Ringwald #elif UC3D
93*1b2596b5SMatthias Ringwald # include "uc3d/osc.h"
94*1b2596b5SMatthias Ringwald #elif UC3L
95*1b2596b5SMatthias Ringwald # include "uc3l/osc.h"
96*1b2596b5SMatthias Ringwald #elif XMEGA
97*1b2596b5SMatthias Ringwald # include "xmega/osc.h"
98*1b2596b5SMatthias Ringwald #else
99*1b2596b5SMatthias Ringwald # error Unsupported chip type
100*1b2596b5SMatthias Ringwald #endif
101*1b2596b5SMatthias Ringwald 
102*1b2596b5SMatthias Ringwald /**
103*1b2596b5SMatthias Ringwald  * \ingroup clk_group
104*1b2596b5SMatthias Ringwald  * \defgroup osc_group Oscillator Management
105*1b2596b5SMatthias Ringwald  *
106*1b2596b5SMatthias Ringwald  * This group contains functions and definitions related to configuring
107*1b2596b5SMatthias Ringwald  * and enabling/disabling on-chip oscillators. Internal RC-oscillators,
108*1b2596b5SMatthias Ringwald  * external crystal oscillators and external clock generators are
109*1b2596b5SMatthias Ringwald  * supported by this module. What all of these have in common is that
110*1b2596b5SMatthias Ringwald  * they swing at a fixed, nominal frequency which is normally not
111*1b2596b5SMatthias Ringwald  * adjustable.
112*1b2596b5SMatthias Ringwald  *
113*1b2596b5SMatthias Ringwald  * \par Example: Enabling an oscillator
114*1b2596b5SMatthias Ringwald  *
115*1b2596b5SMatthias Ringwald  * The following example demonstrates how to enable the external
116*1b2596b5SMatthias Ringwald  * oscillator on XMEGA A and wait for it to be ready to use. The
117*1b2596b5SMatthias Ringwald  * oscillator identifiers are platform-specific, so while the same
118*1b2596b5SMatthias Ringwald  * procedure is used on all platforms, the parameter to osc_enable()
119*1b2596b5SMatthias Ringwald  * will be different from device to device.
120*1b2596b5SMatthias Ringwald  * \code
121*1b2596b5SMatthias Ringwald 	osc_enable(OSC_ID_XOSC);
122*1b2596b5SMatthias Ringwald 	osc_wait_ready(OSC_ID_XOSC); \endcode
123*1b2596b5SMatthias Ringwald  *
124*1b2596b5SMatthias Ringwald  * \section osc_group_board Board-specific Definitions
125*1b2596b5SMatthias Ringwald  * If external oscillators are used, the board code must provide the
126*1b2596b5SMatthias Ringwald  * following definitions for each of those:
127*1b2596b5SMatthias Ringwald  *   - \b BOARD_<osc name>_HZ: The nominal frequency of the oscillator.
128*1b2596b5SMatthias Ringwald  *   - \b BOARD_<osc name>_STARTUP_US: The startup time of the
129*1b2596b5SMatthias Ringwald  *     oscillator in microseconds.
130*1b2596b5SMatthias Ringwald  *   - \b BOARD_<osc name>_TYPE: The type of oscillator connected, i.e.
131*1b2596b5SMatthias Ringwald  *     whether it's a crystal or external clock, and sometimes what kind
132*1b2596b5SMatthias Ringwald  *     of crystal it is. The meaning of this value is platform-specific.
133*1b2596b5SMatthias Ringwald  *
134*1b2596b5SMatthias Ringwald  * @{
135*1b2596b5SMatthias Ringwald  */
136*1b2596b5SMatthias Ringwald 
137*1b2596b5SMatthias Ringwald //! \name Oscillator Management
138*1b2596b5SMatthias Ringwald //@{
139*1b2596b5SMatthias Ringwald /**
140*1b2596b5SMatthias Ringwald  * \fn void osc_enable(uint8_t id)
141*1b2596b5SMatthias Ringwald  * \brief Enable oscillator \a id
142*1b2596b5SMatthias Ringwald  *
143*1b2596b5SMatthias Ringwald  * The startup time and mode value is automatically determined based on
144*1b2596b5SMatthias Ringwald  * definitions in the board code.
145*1b2596b5SMatthias Ringwald  */
146*1b2596b5SMatthias Ringwald /**
147*1b2596b5SMatthias Ringwald  * \fn void osc_disable(uint8_t id)
148*1b2596b5SMatthias Ringwald  * \brief Disable oscillator \a id
149*1b2596b5SMatthias Ringwald  */
150*1b2596b5SMatthias Ringwald /**
151*1b2596b5SMatthias Ringwald  * \fn osc_is_ready(uint8_t id)
152*1b2596b5SMatthias Ringwald  * \brief Determine whether oscillator \a id is ready.
153*1b2596b5SMatthias Ringwald  * \retval true Oscillator \a id is running and ready to use as a clock
154*1b2596b5SMatthias Ringwald  * source.
155*1b2596b5SMatthias Ringwald  * \retval false Oscillator \a id is not running.
156*1b2596b5SMatthias Ringwald  */
157*1b2596b5SMatthias Ringwald /**
158*1b2596b5SMatthias Ringwald  * \fn uint32_t osc_get_rate(uint8_t id)
159*1b2596b5SMatthias Ringwald  * \brief Return the frequency of oscillator \a id in Hz
160*1b2596b5SMatthias Ringwald  */
161*1b2596b5SMatthias Ringwald 
162*1b2596b5SMatthias Ringwald #ifndef __ASSEMBLY__
163*1b2596b5SMatthias Ringwald 
164*1b2596b5SMatthias Ringwald /**
165*1b2596b5SMatthias Ringwald  * \brief Wait until the oscillator identified by \a id is ready
166*1b2596b5SMatthias Ringwald  *
167*1b2596b5SMatthias Ringwald  * This function will busy-wait for the oscillator identified by \a id
168*1b2596b5SMatthias Ringwald  * to become stable and ready to use as a clock source.
169*1b2596b5SMatthias Ringwald  *
170*1b2596b5SMatthias Ringwald  * \param id A number identifying the oscillator to wait for.
171*1b2596b5SMatthias Ringwald  */
osc_wait_ready(uint8_t id)172*1b2596b5SMatthias Ringwald static inline void osc_wait_ready(uint8_t id)
173*1b2596b5SMatthias Ringwald {
174*1b2596b5SMatthias Ringwald 	while (!osc_is_ready(id)) {
175*1b2596b5SMatthias Ringwald 		/* Do nothing */
176*1b2596b5SMatthias Ringwald 	}
177*1b2596b5SMatthias Ringwald }
178*1b2596b5SMatthias Ringwald 
179*1b2596b5SMatthias Ringwald #endif /* __ASSEMBLY__ */
180*1b2596b5SMatthias Ringwald 
181*1b2596b5SMatthias Ringwald //@}
182*1b2596b5SMatthias Ringwald 
183*1b2596b5SMatthias Ringwald //! @}
184*1b2596b5SMatthias Ringwald 
185*1b2596b5SMatthias Ringwald #endif /* OSC_H_INCLUDED */
186