hal_timer.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**************************************************************************************************
  2. Filename: hal_timer.h
  3. Revised: $Date: 2007-07-06 10:42:24 -0700 (Fri, 06 Jul 2007) $
  4. Revision: $Revision: 13579 $
  5. Description: This file contains the interface to the Timer Service.
  6. Copyright 2005-2007 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef HAL_TIMER_H
  34. #define HAL_TIMER_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /***************************************************************************************************
  40. * INCLUDES
  41. ***************************************************************************************************/
  42. #include "hal_board.h"
  43. /***************************************************************************************************
  44. * MACROS
  45. ***************************************************************************************************/
  46. /***************************************************************************************************
  47. * CONSTANTS
  48. ***************************************************************************************************/
  49. /* Timer ID definitions */
  50. #define HAL_TIMER_0 0x00 // 8bit timer
  51. #define HAL_TIMER_1 0x01 // 16bit Mac timer
  52. #define HAL_TIMER_2 0x02 // 8bit timer
  53. #define HAL_TIMER_3 0x03 // 16bit timer
  54. #define HAL_TIMER_MAX 4 // Max number of timer
  55. /* Operation Modes for timer */
  56. #define HAL_TIMER_MODE_NORMAL 0x01 // Normal Mode
  57. #define HAL_TIMER_MODE_CTC 0x02 // Clear Timer On Compare
  58. #define HAL_TIMER_MODE_MASK (HAL_TIMER_MODE_NORMAL | HAL_TIMER_MODE_CTC)
  59. /* Channel definitions */
  60. #define HAL_TIMER_CHANNEL_SINGLE 0x01 // Single Channel - default
  61. #define HAL_TIMER_CHANNEL_A 0x02 // Channel A
  62. #define HAL_TIMER_CHANNEL_B 0x04 // Channel B
  63. #define HAL_TIMER_CHANNEL_C 0x08 // Channel C
  64. #define HAL_TIMER_CHANNEL_MASK (HAL_TIMER_CHANNEL_SINGLE | \
  65. HAL_TIMER_CHANNEL_A | \
  66. HAL_TIMER_CHANNEL_B | \
  67. HAL_TIMER_CHANNEL_C)
  68. /* Channel mode definitions */
  69. #define HAL_TIMER_CH_MODE_INPUT_CAPTURE 0x01 // Channel Mode Input-Capture
  70. #define HAL_TIMER_CH_MODE_OUTPUT_COMPARE 0x02 // Channel Mode Output_Compare
  71. #define HAL_TIMER_CH_MODE_OVERFLOW 0x04 // Channel Mode Overflow
  72. #define HAL_TIMER_CH_MODE_MASK (HAL_TIMER_CH_MODE_INPUT_CAPTURE | \
  73. HAL_TIMER_CH_MODE_OUTPUT_COMPARE | \
  74. HAL_TIMER_CH_MODE_OVERFLOW)
  75. /* Error Code */
  76. #define HAL_TIMER_OK 0x00
  77. #define HAL_TIMER_NOT_OK 0x01
  78. #define HAL_TIMER_PARAMS_ERROR 0x02
  79. #define HAL_TIMER_NOT_CONFIGURED 0x03
  80. #define HAL_TIMER_INVALID_ID 0x04
  81. #define HAL_TIMER_INVALID_CH_MODE 0x05
  82. #define HAL_TIMER_INVALID_OP_MODE 0x06
  83. /* Timer clock pre-scaler definitions for 16bit timer1 and timer3 */
  84. #define HAL_TIMER3_16_TC_STOP 0x00 // No clock, timer stopped
  85. #define HAL_TIMER3_16_TC_DIV1 0x01 // No clock pre-scaling
  86. #define HAL_TIMER3_16_TC_DIV8 0x02 // Clock pre-scaled by 8
  87. #define HAL_TIMER3_16_TC_DIV64 0x03 // Clock pre-scaled by 64
  88. #define HAL_TIMER3_16_TC_DIV256 0x04 // Clock pre-scaled by 256
  89. #define HAL_TIMER3_16_TC_DIV1024 0x05 // Clock pre-scaled by 1024
  90. #define HAL_TIMER3_16_TC_EXTFE 0x06 // External clock (T2), falling edge
  91. #define HAL_TIMER3_16_TC_EXTRE 0x07 // External clock (T2), rising edge
  92. /* Timer clock pre-scaler definitions for 8bit timer0 and timer2 */
  93. #define HAL_TIMER0_8_TC_STOP 0x00 // No clock, timer stopped
  94. #define HAL_TIMER0_8_TC_DIV1 0x01 // No clock pre-scaling
  95. #define HAL_TIMER0_8_TC_DIV8 0x02 // Clock pre-scaled by 8
  96. #define HAL_TIMER0_8_TC_DIV32 0x03 // Clock pre-scaled by 32
  97. #define HAL_TIMER0_8_TC_DIV64 0x04 // Clock pre-scaled by 64
  98. #define HAL_TIMER0_8_TC_DIV128 0x05 // Clock pre-scaled by 128
  99. #define HAL_TIMER0_8_TC_DIV256 0x06 // Clock pre-scaled by 256
  100. #define HAL_TIMER0_8_TC_DIV1024 0x07 // Clock pre-scaled by 1024
  101. /* Timer clock pre-scaler definitions for 8bit timer2 */
  102. #define HAL_TIMER2_8_TC_STOP 0x00 // No clock, timer stopped
  103. #define HAL_TIMER2_8_TC_DIV1 0x01 // No clock pre-scaling
  104. #define HAL_TIMER2_8_TC_DIV8 0x02 // Clock pre-scaled by 8
  105. #define HAL_TIMER2_8_TC_DIV64 0x03 // Clock pre-scaled by 32
  106. #define HAL_TIMER2_8_TC_DIV256 0x04 // Clock pre-scaled by 64
  107. #define HAL_TIMER2_8_TC_DIV1024 0x05 // Clock pre-scaled by 128
  108. #define HAL_TIMER2_8_TC_EXTFE 0x06 // External clock (T2), falling edge
  109. #define HAL_TIMER2_8_TC_EXTRE 0x07 // External clock (T2), rising edge
  110. /***************************************************************************************************
  111. * TYPEDEFS
  112. ***************************************************************************************************/
  113. typedef void (*halTimerCBack_t) (uint8 timerId, uint8 channel, uint8 channelMode);
  114. /***************************************************************************************************
  115. * GLOBAL VARIABLES
  116. ***************************************************************************************************/
  117. /***************************************************************************************************
  118. * FUNCTIONS - API
  119. ***************************************************************************************************/
  120. /*
  121. * Initialize Timer Service
  122. */
  123. extern void HalTimerInit ( void );
  124. /*
  125. * Configure channel in different modes
  126. */
  127. extern uint8 HalTimerConfig ( uint8 timerId,
  128. uint8 opMode,
  129. uint8 channel,
  130. uint8 channelMode,
  131. bool intEnable,
  132. halTimerCBack_t cback );
  133. /*
  134. * Start a Timer
  135. */
  136. extern uint8 HalTimerStart ( uint8 timerId, uint32 timePerTick );
  137. /*
  138. * Stop a Timer
  139. */
  140. extern uint8 HalTimerStop ( uint8 timerId );
  141. /*
  142. * This is used for polling, provide the tick increment
  143. */
  144. extern void HalTimerTick ( void );
  145. /*
  146. * Enable and disable particular timer
  147. */
  148. extern uint8 HalTimerInterruptEnable (uint8 timerId, uint8 channelMode, bool enable);
  149. /***************************************************************************************************
  150. ***************************************************************************************************/
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif