genclk.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * \file
  3. *
  4. * \brief Generic 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 CLK_GENCLK_H_INCLUDED
  47. #define CLK_GENCLK_H_INCLUDED
  48. #include "parts.h"
  49. #if SAM3S
  50. # include "sam3s/genclk.h"
  51. #elif SAM3U
  52. # include "sam3u/genclk.h"
  53. #elif SAM3N
  54. # include "sam3n/genclk.h"
  55. #elif SAM3XA
  56. # include "sam3x/genclk.h"
  57. #elif SAM4S
  58. # include "sam4s/genclk.h"
  59. #elif SAM4L
  60. # include "sam4l/genclk.h"
  61. #elif SAM4E
  62. # include "sam4e/genclk.h"
  63. #elif SAM4N
  64. # include "sam4n/genclk.h"
  65. #elif SAM4C
  66. # include "sam4c/genclk.h"
  67. #elif SAM4CM
  68. # include "sam4cm/genclk.h"
  69. #elif SAM4CP
  70. # include "sam4cp/genclk.h"
  71. #elif SAMG
  72. # include "samg/genclk.h"
  73. #elif SAMV71
  74. # include "samv71/genclk.h"
  75. #elif SAMV70
  76. # include "samv70/genclk.h"
  77. #elif SAME70
  78. # include "same70/genclk.h"
  79. #elif SAMS70
  80. # include "sams70/genclk.h"
  81. #elif (UC3A0 || UC3A1)
  82. # include "uc3a0_a1/genclk.h"
  83. #elif UC3A3
  84. # include "uc3a3_a4/genclk.h"
  85. #elif UC3B
  86. # include "uc3b0_b1/genclk.h"
  87. #elif UC3C
  88. # include "uc3c/genclk.h"
  89. #elif UC3D
  90. # include "uc3d/genclk.h"
  91. #elif UC3L
  92. # include "uc3l/genclk.h"
  93. #else
  94. # error Unsupported chip type
  95. #endif
  96. /**
  97. * \ingroup clk_group
  98. * \defgroup genclk_group Generic Clock Management
  99. *
  100. * Generic clocks are configurable clocks which run outside the system
  101. * clock domain. They are often connected to peripherals which have an
  102. * asynchronous component running independently of the bus clock, e.g.
  103. * USB controllers, low-power timers and RTCs, etc.
  104. *
  105. * Note that not all platforms have support for generic clocks; on such
  106. * platforms, this API will not be available.
  107. *
  108. * @{
  109. */
  110. /**
  111. * \def GENCLK_DIV_MAX
  112. * \brief Maximum divider supported by the generic clock implementation
  113. */
  114. /**
  115. * \enum genclk_source
  116. * \brief Generic clock source ID
  117. *
  118. * Each generic clock may be generated from a different clock source.
  119. * These are the available alternatives provided by the chip.
  120. */
  121. //! \name Generic clock configuration
  122. //@{
  123. /**
  124. * \struct genclk_config
  125. * \brief Hardware representation of a set of generic clock parameters
  126. */
  127. /**
  128. * \fn void genclk_config_defaults(struct genclk_config *cfg,
  129. * unsigned int id)
  130. * \brief Initialize \a cfg to the default configuration for the clock
  131. * identified by \a id.
  132. */
  133. /**
  134. * \fn void genclk_config_read(struct genclk_config *cfg, unsigned int id)
  135. * \brief Read the currently active configuration of the clock
  136. * identified by \a id into \a cfg.
  137. */
  138. /**
  139. * \fn void genclk_config_write(const struct genclk_config *cfg,
  140. * unsigned int id)
  141. * \brief Activate the configuration \a cfg on the clock identified by
  142. * \a id.
  143. */
  144. /**
  145. * \fn void genclk_config_set_source(struct genclk_config *cfg,
  146. * enum genclk_source src)
  147. * \brief Select a new source clock \a src in configuration \a cfg.
  148. */
  149. /**
  150. * \fn void genclk_config_set_divider(struct genclk_config *cfg,
  151. * unsigned int divider)
  152. * \brief Set a new \a divider in configuration \a cfg.
  153. */
  154. /**
  155. * \fn void genclk_enable_source(enum genclk_source src)
  156. * \brief Enable the source clock \a src used by a generic clock.
  157. */
  158. //@}
  159. //! \name Enabling and disabling Generic Clocks
  160. //@{
  161. /**
  162. * \fn void genclk_enable(const struct genclk_config *cfg, unsigned int id)
  163. * \brief Activate the configuration \a cfg on the clock identified by
  164. * \a id and enable it.
  165. */
  166. /**
  167. * \fn void genclk_disable(unsigned int id)
  168. * \brief Disable the generic clock identified by \a id.
  169. */
  170. //@}
  171. /**
  172. * \brief Enable the configuration defined by \a src and \a divider
  173. * for the generic clock identified by \a id.
  174. *
  175. * \param id The ID of the generic clock.
  176. * \param src The source clock of the generic clock.
  177. * \param divider The divider used to generate the generic clock.
  178. */
  179. static inline void genclk_enable_config(unsigned int id, enum genclk_source src, unsigned int divider)
  180. {
  181. struct genclk_config gcfg;
  182. genclk_config_defaults(&gcfg, id);
  183. genclk_enable_source(src);
  184. genclk_config_set_source(&gcfg, src);
  185. genclk_config_set_divider(&gcfg, divider);
  186. genclk_enable(&gcfg, id);
  187. }
  188. //! @}
  189. #endif /* CLK_GENCLK_H_INCLUDED */