gd_timer.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*!
  2. *******************************************************************************
  3. **
  4. ** \file gd_timer.h
  5. **
  6. ** \brief TIMER driver.
  7. **
  8. ** The driver provides functions for timer management.
  9. ** It enables an application to make use of 8 soft timers, 1 hard
  10. ** timer and 1 timestamp timer as a system clock.
  11. **
  12. ** Copyright: 2012 - 2013 (C) GoKe Microelectronics ShangHai Branch
  13. **
  14. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. GOKE MICROELECTRONICS
  15. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  16. ** OMMISSIONS.
  17. **
  18. ** \version
  19. **
  20. ******************************************************************************/
  21. #ifndef _GD_TIMER_H_
  22. #define _GD_TIMER_H_
  23. #include <gtypes.h>
  24. #include <gmodids.h>
  25. /*---------------------------------------------------------------------------*/
  26. /* constants and macros */
  27. /*---------------------------------------------------------------------------*/
  28. #define GD_TIMER_ERR_BASE (GD_TIMER_MODULE_ID<<16) //!< The timer base error code.
  29. /* Note: Pre-scaler define hardcoded to avoid calculation in ISR! */
  30. #define GD_TIMER_RESOLUTION_1_USEC 1UL //!< timer resolution 1 usec
  31. #define GD_TIMER_RESOLUTION_10_USEC 10UL //!< timer resolution 10 usec
  32. #define GD_TIMER_RESOLUTION_100_USEC 100UL //!< timer resolution 100 usec
  33. #define GD_TIMER_RESOLUTION_1_MSEC 1000UL //!< timer resolution 1 msec
  34. #define GD_TIMER_RESOLUTION_10_MSEC 10000UL //!< timer resolution 10 msec
  35. #define GD_TIMER_RESOLUTION_100_MSEC 100000UL //!< timer resolution 100 msec
  36. #define GD_TIMER_RESOLUTION_1_SEC 1000000UL //!< timer resolution 1 sec
  37. #define GD_TIMER_RESOLUTION_1_MIN 60000000UL //!< timer resolution 1 minute
  38. #define GD_TIMER_RESOLUTION_1_HOUR 3600000000UL //!< timer resolution 1 hour
  39. #define GD_TIMER_RESOLUTION_1_HOUR 3600000000UL //!< timer resolution 1 hour
  40. /*---------------------------------------------------------------------------*/
  41. /* types, enums and structures */
  42. /*---------------------------------------------------------------------------*/
  43. /*!
  44. *******************************************************************************
  45. **
  46. ** \brief TIMER driver error codes.
  47. **
  48. ******************************************************************************/
  49. typedef enum
  50. {
  51. /*! Indicates all soft timer are in use. */
  52. GD_ERR_TIMER_NO_FREE_SOFT_TIME = GD_TIMER_ERR_BASE,
  53. /*! Indicates all hard timer are in use */
  54. GD_ERR_TIMER_NO_FREE_HARD_TIME,
  55. /*! Indicates all time stamps are in use. */
  56. GD_ERR_TIMER_NO_FREE_GPREG_TIME,
  57. /*! */
  58. GD_ERR_TIMER_OUTOF_RANG,
  59. }GD_TIMER_ERR_E;
  60. /*!
  61. *******************************************************************************
  62. **
  63. ** \brief Allowed ARC timer settings.
  64. **
  65. ******************************************************************************/
  66. typedef enum
  67. {
  68. /*! Reference to TIMER1 */
  69. GD_REG_TIMER1 = 0,
  70. /*! Reference to TIMER2 */
  71. GD_REG_TIMER2 = 1,
  72. /*! Reference to TIMER3 */
  73. GD_REG_TIMER3 = 2,
  74. }GD_TIMER_REG_E;
  75. typedef enum
  76. {
  77. /*! Reference to */
  78. GD_REG_SOFT_TIMER_IRQ = 0,
  79. /*! Reference to */
  80. GD_REG_HARD_TIMER_IRQ = 1,
  81. /*! Reference to */
  82. GD_REG_GPREG_TIMER_IRQ = 2,
  83. }GD_TIMER_IRQ_E;
  84. /*!
  85. *******************************************************************************
  86. **
  87. ** \brief TIMER driver's initialization parameter.
  88. **
  89. ******************************************************************************/
  90. typedef struct
  91. {
  92. /*! The ARC core timer register to be used for soft timer. */
  93. S8 softTimerReg;
  94. /*! The priority of the soft timer interrupt. */
  95. S8 softTimerpriority;
  96. /*! The ARC core timer register to be used for hard timer. */
  97. S8 hardTimerReg;
  98. /*! The priority of the hard timer interrupt. */
  99. S8 hardTimerpriority;
  100. /*! The ARC timestamp timer register to be used for gpreg IRQ. */
  101. S8 gpregTimerReg;
  102. /*! The priority of the gpreg timer interrupt. */
  103. S8 gpregTimerpriority;
  104. }GD_TIMER_INIT_PARAMS_S;
  105. /*---------------------------------------------------------------------------*/
  106. /* function prototypes */
  107. /*---------------------------------------------------------------------------*/
  108. #ifdef __cplusplus
  109. extern "C" {
  110. #endif
  111. U8 *GD_TIMER_GetRevisionString(void);
  112. GERR GD_TIMER_Init(GD_TIMER_INIT_PARAMS_S* initParams);
  113. GERR GD_TIMER_Exit(void);
  114. GERR GD_TIMER_TimerOpen(GD_HANDLE* pHandle,GD_TIMER_IRQ_E timerIRQ);
  115. GERR GD_TIMER_TimerSet(GD_HANDLE* pHandle, U32 timeValue, GBOOL* flag, void(*fp)());
  116. GERR GD_TIMER_TimerClose(GD_HANDLE* handle);
  117. GERR GD_TIMER_HardTimerOpen(GD_HANDLE* pHandle);
  118. GERR GD_TIMER_HardTimerSet(GD_HANDLE* pHandle, U32 timeValue, GBOOL* flag,void(*fp)());
  119. GERR GD_TIMER_HardTimerClose(GD_HANDLE* pHandle);
  120. GERR GD_TIMER_GpregTimerOpen(GD_HANDLE* pHandle);
  121. GERR GD_TIMER_GpregTimerClose(GD_HANDLE* pHandle);
  122. GERR GD_TIMER_GpregTimerSet(GD_HANDLE* pHandle, U32 timeValue, GBOOL* flag, void(*fp)());
  123. U32 GD_TIMER_ReadTimerStamp(void);
  124. GERR GD_TIMER_SoftTimerOpen(GD_HANDLE* pHandle);
  125. GERR GD_TIMER_SoftTimerClose(GD_HANDLE* pHandle);
  126. GERR GD_TIMER_SoftTimerSet(GD_HANDLE* pHandle, U32 timeValue, GBOOL* flag, void(*fp)());
  127. GERR GD_TIMER_StopSoftTimer(GD_HANDLE* pHandle);
  128. GERR GD_TIMER_ContinueSoftTimer(GD_HANDLE* pHandle);
  129. GERR GD_TIMER_Delay(U32 msecs);
  130. U32 GD_GET_ARM_ClkHz(void);
  131. U32 GD_GET_AHB_ClkHz(void);
  132. U32 GD_GET_APB_ClkHz(void);
  133. U32 GD_GET_UART_ClkHz(void);
  134. U32 GD_GET_IDSP_ClkHz(void);
  135. U32 GD_GET_CORE_ClkHz(void);
  136. U32 GD_GET_DRAM_ClkHz(void);
  137. U32 GD_GET_I2S_ClkHz(void);
  138. U32 GD_GET_SD_ClkHz(void);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif /* _GD_TIMER_H_ */
  143. /* end of gd_timer.h */