tmrHw.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*****************************************************************************
  2. * Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. /****************************************************************************/
  15. /**
  16. * @file tmrHw.h
  17. *
  18. * @brief API definitions for low level Timer driver
  19. *
  20. */
  21. /****************************************************************************/
  22. #ifndef _TMRHW_H
  23. #define _TMRHW_H
  24. #include <csp/stdint.h>
  25. typedef uint32_t tmrHw_ID_t; /* Timer ID */
  26. typedef uint32_t tmrHw_COUNT_t; /* Timer count */
  27. typedef uint32_t tmrHw_INTERVAL_t; /* Timer interval */
  28. typedef uint32_t tmrHw_RATE_t; /* Timer event (count/interrupt) rate */
  29. typedef enum {
  30. tmrHw_INTERRUPT_STATUS_SET, /* Interrupted */
  31. tmrHw_INTERRUPT_STATUS_UNSET /* No Interrupt */
  32. } tmrHw_INTERRUPT_STATUS_e;
  33. typedef enum {
  34. tmrHw_CAPABILITY_CLOCK, /* Clock speed in HHz */
  35. tmrHw_CAPABILITY_RESOLUTION /* Timer resolution in bits */
  36. } tmrHw_CAPABILITY_e;
  37. /****************************************************************************/
  38. /**
  39. * @brief Get timer capability
  40. *
  41. * This function returns various capabilities/attributes of a timer
  42. *
  43. * @return Numeric capability
  44. *
  45. */
  46. /****************************************************************************/
  47. uint32_t tmrHw_getTimerCapability(tmrHw_ID_t timerId, /* [ IN ] Timer Id */
  48. tmrHw_CAPABILITY_e capability /* [ IN ] Timer capability */
  49. );
  50. /****************************************************************************/
  51. /**
  52. * @brief Configures a periodic timer in terms of timer interrupt rate
  53. *
  54. * This function initializes a periodic timer to generate specific number of
  55. * timer interrupt per second
  56. *
  57. * @return On success: Effective timer frequency
  58. * On failure: 0
  59. *
  60. */
  61. /****************************************************************************/
  62. tmrHw_RATE_t tmrHw_setPeriodicTimerRate(tmrHw_ID_t timerId, /* [ IN ] Timer Id */
  63. tmrHw_RATE_t rate /* [ IN ] Number of timer interrupt per second */
  64. );
  65. /****************************************************************************/
  66. /**
  67. * @brief Configures a periodic timer to generate timer interrupt after
  68. * certain time interval
  69. *
  70. * This function initializes a periodic timer to generate timer interrupt
  71. * after every time interval in milisecond
  72. *
  73. * @return On success: Effective interval set in mili-second
  74. * On failure: 0
  75. *
  76. */
  77. /****************************************************************************/
  78. tmrHw_INTERVAL_t tmrHw_setPeriodicTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */
  79. tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */
  80. );
  81. /****************************************************************************/
  82. /**
  83. * @brief Configures a periodic timer to generate timer interrupt just once
  84. * after certain time interval
  85. *
  86. * This function initializes a periodic timer to generate a single ticks after
  87. * certain time interval in milisecond
  88. *
  89. * @return On success: Effective interval set in mili-second
  90. * On failure: 0
  91. *
  92. */
  93. /****************************************************************************/
  94. tmrHw_INTERVAL_t tmrHw_setOneshotTimerInterval(tmrHw_ID_t timerId, /* [ IN ] Timer Id */
  95. tmrHw_INTERVAL_t msec /* [ IN ] Interval in mili-second */
  96. );
  97. /****************************************************************************/
  98. /**
  99. * @brief Configures a timer to run as a free running timer
  100. *
  101. * This function initializes a timer to run as a free running timer
  102. *
  103. * @return Timer resolution (count / sec)
  104. *
  105. */
  106. /****************************************************************************/
  107. tmrHw_RATE_t tmrHw_setFreeRunningTimer(tmrHw_ID_t timerId, /* [ IN ] Timer Id */
  108. uint32_t divider /* [ IN ] Dividing the clock frequency */
  109. ) __attribute__ ((section(".aramtext")));
  110. /****************************************************************************/
  111. /**
  112. * @brief Starts a timer
  113. *
  114. * This function starts a preconfigured timer
  115. *
  116. * @return -1 - On Failure
  117. * 0 - On Success
  118. */
  119. /****************************************************************************/
  120. int tmrHw_startTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */
  121. ) __attribute__ ((section(".aramtext")));
  122. /****************************************************************************/
  123. /**
  124. * @brief Stops a timer
  125. *
  126. * This function stops a running timer
  127. *
  128. * @return -1 - On Failure
  129. * 0 - On Success
  130. */
  131. /****************************************************************************/
  132. int tmrHw_stopTimer(tmrHw_ID_t timerId /* [ IN ] Timer id */
  133. );
  134. /****************************************************************************/
  135. /**
  136. * @brief Gets current timer count
  137. *
  138. * This function returns the current timer value
  139. *
  140. * @return Current downcounting timer value
  141. *
  142. */
  143. /****************************************************************************/
  144. tmrHw_COUNT_t tmrHw_GetCurrentCount(tmrHw_ID_t timerId /* [ IN ] Timer id */
  145. ) __attribute__ ((section(".aramtext")));
  146. /****************************************************************************/
  147. /**
  148. * @brief Gets timer count rate
  149. *
  150. * This function returns the number of counts per second
  151. *
  152. * @return Count rate
  153. *
  154. */
  155. /****************************************************************************/
  156. tmrHw_RATE_t tmrHw_getCountRate(tmrHw_ID_t timerId /* [ IN ] Timer id */
  157. ) __attribute__ ((section(".aramtext")));
  158. /****************************************************************************/
  159. /**
  160. * @brief Enables timer interrupt
  161. *
  162. * This function enables the timer interrupt
  163. *
  164. * @return N/A
  165. *
  166. */
  167. /****************************************************************************/
  168. void tmrHw_enableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */
  169. );
  170. /****************************************************************************/
  171. /**
  172. * @brief Disables timer interrupt
  173. *
  174. * This function disable the timer interrupt
  175. *
  176. * @return N/A
  177. */
  178. /****************************************************************************/
  179. void tmrHw_disableInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */
  180. );
  181. /****************************************************************************/
  182. /**
  183. * @brief Clears the interrupt
  184. *
  185. * This function clears the timer interrupt
  186. *
  187. * @return N/A
  188. *
  189. * @note
  190. * Must be called under the context of ISR
  191. */
  192. /****************************************************************************/
  193. void tmrHw_clearInterrupt(tmrHw_ID_t timerId /* [ IN ] Timer id */
  194. );
  195. /****************************************************************************/
  196. /**
  197. * @brief Gets the interrupt status
  198. *
  199. * This function returns timer interrupt status
  200. *
  201. * @return Interrupt status
  202. */
  203. /****************************************************************************/
  204. tmrHw_INTERRUPT_STATUS_e tmrHw_getInterruptStatus(tmrHw_ID_t timerId /* [ IN ] Timer id */
  205. );
  206. /****************************************************************************/
  207. /**
  208. * @brief Indentifies a timer causing interrupt
  209. *
  210. * This functions returns a timer causing interrupt
  211. *
  212. * @return 0xFFFFFFFF : No timer causing an interrupt
  213. * ! 0xFFFFFFFF : timer causing an interrupt
  214. * @note
  215. * tmrHw_clearIntrrupt() must be called with a valid timer id after calling this function
  216. */
  217. /****************************************************************************/
  218. tmrHw_ID_t tmrHw_getInterruptSource(void);
  219. /****************************************************************************/
  220. /**
  221. * @brief Displays specific timer registers
  222. *
  223. *
  224. * @return void
  225. *
  226. */
  227. /****************************************************************************/
  228. void tmrHw_printDebugInfo(tmrHw_ID_t timerId, /* [ IN ] Timer id */
  229. int (*fpPrint) (const char *, ...) /* [ IN ] Print callback function */
  230. );
  231. /****************************************************************************/
  232. /**
  233. * @brief Use a timer to perform a busy wait delay for a number of usecs.
  234. *
  235. * @return N/A
  236. */
  237. /****************************************************************************/
  238. void tmrHw_udelay(tmrHw_ID_t timerId, /* [ IN ] Timer id */
  239. unsigned long usecs /* [ IN ] usec to delay */
  240. ) __attribute__ ((section(".aramtext")));
  241. #endif /* _TMRHW_H */