efm32_cmu.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Clock management unit (CMU) API for EFM32.
  4. * @author Energy Micro AS
  5. * @version 2.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2011 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * This source code is the property of Energy Micro AS. The source and compiled
  12. * code may only be used on Energy Micro "EFM32" microcontrollers.
  13. *
  14. * This copyright notice may not be removed from the source code nor changed.
  15. *
  16. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  17. * obligation to support this Software. Energy Micro AS is providing the
  18. * Software "AS IS", with no express or implied warranties of any kind,
  19. * including, but not limited to, any implied warranties of merchantability
  20. * or fitness for any particular purpose or warranties against infringement
  21. * of any proprietary rights of a third party.
  22. *
  23. * Energy Micro AS will not be liable for any consequential, incidental, or
  24. * special damages, or any other relief, or for any claim by any third party,
  25. * arising from your use of this Software.
  26. *
  27. ******************************************************************************/
  28. #ifndef __EFM32_CMU_H
  29. #define __EFM32_CMU_H
  30. #include <stdbool.h>
  31. #include "efm32.h"
  32. #include "efm32_bitband.h"
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /***************************************************************************//**
  37. * @addtogroup EFM32_Library
  38. * @{
  39. ******************************************************************************/
  40. /***************************************************************************//**
  41. * @addtogroup CMU
  42. * @{
  43. ******************************************************************************/
  44. /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
  45. /* Select register ids, for internal use */
  46. #define CMU_NOSEL_REG 0
  47. #define CMU_HFCLKSEL_REG 1
  48. #define CMU_LFACLKSEL_REG 2
  49. #define CMU_LFBCLKSEL_REG 3
  50. #define CMU_SEL_REG_POS 0
  51. #define CMU_SEL_REG_MASK 0xf
  52. /* Divisor register ids, for internal use */
  53. #define CMU_NODIV_REG 0
  54. #define CMU_HFPERCLKDIV_REG 1
  55. #define CMU_HFCORECLKDIV_REG 2
  56. #define CMU_LFAPRESC0_REG 3
  57. #define CMU_LFBPRESC0_REG 4
  58. #define CMU_DIV_REG_POS 4
  59. #define CMU_DIV_REG_MASK 0xf
  60. /* Enable register ids, for internal use */
  61. #define CMU_NO_EN_REG 0
  62. #define CMU_HFPERCLKDIV_EN_REG 1
  63. #define CMU_HFPERCLKEN0_EN_REG 2
  64. #define CMU_HFCORECLKEN0_EN_REG 3
  65. #define CMU_LFACLKEN0_EN_REG 4
  66. #define CMU_LFBCLKEN0_EN_REG 5
  67. #define CMU_PCNT_EN_REG 6
  68. #define CMU_EN_REG_POS 8
  69. #define CMU_EN_REG_MASK 0xf
  70. /* Enable register bit position, for internal use */
  71. #define CMU_EN_BIT_POS 12
  72. #define CMU_EN_BIT_MASK 0x1f
  73. /** @endcond */
  74. /*******************************************************************************
  75. ******************************** ENUMS ************************************
  76. ******************************************************************************/
  77. /** Clock divisors. */
  78. typedef enum
  79. {
  80. cmuClkDiv_1 = 0, /**< Divide clock by 1. */
  81. cmuClkDiv_2 = 1, /**< Divide clock by 2. */
  82. cmuClkDiv_4 = 2, /**< Divide clock by 4. */
  83. cmuClkDiv_8 = 3, /**< Divide clock by 8. */
  84. cmuClkDiv_16 = 4, /**< Divide clock by 16. */
  85. cmuClkDiv_32 = 5, /**< Divide clock by 32. */
  86. cmuClkDiv_64 = 6, /**< Divide clock by 64. */
  87. cmuClkDiv_128 = 7, /**< Divide clock by 128. */
  88. cmuClkDiv_256 = 8, /**< Divide clock by 256. */
  89. cmuClkDiv_512 = 9, /**< Divide clock by 512. */
  90. cmuClkDiv_1024 = 10, /**< Divide clock by 1024. */
  91. cmuClkDiv_2048 = 11, /**< Divide clock by 2048. */
  92. cmuClkDiv_4096 = 12, /**< Divide clock by 4096. */
  93. cmuClkDiv_8192 = 13, /**< Divide clock by 8192. */
  94. cmuClkDiv_16384 = 14, /**< Divide clock by 16384. */
  95. cmuClkDiv_32768 = 15 /**< Divide clock by 32768. */
  96. } CMU_ClkDiv_TypeDef;
  97. /** High frequency RC bands. */
  98. typedef enum
  99. {
  100. /** 1MHz RC band. */
  101. cmuHFRCOBand_1MHz = _CMU_HFRCOCTRL_BAND_1MHZ,
  102. /** 7MHz RC band. */
  103. cmuHFRCOBand_7MHz = _CMU_HFRCOCTRL_BAND_7MHZ,
  104. /** 11MHz RC band. */
  105. cmuHFRCOBand_11MHz = _CMU_HFRCOCTRL_BAND_11MHZ,
  106. /** 14MHz RC band. */
  107. cmuHFRCOBand_14MHz = _CMU_HFRCOCTRL_BAND_14MHZ,
  108. /** 21MHz RC band. */
  109. cmuHFRCOBand_21MHz = _CMU_HFRCOCTRL_BAND_21MHZ,
  110. /** 28MHz RC band. */
  111. cmuHFRCOBand_28MHz = _CMU_HFRCOCTRL_BAND_28MHZ
  112. } CMU_HFRCOBand_TypeDef;
  113. /** Clock points in CMU. Please refer to CMU overview in reference manual. */
  114. typedef enum
  115. {
  116. /*******************/
  117. /* HF clock branch */
  118. /*******************/
  119. /** High frequency clock */
  120. cmuClock_HF = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  121. (CMU_HFCLKSEL_REG << CMU_SEL_REG_POS) |
  122. (CMU_NO_EN_REG << CMU_EN_REG_POS) |
  123. (0 << CMU_EN_BIT_POS),
  124. /**********************************/
  125. /* HF peripheral clock sub-branch */
  126. /**********************************/
  127. /** High frequency peripheral clock */
  128. cmuClock_HFPER = (CMU_HFPERCLKDIV_REG << CMU_DIV_REG_POS) |
  129. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  130. (CMU_HFPERCLKDIV_EN_REG << CMU_EN_REG_POS) |
  131. (_CMU_HFPERCLKDIV_HFPERCLKEN_SHIFT << CMU_EN_BIT_POS),
  132. /** Universal sync/async receiver/transmitter 0 clock. */
  133. #if defined(_CMU_HFPERCLKEN0_USART0_MASK)
  134. cmuClock_USART0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  135. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  136. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  137. (_CMU_HFPERCLKEN0_USART0_SHIFT << CMU_EN_BIT_POS),
  138. #endif
  139. /** Universal sync/async receiver/transmitter 1 clock. */
  140. #if defined(_CMU_HFPERCLKEN0_USART1_MASK)
  141. cmuClock_USART1 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  142. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  143. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  144. (_CMU_HFPERCLKEN0_USART1_SHIFT << CMU_EN_BIT_POS),
  145. #endif
  146. /** Universal sync/async receiver/transmitter 2 clock. */
  147. #if defined(_CMU_HFPERCLKEN0_USART2_MASK)
  148. cmuClock_USART2 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  149. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  150. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  151. (_CMU_HFPERCLKEN0_USART2_SHIFT << CMU_EN_BIT_POS),
  152. #endif
  153. /** Universal async receiver/transmitter 0 clock. */
  154. #if defined(_CMU_HFPERCLKEN0_UART0_MASK)
  155. cmuClock_UART0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  156. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  157. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  158. (_CMU_HFPERCLKEN0_UART0_SHIFT << CMU_EN_BIT_POS),
  159. #endif
  160. /** Timer 0 clock. */
  161. #if defined(_CMU_HFPERCLKEN0_TIMER0_MASK)
  162. cmuClock_TIMER0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  163. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  164. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  165. (_CMU_HFPERCLKEN0_TIMER0_SHIFT << CMU_EN_BIT_POS),
  166. #endif
  167. /** Timer 1 clock. */
  168. #if defined(_CMU_HFPERCLKEN0_TIMER1_MASK)
  169. cmuClock_TIMER1 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  170. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  171. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  172. (_CMU_HFPERCLKEN0_TIMER1_SHIFT << CMU_EN_BIT_POS),
  173. #endif
  174. /** Timer 2 clock. */
  175. #if defined(_CMU_HFPERCLKEN0_TIMER2_MASK)
  176. cmuClock_TIMER2 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  177. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  178. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  179. (_CMU_HFPERCLKEN0_TIMER2_SHIFT << CMU_EN_BIT_POS),
  180. #endif
  181. /** Analog comparator 0 clock. */
  182. #if defined(_CMU_HFPERCLKEN0_ACMP0_MASK)
  183. cmuClock_ACMP0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  184. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  185. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  186. (_CMU_HFPERCLKEN0_ACMP0_SHIFT << CMU_EN_BIT_POS),
  187. #endif
  188. /** Analog comparator 1 clock. */
  189. #if defined(_CMU_HFPERCLKEN0_ACMP1_MASK)
  190. cmuClock_ACMP1 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  191. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  192. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  193. (_CMU_HFPERCLKEN0_ACMP1_SHIFT << CMU_EN_BIT_POS),
  194. #endif
  195. /** Peripheral reflex system clock. */
  196. #if defined(PRS_PRESENT)
  197. cmuClock_PRS = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  198. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  199. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  200. (_CMU_HFPERCLKEN0_PRS_SHIFT << CMU_EN_BIT_POS),
  201. #endif
  202. /** Digital to analog converter 0 clock. */
  203. #if defined(_CMU_HFPERCLKEN0_DAC0_MASK)
  204. cmuClock_DAC0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  205. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  206. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  207. (_CMU_HFPERCLKEN0_DAC0_SHIFT << CMU_EN_BIT_POS),
  208. #endif
  209. /** General purpose input/output clock. */
  210. #if defined(GPIO_PRESENT)
  211. cmuClock_GPIO = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  212. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  213. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  214. (_CMU_HFPERCLKEN0_GPIO_SHIFT << CMU_EN_BIT_POS),
  215. #endif
  216. /** Voltage comparator clock. */
  217. #if defined(VCMP_PRESENT)
  218. cmuClock_VCMP = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  219. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  220. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  221. (_CMU_HFPERCLKEN0_VCMP_SHIFT << CMU_EN_BIT_POS),
  222. #endif
  223. /** Analog to digital converter 0 clock. */
  224. #if defined(_CMU_HFPERCLKEN0_ADC0_MASK)
  225. cmuClock_ADC0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  226. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  227. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  228. (_CMU_HFPERCLKEN0_ADC0_SHIFT << CMU_EN_BIT_POS),
  229. #endif
  230. /** I2C 0 clock. */
  231. #if defined(_CMU_HFPERCLKEN0_I2C0_MASK)
  232. cmuClock_I2C0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  233. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  234. (CMU_HFPERCLKEN0_EN_REG << CMU_EN_REG_POS) |
  235. (_CMU_HFPERCLKEN0_I2C0_SHIFT << CMU_EN_BIT_POS),
  236. #endif
  237. /**********************/
  238. /* HF core sub-branch */
  239. /**********************/
  240. /** Core clock */
  241. cmuClock_CORE = (CMU_HFCORECLKDIV_REG << CMU_DIV_REG_POS) |
  242. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  243. (CMU_NO_EN_REG << CMU_EN_REG_POS) |
  244. (0 << CMU_EN_BIT_POS),
  245. /** Advanced encryption standard accelerator clock. */
  246. #if defined(AES_PRESENT)
  247. cmuClock_AES = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  248. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  249. (CMU_HFCORECLKEN0_EN_REG << CMU_EN_REG_POS) |
  250. (_CMU_HFCORECLKEN0_AES_SHIFT << CMU_EN_BIT_POS),
  251. #endif
  252. /** Direct memory access controller clock. */
  253. #if defined(DMA_PRESENT)
  254. cmuClock_DMA = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  255. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  256. (CMU_HFCORECLKEN0_EN_REG << CMU_EN_REG_POS) |
  257. (_CMU_HFCORECLKEN0_DMA_SHIFT << CMU_EN_BIT_POS),
  258. #endif
  259. /** Low energy clocking module clock. */
  260. cmuClock_CORELE = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  261. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  262. (CMU_HFCORECLKEN0_EN_REG << CMU_EN_REG_POS) |
  263. (_CMU_HFCORECLKEN0_LE_SHIFT << CMU_EN_BIT_POS),
  264. /** External bus interface clock. */
  265. #if defined(EBI_PRESENT)
  266. cmuClock_EBI = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  267. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  268. (CMU_HFCORECLKEN0_EN_REG << CMU_EN_REG_POS) |
  269. (_CMU_HFCORECLKEN0_EBI_SHIFT << CMU_EN_BIT_POS),
  270. #endif
  271. /***************/
  272. /* LF A branch */
  273. /***************/
  274. /** Low frequency A clock */
  275. cmuClock_LFA = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  276. (CMU_LFACLKSEL_REG << CMU_SEL_REG_POS) |
  277. (CMU_NO_EN_REG << CMU_EN_REG_POS) |
  278. (0 << CMU_EN_BIT_POS),
  279. /** Real time counter clock. */
  280. #if defined(RTC_PRESENT)
  281. cmuClock_RTC = (CMU_LFAPRESC0_REG << CMU_DIV_REG_POS) |
  282. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  283. (CMU_LFACLKEN0_EN_REG << CMU_EN_REG_POS) |
  284. (_CMU_LFACLKEN0_RTC_SHIFT << CMU_EN_BIT_POS),
  285. #endif
  286. /** Low energy timer 0 clock. */
  287. #if defined(_CMU_LFACLKEN0_LETIMER0_MASK)
  288. cmuClock_LETIMER0 = (CMU_LFAPRESC0_REG << CMU_DIV_REG_POS) |
  289. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  290. (CMU_LFACLKEN0_EN_REG << CMU_EN_REG_POS) |
  291. (_CMU_LFACLKEN0_LETIMER0_SHIFT << CMU_EN_BIT_POS),
  292. #endif
  293. /** Liquid crystal display, pre FDIV clock. */
  294. #if defined(_CMU_LFACLKEN0_LCD_MASK)
  295. cmuClock_LCDpre = (CMU_LFAPRESC0_REG << CMU_DIV_REG_POS) |
  296. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  297. (CMU_NO_EN_REG << CMU_EN_REG_POS) |
  298. (0 << CMU_EN_BIT_POS),
  299. /** Liquid crystal display clock. Please notice that FDIV prescaler
  300. * must be set by special API. */
  301. cmuClock_LCD = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  302. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  303. (CMU_LFACLKEN0_EN_REG << CMU_EN_REG_POS) |
  304. (_CMU_LFACLKEN0_LCD_SHIFT << CMU_EN_BIT_POS),
  305. #endif
  306. /** Pulse counter 0 clock. */
  307. #if defined(_CMU_PCNTCTRL_PCNT0CLKEN_MASK)
  308. cmuClock_PCNT0 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  309. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  310. (CMU_PCNT_EN_REG << CMU_EN_REG_POS) |
  311. (_CMU_PCNTCTRL_PCNT0CLKEN_SHIFT << CMU_EN_BIT_POS),
  312. #endif
  313. /** Pulse counter 1 clock. */
  314. #if defined(_CMU_PCNTCTRL_PCNT1CLKEN_MASK)
  315. cmuClock_PCNT1 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  316. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  317. (CMU_PCNT_EN_REG << CMU_EN_REG_POS) |
  318. (_CMU_PCNTCTRL_PCNT1CLKEN_SHIFT << CMU_EN_BIT_POS),
  319. #endif
  320. /** Pulse counter 2 clock. */
  321. #if defined(_CMU_PCNTCTRL_PCNT2CLKEN_MASK)
  322. cmuClock_PCNT2 = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  323. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  324. (CMU_PCNT_EN_REG << CMU_EN_REG_POS) |
  325. (_CMU_PCNTCTRL_PCNT2CLKEN_SHIFT << CMU_EN_BIT_POS),
  326. #endif
  327. /** LESENSE clock. */
  328. #if defined(_CMU_LFACLKEN0_LESENSE_MASK)
  329. cmuClock_LESENSE = (CMU_LFAPRESC0_REG << CMU_DIV_REG_POS) |
  330. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  331. (CMU_LFACLKEN0_EN_REG << CMU_EN_REG_POS) |
  332. (_CMU_LFACLKEN0_LESENSE_SHIFT << CMU_EN_BIT_POS),
  333. #endif
  334. /***************/
  335. /* LF B branch */
  336. /***************/
  337. /** Low frequency B clock */
  338. cmuClock_LFB = (CMU_NODIV_REG << CMU_DIV_REG_POS) |
  339. (CMU_LFBCLKSEL_REG << CMU_SEL_REG_POS) |
  340. (CMU_NO_EN_REG << CMU_EN_REG_POS) |
  341. (0 << CMU_EN_BIT_POS),
  342. /** Low energy universal asynchronous receiver/transmitter 0 clock. */
  343. #if defined(_CMU_LFBCLKEN0_LEUART0_MASK)
  344. cmuClock_LEUART0 = (CMU_LFBPRESC0_REG << CMU_DIV_REG_POS) |
  345. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  346. (CMU_LFBCLKEN0_EN_REG << CMU_EN_REG_POS) |
  347. (_CMU_LFBCLKEN0_LEUART0_SHIFT << CMU_EN_BIT_POS),
  348. #endif
  349. /** Low energy universal asynchronous receiver/transmitter 1 clock. */
  350. #if defined(_CMU_LFBCLKEN0_LEUART1_MASK)
  351. cmuClock_LEUART1 = (CMU_LFBPRESC0_REG << CMU_DIV_REG_POS) |
  352. (CMU_NOSEL_REG << CMU_SEL_REG_POS) |
  353. (CMU_LFBCLKEN0_EN_REG << CMU_EN_REG_POS) |
  354. (_CMU_LFBCLKEN0_LEUART1_SHIFT << CMU_EN_BIT_POS),
  355. #endif
  356. } CMU_Clock_TypeDef;
  357. /** Oscillator types. */
  358. typedef enum
  359. {
  360. cmuOsc_LFXO, /**< Low frequency crystal oscillator. */
  361. cmuOsc_LFRCO, /**< Low frequency RC oscillator. */
  362. cmuOsc_HFXO, /**< High frequency crystal oscillator. */
  363. cmuOsc_HFRCO, /**< High frequency RC oscillator. */
  364. cmuOsc_AUXHFRCO, /**< Auxiliary high frequency RC oscillator. */
  365. #if defined(_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
  366. cmuOsc_ULFRCO /**< Ultra low frequency RC oscillator. */
  367. #endif
  368. } CMU_Osc_TypeDef;
  369. /** Selectable clock sources. */
  370. typedef enum
  371. {
  372. cmuSelect_Error, /**< Usage error. */
  373. cmuSelect_Disabled, /**< Clock selector disabled. */
  374. cmuSelect_LFXO, /**< Low frequency crystal oscillator. */
  375. cmuSelect_LFRCO, /**< Low frequency RC oscillator. */
  376. cmuSelect_HFXO, /**< High frequency crystal oscillator. */
  377. cmuSelect_HFRCO, /**< High frequency RC oscillator. */
  378. cmuSelect_CORELEDIV2, /**< Core low energy clock divided by 2. */
  379. #if defined(_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
  380. cmuSelect_ULFRCO /**< Ultra low frequency RC oscillator. */
  381. #endif
  382. } CMU_Select_TypeDef;
  383. /*******************************************************************************
  384. ***************************** PROTOTYPES **********************************
  385. ******************************************************************************/
  386. void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable);
  387. uint32_t CMU_ClockFreqGet(CMU_Clock_TypeDef clock);
  388. CMU_ClkDiv_TypeDef CMU_ClockDivGet(CMU_Clock_TypeDef clock);
  389. CMU_Select_TypeDef CMU_ClockSelectGet(CMU_Clock_TypeDef clock);
  390. void CMU_ClockDivSet(CMU_Clock_TypeDef clock, CMU_ClkDiv_TypeDef div);
  391. void CMU_ClockSelectSet(CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref);
  392. CMU_HFRCOBand_TypeDef CMU_HFRCOBandGet(void);
  393. void CMU_HFRCOBandSet(CMU_HFRCOBand_TypeDef band);
  394. void CMU_HFRCOStartupDelaySet(uint32_t delay);
  395. uint32_t CMU_HFRCOStartupDelayGet(void);
  396. void CMU_OscillatorEnable(CMU_Osc_TypeDef osc, bool enable, bool wait);
  397. uint32_t CMU_OscillatorTuningGet(CMU_Osc_TypeDef osc);
  398. void CMU_OscillatorTuningSet(CMU_Osc_TypeDef osc, uint32_t val);
  399. bool CMU_PCNTClockExternalGet(unsigned int inst);
  400. void CMU_PCNTClockExternalSet(unsigned int inst, bool external);
  401. uint32_t CMU_LCDClkFDIVGet(void);
  402. void CMU_LCDClkFDIVSet(uint32_t div);
  403. void CMU_FreezeEnable(bool enable);
  404. uint32_t CMU_Calibrate(uint32_t HFCycles, CMU_Osc_TypeDef reference);
  405. void CMU_CalibrateConfig(uint32_t downCycles, CMU_Osc_TypeDef downSel,
  406. CMU_Osc_TypeDef upSel);
  407. /***************************************************************************//**
  408. * @brief
  409. * Clear one or more pending CMU interrupts.
  410. *
  411. * @param[in] flags
  412. * CMU interrupt sources to clear.
  413. ******************************************************************************/
  414. static __INLINE void CMU_IntClear(uint32_t flags)
  415. {
  416. CMU->IFC = flags;
  417. }
  418. /***************************************************************************//**
  419. * @brief
  420. * Disable one or more CMU interrupts.
  421. *
  422. * @param[in] flags
  423. * CMU interrupt sources to disable.
  424. ******************************************************************************/
  425. static __INLINE void CMU_IntDisable(uint32_t flags)
  426. {
  427. CMU->IEN &= ~flags;
  428. }
  429. /***************************************************************************//**
  430. * @brief
  431. * Enable one or more CMU interrupts.
  432. *
  433. * @note
  434. * Depending on the use, a pending interrupt may already be set prior to
  435. * enabling the interrupt. Consider using CMU_IntClear() prior to enabling
  436. * if such a pending interrupt should be ignored.
  437. *
  438. * @param[in] flags
  439. * CMU interrupt sources to enable.
  440. ******************************************************************************/
  441. static __INLINE void CMU_IntEnable(uint32_t flags)
  442. {
  443. CMU->IEN |= flags;
  444. }
  445. /***************************************************************************//**
  446. * @brief
  447. * Get pending CMU interrupts.
  448. *
  449. * @return
  450. * CMU interrupt sources pending.
  451. ******************************************************************************/
  452. static __INLINE uint32_t CMU_IntGet(void)
  453. {
  454. return CMU->IF;
  455. }
  456. /***************************************************************************//**
  457. * @brief
  458. * Get enabled and pending CMU interrupt flags.
  459. *
  460. * @details
  461. * Useful for handling more interrupt sources in the same interrupt handler.
  462. *
  463. * @note
  464. * The event bits are not cleared by the use of this function.
  465. *
  466. * @return
  467. * Pending and enabled CMU interrupt sources.
  468. * The return value is the bitwise AND combination of
  469. * - the OR combination of enabled interrupt sources in CMU_IEN_nnn
  470. * register (CMU_IEN_nnn) and
  471. * - the OR combination of valid interrupt flags of the CMU module
  472. * (CMU_IF_nnn).
  473. ******************************************************************************/
  474. static __INLINE uint32_t CMU_IntGetEnabled(void)
  475. {
  476. uint32_t tmp = 0U;
  477. /* Store LESENSE->IEN in temporary variable in order to define explicit order
  478. * of volatile accesses. */
  479. tmp = CMU->IEN;
  480. /* Bitwise AND of pending and enabled interrupts */
  481. return CMU->IF & tmp;
  482. }
  483. /**************************************************************************//**
  484. * @brief
  485. * Set one or more pending CMU interrupts from SW.
  486. *
  487. * @param[in] flags
  488. * CMU interrupt sources to set to pending.
  489. *****************************************************************************/
  490. static __INLINE void CMU_IntSet(uint32_t flags)
  491. {
  492. CMU->IFS = flags;
  493. }
  494. /***************************************************************************//**
  495. * @brief
  496. * Lock the CMU in order to protect some of its registers against unintended
  497. * modification.
  498. *
  499. * @details
  500. * Please refer to the reference manual for CMU registers that will be
  501. * locked.
  502. *
  503. * @note
  504. * If locking the CMU registers, they must be unlocked prior to using any
  505. * CMU API functions modifying CMU registers protected by the lock.
  506. ******************************************************************************/
  507. static __INLINE void CMU_Lock(void)
  508. {
  509. CMU->LOCK = CMU_LOCK_LOCKKEY_LOCK;
  510. }
  511. /***************************************************************************//**
  512. * @brief
  513. * Unlock the CMU so that writing to locked registers again is possible.
  514. ******************************************************************************/
  515. static __INLINE void CMU_Unlock(void)
  516. {
  517. CMU->LOCK = CMU_LOCK_LOCKKEY_UNLOCK;
  518. }
  519. /***************************************************************************//**
  520. * @brief
  521. * Get calibration count register
  522. * @note
  523. * If continuous calibrartion mode is active, calibration busy will allmost
  524. * always be on, and we just need to read the value, where the normal case
  525. * would be that this function call has been triggered by the CALRDY
  526. * interrupt flag.
  527. * @return
  528. * Calibration count, the number of UPSEL clocks (see CMU_CalibrateConfig)
  529. * in the period of DOWNSEL oscillator clock cycles configured by a previous
  530. * write operation to CMU->CALCNT
  531. ******************************************************************************/
  532. static __INLINE uint32_t CMU_CalibrateCountGet(void)
  533. {
  534. /* Wait until calibration completes, UNLESS continuous calibration mode is */
  535. /* active */
  536. #if defined (_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
  537. if (!(CMU->CALCTRL & CMU_CALCTRL_CONT))
  538. {
  539. while (CMU->STATUS & CMU_STATUS_CALBSY)
  540. ;
  541. }
  542. #else
  543. while (CMU->STATUS & CMU_STATUS_CALBSY)
  544. ;
  545. #endif
  546. return CMU->CALCNT;
  547. }
  548. /***************************************************************************//**
  549. * @brief
  550. * Starts calibration
  551. * @note
  552. * This call is usually invoked after CMU_CalibrateConfig() and possibly
  553. * CMU_CalibrateCont()
  554. ******************************************************************************/
  555. static __INLINE void CMU_CalibrateStart(void)
  556. {
  557. CMU->CMD = CMU_CMD_CALSTART;
  558. }
  559. #if defined (_EFM32_TINY_FAMILY) || defined(_EFM32_GIANT_FAMILY)
  560. /***************************************************************************//**
  561. * @brief
  562. * Stop the calibration counters
  563. ******************************************************************************/
  564. static __INLINE void CMU_CalibrateStop(void)
  565. {
  566. CMU->CMD = CMU_CMD_CALSTOP;
  567. }
  568. /***************************************************************************//**
  569. * @brief
  570. * Configures continuous calibration mode
  571. * @param[in] enable
  572. * If true, enables continuous calibration, if false disables continuous
  573. * calibrartion
  574. ******************************************************************************/
  575. static __INLINE void CMU_CalibrateCont(bool enable)
  576. {
  577. BITBAND_Peripheral(&(CMU->CALCTRL), _CMU_CALCTRL_CONT_SHIFT, enable);
  578. }
  579. #endif
  580. /** @} (end addtogroup CMU) */
  581. /** @} (end addtogroup EFM32_Library) */
  582. #ifdef __cplusplus
  583. }
  584. #endif
  585. #endif /* __EFM32_CMU_H */