timer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. ******************************************************************************
  3. * @file timer.h
  4. * @author StarFive Technology
  5. * @version V1.0
  6. * @date 07/24/2020
  7. * @brief
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STARFIVE SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * COPYRIGHT 2020 Shanghai StarFive Technology Co., Ltd.
  19. */
  20. #ifndef __TIMER_H__
  21. #define __TIMER_H__
  22. #include <comdef.h>
  23. #if 0
  24. #define RUN_MODE_CONTINOUS 0
  25. #define RUN_MODE_SINGLE 1
  26. #define SOC_SYS_TIMER 0 /* system timer0 */
  27. #define CONFIG_SYS_HZ_CLOCK TIMER_CLK_HZ
  28. struct timer_driver {
  29. void *base;
  30. unsigned long freq;
  31. int irq;
  32. };
  33. struct timer_init_s{
  34. u32 int_en;
  35. u32 run_mode;
  36. u32 size;
  37. u32 one_shot;
  38. u32 count; /* TODO: time value */
  39. void (*callback)(void*);
  40. void *arg;
  41. u32 wdog_reset_en;
  42. };
  43. /*
  44. * public function definition
  45. */
  46. /*---------------------------------------------------
  47. *
  48. * timer_clr_int_status:
  49. * This function clear int_status register.
  50. *
  51. * timer_clr_int_status() interface:
  52. * id:0/1/2 indicate clear timer0/timer1/timer2
  53. int_status register.
  54. *
  55. * Returns: 0 on success, not 0 on failure
  56. */
  57. int timer_clr_int_status(u32 id);
  58. /*---------------------------------------------------
  59. *
  60. * timer_set:
  61. * This function set registers defined by timer_init_s
  62. struct.
  63. *
  64. * timer_set() interface:
  65. * id:0/1/2 indicate clear timer0/timer1/timer2
  66. int_status register.
  67. init:timer_init_s struct ptr.
  68. *
  69. * Returns: 0 on success, not 0 on failure
  70. */
  71. int timer_set(u32 id,struct timer_init_s *init);
  72. /*---------------------------------------------------
  73. *
  74. */
  75. void timer_reload(u32 id);
  76. /*---------------------------------------------------
  77. *
  78. * timer_stop:
  79. * This function disable and clear interrupt regs of the timer.
  80. *
  81. * timer_stop() interface:
  82. * id:0/1/2 indicate clear timer0/timer1/timer2
  83. int_status register.
  84. *
  85. * Returns: 0 on success, not 0 on failure
  86. */
  87. int timer_stop(u32 id);
  88. /*---------------------------------------------------
  89. *
  90. * timer_start:
  91. * This function enable the timer.
  92. *
  93. * timer_start() interface:
  94. * id:0/1/2 indicate clear timer0/timer1/timer2
  95. int_status register.
  96. *
  97. * Returns: 0 on success, not 0 on failure
  98. */
  99. int timer_start(u32 id);
  100. /*---------------------------------------------------
  101. * timer_init:
  102. * This function initialize module hardware and some software structures.
  103. * You must call this function before other operation
  104. *
  105. * Returns: 0 on success, not 0 on failure
  106. */
  107. int timer_init(int id);
  108. /*---------------------------------------------------
  109. * module_exit:
  110. * This function free memory.
  111. *
  112. * Returns: 0 on success, not 0 on failure
  113. */
  114. int timer_exit(void);
  115. #endif
  116. /*---------------------------------------------------
  117. *
  118. * udelay:
  119. * This function used for delay usec microsecond.
  120. *
  121. * udelay() interface:
  122. * usec:0~357913941(MAX) int number.
  123. *
  124. * Returns: 0 on success, not 0 on failure
  125. */
  126. int udelay(u32 usec);
  127. void mdelay(unsigned int ms);
  128. void sdelay(unsigned int s);
  129. u32 get_timer(unsigned int base);
  130. /*---------------------------------------------------
  131. *
  132. * get_ticks:
  133. * This function get system ticks number.
  134. *
  135. * get_ticks() interface:
  136. * tick_base:base number of system ticks.
  137. *
  138. * Returns: a long long int number represent how many
  139. ticks from system start based on tick_base.
  140. */
  141. unsigned long long get_ticks(void);
  142. /*---------------------------------------------------
  143. *
  144. * usec_to_tick:
  145. * This function convert microsecond to system ticks.
  146. *
  147. * usec_to_tick() interface:
  148. * usec:0~357913941(MAX) int number.
  149. *
  150. * Returns: converted system ticks.
  151. */
  152. u64 usec_to_tick(u64 usec);
  153. #define delay udelay
  154. #endif /* __TIMER_H__ */