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