efm32_letimer.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Low Energy Timer (LETIMER) peripheral API for EFM32.
  4. * @author Energy Micro AS
  5. * @version 2.0.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 bitwise logic OR
  141. * combination of valid interrupt flags for the LETIMER module
  142. * (LETIMER_IF_nnn).
  143. ******************************************************************************/
  144. static __INLINE void LETIMER_IntClear(LETIMER_TypeDef *letimer, uint32_t flags)
  145. {
  146. letimer->IFC = flags;
  147. }
  148. /***************************************************************************//**
  149. * @brief
  150. * Disable one or more LETIMER interrupts.
  151. *
  152. * @param[in] letimer
  153. * Pointer to LETIMER peripheral register block.
  154. *
  155. * @param[in] flags
  156. * LETIMER interrupt sources to disable. Use a bitwise logic OR combination of
  157. * valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  158. ******************************************************************************/
  159. static __INLINE void LETIMER_IntDisable(LETIMER_TypeDef *letimer, uint32_t flags)
  160. {
  161. letimer->IEN &= ~(flags);
  162. }
  163. /***************************************************************************//**
  164. * @brief
  165. * Enable one or more LETIMER interrupts.
  166. *
  167. * @note
  168. * Depending on the use, a pending interrupt may already be set prior to
  169. * enabling the interrupt. Consider using LETIMER_IntClear() prior to enabling
  170. * if such a pending interrupt should be ignored.
  171. *
  172. * @param[in] letimer
  173. * Pointer to LETIMER peripheral register block.
  174. *
  175. * @param[in] flags
  176. * LETIMER interrupt sources to enable. Use a bitwise logic OR combination of
  177. * valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  178. ******************************************************************************/
  179. static __INLINE void LETIMER_IntEnable(LETIMER_TypeDef *letimer, uint32_t flags)
  180. {
  181. letimer->IEN |= flags;
  182. }
  183. /***************************************************************************//**
  184. * @brief
  185. * Get pending LETIMER interrupt flags.
  186. *
  187. * @note
  188. * The event bits are not cleared by the use of this function.
  189. *
  190. * @param[in] letimer
  191. * Pointer to LETIMER peripheral register block.
  192. *
  193. * @return
  194. * LETIMER interrupt sources pending. A bitwise logic OR combination of
  195. * valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  196. ******************************************************************************/
  197. static __INLINE uint32_t LETIMER_IntGet(LETIMER_TypeDef *letimer)
  198. {
  199. return(letimer->IF);
  200. }
  201. /***************************************************************************//**
  202. * @brief
  203. * Set one or more pending LETIMER interrupts from SW.
  204. *
  205. * @param[in] letimer
  206. * Pointer to LETIMER peripheral register block.
  207. *
  208. * @param[in] flags
  209. * LETIMER interrupt sources to set to pending. Use a bitwise logic OR
  210. * combination of valid interrupt flags for the LETIMER module (LETIMER_IF_nnn).
  211. ******************************************************************************/
  212. static __INLINE void LETIMER_IntSet(LETIMER_TypeDef *letimer, uint32_t flags)
  213. {
  214. letimer->IFS = flags;
  215. }
  216. uint32_t LETIMER_RepeatGet(LETIMER_TypeDef *letimer, unsigned int rep);
  217. void LETIMER_RepeatSet(LETIMER_TypeDef *letimer,
  218. unsigned int rep,
  219. uint32_t value);
  220. void LETIMER_Reset(LETIMER_TypeDef *letimer);
  221. /** @} (end addtogroup LETIMER) */
  222. /** @} (end addtogroup EFM32_Library) */
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif /* __EFM32_LETIMER_H */