CG_timer.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.c
  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. /*
  20. *******************************************************************************
  21. ** Include files
  22. *******************************************************************************
  23. */
  24. #include "CG_macrodriver.h"
  25. #include "CG_timer.h"
  26. /* Start user code for include. Do not edit comment generated here */
  27. /* End user code. Do not edit comment generated here */
  28. #include "CG_userdefine.h"
  29. /*
  30. *******************************************************************************
  31. ** Global define
  32. *******************************************************************************
  33. */
  34. /* Count Clock (TABnCTL0) */
  35. #define TAB_CNT_CLK 0x00 /* Count Clock fxx */
  36. #define TAB_CNT_CLK_2 0x01 /* Count Clock fxx/2 */
  37. #define TAB_CNT_CLK_4 0x02 /* Count Clock fxx/4 */
  38. #define TAB_CNT_CLK_8 0x03 /* Count Clock fxx/8 */
  39. #define TAB_CNT_CLK_16 0x04 /* Count Clock fxx/16 */
  40. #define TAB_CNT_CLK_32 0x05 /* Count Clock fxx/32 */
  41. #define TAB_CNT_CLK_64 0x06 /* Count Clock fxx/64 */
  42. #define TAB_CNT_CLK_128 0x07 /* Count Clock fxx/128 */
  43. /* Mode (TABkMD2 + TABkMD1 + TABkMD0) */
  44. #define TAB_INTERVAL_MODE 0x00 /* Interval Timer Mode */
  45. /* TAB0I/O Control Register (TABmIOC0) */
  46. #define TAB_TOB00_DISABLE 0x00 /* TOB00 Output Disable */
  47. #define TAB_TOB00_ENABLE 0x01 /* TOB00 Output Enable */
  48. #define TAB_TOB00_HI_LEV_ST 0x00 /* TOB00 Output High Level Start */
  49. #define TAB_TOB00_LO_LEV_ST 0x02 /* TOB00 Output Low Level Start */
  50. #define TAB_TOB01_DISABLE 0x00 /* TOB01 Output Disable */
  51. #define TAB_TOB01_ENABLE 0x04 /* TOB01 Output Enable */
  52. #define TAB_TOB01_HI_LEV_ST 0x00 /* TOB01 Output High Level Start */
  53. #define TAB_TOB01_LO_LEV_ST 0x08 /* TOB01 Output Low Level Start */
  54. #define TAB_TOB02_DISABLE 0x00 /* TOB02 Output Disable */
  55. #define TAB_TOB02_ENABLE 0x10 /* TOB02 Output Enable */
  56. #define TAB_TOB02_HI_LEV_ST 0x00 /* TOB02 Output High Level Start */
  57. #define TAB_TOB02_LO_LEV_ST 0x20 /* TOB02 Output Low Level Start */
  58. #define TAB_TOB03_DISABLE 0x00 /* TOB03 Output Disable */
  59. #define TAB_TOB03_ENABLE 0x40 /* TOB03 Output Enable */
  60. #define TAB_TOB03_HI_LEV_ST 0x00 /* TOB03 Output High Level Start */
  61. #define TAB_TOB03_LO_LEV_ST 0x80 /* TOB03 Output Low Level Start */
  62. /* Start user code for global. Do not edit comment generated here */
  63. /* End user code. Do not edit comment generated here */
  64. void timerab_interval(void)
  65. {
  66. TAB0CTL0 = TAB_CNT_CLK_32; /* TAB0CKS2 = 1 + TAB0CKS1 = 0 + TAB0CKS0 = 0 */
  67. /* : Clock Count = fxx/32 */
  68. TAB0CTL1 = TAB_INTERVAL_MODE; /* TAB0MD2 = 0 + TAB0MD1 = 0 + TAB0MD0 = 0 */
  69. /* : Interval Timer Mode */
  70. // TAB0IOC2 = TAB_TOB03_LO_LEV_ST | /* TAB0OL3 = 1 : TOB03 Low Level Start */
  71. // TAB_TOB03_DISABLE | /* TAB0OE3 = 0 : TOB03 Output Disable */
  72. // TAB_TOB02_LO_LEV_ST | /* TAB0OL2 = 1 : TOB02 Low Level Start */
  73. // TAB_TOB02_DISABLE | /* TAB0OE2 = 0 : TOB02 Output Disable */
  74. // TAB_TOB01_HI_LEV_ST | /* TAB0OL1 = 0 : TOB01 High Level Start */
  75. // TAB_TOB01_ENABLE | /* TAB0OE1 = 1 : TOB01 Output Enable */
  76. // TAB_TOB00_HI_LEV_ST | /* TAB0OL0 = 0 : TOB00 High Level Start */
  77. // TAB_TOB00_ENABLE; /* TAB0OE0 = 1 : TOB00 Output Enable */
  78. TAB0CCR0 = 19999; /* Compare Register */
  79. TAB0CCR1 = 0xFFFF; /* Compare Register */
  80. TAB0CCR2 = 0xFFFF; /* No Use */
  81. TAB0CCR3 = 0xFFFF; /* No Use */
  82. }
  83. /*
  84. **-----------------------------------------------------------------------------
  85. **
  86. ** Abstract:
  87. ** This function initializes the TAB0 module.
  88. **
  89. ** Parameters:
  90. ** None
  91. **
  92. ** Returns:
  93. ** None
  94. **
  95. **-----------------------------------------------------------------------------
  96. */
  97. void TAB0_Init(void)
  98. {
  99. TAB0CE = 0; /* Stop TAB */
  100. /* Port Definition */
  101. // PFC1 = 0x00; /* PFC17 = 0 : TOB00 Output */
  102. /* PFC10 = 0 : TOB01 Output */
  103. // PFCE1 = 0x01; /* PFCE10 = 1 : TOB01 Output */
  104. // PMC1 = 0x81; /* PMC17 = 1 : TOB00 Output/INTP09 Input */
  105. /* PMC10 = 1 : TOB0T1 Output/TIB01 Input/TOB01 Output */
  106. /* Enable Interrupt */
  107. TB0CCMK0 = 0; /* TB0CCMK0 = 0 : INTTB0CC0 Enable */
  108. TB0CCMK1 = 1; /* TB0CCMK1 = 0 : INTTB0CC1 Enable */
  109. TB0CCMK2 = 1; /* TB0CCMK2 = 1 : INTTB0CC2 Disable */
  110. TB0CCMK3 = 1; /* TB0CCMK3 = 1 : INTTB0CC3 Disable */
  111. timerab_interval();
  112. }
  113. /*
  114. **-----------------------------------------------------------------------------
  115. **
  116. ** Abstract:
  117. ** This function starts TMP0 counter.
  118. **
  119. ** Parameters:
  120. ** None
  121. **
  122. ** Returns:
  123. ** None
  124. **
  125. **-----------------------------------------------------------------------------
  126. */
  127. void TAB0_Start(void)
  128. {
  129. TB0CCIF0 = 0U; /* clear INTTP0CC0 interrupt flag */
  130. TB0CCMK0 = 0U; /* enable INTTP0CC0 interrupt */
  131. TAB0CE = 1U; /* enable TMP0 operation */
  132. }
  133. /*
  134. **-----------------------------------------------------------------------------
  135. **
  136. ** Abstract:
  137. ** This function stops TMP0 counter.
  138. **
  139. ** Parameters:
  140. ** None
  141. **
  142. ** Returns:
  143. ** None
  144. **
  145. **-----------------------------------------------------------------------------
  146. */
  147. void TAB0_Stop(void)
  148. {
  149. TAB0CE = 0U; /* disable TMP0 operation */
  150. TB0CCMK0 = 1U; /* disable INTTP0CC0 interrupt */
  151. TB0CCIF0 = 0U; /* clear INTTP0CC0 interrupt flag */
  152. }
  153. /*
  154. **-----------------------------------------------------------------------------
  155. **
  156. ** Abstract:
  157. ** This function changes TMP0 register value.
  158. **
  159. ** Parameters:
  160. ** array_reg: register value buffer
  161. ** array_num: register index to be changed
  162. **
  163. ** Returns:
  164. ** MD_OK
  165. ** MD_ARGERROR
  166. **
  167. **-----------------------------------------------------------------------------
  168. */
  169. MD_STATUS TAB0_ChangeTimerCondition(USHORT *array_reg, UCHAR array_num)
  170. {
  171. MD_STATUS status = MD_OK;
  172. switch (array_num)
  173. {
  174. case 1U:
  175. TAB0CCR0 = array_reg[0U];
  176. status = MD_OK;
  177. break;
  178. case 2U:
  179. TAB0CCR0 = array_reg[0U];
  180. TAB0CCR1 = array_reg[1U];
  181. status = MD_OK;
  182. break;
  183. default:
  184. status = MD_ARGERROR;
  185. break;
  186. }
  187. return (status);
  188. }
  189. /* Start user code for adding. Do not edit comment generated here */
  190. /* End user code. Do not edit comment generated here */