efm32_rtc.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Real Time Counter (RTC) 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_RTC_H
  29. #define __EFM32_RTC_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 RTC
  41. * @{
  42. ******************************************************************************/
  43. /*******************************************************************************
  44. ******************************* STRUCTS ***********************************
  45. ******************************************************************************/
  46. /** RTC initialization structure. */
  47. typedef struct
  48. {
  49. bool enable; /**< Start counting when init completed. */
  50. bool debugRun; /**< Counter shall keep running during debug halt. */
  51. bool comp0Top; /**< Use compare register 0 as max count value. */
  52. } RTC_Init_TypeDef;
  53. /** Suggested default config for RTC init structure. */
  54. #define RTC_INIT_DEFAULT \
  55. { true, /* Start counting when init done */ \
  56. false, /* Disable updating during debug halt */ \
  57. true /* Restart counting from 0 when reaching COMP0 */ \
  58. }
  59. /*******************************************************************************
  60. ***************************** PROTOTYPES **********************************
  61. ******************************************************************************/
  62. uint32_t RTC_CompareGet(unsigned int comp);
  63. void RTC_CompareSet(unsigned int comp, uint32_t value);
  64. /***************************************************************************//**
  65. * @brief
  66. * Get RTC counter value.
  67. *
  68. * @return
  69. * Current RTC counter value.
  70. ******************************************************************************/
  71. static __INLINE uint32_t RTC_CounterGet(void)
  72. {
  73. return(RTC->CNT);
  74. }
  75. void RTC_CounterReset(void);
  76. void RTC_Enable(bool enable);
  77. void RTC_FreezeEnable(bool enable);
  78. void RTC_Init(const RTC_Init_TypeDef *init);
  79. /***************************************************************************//**
  80. * @brief
  81. * Clear one or more pending RTC interrupts.
  82. *
  83. * @param[in] flags
  84. * RTC interrupt sources to clear. Use a set of interrupt flags OR-ed
  85. * together to clear multiple interrupt sources for the RTC module
  86. * (RTC_IFS_nnn).
  87. ******************************************************************************/
  88. static __INLINE void RTC_IntClear(uint32_t flags)
  89. {
  90. RTC->IFC = flags;
  91. }
  92. /***************************************************************************//**
  93. * @brief
  94. * Disable one or more RTC interrupts.
  95. *
  96. * @param[in] flags
  97. * RTC interrupt sources to disable. Use a set of interrupt flags OR-ed
  98. * together to disable multiple interrupt sources for the RTC module
  99. * (RTC_IFS_nnn).
  100. ******************************************************************************/
  101. static __INLINE void RTC_IntDisable(uint32_t flags)
  102. {
  103. RTC->IEN &= ~(flags);
  104. }
  105. /***************************************************************************//**
  106. * @brief
  107. * Enable one or more RTC interrupts.
  108. *
  109. * @note
  110. * Depending on the use, a pending interrupt may already be set prior to
  111. * enabling the interrupt. Consider using RTC_IntClear() prior to enabling
  112. * if such a pending interrupt should be ignored.
  113. *
  114. * @param[in] flags
  115. * RTC interrupt sources to enable. Use a set of interrupt flags OR-ed
  116. * together to set multiple interrupt sources for the RTC module
  117. * (RTC_IFS_nnn).
  118. ******************************************************************************/
  119. static __INLINE void RTC_IntEnable(uint32_t flags)
  120. {
  121. RTC->IEN |= flags;
  122. }
  123. /***************************************************************************//**
  124. * @brief
  125. * Get pending RTC interrupt flags.
  126. *
  127. * @note
  128. * The event bits are not cleared by the use of this function.
  129. *
  130. * @return
  131. * Pending RTC interrupt sources. Returns a set of interrupt flags OR-ed
  132. * together for multiple interrupt sources in the RTC module (RTC_IFS_nnn).
  133. ******************************************************************************/
  134. static __INLINE uint32_t RTC_IntGet(void)
  135. {
  136. return(RTC->IF);
  137. }
  138. /***************************************************************************//**
  139. * @brief
  140. * Set one or more pending RTC interrupts from SW.
  141. *
  142. * @param[in] flags
  143. * RTC interrupt sources to set to pending. Use a set of interrupt flags
  144. * OR-ed together to set multiple interrupt sources for the RTC module
  145. * (RTC_IFS_nnn).
  146. ******************************************************************************/
  147. static __INLINE void RTC_IntSet(uint32_t flags)
  148. {
  149. RTC->IFS = flags;
  150. }
  151. void RTC_Reset(void);
  152. /** @} (end addtogroup RTC) */
  153. /** @} (end addtogroup EFM32_Library) */
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* __EFM32_RTC_H */