efm32_rtc.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Real Time Counter (RTC) 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_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_Enable(bool enable);
  76. void RTC_FreezeEnable(bool enable);
  77. void RTC_Init(const RTC_Init_TypeDef *init);
  78. /***************************************************************************//**
  79. * @brief
  80. * Clear one or more pending RTC interrupts.
  81. *
  82. * @param[in] flags
  83. * Pending RTC interrupt source to clear. Use a logical OR combination of
  84. * valid interrupt flags for the RTC module (RTC_IF_nnn).
  85. ******************************************************************************/
  86. static __INLINE void RTC_IntClear(uint32_t flags)
  87. {
  88. RTC->IFC = flags;
  89. }
  90. /***************************************************************************//**
  91. * @brief
  92. * Disable one or more RTC interrupts.
  93. *
  94. * @param[in] flags
  95. * RTC interrupt sources to disable. Use a logical OR combination of
  96. * valid interrupt flags for the RTC module (RTC_IF_nnn).
  97. ******************************************************************************/
  98. static __INLINE void RTC_IntDisable(uint32_t flags)
  99. {
  100. RTC->IEN &= ~(flags);
  101. }
  102. /***************************************************************************//**
  103. * @brief
  104. * Enable one or more RTC interrupts.
  105. *
  106. * @note
  107. * Depending on the use, a pending interrupt may already be set prior to
  108. * enabling the interrupt. Consider using RTC_IntClear() prior to enabling
  109. * if such a pending interrupt should be ignored.
  110. *
  111. * @param[in] flags
  112. * RTC interrupt sources to enable. Use a logical OR combination of
  113. * valid interrupt flags for the RTC module (RTC_IF_nnn).
  114. ******************************************************************************/
  115. static __INLINE void RTC_IntEnable(uint32_t flags)
  116. {
  117. RTC->IEN |= flags;
  118. }
  119. /***************************************************************************//**
  120. * @brief
  121. * Get pending RTC interrupt flags.
  122. *
  123. * @note
  124. * The event bits are not cleared by the use of this function.
  125. *
  126. * @return
  127. * RTC interrupt sources pending. A logical OR combination of valid
  128. * interrupt flags for the RTC module (RTC_IF_nnn).
  129. ******************************************************************************/
  130. static __INLINE uint32_t RTC_IntGet(void)
  131. {
  132. return(RTC->IF);
  133. }
  134. /***************************************************************************//**
  135. * @brief
  136. * Set one or more pending RTC interrupts from SW.
  137. *
  138. * @param[in] flags
  139. * RTC interrupt sources to set to pending. Use a logical OR combination of
  140. * valid interrupt flags for the RTC module (RTC_IF_nnn).
  141. ******************************************************************************/
  142. static __INLINE void RTC_IntSet(uint32_t flags)
  143. {
  144. RTC->IFS = flags;
  145. }
  146. /** @} (end addtogroup RTC) */
  147. /** @} (end addtogroup EFM32_Library) */
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* __EFM32_RTC_H */