timer.h 4.1 KB

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