drv_timer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_timer.h
  18. * @brief header file for timer driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_TIMER_H_
  23. #define _CSI_TIMER_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_common.h>
  29. /// definition for timer handle.
  30. typedef void *timer_handle_t;
  31. /*----- TIMER Control Codes: Mode -----*/
  32. typedef enum {
  33. TIMER_MODE_FREE_RUNNING = 0, ///< free running mode
  34. TIMER_MODE_RELOAD ///< reload mode
  35. } timer_mode_e;
  36. /**
  37. \brief TIMER Status
  38. */
  39. typedef struct {
  40. uint32_t active : 1; ///< timer active flag
  41. uint32_t timeout : 1; ///< timeout flag
  42. } timer_status_t;
  43. /**
  44. \brief TIMER Event
  45. */
  46. typedef enum {
  47. TIMER_EVENT_TIMEOUT = 0 ///< time out event
  48. } timer_event_e;
  49. typedef void (*timer_event_cb_t)(timer_event_e event, void *arg); ///< Pointer to \ref timer_event_cb_t : TIMER Event call back.
  50. /**
  51. \brief TIMER Device Driver Capabilities.
  52. */
  53. typedef struct {
  54. uint32_t interrupt_mode : 1; ///< supports Interrupt mode
  55. } timer_capabilities_t;
  56. /**
  57. \brief get timer instance count.
  58. \return timer instance count
  59. */
  60. int32_t csi_timer_get_instance_count(void);
  61. /**
  62. \brief Initialize TIMER Interface. 1. Initializes the resources needed for the TIMER interface 2.registers event callback function
  63. \param[in] idx instance timer index
  64. \param[in] cb_event Pointer to \ref timer_event_cb_t
  65. \param[in] cb_arg arguments of cb_event
  66. \return pointer to timer instance
  67. */
  68. timer_handle_t csi_timer_initialize(int32_t idx, timer_event_cb_t cb_event, void *cb_arg);
  69. /**
  70. \brief De-initialize TIMER Interface. stops operation and releases the software resources used by the interface
  71. \param[in] handle timer handle to operate.
  72. \return error code
  73. */
  74. int32_t csi_timer_uninitialize(timer_handle_t handle);
  75. /**
  76. \brief Get driver capabilities.
  77. \param[in] handle timer handle to operate.
  78. \return \ref timer_capabilities_t
  79. */
  80. timer_capabilities_t csi_timer_get_capabilities(timer_handle_t handle);
  81. /**
  82. \brief config timer mode.
  83. \param[in] handle timer handle to operate.
  84. \param[in] mode \ref timer_mode_e
  85. \return error code
  86. */
  87. int32_t csi_timer_config(timer_handle_t handle, timer_mode_e mode);
  88. /**
  89. \brief Set timer.
  90. \param[in] handle timer handle to operate.
  91. \param[in] timeout the timeout value in microseconds(us).
  92. \return error code
  93. */
  94. int32_t csi_timer_set_timeout(timer_handle_t handle, uint32_t timeout);
  95. /**
  96. \brief Start timer.
  97. \param[in] handle timer handle to operate.
  98. \param[in] apbfreq APB frequency
  99. \return error code
  100. */
  101. int32_t csi_timer_start(timer_handle_t handle, uint32_t apbfreq);
  102. /**
  103. \brief Stop timer.
  104. \param[in] handle timer handle to operate.
  105. \return error code
  106. */
  107. int32_t csi_timer_stop(timer_handle_t handle);
  108. /**
  109. \brief suspend timer.
  110. \param[in] handle timer handle to operate.
  111. \return error code
  112. */
  113. int32_t csi_timer_suspend(timer_handle_t handle);
  114. /**
  115. \brief resume timer.
  116. \param[in] handle timer handle to operate.
  117. \return error code
  118. */
  119. int32_t csi_timer_resume(timer_handle_t handle);
  120. /**
  121. \brief get timer current value
  122. \param[in] handle timer handle to operate.
  123. \param[in] value timer current value
  124. \return error code
  125. */
  126. int32_t csi_timer_get_current_value(timer_handle_t handle, uint32_t *value);
  127. /**
  128. \brief Get TIMER status.
  129. \param[in] handle timer handle to operate.
  130. \return TIMER status \ref timer_status_t
  131. */
  132. timer_status_t csi_timer_get_status(timer_handle_t handle);
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif /* _CSI_TIMER_H_ */