em_rtc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Real Time Counter (RTC) peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_RTC_H
  34. #define __EM_RTC_H
  35. #include <stdbool.h>
  36. #include "em_part.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /***************************************************************************//**
  41. * @addtogroup EM_Library
  42. * @{
  43. ******************************************************************************/
  44. /***************************************************************************//**
  45. * @addtogroup RTC
  46. * @{
  47. ******************************************************************************/
  48. /*******************************************************************************
  49. ******************************* STRUCTS ***********************************
  50. ******************************************************************************/
  51. /** RTC initialization structure. */
  52. typedef struct
  53. {
  54. bool enable; /**< Start counting when init completed. */
  55. bool debugRun; /**< Counter shall keep running during debug halt. */
  56. bool comp0Top; /**< Use compare register 0 as max count value. */
  57. } RTC_Init_TypeDef;
  58. /** Suggested default config for RTC init structure. */
  59. #define RTC_INIT_DEFAULT \
  60. { true, /* Start counting when init done */ \
  61. false, /* Disable updating during debug halt */ \
  62. true /* Restart counting from 0 when reaching COMP0 */ \
  63. }
  64. /*******************************************************************************
  65. ***************************** PROTOTYPES **********************************
  66. ******************************************************************************/
  67. uint32_t RTC_CompareGet(unsigned int comp);
  68. void RTC_CompareSet(unsigned int comp, uint32_t value);
  69. /***************************************************************************//**
  70. * @brief
  71. * Get RTC counter value.
  72. *
  73. * @return
  74. * Current RTC counter value.
  75. ******************************************************************************/
  76. __STATIC_INLINE uint32_t RTC_CounterGet(void)
  77. {
  78. return(RTC->CNT);
  79. }
  80. void RTC_CounterReset(void);
  81. void RTC_Enable(bool enable);
  82. void RTC_FreezeEnable(bool enable);
  83. void RTC_Init(const RTC_Init_TypeDef *init);
  84. /***************************************************************************//**
  85. * @brief
  86. * Clear one or more pending RTC interrupts.
  87. *
  88. * @param[in] flags
  89. * RTC interrupt sources to clear. Use a set of interrupt flags OR-ed
  90. * together to clear multiple interrupt sources for the RTC module
  91. * (RTC_IFS_nnn).
  92. ******************************************************************************/
  93. __STATIC_INLINE void RTC_IntClear(uint32_t flags)
  94. {
  95. RTC->IFC = flags;
  96. }
  97. /***************************************************************************//**
  98. * @brief
  99. * Disable one or more RTC interrupts.
  100. *
  101. * @param[in] flags
  102. * RTC interrupt sources to disable. Use a set of interrupt flags OR-ed
  103. * together to disable multiple interrupt sources for the RTC module
  104. * (RTC_IFS_nnn).
  105. ******************************************************************************/
  106. __STATIC_INLINE void RTC_IntDisable(uint32_t flags)
  107. {
  108. RTC->IEN &= ~(flags);
  109. }
  110. /***************************************************************************//**
  111. * @brief
  112. * Enable one or more RTC interrupts.
  113. *
  114. * @note
  115. * Depending on the use, a pending interrupt may already be set prior to
  116. * enabling the interrupt. Consider using RTC_IntClear() prior to enabling
  117. * if such a pending interrupt should be ignored.
  118. *
  119. * @param[in] flags
  120. * RTC interrupt sources to enable. Use a set of interrupt flags OR-ed
  121. * together to set multiple interrupt sources for the RTC module
  122. * (RTC_IFS_nnn).
  123. ******************************************************************************/
  124. __STATIC_INLINE void RTC_IntEnable(uint32_t flags)
  125. {
  126. RTC->IEN |= flags;
  127. }
  128. /***************************************************************************//**
  129. * @brief
  130. * Get pending RTC interrupt flags.
  131. *
  132. * @note
  133. * The event bits are not cleared by the use of this function.
  134. *
  135. * @return
  136. * Pending RTC interrupt sources. Returns a set of interrupt flags OR-ed
  137. * together for multiple interrupt sources in the RTC module (RTC_IFS_nnn).
  138. ******************************************************************************/
  139. __STATIC_INLINE uint32_t RTC_IntGet(void)
  140. {
  141. return(RTC->IF);
  142. }
  143. /***************************************************************************//**
  144. * @brief
  145. * Set one or more pending RTC interrupts from SW.
  146. *
  147. * @param[in] flags
  148. * RTC interrupt sources to set to pending. Use a set of interrupt flags
  149. * OR-ed together to set multiple interrupt sources for the RTC module
  150. * (RTC_IFS_nnn).
  151. ******************************************************************************/
  152. __STATIC_INLINE void RTC_IntSet(uint32_t flags)
  153. {
  154. RTC->IFS = flags;
  155. }
  156. void RTC_Reset(void);
  157. /** @} (end addtogroup RTC) */
  158. /** @} (end addtogroup EM_Library) */
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* __EM_RTC_H */