hosal_timer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 HOSAL_TIMER_H
  31. #define HOSAL_TIMER_H
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /** @addtogroup hal_timer TIMER
  36. * timer hal API.
  37. *
  38. * @{
  39. */
  40. #include <stdint.h>
  41. #define TIMER_RELOAD_PERIODIC 1 /**< timer reload automatic */
  42. #define TIMER_RELOAD_ONCE 2 /**< timer reload once and need to reload manually */
  43. typedef void (*hosal_timer_cb_t)(void *arg); /**< Define timer handle function type */
  44. /**
  45. * Define timer config args
  46. */
  47. typedef struct {
  48. uint32_t period; /**< timer period, us */
  49. uint8_t reload_mode; /**< auto reload or not */
  50. hosal_timer_cb_t cb; /**< timer handle when expired */
  51. void *arg; /**< timer handle args */
  52. } hosal_timer_config_t;
  53. /**
  54. * Define timer dev handle
  55. */
  56. typedef struct {
  57. int8_t port; /**< timer port */
  58. hosal_timer_config_t config; /**< timer config */
  59. void *priv; /**< priv data */
  60. } hosal_timer_dev_t;
  61. /**
  62. * init a hardware timer
  63. *
  64. * @param[in] tim timer device
  65. *
  66. * @return
  67. * - 0 : success
  68. * - other :error
  69. */
  70. int hosal_timer_init(hosal_timer_dev_t *tim);
  71. /**
  72. * start a hardware timer
  73. *
  74. * @param[in] tim timer device
  75. *
  76. * @return
  77. * - 0 : success
  78. * - other : error
  79. */
  80. int hosal_timer_start(hosal_timer_dev_t *tim);
  81. /**
  82. * stop a hardware timer
  83. *
  84. * @param[in] tim timer device
  85. *
  86. * @return none
  87. */
  88. void hosal_timer_stop(hosal_timer_dev_t *tim);
  89. /**
  90. * De-initialises an TIMER interface, Turns off an TIMER hardware interface
  91. *
  92. * @param[in] tim timer device
  93. *
  94. * @return
  95. * - 0 : success
  96. * - other : error
  97. */
  98. int hosal_timer_finalize(hosal_timer_dev_t *tim);
  99. /** @} */
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* HAL_TIMER_H */