drv_rtc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file drv_rtc.h
  18. * @brief header file for rtc driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_RTC_H_
  23. #define _CSI_RTC_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_common.h>
  29. #include <sys/time.h>
  30. /// definition for rtc handle.
  31. typedef void *rtc_handle_t;
  32. /****** rtc specific error codes *****/
  33. typedef enum {
  34. EDRV_RTC_TIME = (EDRV_SPECIFIC + 1), ///< timer data not supported
  35. } drv_rtc_error_e;
  36. /**
  37. \brief RTC Status
  38. */
  39. typedef struct {
  40. uint32_t active : 1; ///< rtc is running or not
  41. } rtc_status_t;
  42. /****** RTC Event *****/
  43. typedef enum {
  44. RTC_EVENT_TIMER_INTRERRUPT = 0 ///< generate interrupt
  45. } rtc_event_e;
  46. typedef void (*rtc_event_cb_t)(rtc_event_e event); ///< Pointer to \ref rtc_event_cb_t : RTC Event call back.
  47. /**
  48. \brief RTC Device Driver Capabilities.
  49. */
  50. typedef struct {
  51. uint32_t interrupt_mode : 1; ///< supports Interrupt mode
  52. uint32_t wrap_mode : 1; ///< supports wrap mode
  53. } rtc_capabilities_t;
  54. /**
  55. \brief get rtc instance count.
  56. \return rtc instance count
  57. */
  58. int32_t csi_rtc_get_instance_count(void);
  59. /**
  60. \brief Initialize RTC Interface. 1. Initializes the resources needed for the RTC interface 2.registers event callback function
  61. \param[in] idx must not exceed return value of csi_rtc_get_instance_count()
  62. \param[in] cb_event Pointer to \ref rtc_event_cb_t
  63. \return pointer to rtc instance
  64. */
  65. rtc_handle_t csi_rtc_initialize(int32_t idx, rtc_event_cb_t cb_event);
  66. /**
  67. \brief De-initialize RTC Interface. stops operation and releases the software resources used by the interface
  68. \param[in] handle rtc handle to operate.
  69. \return error code
  70. */
  71. int32_t csi_rtc_uninitialize(rtc_handle_t handle);
  72. /**
  73. \brief Get driver capabilities.
  74. \param[in] handle rtc handle to operate.
  75. \return \ref rtc_capabilities_t
  76. */
  77. rtc_capabilities_t csi_rtc_get_capabilities(rtc_handle_t handle);
  78. /**
  79. \brief Set RTC timer.
  80. \param[in] handle rtc handle to operate.
  81. \param[in] rtctime pointer to rtc time
  82. \return error code
  83. */
  84. int32_t csi_rtc_set_time(rtc_handle_t handle, const struct tm *rtctime);
  85. /**
  86. \brief Get RTC timer.
  87. \param[in] handle rtc handle to operate.
  88. \param[in] rtctime pointer to rtc time
  89. \return error code
  90. */
  91. int32_t csi_rtc_get_time(rtc_handle_t handle, struct tm *rtctime);
  92. /**
  93. \brief Start RTC timer.
  94. \param[in] handle rtc handle to operate.
  95. \return error code
  96. */
  97. int32_t csi_rtc_start(rtc_handle_t handle);
  98. /**
  99. \brief Stop RTC timer.
  100. \param[in] handle rtc handle to operate.
  101. \return error code
  102. */
  103. int32_t csi_rtc_stop(rtc_handle_t handle);
  104. /**
  105. \brief config rtc mode.
  106. \param[in] handle rtc handle to operate.
  107. \return error code
  108. */
  109. //int32_t drv_rtc_config (rtc_handle_t handle/*,rtc_mode_e mode*/);
  110. /**
  111. \brief Get RTC status.
  112. \param[in] handle rtc handle to operate.
  113. \return RTC status \ref rtc_status_t
  114. */
  115. rtc_status_t csi_rtc_get_status(rtc_handle_t handle);
  116. /**
  117. \brief config RTC timer.
  118. \param[in] handle rtc handle to operate.
  119. \param[in] rtctime time to wake up
  120. \return error code
  121. */
  122. int32_t csi_rtc_timer_config(rtc_handle_t handle, const struct tm *rtctime);
  123. /**
  124. \brief disable or enable RTC timer.
  125. \param[in] handle rtc handle to operate.
  126. \param[in] en set 1 enable for rtc timer
  127. \return error code
  128. */
  129. int32_t csi_rtc_timer_enable(rtc_handle_t handle, uint8_t en);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* _CSI_RTC_H_ */