1 /** 2 * \file 3 * 4 * \brief System clock management 5 * 6 * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved. 7 * 8 * \asf_license_start 9 * 10 * \page License 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions are met: 14 * 15 * 1. Redistributions of source code must retain the above copyright notice, 16 * this list of conditions and the following disclaimer. 17 * 18 * 2. Redistributions in binary form must reproduce the above copyright notice, 19 * this list of conditions and the following disclaimer in the documentation 20 * and/or other materials provided with the distribution. 21 * 22 * 3. The name of Atmel may not be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * 4. This software may only be redistributed and used in connection with an 26 * Atmel microcontroller product. 27 * 28 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 31 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 32 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 * 40 * \asf_license_stop 41 * 42 */ 43 /* 44 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> 45 */ 46 #ifndef SYSCLK_H_INCLUDED 47 #define SYSCLK_H_INCLUDED 48 49 #include "parts.h" 50 #include "conf_clock.h" 51 52 #if SAM3S 53 # include "sam3s/sysclk.h" 54 #elif SAM3U 55 # include "sam3u/sysclk.h" 56 #elif SAM3N 57 # include "sam3n/sysclk.h" 58 #elif SAM3XA 59 # include "sam3x/sysclk.h" 60 #elif SAM4S 61 # include "sam4s/sysclk.h" 62 #elif SAM4E 63 # include "sam4e/sysclk.h" 64 #elif SAM4C 65 # include "sam4c/sysclk.h" 66 #elif SAM4CM 67 # include "sam4cm/sysclk.h" 68 #elif SAM4CP 69 # include "sam4cp/sysclk.h" 70 #elif SAM4L 71 # include "sam4l/sysclk.h" 72 #elif SAM4N 73 # include "sam4n/sysclk.h" 74 #elif SAMG 75 # include "samg/sysclk.h" 76 #elif SAMV71 77 # include "samv71/sysclk.h" 78 #elif SAMV70 79 # include "samv70/sysclk.h" 80 #elif SAME70 81 # include "same70/sysclk.h" 82 #elif SAMS70 83 # include "sams70/sysclk.h" 84 #elif (UC3A0 || UC3A1) 85 # include "uc3a0_a1/sysclk.h" 86 #elif UC3A3 87 # include "uc3a3_a4/sysclk.h" 88 #elif UC3B 89 # include "uc3b0_b1/sysclk.h" 90 #elif UC3C 91 # include "uc3c/sysclk.h" 92 #elif UC3D 93 # include "uc3d/sysclk.h" 94 #elif UC3L 95 # include "uc3l/sysclk.h" 96 #elif XMEGA 97 # include "xmega/sysclk.h" 98 #elif MEGA 99 # include "mega/sysclk.h" 100 #else 101 # error Unsupported chip type 102 #endif 103 104 /** 105 * \defgroup clk_group Clock Management 106 */ 107 108 /** 109 * \ingroup clk_group 110 * \defgroup sysclk_group System Clock Management 111 * 112 * See \ref sysclk_quickstart. 113 * 114 * The <em>sysclk</em> API covers the <em>system clock</em> and all 115 * clocks derived from it. The system clock is a chip-internal clock on 116 * which all <em>synchronous clocks</em>, i.e. CPU and bus/peripheral 117 * clocks, are based. The system clock is typically generated from one 118 * of a variety of sources, which may include crystal and RC oscillators 119 * as well as PLLs. The clocks derived from the system clock are 120 * sometimes also known as <em>synchronous clocks</em>, since they 121 * always run synchronously with respect to each other, as opposed to 122 * <em>generic clocks</em> which may run from different oscillators or 123 * PLLs. 124 * 125 * Most applications should simply call sysclk_init() to initialize 126 * everything related to the system clock and its source (oscillator, 127 * PLL or DFLL), and leave it at that. More advanced applications, and 128 * platform-specific drivers, may require additional services from the 129 * clock system, some of which may be platform-specific. 130 * 131 * \section sysclk_group_platform Platform Dependencies 132 * 133 * The sysclk API is partially chip- or platform-specific. While all 134 * platforms provide mostly the same functionality, there are some 135 * variations around how different bus types and clock tree structures 136 * are handled. 137 * 138 * The following functions are available on all platforms with the same 139 * parameters and functionality. These functions may be called freely by 140 * portable applications, drivers and services: 141 * - sysclk_init() 142 * - sysclk_set_source() 143 * - sysclk_get_main_hz() 144 * - sysclk_get_cpu_hz() 145 * - sysclk_get_peripheral_bus_hz() 146 * 147 * The following functions are available on all platforms, but there may 148 * be variations in the function signature (i.e. parameters) and 149 * behavior. These functions are typically called by platform-specific 150 * parts of drivers, and applications that aren't intended to be 151 * portable: 152 * - sysclk_enable_peripheral_clock() 153 * - sysclk_disable_peripheral_clock() 154 * - sysclk_enable_module() 155 * - sysclk_disable_module() 156 * - sysclk_module_is_enabled() 157 * - sysclk_set_prescalers() 158 * 159 * All other functions should be considered platform-specific. 160 * Enabling/disabling clocks to specific peripherals as well as 161 * determining the speed of these clocks should be done by calling 162 * functions provided by the driver for that peripheral. 163 * 164 * @{ 165 */ 166 167 //! \name System Clock Initialization 168 //@{ 169 /** 170 * \fn void sysclk_init(void) 171 * \brief Initialize the synchronous clock system. 172 * 173 * This function will initialize the system clock and its source. This 174 * includes: 175 * - Mask all synchronous clocks except for any clocks which are 176 * essential for normal operation (for example internal memory 177 * clocks). 178 * - Set up the system clock prescalers as specified by the 179 * application's configuration file. 180 * - Enable the clock source specified by the application's 181 * configuration file (oscillator or PLL) and wait for it to become 182 * stable. 183 * - Set the main system clock source to the clock specified by the 184 * application's configuration file. 185 * 186 * Since all non-essential peripheral clocks are initially disabled, it 187 * is the responsibility of the peripheral driver to re-enable any 188 * clocks that are needed for normal operation. 189 */ 190 //@} 191 192 //! @} 193 194 #endif /* SYSCLK_H_INCLUDED */ 195