CG_timer.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. *******************************************************************************
  3. * Copyright(C) NEC Electronics Corporation 2010
  4. * All rights reserved by NEC Electronics Corporation.
  5. * This program should be used on your own responsibility.
  6. * NEC Electronics Corporation assumes no responsibility for any losses
  7. * incurred by customers or third parties arising from the use of this file.
  8. *
  9. * This device driver was created by Applilet3 for V850ES/Jx3
  10. * 32-Bit Single-Chip Microcontrollers
  11. * Filename: CG_timer.h
  12. * Abstract: This file implements device driver for Timer module.
  13. * APIlib: Applilet3 for V850ES/Jx3 V2.01 [20 Apr 2010]
  14. * Device: uPD70F3746
  15. * Compiler: IAR Systems ICCV850
  16. * Creation date: 6/26/2010
  17. *******************************************************************************
  18. */
  19. #ifndef _MDTIMER_
  20. #define _MDTIMER_
  21. /*
  22. *******************************************************************************
  23. ** Register bit define
  24. *******************************************************************************
  25. */
  26. /*
  27. TMP control register 0 (TPnCTL0)
  28. */
  29. /* TMP operation control (TPnCE) */
  30. #define _00_TMP_OPERATION_DISABLE 0x00U /* disable internal operating clock operation (asynchronously reset TMPn) */
  31. #define _80_TMP_OPERATION_ENABLE 0x80U /* enable internal operating clock operation */
  32. /* Internal count clock selection (TPnCKS2 - TPnCKS0) */
  33. #define _00_TMP_INTERNAL_CLOCK0 0x00U /* fXX */
  34. #define _01_TMP_INTERNAL_CLOCK1 0x01U /* fXX/2 */
  35. #define _02_TMP_INTERNAL_CLOCK2 0x02U /* fXX/2^2 */
  36. #define _03_TMP_INTERNAL_CLOCK3 0x03U /* fXX/2^3 */
  37. #define _04_TMP_INTERNAL_CLOCK4 0x04U /* fXX/2^4 */
  38. #define _05_TMP_INTERNAL_CLOCK5 0x05U /* fXX/2^5 */
  39. #define _06_TMP_INTERNAL_CLOCK6 0x06U /* fXX/2^6 or fXX/2^8 */
  40. #define _07_TMP_INTERNAL_CLOCK7 0x07U /* fXX/2^7 or fXX/2^9 */
  41. /*
  42. TMP control register 1 (TPnCTL1)
  43. */
  44. /* Software trigger control (TPnEST) */
  45. #define _00_TMP_SOFTTRIGGER_OFF 0x00U /* no operation */
  46. #define _40_TMP_SOFTTRIGGER_ON 0x40U /* in one-shot pulse mode: One-shot pulse software trigger */
  47. /* in external trigger pulse output mode: Pulse output software trigger */
  48. /* Count clock selection (TPnEEE) */
  49. #define _00_TMP_INTERNAL_CLOCK 0x00U /* use the internal clock (clock selected with bits TPnCKS2 to TPnCKS0) */
  50. #define _20_TMP_EXTERNAL_CLOCK 0x20U /* use the external clock from the TIPn0 input pin */
  51. /* Timer mode selection (TPnMD2 - TPnMD0) */
  52. #define _00_TMP_MODE_INTERVAL 0x00U /* interval timer mode */
  53. #define _01_TMP_MODE_EXTERNALCOUNT 0x01U /* external event counter mode */
  54. #define _02_TMP_MODE_EXTERNALTRG 0x02U /* external trigger pulse output mode */
  55. #define _03_TMP_MODE_ONESHOT 0x03U /* one-shot pulse mode */
  56. #define _04_TMP_MODE_PWM 0x04U /* PWM mode */
  57. #define _05_TMP_MODE_FREERUNNING 0x05U /* free-running mode */
  58. #define _06_TMP_MODE_PULSEMEASURE 0x06U /* pulse width measurement mode */
  59. /*
  60. TMP I/O control register 0 (TPnIOC0)
  61. */
  62. /* TOPn0 pin output level setting (TPnOL0) */
  63. #define _00_TMP_OUTPUT0_NORMAL 0x00U /* normal output */
  64. #define _02_TMP_OUTPUT0_INVERTED 0x02U /* inverted output */
  65. /* TOPn0 pin output setting (TPnOE0) */
  66. #define _00_TMP_OUTPUT0_DISABLE 0x00U /* disable timer output */
  67. #define _01_TMP_OUTPUT0_ENABLE 0x01U /* enable timer output (TOPn0 pin outputs pulses) */
  68. /* TOPn1 pin output level setting (TPnOL1) */
  69. #define _00_TMP_OUTPUT1_NORMAL 0x00U /* normal output */
  70. #define _08_TMP_OUTPUT1_INVERTED 0x08U /* inverted output */
  71. /* TOPn1 pin output setting (TPnOE1) */
  72. #define _00_TMP_OUTPUT1_DISABLE 0x00U /* disable timer output */
  73. #define _04_TMP_OUTPUT1_ENABLE 0x04U /* enable timer output (TOPn1 pin outputs pulses) */
  74. /*
  75. TMP I/O control register 1 (TPnIOC1)
  76. */
  77. /* Capture trigger input signal (TIPn1 pin) valid edge setting (TPnIS3,TPnIS2) */
  78. #define _00_TMP_INPUT1_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  79. #define _04_TMP_INPUT1_EDGE_RISING 0x04U /* detection of rising edge */
  80. #define _08_TMP_INPUT1_EDGE_FALLING 0x08U /* detection of falling edge */
  81. #define _0C_TMP_INPUT1_EDGE_BOTH 0x0CU /* detection of both edges */
  82. /* Capture trigger input signal (TIPn0 pin) valid edge setting (TPnIS1,TPnIS0) */
  83. #define _00_TMP_INPUT0_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  84. #define _01_TMP_INPUT0_EDGE_RISING 0x01U /* detection of rising edge */
  85. #define _02_TMP_INPUT0_EDGE_FALLING 0x02U /* detection of falling edge */
  86. #define _03_TMP_INPUT0_EDGE_BOTH 0x03U /* detection of both edges */
  87. /*
  88. TMP I/O control register 2 (TPnIOC2)
  89. */
  90. /* External event count input signal (TIPn0 pin) valid edge setting (TPnEES1,TPnEES0) */
  91. #define _00_TMP_EXTCOUNT_EDGE_NONE 0x00U /* detect no edge (external event count is invalid) */
  92. #define _04_TMP_EXTCOUNT_EDGE_RISING 0x04U /* detection of rising edge */
  93. #define _08_TMP_EXTCOUNT_EDGE_FALLING 0x08U /* detection of falling edge */
  94. #define _0C_TMP_EXTCOUNT_EDGE_BOTH 0x0CU /* detection of both edges */
  95. /* External trigger input signal (TIPn0 pin) valid edge setting (TPnETS1,TPnETS0) */
  96. #define _00_TMP_EXTTRIGGER_EDGE_NONE 0x00U /* detect no edge (external trigger is invalid) */
  97. #define _01_TMP_EXTTRIGGER_EDGE_RISING 0x01U /* detection of rising edge */
  98. #define _02_TMP_EXTTRIGGER_EDGE_FALLING 0x02U /* detection of falling edge */
  99. #define _03_TMP_EXTTRIGGER_EDGE_BOTH 0x03U /* detection of both edges */
  100. /*
  101. TMP option register 0 (TPnOPT0)
  102. */
  103. /* TPnCCR1 register capture/compare selection (TPnCCS1) */
  104. #define _00_TMP_CCR1_COMPARE 0x00U /* compare register */
  105. #define _20_TMP_CCR1_CAPTURE 0x20U /* capture register */
  106. /* TPnCCR0 register capture/compare selection (TPnCCS0) */
  107. #define _00_TMP_CCR0_COMPARE 0x00U /* compare register */
  108. #define _10_TMP_CCR0_CAPTURE 0x10U /* capture register */
  109. /* TMPn overflow detection flag (TPnOVF) */
  110. #define _01_TMP_OVERFLOW_OCCUR 0x01U /* overflow occurred */
  111. #define _00_TMP_OVERFLOW_CLEAR 0x00U /* clear overflow */
  112. /*
  113. TMQ0 control register 0 (TQ0CTL0)
  114. */
  115. /* TMQ operation control (TQ0CE) */
  116. #define _00_TMQ_OPERATION_DISABLE 0x00U /* disable internal operating clock operation (asynchronously reset TMQ0) */
  117. #define _80_TMQ_OPERATION_ENABLE 0x80U /* enable internal operating clock operation */
  118. /* Internal count clock selection (TQ0CKS2 - TQ0CKS0) */
  119. #define _00_TMQ_INTERNAL_CLOCK0 0x00U /* fXX */
  120. #define _01_TMQ_INTERNAL_CLOCK1 0x01U /* fXX/2 */
  121. #define _02_TMQ_INTERNAL_CLOCK2 0x02U /* fXX/2^2 */
  122. #define _03_TMQ_INTERNAL_CLOCK3 0x03U /* fXX/2^3 */
  123. #define _04_TMQ_INTERNAL_CLOCK4 0x04U /* fXX/2^4 */
  124. #define _05_TMQ_INTERNAL_CLOCK5 0x05U /* fXX/2^5 */
  125. #define _06_TMQ_INTERNAL_CLOCK6 0x06U /* fXX/2^6 */
  126. #define _07_TMQ_INTERNAL_CLOCK7 0x07U /* fXX/2^7 */
  127. /*
  128. TMQ0 control register 1 (TQ0CTL1)
  129. */
  130. /* Software trigger control (TQ0EST) */
  131. #define _00_TMQ_SOFTTRIGGER_OFF 0x00U /* no operation */
  132. #define _40_TMQ_SOFTTRIGGER_ON 0x40U /* in one-shot pulse mode: One-shot pulse software trigger */
  133. /* in external trigger pulse output mode: Pulse output software trigger */
  134. /* Count clock selection (TQ0EEE) */
  135. #define _00_TMQ_INTERNAL_CLOCK 0x00U /* use the internal clock (clock selected with bits TQ0CKS2 to TQ0CKS0) */
  136. #define _20_TMQ_EXTERNAL_CLOCK 0x20U /* use the external clock from the TIQ00 input pin */
  137. /* Timer mode selection (TQ0MD2 - TQ0MD0) */
  138. #define _00_TMQ_MODE_INTERVAL 0x00U /* interval timer mode */
  139. #define _01_TMQ_MODE_EXTERNALCOUNT 0x01U /* external event counter mode */
  140. #define _02_TMQ_MODE_EXTERNALTRG 0x02U /* external trigger pulse output mode */
  141. #define _03_TMQ_MODE_ONESHOT 0x03U /* one-shot pulse mode */
  142. #define _04_TMQ_MODE_PWM 0x04U /* PWM mode */
  143. #define _05_TMQ_MODE_FREERUNNING 0x05U /* free-running mode */
  144. #define _06_TMQ_MODE_PULSEMEASURE 0x06U /* pulse width measurement mode */
  145. /*
  146. TMQ0 I/O control register 0 (TQ0IOC0)
  147. */
  148. /* TOQ00 pin output level setting (TQ0OL0) */
  149. #define _00_TMQ_OUTPUT0_NORMAL 0x00U /* normal output */
  150. #define _02_TMQ_OUTPUT0_INVERTED 0x02U /* inverted output */
  151. /* TOQ00 pin output setting (TQ0OE0) */
  152. #define _00_TMQ_OUTPUT0_DISABLE 0x00U /* disable timer output */
  153. #define _01_TMQ_OUTPUT0_ENABLE 0x01U /* enable timer output (TOQ00 pin outputs pulses) */
  154. /* TOQ01 pin output level setting (TQ0OL1) */
  155. #define _00_TMQ_OUTPUT1_NORMAL 0x00U /* normal output */
  156. #define _08_TMQ_OUTPUT1_INVERTED 0x08U /* inverted output */
  157. /* TOQ01 pin output setting (TQ0OE1) */
  158. #define _00_TMQ_OUTPUT1_DISABLE 0x00U /* disable timer output */
  159. #define _04_TMQ_OUTPUT1_ENABLE 0x04U /* enable timer output (TOQ01 pin outputs pulses) */
  160. /* TOQ02 pin output level setting (TQ0OL2) */
  161. #define _00_TMQ_OUTPUT2_NORMAL 0x00U /* normal output */
  162. #define _20_TMQ_OUTPUT2_INVERTED 0x20U /* inverted output */
  163. /* TOQ02 pin output setting (TQ0OE2) */
  164. #define _00_TMQ_OUTPUT2_DISABLE 0x00U /* disable timer output */
  165. #define _10_TMQ_OUTPUT2_ENABLE 0x10U /* enable timer output (TOQ02 pin outputs pulses) */
  166. /* TOQ03 pin output level setting (TQ0OL3) */
  167. #define _00_TMQ_OUTPUT3_NORMAL 0x00U /* normal output */
  168. #define _80_TMQ_OUTPUT3_INVERTED 0x80U /* inverted output */
  169. /* TOQ03 pin output setting (TQ0OE3) */
  170. #define _00_TMQ_OUTPUT3_DISABLE 0x00U /* disable timer output */
  171. #define _40_TMQ_OUTPUT3_ENABLE 0x40U /* enable timer output (TOQ03 pin outputs pulses) */
  172. /*
  173. TMQ0 I/O control register 1 (TQ0IOC1)
  174. */
  175. /* Capture trigger input signal (TIQ00 pin) valid edge setting (TQ0IS1,TQ0IS0) */
  176. #define _00_TMQ_INPUT0_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  177. #define _01_TMQ_INPUT0_EDGE_RISING 0x01U /* detection of rising edge */
  178. #define _02_TMQ_INPUT0_EDGE_FALLING 0x02U /* detection of falling edge */
  179. #define _03_TMQ_INPUT0_EDGE_BOTH 0x03U /* detection of both edges */
  180. /* Capture trigger input signal (TIQ01 pin) valid edge setting (TQ0IS3,TQ0IS2) */
  181. #define _00_TMQ_INPUT1_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  182. #define _04_TMQ_INPUT1_EDGE_RISING 0x04U /* detection of rising edge */
  183. #define _08_TMQ_INPUT1_EDGE_FALLING 0x08U /* detection of falling edge */
  184. #define _0C_TMQ_INPUT1_EDGE_BOTH 0x0CU /* detection of both edges */
  185. /* Capture trigger input signal (TIQ02 pin) valid edge setting (TQ0IS5,TQ0IS4) */
  186. #define _00_TMQ_INPUT2_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  187. #define _10_TMQ_INPUT2_EDGE_RISING 0x10U /* detection of rising edge */
  188. #define _20_TMQ_INPUT2_EDGE_FALLING 0x20U /* detection of falling edge */
  189. #define _30_TMQ_INPUT2_EDGE_BOTH 0x30U /* detection of both edges */
  190. /* Capture trigger input signal (TIQ03 pin) valid edge setting (TQ0IS7,TQ0IS6) */
  191. #define _00_TMQ_INPUT3_EDGE_NONE 0x00U /* detect no edge (capture operation is invalid) */
  192. #define _40_TMQ_INPUT3_EDGE_RISING 0x40U /* detection of rising edge */
  193. #define _80_TMQ_INPUT3_EDGE_FALLING 0x80U /* detection of falling edge */
  194. #define _C0_TMQ_INPUT3_EDGE_BOTH 0xC0U /* detection of both edges */
  195. /*
  196. TMQ0 I/O control register 2 (TQ0IOC2)
  197. */
  198. /* External event count input signal (TIQ00 pin) valid edge setting (TQ0EES1,TQ0EES0) */
  199. #define _00_TMQ_EXTCOUNT_EDGE_NONE 0x00U /* detect no edge (external event count is invalid) */
  200. #define _04_TMQ_EXTCOUNT_EDGE_RISING 0x04U /* detection of rising edge */
  201. #define _08_TMQ_EXTCOUNT_EDGE_FALLING 0x08U /* detection of falling edge */
  202. #define _0C_TMQ_EXTCOUNT_EDGE_BOTH 0x0CU /* detection of both edges */
  203. /* External trigger input signal (TIQ00 pin) valid edge setting (TQ0ETS1,TQ0ETS0) */
  204. #define _00_TMQ_EXTTRIGGER_EDGE_NONE 0x00U /* detect no edge (external trigger is invalid) */
  205. #define _01_TMQ_EXTTRIGGER_EDGE_RISING 0x01U /* detection of rising edge */
  206. #define _02_TMQ_EXTTRIGGER_EDGE_FALLING 0x02U /* detection of falling edge */
  207. #define _03_TMQ_EXTTRIGGER_EDGE_BOTH 0x03U /* detection of both edges */
  208. /*
  209. TMQ0 option register 0 (TQ0OPT0)
  210. */
  211. /* TQ0CCR3 register capture/compare selection (TQ0CCS3) */
  212. #define _00_TMQ_CCR3_COMPARE 0x00U /* compare register */
  213. #define _80_TMQ_CCR3_CAPTURE 0x80U /* capture register */
  214. /* TQ0CCR2 register capture/compare selection (TQ0CCS2) */
  215. #define _00_TMQ_CCR2_COMPARE 0x00U /* compare register */
  216. #define _40_TMQ_CCR2_CAPTURE 0x40U /* capture register */
  217. /* TQ0CCR1 register capture/compare selection (TQ0CCS1) */
  218. #define _00_TMQ_CCR1_COMPARE 0x00U /* compare register */
  219. #define _20_TMQ_CCR1_CAPTURE 0x20U /* capture register */
  220. /* TQ0CCR0 register capture/compare selection (TQ0CCS0) */
  221. #define _00_TMQ_CCR0_COMPARE 0x00U /* compare register */
  222. #define _10_TMQ_CCR0_CAPTURE 0x10U /* capture register */
  223. /* TMQ0 overflow detection flag (TQ0OVF) */
  224. #define _01_TMQ_OVERFLOW_OCCUR 0x01U /* overflow occurred */
  225. #define _00_TMQ_OVERFLOW_CLEAR 0x00U /* clear overflow */
  226. /*
  227. TMM0 control register 0 (TM0CTL0)
  228. */
  229. /* TMM0 operation control (TM0CE) */
  230. #define _00_TMM_OPERATION_DISABLE 0x00U /* disable internal operating clock operation (asynchronously reset TMM0) */
  231. #define _80_TMM_OPERATION_ENABLE 0x80U /* enable internal operating clock operation */
  232. /* Internal count clock selection (TM0CKS2 - TM0CKS0) */
  233. #define _00_TMM_INTERNAL_CLOCK0 0x00U /* fXX */
  234. #define _01_TMM_INTERNAL_CLOCK1 0x01U /* fXX/2 */
  235. #define _02_TMM_INTERNAL_CLOCK2 0x02U /* fXX/4 */
  236. #define _03_TMM_INTERNAL_CLOCK3 0x03U /* fXX/64 */
  237. #define _04_TMM_INTERNAL_CLOCK4 0x04U /* fXX/512 */
  238. #define _05_TMM_INTERNAL_CLOCK5 0x05U /* INTWT */
  239. #define _06_TMM_INTERNAL_CLOCK6 0x06U /* fR/8 */
  240. #define _07_TMM_INTERNAL_CLOCK7 0x07U /* fXT */
  241. /*
  242. *******************************************************************************
  243. ** Macro define
  244. *******************************************************************************
  245. */
  246. /* TMP0 compare register 0 (TP0CCR0)*/
  247. #define _9C3F_TMP0_CCR0_VALUE 0x9C3FU
  248. enum TMChannel
  249. {
  250. TMCHANNEL0, TMCHANNEL1, TMCHANNEL2, TMCHANNEL3
  251. };
  252. /*
  253. *******************************************************************************
  254. ** Function define
  255. *******************************************************************************
  256. */
  257. void TAB0_Init(void);
  258. void TAB0_Start(void);
  259. void TAB0_Stop(void);
  260. MD_STATUS TAB0_ChangeTimerCondition(USHORT *array_reg, UCHAR array_num);
  261. __interrupt void MD_INTTP0CC0(void);
  262. /* Start user code for function. Do not edit comment generated here */
  263. /* End user code. Do not edit comment generated here */
  264. #endif