osc.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * \file
  3. *
  4. * \brief Oscillator 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 OSC_H_INCLUDED
  47. #define OSC_H_INCLUDED
  48. #include "parts.h"
  49. #include "conf_clock.h"
  50. #if SAM3S
  51. # include "sam3s/osc.h"
  52. #elif SAM3XA
  53. # include "sam3x/osc.h"
  54. #elif SAM3U
  55. # include "sam3u/osc.h"
  56. #elif SAM3N
  57. # include "sam3n/osc.h"
  58. #elif SAM4S
  59. # include "sam4s/osc.h"
  60. #elif SAM4E
  61. # include "sam4e/osc.h"
  62. #elif SAM4C
  63. # include "sam4c/osc.h"
  64. #elif SAM4CM
  65. # include "sam4cm/osc.h"
  66. #elif SAM4CP
  67. # include "sam4cp/osc.h"
  68. #elif SAM4L
  69. # include "sam4l/osc.h"
  70. #elif SAM4N
  71. # include "sam4n/osc.h"
  72. #elif SAMG
  73. # include "samg/osc.h"
  74. #elif SAMV71
  75. # include "samv71/osc.h"
  76. #elif SAMV70
  77. # include "samv70/osc.h"
  78. #elif SAME70
  79. # include "same70/osc.h"
  80. #elif SAMS70
  81. # include "sams70/osc.h"
  82. #elif (UC3A0 || UC3A1)
  83. # include "uc3a0_a1/osc.h"
  84. #elif UC3A3
  85. # include "uc3a3_a4/osc.h"
  86. #elif UC3B
  87. # include "uc3b0_b1/osc.h"
  88. #elif UC3C
  89. # include "uc3c/osc.h"
  90. #elif UC3D
  91. # include "uc3d/osc.h"
  92. #elif UC3L
  93. # include "uc3l/osc.h"
  94. #elif XMEGA
  95. # include "xmega/osc.h"
  96. #else
  97. # error Unsupported chip type
  98. #endif
  99. /**
  100. * \ingroup clk_group
  101. * \defgroup osc_group Oscillator Management
  102. *
  103. * This group contains functions and definitions related to configuring
  104. * and enabling/disabling on-chip oscillators. Internal RC-oscillators,
  105. * external crystal oscillators and external clock generators are
  106. * supported by this module. What all of these have in common is that
  107. * they swing at a fixed, nominal frequency which is normally not
  108. * adjustable.
  109. *
  110. * \par Example: Enabling an oscillator
  111. *
  112. * The following example demonstrates how to enable the external
  113. * oscillator on XMEGA A and wait for it to be ready to use. The
  114. * oscillator identifiers are platform-specific, so while the same
  115. * procedure is used on all platforms, the parameter to osc_enable()
  116. * will be different from device to device.
  117. * \code
  118. osc_enable(OSC_ID_XOSC);
  119. osc_wait_ready(OSC_ID_XOSC); \endcode
  120. *
  121. * \section osc_group_board Board-specific Definitions
  122. * If external oscillators are used, the board code must provide the
  123. * following definitions for each of those:
  124. * - \b BOARD_<osc name>_HZ: The nominal frequency of the oscillator.
  125. * - \b BOARD_<osc name>_STARTUP_US: The startup time of the
  126. * oscillator in microseconds.
  127. * - \b BOARD_<osc name>_TYPE: The type of oscillator connected, i.e.
  128. * whether it's a crystal or external clock, and sometimes what kind
  129. * of crystal it is. The meaning of this value is platform-specific.
  130. *
  131. * @{
  132. */
  133. //! \name Oscillator Management
  134. //@{
  135. /**
  136. * \fn void osc_enable(uint8_t id)
  137. * \brief Enable oscillator \a id
  138. *
  139. * The startup time and mode value is automatically determined based on
  140. * definitions in the board code.
  141. */
  142. /**
  143. * \fn void osc_disable(uint8_t id)
  144. * \brief Disable oscillator \a id
  145. */
  146. /**
  147. * \fn osc_is_ready(uint8_t id)
  148. * \brief Determine whether oscillator \a id is ready.
  149. * \retval true Oscillator \a id is running and ready to use as a clock
  150. * source.
  151. * \retval false Oscillator \a id is not running.
  152. */
  153. /**
  154. * \fn uint32_t osc_get_rate(uint8_t id)
  155. * \brief Return the frequency of oscillator \a id in Hz
  156. */
  157. #ifndef __ASSEMBLY__
  158. /**
  159. * \brief Wait until the oscillator identified by \a id is ready
  160. *
  161. * This function will busy-wait for the oscillator identified by \a id
  162. * to become stable and ready to use as a clock source.
  163. *
  164. * \param id A number identifying the oscillator to wait for.
  165. */
  166. static inline void osc_wait_ready(uint8_t id)
  167. {
  168. while (!osc_is_ready(id)) {
  169. /* Do nothing */
  170. }
  171. }
  172. #endif /* __ASSEMBLY__ */
  173. //@}
  174. //! @}
  175. #endif /* OSC_H_INCLUDED */