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.9 of the AmbiqSuite Development Package.
  45. //
  46. //*****************************************************************************
  47. #ifndef AM_HAL_RTC_H
  48. #define AM_HAL_RTC_H
  49. #ifdef __cplusplus
  50. extern "C"
  51. {
  52. #endif
  53. //*****************************************************************************
  54. //
  55. //! @name OSC Start and Stop
  56. //! @brief OSC Start and Stop defines.
  57. //!
  58. //! OSC Start and Stop defines to be used with \e am_hal_clkgen_osc_x().
  59. //! @{
  60. //
  61. //*****************************************************************************
  62. #define AM_HAL_RTC_OSC_LFRC 0x1
  63. #define AM_HAL_RTC_OSC_XT 0x0
  64. //! @}
  65. //*****************************************************************************
  66. //
  67. //! @name RTC Interrupts
  68. //! @brief Macro definitions for RTC interrupt status bits.
  69. //!
  70. //! These macros correspond to the bits in the RTC interrupt status register.
  71. //! They may be used with any of the \e am_hal_rtc_int_x() functions.
  72. //!
  73. //! @{
  74. //
  75. //*****************************************************************************
  76. #define AM_HAL_RTC_INT_ALM AM_REG_RTC_INTEN_ALM_M
  77. #define AM_HAL_RTC_INT_OF AM_REG_RTC_INTEN_OF_M
  78. #define AM_HAL_RTC_INT_ACC AM_REG_RTC_INTEN_ACC_M
  79. #define AM_HAL_RTC_INT_ACF AM_REG_RTC_INTEN_ACF_M
  80. //! @}
  81. //*****************************************************************************
  82. //
  83. //! @name RTC Alarm Repeat Interval.
  84. //! @brief Macro definitions for the RTC alarm repeat interval.
  85. //!
  86. //! These macros correspond to the RPT bits in the RTCCTL register.
  87. //! They may be used with the \e am_hal_rtc_alarm_interval_set() function.
  88. //!
  89. //! Note: AM_HAL_RTC_ALM_RPT_10TH and AM_HAL_RTC_ALM_RPT_100TH do not
  90. //! correspond to the RPT bits but are used in conjunction with setting the
  91. //! ALM100 bits in the ALMLOW register.
  92. //!
  93. //! @{
  94. //
  95. //*****************************************************************************
  96. #define AM_HAL_RTC_ALM_RPT_DIS 0x0
  97. #define AM_HAL_RTC_ALM_RPT_YR 0x1
  98. #define AM_HAL_RTC_ALM_RPT_MTH 0x2
  99. #define AM_HAL_RTC_ALM_RPT_WK 0x3
  100. #define AM_HAL_RTC_ALM_RPT_DAY 0x4
  101. #define AM_HAL_RTC_ALM_RPT_HR 0x5
  102. #define AM_HAL_RTC_ALM_RPT_MIN 0x6
  103. #define AM_HAL_RTC_ALM_RPT_SEC 0x7
  104. #define AM_HAL_RTC_ALM_RPT_10TH 0x8
  105. #define AM_HAL_RTC_ALM_RPT_100TH 0x9
  106. //! @}
  107. //*****************************************************************************
  108. //
  109. //! @name RTC Alarm 100 Interval.
  110. //! @brief Macro definitions for the RTC alarm ms intervals.
  111. //!
  112. //! These macros are used inside the #am_hal_rtc_alarm_interval_set function
  113. //! when 10ms and 100ms repeated alarm intervals are desired.
  114. //!
  115. //! @{
  116. //
  117. //*****************************************************************************
  118. #define AM_HAL_RTC_ALM100_DEFAULT 0x00
  119. #define AM_HAL_RTC_ALM100_10TH 0xF0
  120. #define AM_HAL_RTC_ALM100_100TH 0xFF
  121. //! @}
  122. //*****************************************************************************
  123. //
  124. //! @brief The basic time structure used by the HAL for RTC interaction.
  125. //!
  126. //! All values are positive whole numbers. The HAL routines convert back and
  127. //! forth to BCD.
  128. //
  129. //*****************************************************************************
  130. typedef struct am_hal_rtc_time_struct
  131. {
  132. uint32_t ui32ReadError;
  133. uint32_t ui32CenturyEnable;
  134. uint32_t ui32Weekday;
  135. uint32_t ui32Century;
  136. uint32_t ui32Year;
  137. uint32_t ui32Month;
  138. uint32_t ui32DayOfMonth;
  139. uint32_t ui32Hour;
  140. uint32_t ui32Minute;
  141. uint32_t ui32Second;
  142. uint32_t ui32Hundredths;
  143. }am_hal_rtc_time_t;
  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. //*****************************************************************************