xref: /btstack/port/samv71-xplained-atwilc3000/ASF/common/services/clock/sysclk.h (revision 1b2596b5303dd8caeea8565532c93cca8dab8cc4)
1*1b2596b5SMatthias Ringwald /**
2*1b2596b5SMatthias Ringwald  * \file
3*1b2596b5SMatthias Ringwald  *
4*1b2596b5SMatthias Ringwald  * \brief System clock 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 SYSCLK_H_INCLUDED
47*1b2596b5SMatthias Ringwald #define SYSCLK_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/sysclk.h"
54*1b2596b5SMatthias Ringwald #elif SAM3U
55*1b2596b5SMatthias Ringwald # include "sam3u/sysclk.h"
56*1b2596b5SMatthias Ringwald #elif SAM3N
57*1b2596b5SMatthias Ringwald # include "sam3n/sysclk.h"
58*1b2596b5SMatthias Ringwald #elif SAM3XA
59*1b2596b5SMatthias Ringwald # include "sam3x/sysclk.h"
60*1b2596b5SMatthias Ringwald #elif SAM4S
61*1b2596b5SMatthias Ringwald # include "sam4s/sysclk.h"
62*1b2596b5SMatthias Ringwald #elif SAM4E
63*1b2596b5SMatthias Ringwald # include "sam4e/sysclk.h"
64*1b2596b5SMatthias Ringwald #elif SAM4C
65*1b2596b5SMatthias Ringwald # include "sam4c/sysclk.h"
66*1b2596b5SMatthias Ringwald #elif SAM4CM
67*1b2596b5SMatthias Ringwald # include "sam4cm/sysclk.h"
68*1b2596b5SMatthias Ringwald #elif SAM4CP
69*1b2596b5SMatthias Ringwald # include "sam4cp/sysclk.h"
70*1b2596b5SMatthias Ringwald #elif SAM4L
71*1b2596b5SMatthias Ringwald # include "sam4l/sysclk.h"
72*1b2596b5SMatthias Ringwald #elif SAM4N
73*1b2596b5SMatthias Ringwald # include "sam4n/sysclk.h"
74*1b2596b5SMatthias Ringwald #elif SAMG
75*1b2596b5SMatthias Ringwald # include "samg/sysclk.h"
76*1b2596b5SMatthias Ringwald #elif SAMV71
77*1b2596b5SMatthias Ringwald # include "samv71/sysclk.h"
78*1b2596b5SMatthias Ringwald #elif SAMV70
79*1b2596b5SMatthias Ringwald # include "samv70/sysclk.h"
80*1b2596b5SMatthias Ringwald #elif SAME70
81*1b2596b5SMatthias Ringwald # include "same70/sysclk.h"
82*1b2596b5SMatthias Ringwald #elif SAMS70
83*1b2596b5SMatthias Ringwald # include "sams70/sysclk.h"
84*1b2596b5SMatthias Ringwald #elif (UC3A0 || UC3A1)
85*1b2596b5SMatthias Ringwald # include "uc3a0_a1/sysclk.h"
86*1b2596b5SMatthias Ringwald #elif UC3A3
87*1b2596b5SMatthias Ringwald # include "uc3a3_a4/sysclk.h"
88*1b2596b5SMatthias Ringwald #elif UC3B
89*1b2596b5SMatthias Ringwald # include "uc3b0_b1/sysclk.h"
90*1b2596b5SMatthias Ringwald #elif UC3C
91*1b2596b5SMatthias Ringwald # include "uc3c/sysclk.h"
92*1b2596b5SMatthias Ringwald #elif UC3D
93*1b2596b5SMatthias Ringwald # include "uc3d/sysclk.h"
94*1b2596b5SMatthias Ringwald #elif UC3L
95*1b2596b5SMatthias Ringwald # include "uc3l/sysclk.h"
96*1b2596b5SMatthias Ringwald #elif XMEGA
97*1b2596b5SMatthias Ringwald # include "xmega/sysclk.h"
98*1b2596b5SMatthias Ringwald #elif MEGA
99*1b2596b5SMatthias Ringwald # include "mega/sysclk.h"
100*1b2596b5SMatthias Ringwald #else
101*1b2596b5SMatthias Ringwald # error Unsupported chip type
102*1b2596b5SMatthias Ringwald #endif
103*1b2596b5SMatthias Ringwald 
104*1b2596b5SMatthias Ringwald /**
105*1b2596b5SMatthias Ringwald  * \defgroup clk_group Clock Management
106*1b2596b5SMatthias Ringwald  */
107*1b2596b5SMatthias Ringwald 
108*1b2596b5SMatthias Ringwald /**
109*1b2596b5SMatthias Ringwald  * \ingroup clk_group
110*1b2596b5SMatthias Ringwald  * \defgroup sysclk_group System Clock Management
111*1b2596b5SMatthias Ringwald  *
112*1b2596b5SMatthias Ringwald  * See \ref sysclk_quickstart.
113*1b2596b5SMatthias Ringwald  *
114*1b2596b5SMatthias Ringwald  * The <em>sysclk</em> API covers the <em>system clock</em> and all
115*1b2596b5SMatthias Ringwald  * clocks derived from it. The system clock is a chip-internal clock on
116*1b2596b5SMatthias Ringwald  * which all <em>synchronous clocks</em>, i.e. CPU and bus/peripheral
117*1b2596b5SMatthias Ringwald  * clocks, are based. The system clock is typically generated from one
118*1b2596b5SMatthias Ringwald  * of a variety of sources, which may include crystal and RC oscillators
119*1b2596b5SMatthias Ringwald  * as well as PLLs.  The clocks derived from the system clock are
120*1b2596b5SMatthias Ringwald  * sometimes also known as <em>synchronous clocks</em>, since they
121*1b2596b5SMatthias Ringwald  * always run synchronously with respect to each other, as opposed to
122*1b2596b5SMatthias Ringwald  * <em>generic clocks</em> which may run from different oscillators or
123*1b2596b5SMatthias Ringwald  * PLLs.
124*1b2596b5SMatthias Ringwald  *
125*1b2596b5SMatthias Ringwald  * Most applications should simply call sysclk_init() to initialize
126*1b2596b5SMatthias Ringwald  * everything related to the system clock and its source (oscillator,
127*1b2596b5SMatthias Ringwald  * PLL or DFLL), and leave it at that. More advanced applications, and
128*1b2596b5SMatthias Ringwald  * platform-specific drivers, may require additional services from the
129*1b2596b5SMatthias Ringwald  * clock system, some of which may be platform-specific.
130*1b2596b5SMatthias Ringwald  *
131*1b2596b5SMatthias Ringwald  * \section sysclk_group_platform Platform Dependencies
132*1b2596b5SMatthias Ringwald  *
133*1b2596b5SMatthias Ringwald  * The sysclk API is partially chip- or platform-specific. While all
134*1b2596b5SMatthias Ringwald  * platforms provide mostly the same functionality, there are some
135*1b2596b5SMatthias Ringwald  * variations around how different bus types and clock tree structures
136*1b2596b5SMatthias Ringwald  * are handled.
137*1b2596b5SMatthias Ringwald  *
138*1b2596b5SMatthias Ringwald  * The following functions are available on all platforms with the same
139*1b2596b5SMatthias Ringwald  * parameters and functionality. These functions may be called freely by
140*1b2596b5SMatthias Ringwald  * portable applications, drivers and services:
141*1b2596b5SMatthias Ringwald  *   - sysclk_init()
142*1b2596b5SMatthias Ringwald  *   - sysclk_set_source()
143*1b2596b5SMatthias Ringwald  *   - sysclk_get_main_hz()
144*1b2596b5SMatthias Ringwald  *   - sysclk_get_cpu_hz()
145*1b2596b5SMatthias Ringwald  *   - sysclk_get_peripheral_bus_hz()
146*1b2596b5SMatthias Ringwald  *
147*1b2596b5SMatthias Ringwald  * The following functions are available on all platforms, but there may
148*1b2596b5SMatthias Ringwald  * be variations in the function signature (i.e. parameters) and
149*1b2596b5SMatthias Ringwald  * behavior. These functions are typically called by platform-specific
150*1b2596b5SMatthias Ringwald  * parts of drivers, and applications that aren't intended to be
151*1b2596b5SMatthias Ringwald  * portable:
152*1b2596b5SMatthias Ringwald  *   - sysclk_enable_peripheral_clock()
153*1b2596b5SMatthias Ringwald  *   - sysclk_disable_peripheral_clock()
154*1b2596b5SMatthias Ringwald  *   - sysclk_enable_module()
155*1b2596b5SMatthias Ringwald  *   - sysclk_disable_module()
156*1b2596b5SMatthias Ringwald  *   - sysclk_module_is_enabled()
157*1b2596b5SMatthias Ringwald  *   - sysclk_set_prescalers()
158*1b2596b5SMatthias Ringwald  *
159*1b2596b5SMatthias Ringwald  * All other functions should be considered platform-specific.
160*1b2596b5SMatthias Ringwald  * Enabling/disabling clocks to specific peripherals as well as
161*1b2596b5SMatthias Ringwald  * determining the speed of these clocks should be done by calling
162*1b2596b5SMatthias Ringwald  * functions provided by the driver for that peripheral.
163*1b2596b5SMatthias Ringwald  *
164*1b2596b5SMatthias Ringwald  * @{
165*1b2596b5SMatthias Ringwald  */
166*1b2596b5SMatthias Ringwald 
167*1b2596b5SMatthias Ringwald //! \name System Clock Initialization
168*1b2596b5SMatthias Ringwald //@{
169*1b2596b5SMatthias Ringwald /**
170*1b2596b5SMatthias Ringwald  * \fn void sysclk_init(void)
171*1b2596b5SMatthias Ringwald  * \brief Initialize the synchronous clock system.
172*1b2596b5SMatthias Ringwald  *
173*1b2596b5SMatthias Ringwald  * This function will initialize the system clock and its source. This
174*1b2596b5SMatthias Ringwald  * includes:
175*1b2596b5SMatthias Ringwald  *   - Mask all synchronous clocks except for any clocks which are
176*1b2596b5SMatthias Ringwald  *     essential for normal operation (for example internal memory
177*1b2596b5SMatthias Ringwald  *     clocks).
178*1b2596b5SMatthias Ringwald  *   - Set up the system clock prescalers as specified by the
179*1b2596b5SMatthias Ringwald  *     application's configuration file.
180*1b2596b5SMatthias Ringwald  *   - Enable the clock source specified by the application's
181*1b2596b5SMatthias Ringwald  *     configuration file (oscillator or PLL) and wait for it to become
182*1b2596b5SMatthias Ringwald  *     stable.
183*1b2596b5SMatthias Ringwald  *   - Set the main system clock source to the clock specified by the
184*1b2596b5SMatthias Ringwald  *     application's configuration file.
185*1b2596b5SMatthias Ringwald  *
186*1b2596b5SMatthias Ringwald  * Since all non-essential peripheral clocks are initially disabled, it
187*1b2596b5SMatthias Ringwald  * is the responsibility of the peripheral driver to re-enable any
188*1b2596b5SMatthias Ringwald  * clocks that are needed for normal operation.
189*1b2596b5SMatthias Ringwald  */
190*1b2596b5SMatthias Ringwald //@}
191*1b2596b5SMatthias Ringwald 
192*1b2596b5SMatthias Ringwald //! @}
193*1b2596b5SMatthias Ringwald 
194*1b2596b5SMatthias Ringwald #endif /* SYSCLK_H_INCLUDED */
195