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