![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_Atmel/TARGET_SAM_CortexM4/services/clock/genclk.h@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /** |
kadonotakashi | 0:8fdf9a60065b | 2 | * \file |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * \brief Generic clock management |
kadonotakashi | 0:8fdf9a60065b | 5 | * |
kadonotakashi | 0:8fdf9a60065b | 6 | * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved. |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * \asf_license_start |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * \page License |
kadonotakashi | 0:8fdf9a60065b | 11 | * |
kadonotakashi | 0:8fdf9a60065b | 12 | * Redistribution and use in source and binary forms, with or without |
kadonotakashi | 0:8fdf9a60065b | 13 | * modification, are permitted provided that the following conditions are met: |
kadonotakashi | 0:8fdf9a60065b | 14 | * |
kadonotakashi | 0:8fdf9a60065b | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
kadonotakashi | 0:8fdf9a60065b | 16 | * this list of conditions and the following disclaimer. |
kadonotakashi | 0:8fdf9a60065b | 17 | * |
kadonotakashi | 0:8fdf9a60065b | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
kadonotakashi | 0:8fdf9a60065b | 19 | * this list of conditions and the following disclaimer in the documentation |
kadonotakashi | 0:8fdf9a60065b | 20 | * and/or other materials provided with the distribution. |
kadonotakashi | 0:8fdf9a60065b | 21 | * |
kadonotakashi | 0:8fdf9a60065b | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
kadonotakashi | 0:8fdf9a60065b | 23 | * from this software without specific prior written permission. |
kadonotakashi | 0:8fdf9a60065b | 24 | * |
kadonotakashi | 0:8fdf9a60065b | 25 | * 4. This software may only be redistributed and used in connection with an |
kadonotakashi | 0:8fdf9a60065b | 26 | * Atmel microcontroller product. |
kadonotakashi | 0:8fdf9a60065b | 27 | * |
kadonotakashi | 0:8fdf9a60065b | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
kadonotakashi | 0:8fdf9a60065b | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
kadonotakashi | 0:8fdf9a60065b | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
kadonotakashi | 0:8fdf9a60065b | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
kadonotakashi | 0:8fdf9a60065b | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
kadonotakashi | 0:8fdf9a60065b | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
kadonotakashi | 0:8fdf9a60065b | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
kadonotakashi | 0:8fdf9a60065b | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
kadonotakashi | 0:8fdf9a60065b | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
kadonotakashi | 0:8fdf9a60065b | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
kadonotakashi | 0:8fdf9a60065b | 38 | * POSSIBILITY OF SUCH DAMAGE. |
kadonotakashi | 0:8fdf9a60065b | 39 | * |
kadonotakashi | 0:8fdf9a60065b | 40 | * \asf_license_stop |
kadonotakashi | 0:8fdf9a60065b | 41 | * |
kadonotakashi | 0:8fdf9a60065b | 42 | */ |
kadonotakashi | 0:8fdf9a60065b | 43 | /* |
kadonotakashi | 0:8fdf9a60065b | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
kadonotakashi | 0:8fdf9a60065b | 45 | */ |
kadonotakashi | 0:8fdf9a60065b | 46 | #ifndef CLK_GENCLK_H_INCLUDED |
kadonotakashi | 0:8fdf9a60065b | 47 | #define CLK_GENCLK_H_INCLUDED |
kadonotakashi | 0:8fdf9a60065b | 48 | |
kadonotakashi | 0:8fdf9a60065b | 49 | #include "parts.h" |
kadonotakashi | 0:8fdf9a60065b | 50 | |
kadonotakashi | 0:8fdf9a60065b | 51 | #if SAM3S |
kadonotakashi | 0:8fdf9a60065b | 52 | # include "sam3s/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 53 | #elif SAM3U |
kadonotakashi | 0:8fdf9a60065b | 54 | # include "sam3u/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 55 | #elif SAM3N |
kadonotakashi | 0:8fdf9a60065b | 56 | # include "sam3n/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 57 | #elif SAM3XA |
kadonotakashi | 0:8fdf9a60065b | 58 | # include "sam3x/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 59 | #elif SAM4S |
kadonotakashi | 0:8fdf9a60065b | 60 | # include "sam4s/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 61 | #elif SAM4L |
kadonotakashi | 0:8fdf9a60065b | 62 | # include "sam4l/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 63 | #elif SAM4E |
kadonotakashi | 0:8fdf9a60065b | 64 | # include "sam4e/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 65 | #elif SAM4N |
kadonotakashi | 0:8fdf9a60065b | 66 | # include "sam4n/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 67 | #elif SAM4C |
kadonotakashi | 0:8fdf9a60065b | 68 | # include "sam4c/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 69 | #elif SAM4CM |
kadonotakashi | 0:8fdf9a60065b | 70 | # include "sam4cm/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 71 | #elif SAM4CP |
kadonotakashi | 0:8fdf9a60065b | 72 | # include "sam4cp/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 73 | #elif SAMG |
kadonotakashi | 0:8fdf9a60065b | 74 | # include "samg/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 75 | #elif SAMV71 |
kadonotakashi | 0:8fdf9a60065b | 76 | # include "samv71/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 77 | #elif SAMV70 |
kadonotakashi | 0:8fdf9a60065b | 78 | # include "samv70/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 79 | #elif SAME70 |
kadonotakashi | 0:8fdf9a60065b | 80 | # include "same70/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 81 | #elif SAMS70 |
kadonotakashi | 0:8fdf9a60065b | 82 | # include "sams70/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 83 | #elif (UC3A0 || UC3A1) |
kadonotakashi | 0:8fdf9a60065b | 84 | # include "uc3a0_a1/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 85 | #elif UC3A3 |
kadonotakashi | 0:8fdf9a60065b | 86 | # include "uc3a3_a4/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 87 | #elif UC3B |
kadonotakashi | 0:8fdf9a60065b | 88 | # include "uc3b0_b1/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 89 | #elif UC3C |
kadonotakashi | 0:8fdf9a60065b | 90 | # include "uc3c/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 91 | #elif UC3D |
kadonotakashi | 0:8fdf9a60065b | 92 | # include "uc3d/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 93 | #elif UC3L |
kadonotakashi | 0:8fdf9a60065b | 94 | # include "uc3l/genclk.h" |
kadonotakashi | 0:8fdf9a60065b | 95 | #else |
kadonotakashi | 0:8fdf9a60065b | 96 | # error Unsupported chip type |
kadonotakashi | 0:8fdf9a60065b | 97 | #endif |
kadonotakashi | 0:8fdf9a60065b | 98 | |
kadonotakashi | 0:8fdf9a60065b | 99 | /** |
kadonotakashi | 0:8fdf9a60065b | 100 | * \ingroup clk_group |
kadonotakashi | 0:8fdf9a60065b | 101 | * \defgroup genclk_group Generic Clock Management |
kadonotakashi | 0:8fdf9a60065b | 102 | * |
kadonotakashi | 0:8fdf9a60065b | 103 | * Generic clocks are configurable clocks which run outside the system |
kadonotakashi | 0:8fdf9a60065b | 104 | * clock domain. They are often connected to peripherals which have an |
kadonotakashi | 0:8fdf9a60065b | 105 | * asynchronous component running independently of the bus clock, e.g. |
kadonotakashi | 0:8fdf9a60065b | 106 | * USB controllers, low-power timers and RTCs, etc. |
kadonotakashi | 0:8fdf9a60065b | 107 | * |
kadonotakashi | 0:8fdf9a60065b | 108 | * Note that not all platforms have support for generic clocks; on such |
kadonotakashi | 0:8fdf9a60065b | 109 | * platforms, this API will not be available. |
kadonotakashi | 0:8fdf9a60065b | 110 | * |
kadonotakashi | 0:8fdf9a60065b | 111 | * @{ |
kadonotakashi | 0:8fdf9a60065b | 112 | */ |
kadonotakashi | 0:8fdf9a60065b | 113 | |
kadonotakashi | 0:8fdf9a60065b | 114 | /** |
kadonotakashi | 0:8fdf9a60065b | 115 | * \def GENCLK_DIV_MAX |
kadonotakashi | 0:8fdf9a60065b | 116 | * \brief Maximum divider supported by the generic clock implementation |
kadonotakashi | 0:8fdf9a60065b | 117 | */ |
kadonotakashi | 0:8fdf9a60065b | 118 | /** |
kadonotakashi | 0:8fdf9a60065b | 119 | * \enum genclk_source |
kadonotakashi | 0:8fdf9a60065b | 120 | * \brief Generic clock source ID |
kadonotakashi | 0:8fdf9a60065b | 121 | * |
kadonotakashi | 0:8fdf9a60065b | 122 | * Each generic clock may be generated from a different clock source. |
kadonotakashi | 0:8fdf9a60065b | 123 | * These are the available alternatives provided by the chip. |
kadonotakashi | 0:8fdf9a60065b | 124 | */ |
kadonotakashi | 0:8fdf9a60065b | 125 | |
kadonotakashi | 0:8fdf9a60065b | 126 | //! \name Generic clock configuration |
kadonotakashi | 0:8fdf9a60065b | 127 | //@{ |
kadonotakashi | 0:8fdf9a60065b | 128 | /** |
kadonotakashi | 0:8fdf9a60065b | 129 | * \struct genclk_config |
kadonotakashi | 0:8fdf9a60065b | 130 | * \brief Hardware representation of a set of generic clock parameters |
kadonotakashi | 0:8fdf9a60065b | 131 | */ |
kadonotakashi | 0:8fdf9a60065b | 132 | /** |
kadonotakashi | 0:8fdf9a60065b | 133 | * \fn void genclk_config_defaults(struct genclk_config *cfg, |
kadonotakashi | 0:8fdf9a60065b | 134 | * unsigned int id) |
kadonotakashi | 0:8fdf9a60065b | 135 | * \brief Initialize \a cfg to the default configuration for the clock |
kadonotakashi | 0:8fdf9a60065b | 136 | * identified by \a id. |
kadonotakashi | 0:8fdf9a60065b | 137 | */ |
kadonotakashi | 0:8fdf9a60065b | 138 | /** |
kadonotakashi | 0:8fdf9a60065b | 139 | * \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id) |
kadonotakashi | 0:8fdf9a60065b | 140 | * \brief Read the currently active configuration of the clock |
kadonotakashi | 0:8fdf9a60065b | 141 | * identified by \a id into \a cfg. |
kadonotakashi | 0:8fdf9a60065b | 142 | */ |
kadonotakashi | 0:8fdf9a60065b | 143 | /** |
kadonotakashi | 0:8fdf9a60065b | 144 | * \fn void genclk_config_write(const struct genclk_config *cfg, |
kadonotakashi | 0:8fdf9a60065b | 145 | * unsigned int id) |
kadonotakashi | 0:8fdf9a60065b | 146 | * \brief Activate the configuration \a cfg on the clock identified by |
kadonotakashi | 0:8fdf9a60065b | 147 | * \a id. |
kadonotakashi | 0:8fdf9a60065b | 148 | */ |
kadonotakashi | 0:8fdf9a60065b | 149 | /** |
kadonotakashi | 0:8fdf9a60065b | 150 | * \fn void genclk_config_set_source(struct genclk_config *cfg, |
kadonotakashi | 0:8fdf9a60065b | 151 | * enum genclk_source src) |
kadonotakashi | 0:8fdf9a60065b | 152 | * \brief Select a new source clock \a src in configuration \a cfg. |
kadonotakashi | 0:8fdf9a60065b | 153 | */ |
kadonotakashi | 0:8fdf9a60065b | 154 | /** |
kadonotakashi | 0:8fdf9a60065b | 155 | * \fn void genclk_config_set_divider(struct genclk_config *cfg, |
kadonotakashi | 0:8fdf9a60065b | 156 | * unsigned int divider) |
kadonotakashi | 0:8fdf9a60065b | 157 | * \brief Set a new \a divider in configuration \a cfg. |
kadonotakashi | 0:8fdf9a60065b | 158 | */ |
kadonotakashi | 0:8fdf9a60065b | 159 | /** |
kadonotakashi | 0:8fdf9a60065b | 160 | * \fn void genclk_enable_source(enum genclk_source src) |
kadonotakashi | 0:8fdf9a60065b | 161 | * \brief Enable the source clock \a src used by a generic clock. |
kadonotakashi | 0:8fdf9a60065b | 162 | */ |
kadonotakashi | 0:8fdf9a60065b | 163 | //@} |
kadonotakashi | 0:8fdf9a60065b | 164 | |
kadonotakashi | 0:8fdf9a60065b | 165 | //! \name Enabling and disabling Generic Clocks |
kadonotakashi | 0:8fdf9a60065b | 166 | //@{ |
kadonotakashi | 0:8fdf9a60065b | 167 | /** |
kadonotakashi | 0:8fdf9a60065b | 168 | * \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id) |
kadonotakashi | 0:8fdf9a60065b | 169 | * \brief Activate the configuration \a cfg on the clock identified by |
kadonotakashi | 0:8fdf9a60065b | 170 | * \a id and enable it. |
kadonotakashi | 0:8fdf9a60065b | 171 | */ |
kadonotakashi | 0:8fdf9a60065b | 172 | /** |
kadonotakashi | 0:8fdf9a60065b | 173 | * \fn void genclk_disable(unsigned int id) |
kadonotakashi | 0:8fdf9a60065b | 174 | * \brief Disable the generic clock identified by \a id. |
kadonotakashi | 0:8fdf9a60065b | 175 | */ |
kadonotakashi | 0:8fdf9a60065b | 176 | //@} |
kadonotakashi | 0:8fdf9a60065b | 177 | |
kadonotakashi | 0:8fdf9a60065b | 178 | /** |
kadonotakashi | 0:8fdf9a60065b | 179 | * \brief Enable the configuration defined by \a src and \a divider |
kadonotakashi | 0:8fdf9a60065b | 180 | * for the generic clock identified by \a id. |
kadonotakashi | 0:8fdf9a60065b | 181 | * |
kadonotakashi | 0:8fdf9a60065b | 182 | * \param id The ID of the generic clock. |
kadonotakashi | 0:8fdf9a60065b | 183 | * \param src The source clock of the generic clock. |
kadonotakashi | 0:8fdf9a60065b | 184 | * \param divider The divider used to generate the generic clock. |
kadonotakashi | 0:8fdf9a60065b | 185 | */ |
kadonotakashi | 0:8fdf9a60065b | 186 | static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider) |
kadonotakashi | 0:8fdf9a60065b | 187 | { |
kadonotakashi | 0:8fdf9a60065b | 188 | struct genclk_config gcfg; |
kadonotakashi | 0:8fdf9a60065b | 189 | |
kadonotakashi | 0:8fdf9a60065b | 190 | genclk_config_defaults(&gcfg, id); |
kadonotakashi | 0:8fdf9a60065b | 191 | genclk_enable_source(src); |
kadonotakashi | 0:8fdf9a60065b | 192 | genclk_config_set_source(&gcfg, src); |
kadonotakashi | 0:8fdf9a60065b | 193 | genclk_config_set_divider(&gcfg, divider); |
kadonotakashi | 0:8fdf9a60065b | 194 | genclk_enable(&gcfg, id); |
kadonotakashi | 0:8fdf9a60065b | 195 | } |
kadonotakashi | 0:8fdf9a60065b | 196 | |
kadonotakashi | 0:8fdf9a60065b | 197 | //! @} |
kadonotakashi | 0:8fdf9a60065b | 198 | |
kadonotakashi | 0:8fdf9a60065b | 199 | #endif /* CLK_GENCLK_H_INCLUDED */ |