hosal_rtc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (c) 2016-2022 Bouffalolab.
  3. *
  4. * This file is part of
  5. * *** Bouffalolab Software Dev Kit ***
  6. * (see www.bouffalolab.com).
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of Bouffalo Lab nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __HAL_RTC_H__
  31. #define __HAL_RTC_H__
  32. /** @addtogroup hal_rtc RTC
  33. * rtc hal API.
  34. *
  35. * @{
  36. */
  37. #include <stdint.h>
  38. #define HOSAL_RTC_FORMAT_DEC 1 /**< RTC DEC format */
  39. #define HOSAL_RTC_FORMAT_BCD 2 /**< RTC BCD format */
  40. /**
  41. * @brief rtc config struct
  42. */
  43. typedef struct {
  44. uint8_t format; /**< time formart DEC or BCD */
  45. } hosal_rtc_config_t;
  46. /**
  47. * @brief rtc dev struct
  48. */
  49. typedef struct {
  50. uint8_t port; /**< rtc port */
  51. hosal_rtc_config_t config; /**< rtc config */
  52. void *priv; /**< priv data */
  53. } hosal_rtc_dev_t;
  54. /**
  55. * @brief RTC time struct
  56. */
  57. typedef struct {
  58. uint8_t sec; /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
  59. uint8_t min; /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
  60. uint8_t hr; /**< DEC format:value range from 0 to 23, BCD format:value range from 0x00 to 0x23 */
  61. uint8_t date; /**< DEC format:value range from 1 to 31, BCD format:value range from 0x01 to 0x31 */
  62. uint8_t month; /**< DEC format:value range from 1 to 12, BCD format:value range from 0x01 to 0x12 */
  63. uint16_t year; /**< DEC format:value range from 0 to 9999, BCD format:value range from 0x0000 to 0x9999 */
  64. } hosal_rtc_time_t;
  65. /**
  66. * @brief This function will initialize the on board CPU real time clock
  67. *
  68. *
  69. * @param[in] rtc rtc device
  70. *
  71. * @return
  72. * - 0 : success
  73. * - other : fail
  74. */
  75. int hosal_rtc_init(hosal_rtc_dev_t *rtc);
  76. /**
  77. * @brief This function will set MCU RTC time to a new value.
  78. *
  79. * @param[in] rtc rtc device
  80. * @param[in] time pointer to a time structure
  81. *
  82. * @return
  83. * - 0 : success
  84. * - other : fail
  85. */
  86. int hosal_rtc_set_time(hosal_rtc_dev_t *rtc, const hosal_rtc_time_t *time);
  87. /**
  88. * @brief This function will return the value of time read from the on board CPU real time clock.
  89. *
  90. * @param[in] rtc rtc device
  91. * @param[out] time pointer to a time structure
  92. *
  93. * @return
  94. * - 0 : success
  95. * - other : fail
  96. */
  97. int hosal_rtc_get_time(hosal_rtc_dev_t *rtc, hosal_rtc_time_t *time);
  98. /**
  99. * @brief This function will set MCU RTC time to a new value.
  100. *
  101. * @param[in] rtc rtc device
  102. * @param[in] time_stamp new time value
  103. *
  104. * @return
  105. * - 0 : success
  106. * - other : fail
  107. */
  108. int hosal_rtc_set_count(hosal_rtc_dev_t *rtc, uint64_t *time_stamp);
  109. /**
  110. * @brief This function will return the value of time read from the on board CPU real time clock.
  111. *
  112. * @param[in] rtc rtc device
  113. * @param[in] time_stamp new time value
  114. *
  115. * @return
  116. * - 0 : success
  117. * - other : fail
  118. */
  119. int hosal_rtc_get_count(hosal_rtc_dev_t *rtc, uint64_t *time_stamp);
  120. /**
  121. * @brief De-initialises an RTC interface, Turns off an RTC hardware interface
  122. *
  123. * @param[in] RTC the interface which should be de-initialised
  124. *
  125. * @return
  126. * - 0 : success
  127. * - other : fail
  128. */
  129. int hosal_rtc_finalize(hosal_rtc_dev_t *rtc);
  130. /** @} */
  131. #endif /* HAL_RTC_H */