yc_timer.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /**
  11. *@file timer.h
  12. *@brief timer support for application.
  13. */
  14. #ifndef DRIVERS_TIMER_YC_TIMER_H_
  15. #define DRIVERS_TIMER_YC_TIMER_H_
  16. #include <stdbool.h>
  17. #include <stdio.h>
  18. #include "yc11xx.h"
  19. #include "ycdef.h"
  20. typedef struct SYSTEM_TIME_HANDLE
  21. {
  22. void (*init)(void);
  23. unsigned int (*get_run_ticks)(void);
  24. unsigned int (*get_run_tickms)(void);
  25. }sys_time_handle_t;
  26. extern sys_time_handle_t sys_time_handle;
  27. /**
  28. *@brief system tick.
  29. */
  30. //#define SYSTEM_CLOCK (48000000UL)
  31. #define SYSTEM_CLOCK (24000000UL)
  32. #define CLOCK_DIVISOR 1000
  33. #define CLK_SUBSLOT_10_MS (32)
  34. #define SYSTEM_TIMER_UNIT_SUBSLOTS (CLK_SUBSLOT_10_MS)
  35. extern uint32_t SYStick_count;
  36. typedef void (*Timer_Expire_CB)(int params);
  37. /**
  38. *@brief Timer_state.
  39. */
  40. typedef enum
  41. {
  42. TIMER_STOP,
  43. TIMER_START,
  44. }TIMER_STATUS;
  45. /**
  46. *@brief Timer_type.
  47. */
  48. typedef enum
  49. {
  50. TIMER_SINGLE, /*!< */
  51. TIMER_CYCLE, /*!< */
  52. TIMER_TYPE_BIT=0x80,
  53. }TIMER_TYPE;
  54. /**
  55. *@brief System timer type.
  56. */
  57. typedef struct sTimerType
  58. {
  59. uint32_t mTimerValue;
  60. uint32_t mTick;
  61. TIMER_STATUS mTimerStatus;
  62. TIMER_TYPE mIsCycle;
  63. Timer_Expire_CB pfExpireCb;
  64. struct sTimerType *pNextTimer;
  65. int32_t cbParams;
  66. }SYS_TIMER_TYPE;
  67. /**
  68. *@brief Timer_number.
  69. */
  70. typedef enum
  71. {
  72. SYS_TIMER_0,
  73. SYS_TIMER_1,
  74. SYS_TIMER_2,
  75. SYS_TIMER_3,
  76. SYS_TIMER_4,
  77. SYS_TIMER_5,
  78. SYS_TIMER_6,
  79. SYS_TIMER_7,
  80. SYS_TIMER_8,
  81. }SYS_TIMER_INDEX;
  82. #define OS_ENTER_CRITICAL() __disable_irq()
  83. #define OS_EXIT_CRITICAL() __enable_irq()
  84. /**
  85. *@brief Timer initialization.
  86. *@param None.
  87. *@return None.
  88. */
  89. void SYS_TimerInit();
  90. /**
  91. *@brief This function can set a timer.
  92. *@param pTimer
  93. *@param tick
  94. *@param type
  95. *@param pfExpire_CB
  96. *@retval true sucess.
  97. *@retval false failure.
  98. */
  99. bool SYS_SetTimer(SYS_TIMER_TYPE *pTimer, int tick,TIMER_TYPE type,Timer_Expire_CB pfExpire_CB);
  100. /**
  101. *@brief Timer polling.
  102. */
  103. void SYS_timerPolling();
  104. /**
  105. *@brief release timer.
  106. *@param pTimer .@ref SYS_TIMER_TYPE
  107. *@retval true success.
  108. *@retval false failure.
  109. */
  110. bool SYS_ReleaseTimer(SYS_TIMER_TYPE *pTimer);
  111. /**
  112. *@brief Timer expire default handle.
  113. *@param None.
  114. *@return None.
  115. */
  116. void SYS_TimerExpireDefaultHandle();
  117. /**
  118. *@brief release all timer.
  119. *@param None.
  120. *@return None.
  121. */
  122. void SYS_ReleaseAllTimer();
  123. /**
  124. *@brief Check timer exist.
  125. *@param pTimer will be check exist or not.@ref SYS_TIMER_TYPE
  126. *@retval true this timer is exist.
  127. *@retval false the timer is not exist.
  128. */
  129. bool SYS_TimerisExist(SYS_TIMER_TYPE *pTimer);
  130. bool SYS_ResetTimer(SYS_TIMER_TYPE *pTimer);
  131. void SYS_delay_us(uint32_t nus);
  132. void SYS_delay_ms(uint32_t nms);
  133. void SYStick_handle();
  134. void SYS_ClkTicks(void);
  135. #endif