am_hal_rtc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //*****************************************************************************
  2. //
  3. // am_hal_rtc.h
  4. //! @file
  5. //!
  6. //! @brief Functions for interfacing and accessing the Real-Time Clock (RTC).
  7. //!
  8. //! @addtogroup rtc2 Real-Time Clock (RTC)
  9. //! @ingroup apollo2hal
  10. //! @{
  11. //
  12. //*****************************************************************************
  13. //*****************************************************************************
  14. //
  15. // Copyright (c) 2017, Ambiq Micro
  16. // All rights reserved.
  17. //
  18. // Redistribution and use in source and binary forms, with or without
  19. // modification, are permitted provided that the following conditions are met:
  20. //
  21. // 1. Redistributions of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // 2. Redistributions in binary form must reproduce the above copyright
  25. // notice, this list of conditions and the following disclaimer in the
  26. // documentation and/or other materials provided with the distribution.
  27. //
  28. // 3. Neither the name of the copyright holder nor the names of its
  29. // contributors may be used to endorse or promote products derived from this
  30. // software without specific prior written permission.
  31. //
  32. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  36. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. // POSSIBILITY OF SUCH DAMAGE.
  43. //
  44. // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #ifndef AM_HAL_RTC_H
  48. #define AM_HAL_RTC_H
  49. //*****************************************************************************
  50. //
  51. //! @name OSC Start and Stop
  52. //! @brief OSC Start and Stop defines.
  53. //!
  54. //! OSC Start and Stop defines to be used with \e am_hal_clkgen_osc_x().
  55. //! @{
  56. //
  57. //*****************************************************************************
  58. #define AM_HAL_RTC_OSC_LFRC 0x1
  59. #define AM_HAL_RTC_OSC_XT 0x0
  60. //! @}
  61. //*****************************************************************************
  62. //
  63. //! @name RTC Interrupts
  64. //! @brief Macro definitions for RTC interrupt status bits.
  65. //!
  66. //! These macros correspond to the bits in the RTC interrupt status register.
  67. //! They may be used with any of the \e am_hal_rtc_int_x() functions.
  68. //!
  69. //! @{
  70. //
  71. //*****************************************************************************
  72. #define AM_HAL_RTC_INT_ALM AM_REG_RTC_INTEN_ALM_M
  73. #define AM_HAL_RTC_INT_OF AM_REG_RTC_INTEN_OF_M
  74. #define AM_HAL_RTC_INT_ACC AM_REG_RTC_INTEN_ACC_M
  75. #define AM_HAL_RTC_INT_ACF AM_REG_RTC_INTEN_ACF_M
  76. //! @}
  77. //*****************************************************************************
  78. //
  79. //! @name RTC Alarm Repeat Interval.
  80. //! @brief Macro definitions for the RTC alarm repeat interval.
  81. //!
  82. //! These macros correspond to the RPT bits in the RTCCTL register.
  83. //! They may be used with the \e am_hal_rtc_alarm_interval_set() function.
  84. //!
  85. //! Note: AM_HAL_RTC_ALM_RPT_10TH and AM_HAL_RTC_ALM_RPT_100TH do not
  86. //! correspond to the RPT bits but are used in conjunction with setting the
  87. //! ALM100 bits in the ALMLOW register.
  88. //!
  89. //! @{
  90. //
  91. //*****************************************************************************
  92. #define AM_HAL_RTC_ALM_RPT_DIS 0x0
  93. #define AM_HAL_RTC_ALM_RPT_YR 0x1
  94. #define AM_HAL_RTC_ALM_RPT_MTH 0x2
  95. #define AM_HAL_RTC_ALM_RPT_WK 0x3
  96. #define AM_HAL_RTC_ALM_RPT_DAY 0x4
  97. #define AM_HAL_RTC_ALM_RPT_HR 0x5
  98. #define AM_HAL_RTC_ALM_RPT_MIN 0x6
  99. #define AM_HAL_RTC_ALM_RPT_SEC 0x7
  100. #define AM_HAL_RTC_ALM_RPT_10TH 0x8
  101. #define AM_HAL_RTC_ALM_RPT_100TH 0x9
  102. //! @}
  103. //*****************************************************************************
  104. //
  105. //! @name RTC Alarm 100 Interval.
  106. //! @brief Macro definitions for the RTC alarm ms intervals.
  107. //!
  108. //! These macros are used inside the #am_hal_rtc_alarm_interval_set function
  109. //! when 10ms and 100ms repeated alarm intervals are desired.
  110. //!
  111. //! @{
  112. //
  113. //*****************************************************************************
  114. #define AM_HAL_RTC_ALM100_DEFAULT 0x00
  115. #define AM_HAL_RTC_ALM100_10TH 0xF0
  116. #define AM_HAL_RTC_ALM100_100TH 0xFF
  117. //! @}
  118. //*****************************************************************************
  119. //
  120. //! @brief The basic time structure used by the HAL for RTC interaction.
  121. //!
  122. //! All values are positive whole numbers. The HAL routines convert back and
  123. //! forth to BCD.
  124. //
  125. //*****************************************************************************
  126. typedef struct am_hal_rtc_time_struct
  127. {
  128. uint32_t ui32ReadError;
  129. uint32_t ui32CenturyEnable;
  130. uint32_t ui32Weekday;
  131. uint32_t ui32Century;
  132. uint32_t ui32Year;
  133. uint32_t ui32Month;
  134. uint32_t ui32DayOfMonth;
  135. uint32_t ui32Hour;
  136. uint32_t ui32Minute;
  137. uint32_t ui32Second;
  138. uint32_t ui32Hundredths;
  139. }am_hal_rtc_time_t;
  140. #ifdef __cplusplus
  141. extern "C"
  142. {
  143. #endif
  144. //*****************************************************************************
  145. //
  146. // External function definitions
  147. //
  148. //*****************************************************************************
  149. extern void am_hal_rtc_osc_select(uint32_t ui32OSC);
  150. extern void am_hal_rtc_osc_enable(void);
  151. extern void am_hal_rtc_osc_disable(void);
  152. extern void am_hal_rtc_time_12hour(bool b12Hour);
  153. extern void am_hal_rtc_time_set(am_hal_rtc_time_t *pTime);
  154. extern uint32_t am_hal_rtc_time_get(am_hal_rtc_time_t *pTime);
  155. extern void am_hal_rtc_alarm_interval_set(uint32_t ui32RepeatInterval);
  156. extern void am_hal_rtc_alarm_set(am_hal_rtc_time_t *pTime,
  157. uint32_t ui32RepeatInterval);
  158. extern void am_hal_rtc_alarm_get(am_hal_rtc_time_t *pTime);
  159. extern void am_hal_rtc_int_enable(uint32_t ui32Interrupt);
  160. extern uint32_t am_hal_rtc_int_enable_get(void);
  161. extern void am_hal_rtc_int_disable(uint32_t ui32Interrupt);
  162. extern void am_hal_rtc_int_clear(uint32_t ui32Interrupt);
  163. extern void am_hal_rtc_int_set(uint32_t ui32Interrupt);
  164. extern uint32_t am_hal_rtc_int_status_get(bool bEnabledOnly);
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif // AM_HAL_RTC_H
  169. //*****************************************************************************
  170. //
  171. // End Doxygen group.
  172. //! @}
  173. //
  174. //*****************************************************************************