efm32_letimer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Low Energy Timer (LETIMER) peripheral API for EFM32.
  4. * @author Energy Micro AS
  5. * @version 1.3.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2010 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_LETIMER_H
  29. #define __EFM32_LETIMER_H
  30. #include <stdbool.h>
  31. #include "efm32.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /***************************************************************************//**
  36. * @addtogroup EFM32_Library
  37. * @{
  38. ******************************************************************************/
  39. /***************************************************************************//**
  40. * @addtogroup LETIMER
  41. * @{
  42. ******************************************************************************/
  43. /*******************************************************************************
  44. ******************************** ENUMS ************************************
  45. ******************************************************************************/
  46. /** Repeat mode. */
  47. typedef enum
  48. {
  49. /** Count until stopped by SW. */
  50. letimerRepeatFree = _LETIMER_CTRL_REPMODE_FREE,
  51. /** Count REP0 times. */
  52. letimerRepeatOneshot = _LETIMER_CTRL_REPMODE_ONESHOT,
  53. /**
  54. * Count REP0 times, if REP1 has been written to, it is loaded into
  55. * REP0 when REP0 is about to be decremented to 0.
  56. */
  57. letimerRepeatBuffered = _LETIMER_CTRL_REPMODE_BUFFERED,
  58. /**
  59. * Run as long as both REP0 and REP1 are not 0. Both REP0 and REP1
  60. * are decremented when counter underflows.
  61. */
  62. letimerRepeatDouble = _LETIMER_CTRL_REPMODE_DOUBLE
  63. } LETIMER_RepeatMode_TypeDef;
  64. /** Underflow action on output. */
  65. typedef enum
  66. {
  67. /** No output action. */
  68. letimerUFOANone = _LETIMER_CTRL_UFOA0_NONE,
  69. /** Toggle output when counter underflows. */
  70. letimerUFOAToggle = _LETIMER_CTRL_UFOA0_TOGGLE,
  71. /** Hold output one LETIMER clock cycle when counter underflows. */
  72. letimerUFOAPulse = _LETIMER_CTRL_UFOA0_PULSE,
  73. /** Set output idle when counter underflows, and active when matching COMP1. */
  74. letimerUFOAPwm = _LETIMER_CTRL_UFOA0_PWM
  75. } LETIMER_UFOA_TypeDef;
  76. /*******************************************************************************
  77. ******************************* STRUCTS ***********************************
  78. ******************************************************************************/
  79. /** LETIMER initialization structure. */
  80. typedef struct
  81. {
  82. bool enable; /**< Start counting when init completed. */
  83. bool debugRun; /**< Counter shall keep running during debug halt. */
  84. bool rtcComp0Enable; /**< Start counting on RTC COMP0 match. */
  85. bool rtcComp1Enable; /**< Start counting on RTC COMP1 match. */
  86. bool comp0Top; /**< Load COMP0 register into CNT when counter underflows. */
  87. bool bufTop; /**< Load COMP1 into COMP0 when REP0 reaches 0. */
  88. uint8_t out0Pol; /**< Idle value for output 0. */
  89. uint8_t out1Pol; /**< Idle value for output 1. */
  90. LETIMER_UFOA_TypeDef ufoa0; /**< Underflow output 0 action. */
  91. LETIMER_UFOA_TypeDef ufoa1; /**< Underflow output 1 action. */
  92. LETIMER_RepeatMode_TypeDef repMode; /**< Repeat mode. */
  93. } LETIMER_Init_TypeDef;
  94. /** Default config for LETIMER init structure. */
  95. #define LETIMER_INIT_DEFAULT \
  96. { true, /* Enable timer when init complete. */ \
  97. false, /* Stop counter during debug halt. */ \
  98. false, /* Do not start counting on RTC COMP0 match. */ \
  99. false, /* Do not start counting on RTC COMP1 match. */ \
  100. false, /* Do not load COMP0 into CNT on underflow. */ \
  101. false, /* Do not load COMP1 into COMP0 when REP0 reaches 0. */ \
  102. 0, /* Idle value 0 for output 0. */ \
  103. 0, /* Idle value 0 for output 1. */ \
  104. letimerUFOANone, /* No action on underflow on output 0. */ \
  105. letimerUFOANone, /* No action on underflow on output 1. */ \
  106. letimerRepeatFree /* Count until stopped by SW. */ \
  107. }
  108. /*******************************************************************************
  109. ***************************** PROTOTYPES **********************************
  110. ******************************************************************************/
  111. uint32_t LETIMER_CompareGet(LETIMER_TypeDef *letimer, unsigned int comp);
  112. void LETIMER_CompareSet(LETIMER_TypeDef *letimer,
  113. unsigned int comp,
  114. uint32_t value);
  115. /***************************************************************************//**
  116. * @brief
  117. * Get LETIMER counter value.
  118. *
  119. * @param[in] letimer
  120. * Pointer to LETIMER peripheral register block.
  121. *
  122. * @return
  123. * Current LETIMER counter value.
  124. ******************************************************************************/
  125. static __INLINE uint32_t LETIMER_CounterGet(LETIMER_TypeDef *letimer)
  126. {
  127. return(letimer->CNT);
  128. }
  129. void LETIMER_Enable(LETIMER_TypeDef *letimer, bool enable);
  130. void LETIMER_FreezeEnable(LETIMER_TypeDef *letimer, bool enable);
  131. void LETIMER_Init(LETIMER_TypeDef *letimer, const LETIMER_Init_TypeDef *init);
  132. /***************************************************************************//**
  133. * @brief
  134. * Clear one or more pending LETIMER interrupts.
  135. *
  136. * @param[in] letimer
  137. * Pointer to LETIMER peripheral register block.
  138. *
  139. * @param[in] flags
  140. * Pending LETIMER interrupt source to clear. Use a logical OR combination
  141. * of valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  142. ******************************************************************************/
  143. static __INLINE void LETIMER_IntClear(LETIMER_TypeDef *letimer, uint32_t flags)
  144. {
  145. letimer->IFC = flags;
  146. }
  147. /***************************************************************************//**
  148. * @brief
  149. * Disable one or more LETIMER interrupts.
  150. *
  151. * @param[in] letimer
  152. * Pointer to LETIMER peripheral register block.
  153. *
  154. * @param[in] flags
  155. * LETIMER interrupt sources to disable. Use a logical OR combination of
  156. * valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  157. ******************************************************************************/
  158. static __INLINE void LETIMER_IntDisable(LETIMER_TypeDef *letimer, uint32_t flags)
  159. {
  160. letimer->IEN &= ~(flags);
  161. }
  162. /***************************************************************************//**
  163. * @brief
  164. * Enable one or more LETIMER interrupts.
  165. *
  166. * @note
  167. * Depending on the use, a pending interrupt may already be set prior to
  168. * enabling the interrupt. Consider using LETIMER_IntClear() prior to enabling
  169. * if such a pending interrupt should be ignored.
  170. *
  171. * @param[in] letimer
  172. * Pointer to LETIMER peripheral register block.
  173. *
  174. * @param[in] flags
  175. * LETIMER interrupt sources to enable. Use a logical OR combination of
  176. * valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  177. ******************************************************************************/
  178. static __INLINE void LETIMER_IntEnable(LETIMER_TypeDef *letimer, uint32_t flags)
  179. {
  180. letimer->IEN |= flags;
  181. }
  182. /***************************************************************************//**
  183. * @brief
  184. * Get pending LETIMER interrupt flags.
  185. *
  186. * @note
  187. * The event bits are not cleared by the use of this function.
  188. *
  189. * @param[in] letimer
  190. * Pointer to LETIMER peripheral register block.
  191. *
  192. * @return
  193. * LETIMER interrupt sources pending. A logical OR combination of valid
  194. * interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  195. ******************************************************************************/
  196. static __INLINE uint32_t LETIMER_IntGet(LETIMER_TypeDef *letimer)
  197. {
  198. return(letimer->IF);
  199. }
  200. /***************************************************************************//**
  201. * @brief
  202. * Set one or more pending LETIMER interrupts from SW.
  203. *
  204. * @param[in] letimer
  205. * Pointer to LETIMER peripheral register block.
  206. *
  207. * @param[in] flags
  208. * LETIMER interrupt sources to set to pending. Use a logical OR combination
  209. * of valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  210. ******************************************************************************/
  211. static __INLINE void LETIMER_IntSet(LETIMER_TypeDef *letimer, uint32_t flags)
  212. {
  213. letimer->IFS = flags;
  214. }
  215. uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep);
  216. void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,
  217. unsigned int rep,
  218. uint32_t value);
  219. void LETIMER_Reset(LETIMER_TypeDef *letimer);
  220. /** @} (end addtogroup LETIMER) */
  221. /** @} (end addtogroup EFM32_Library) */
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225. #endif /* __EFM32_LETIMER_H */