stimer.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*----------------------------------------------------------------------------
  2. * Copyright (c) <2018>, <Huawei Technologies Co., Ltd>
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without modification,
  5. * are permitted provided that the following conditions are met:
  6. * 1. Redistributions of source code must retain the above copyright notice, this list of
  7. * conditions and the following disclaimer.
  8. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  9. * of conditions and the following disclaimer in the documentation and/or other materials
  10. * provided with the distribution.
  11. * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  12. * to endorse or promote products derived from this software without specific prior written
  13. * permission.
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *---------------------------------------------------------------------------*/
  26. /*----------------------------------------------------------------------------
  27. * Notice of Export Control Law
  28. * ===============================================
  29. * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
  30. * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
  31. * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
  32. * applicable export control laws and regulations.
  33. *---------------------------------------------------------------------------*/
  34. /**
  35. * DATE AUTHOR INSTRUCTION
  36. * 2019-07-26 18:05 zhangqianfu The first version
  37. *
  38. */
  39. #ifndef LITEOS_LAB_IOT_LINK_STIMER_STIMER_H_
  40. #define LITEOS_LAB_IOT_LINK_STIMER_STIMER_H_
  41. #include <stddef.h>
  42. #include <stdint.h>
  43. ////////////////DEFINES FOR THE STIMER HEADER///////////////////////////////////
  44. ///< defines for the soft timer operation method,you could use it with the stimer_ioctl function
  45. typedef enum
  46. {
  47. en_stimer_opt_stop = 0, ///< stop the soft timer
  48. en_stimer_opt_start, ///< start the soft timer
  49. en_stimer_opt_gettime, ///< get the left time
  50. en_stimer_opt_recycle, ///< reset the cycle
  51. en_stimer_opt_reflag, ///< reset the flag
  52. }en_stimer_opt_t;
  53. ///< defines for the soft timer handle returned by the create function and used for ioctl and delete function
  54. ///< the user should never supposed any data structure for the handle, you could only use the api supplied
  55. typedef void* stimer_t;
  56. ///< defines for the flag when create the soft timer
  57. #define cn_stimer_flag_once (1<<0)
  58. #define cn_stimer_flag_start (1<<1)
  59. ///< define the soft timer interrupt service function
  60. typedef void (*fn_stimer_handler)(void *arg);
  61. /**
  62. * @brief: this function used for initialize the timer component, should be called after the os
  63. *
  64. * @return: 0 success while -1 failed
  65. * */
  66. int32_t stimer_init();
  67. /**
  68. * @brief: you could use this function for create a soft timer as you wished
  69. *
  70. * @param[in]:name, the soft timer name
  71. * @param[in]:handler, the soft timer handler when the timer is activated
  72. * @param[in]:arg, the argument will supplied for the handler
  73. * @param[in]:cycle, the soft timer cycle
  74. * @param[in]:flag, you could use cn_stimer_flag_once or cn_stimer_flag_start or both
  75. *
  76. * @return:soft timer handler, you could use it for ioctl or delete;if failed NULL
  77. * will be returned
  78. *
  79. * */
  80. stimer_t stimer_create(const char *name,fn_stimer_handler handler, \
  81. void *arg,uint32_t cycle,uint32_t flag);
  82. /**
  83. * @brief: you could use this function to delete the soft timer you created
  84. *
  85. * @param[in]:timer handler,returned by the create function
  86. *
  87. * @return:0 success while -1 or others failed
  88. *
  89. * */
  90. int32_t stimer_delete(stimer_t timer);
  91. /**
  92. * @brief: you could use this function to control the function
  93. *
  94. * @param[in]:timer,returned by the create function
  95. * @param[in]:opt,defined by en_stimer_opt_t, and the arg is corresponding parameters
  96. * @param[in]:arg, corresponding to the opt
  97. *
  98. * @return:0 success while -1 or others failed
  99. *
  100. * */
  101. int32_t stimer_ioctl(stimer_t timer,en_stimer_opt_t opt, void *arg);
  102. #endif /* LITEOS_LAB_IOT_LINK_STIMER_STIMER_H_ */