wm_timer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * @file wm_timer.h
  3. *
  4. * @brief Timer Driver Module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_TIMER_H
  11. #define WM_TIMER_H
  12. #include "wm_type_def.h"
  13. /** invalid timer id */
  14. #define WM_TIMER_ID_INVALID 0xFF
  15. /** timer interrupt callback */
  16. typedef void (*tls_timer_irq_callback)(void *arg);
  17. /** timer unit */
  18. enum tls_timer_unit{
  19. TLS_TIMER_UNIT_US = 0, /**< microsecond level(us) */
  20. TLS_TIMER_UNIT_MS /**< millisecond level(ms) */
  21. };
  22. /** timer configuration */
  23. struct tls_timer_cfg {
  24. enum tls_timer_unit unit; /**< timer accuracy */
  25. u32 timeout; /**< timeout period */
  26. bool is_repeat; /**< cycle timer */
  27. tls_timer_irq_callback callback; /**< timeout callback function */
  28. void *arg; /**< parameter fot the timeout callback function */
  29. };
  30. /**
  31. * @defgroup Driver_APIs Driver APIs
  32. * @brief Driver APIs
  33. */
  34. /**
  35. * @addtogroup Driver_APIs
  36. * @{
  37. */
  38. /**
  39. * @defgroup TIMER_Driver_APIs TIMER Driver APIs
  40. * @brief TIMER driver APIs
  41. */
  42. /**
  43. * @addtogroup TIMER_Driver_APIs
  44. * @{
  45. */
  46. /**
  47. * @brief This function is used to create a timer
  48. *
  49. * @param[in] cfg timer configuration
  50. *
  51. * @retval WM_TIMER_ID_INVALID failed
  52. * @retval other timer id
  53. *
  54. * @note
  55. * User does not need to clear the interrupt flag.
  56. * Rtc callback function is called in interrupt,
  57. * so do not operate the critical data in the callback fuuction.
  58. * Sending messages to other tasks to handle is recommended.
  59. */
  60. u8 tls_timer_create(struct tls_timer_cfg *cfg);
  61. /**
  62. * @brief This function is used to start a timer
  63. *
  64. * @param[in] timer_id timer id
  65. *
  66. * @return None
  67. *
  68. * @note None
  69. */
  70. void tls_timer_start(u8 timer_id);
  71. /**
  72. * @brief This function is used to stop a timer
  73. *
  74. * @param[in] timer_id timer id
  75. *
  76. * @return None
  77. *
  78. * @note None
  79. */
  80. void tls_timer_stop(u8 timer_id);
  81. /**
  82. * @brief This function is used to change a timer wait time
  83. *
  84. * @param[in] timer_id timer id[0~5]
  85. *
  86. * @param[in] newtime new wait time
  87. *
  88. * @retval None
  89. *
  90. * @note If the timer does not start, this function will start the timer
  91. */
  92. void tls_timer_change(u8 timer_id, u32 newtime);
  93. /**
  94. * @brief This function is used to read a timer's current value
  95. *
  96. * @param[in] timer_id timer id[0~5]
  97. *
  98. * @retval timer's current value
  99. *
  100. * @note none
  101. */
  102. u32 tls_timer_read(u8 timer_id);
  103. /**
  104. * @brief This function is used to delete a timer
  105. *
  106. * @param[in] timer_id timer id
  107. *
  108. * @return None
  109. *
  110. * @note None
  111. */
  112. void tls_timer_destroy(u8 timer_id);
  113. /**
  114. * @}
  115. */
  116. /**
  117. * @}
  118. */
  119. #endif /* WM_TIMER_H */