summaryrefslogtreecommitdiff
path: root/bsp/upd70f3454/drivers/CG_timer.c
blob: 179cea2849739638edcb63bf8f9832e890865ff4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
*******************************************************************************
* Copyright(C) NEC Electronics Corporation 2010
* All rights reserved by NEC Electronics Corporation.
* This program should be used on your own responsibility.
* NEC Electronics Corporation assumes no responsibility for any losses
* incurred by customers or third parties arising from the use of this file.
*
* This device driver was created by Applilet3 for V850ES/Jx3
* 32-Bit Single-Chip Microcontrollers
* Filename:	CG_timer.c
* Abstract:	This file implements device driver for Timer module.
* APIlib:	Applilet3 for V850ES/Jx3 V2.01 [20 Apr 2010]
* Device:	uPD70F3746
* Compiler:	IAR Systems ICCV850
* Creation date:	6/26/2010
*******************************************************************************
*/

/*
*******************************************************************************
** Include files
*******************************************************************************
*/
#include "CG_macrodriver.h"
#include "CG_timer.h"
/* Start user code for include. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#include "CG_userdefine.h"

/*
*******************************************************************************
**  Global define
*******************************************************************************
*/
/* Count Clock (TABnCTL0) */
#define	TAB_CNT_CLK				0x00	/* Count Clock fxx */
#define	TAB_CNT_CLK_2			0x01	/* Count Clock fxx/2 */
#define	TAB_CNT_CLK_4			0x02	/* Count Clock fxx/4 */
#define	TAB_CNT_CLK_8			0x03	/* Count Clock fxx/8 */
#define	TAB_CNT_CLK_16			0x04	/* Count Clock fxx/16 */
#define	TAB_CNT_CLK_32			0x05	/* Count Clock fxx/32 */
#define	TAB_CNT_CLK_64			0x06	/* Count Clock fxx/64 */
#define	TAB_CNT_CLK_128			0x07	/* Count Clock fxx/128 */
/* Mode (TABkMD2 + TABkMD1 + TABkMD0) */
#define	TAB_INTERVAL_MODE		0x00	/* Interval Timer Mode */
/* TAB0I/O Control Register (TABmIOC0) */
#define	TAB_TOB00_DISABLE		0x00	/* TOB00 Output Disable */
#define	TAB_TOB00_ENABLE		0x01	/* TOB00 Output Enable */
#define	TAB_TOB00_HI_LEV_ST		0x00	/* TOB00 Output High Level Start */
#define	TAB_TOB00_LO_LEV_ST		0x02	/* TOB00 Output Low Level Start */
#define	TAB_TOB01_DISABLE		0x00	/* TOB01 Output Disable */
#define	TAB_TOB01_ENABLE		0x04	/* TOB01 Output Enable */
#define	TAB_TOB01_HI_LEV_ST		0x00	/* TOB01 Output High Level Start */
#define	TAB_TOB01_LO_LEV_ST		0x08	/* TOB01 Output Low Level Start */
#define	TAB_TOB02_DISABLE		0x00	/* TOB02 Output Disable */
#define	TAB_TOB02_ENABLE		0x10	/* TOB02 Output Enable */
#define	TAB_TOB02_HI_LEV_ST		0x00	/* TOB02 Output High Level Start */
#define	TAB_TOB02_LO_LEV_ST		0x20	/* TOB02 Output Low Level Start */
#define	TAB_TOB03_DISABLE		0x00	/* TOB03 Output Disable */
#define	TAB_TOB03_ENABLE		0x40	/* TOB03 Output Enable */
#define	TAB_TOB03_HI_LEV_ST		0x00	/* TOB03 Output High Level Start */
#define	TAB_TOB03_LO_LEV_ST		0x80	/* TOB03 Output Low Level Start */
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

void timerab_interval(void)
{
	TAB0CTL0 = TAB_CNT_CLK_32;			/* TAB0CKS2 = 1 + TAB0CKS1 = 0 + TAB0CKS0 = 0 */
										/*  : Clock Count = fxx/32 */
	TAB0CTL1 = TAB_INTERVAL_MODE;		/* TAB0MD2 = 0 + TAB0MD1 = 0 + TAB0MD0 = 0 */
										/*  : Interval Timer Mode */
//	TAB0IOC2 = TAB_TOB03_LO_LEV_ST |	/* TAB0OL3 = 1 : TOB03 Low Level Start */
//			   TAB_TOB03_DISABLE   |	/* TAB0OE3 = 0 : TOB03 Output Disable */
//			   TAB_TOB02_LO_LEV_ST |	/* TAB0OL2 = 1 : TOB02 Low Level Start */
//			   TAB_TOB02_DISABLE   |	/* TAB0OE2 = 0 : TOB02 Output Disable */
//			   TAB_TOB01_HI_LEV_ST |	/* TAB0OL1 = 0 : TOB01 High Level Start */
//			   TAB_TOB01_ENABLE    |	/* TAB0OE1 = 1 : TOB01 Output Enable */
//			   TAB_TOB00_HI_LEV_ST |	/* TAB0OL0 = 0 : TOB00 High Level Start */
//			   TAB_TOB00_ENABLE;		/* TAB0OE0 = 1 : TOB00 Output Enable */
	TAB0CCR0	= 19999;				/* Compare Register */
	TAB0CCR1 = 0xFFFF;					/* Compare Register */
	TAB0CCR2 = 0xFFFF;					/* No Use */
	TAB0CCR3 = 0xFFFF;					/* No Use */
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function initializes the TAB0 module.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void TAB0_Init(void)
{
	TAB0CE = 0;							/* Stop TAB */

	/* Port Definition */
//	PFC1 = 0x00;						/* PFC17 = 0 : TOB00 Output */
										/* PFC10 = 0 : TOB01 Output */
//	PFCE1 = 0x01;						/* PFCE10 = 1 : TOB01 Output */
//	PMC1 = 0x81;						/* PMC17 = 1 : TOB00 Output/INTP09 Input */
										/* PMC10 = 1 : TOB0T1 Output/TIB01 Input/TOB01 Output */

	/* Enable Interrupt */
	TB0CCMK0 = 0;						/* TB0CCMK0 = 0 : INTTB0CC0 Enable */
	TB0CCMK1 = 1;						/* TB0CCMK1 = 0 : INTTB0CC1 Enable */
	TB0CCMK2 = 1;						/* TB0CCMK2 = 1 : INTTB0CC2 Disable */
	TB0CCMK3 = 1;						/* TB0CCMK3 = 1 : INTTB0CC3 Disable */

	timerab_interval();
}
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function starts TMP0 counter.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void TAB0_Start(void)
{
	TB0CCIF0 = 0U;	/* clear INTTP0CC0 interrupt flag */
	TB0CCMK0 = 0U;	/* enable INTTP0CC0 interrupt */
	TAB0CE = 1U;	/* enable TMP0 operation */
}
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function stops TMP0 counter.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void TAB0_Stop(void)
{
	TAB0CE = 0U;	/* disable TMP0 operation */
	TB0CCMK0 = 1U;	/* disable INTTP0CC0 interrupt */
	TB0CCIF0 = 0U;	/* clear INTTP0CC0 interrupt flag */
}
/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function changes TMP0 register value.
**
**  Parameters:
**	array_reg: register value buffer
**	array_num: register index to be changed
**
**  Returns:
**	MD_OK
**	MD_ARGERROR
**
**-----------------------------------------------------------------------------
*/
MD_STATUS TAB0_ChangeTimerCondition(USHORT *array_reg, UCHAR array_num)
{
	MD_STATUS status = MD_OK;

	switch (array_num)
	{
		case 1U:
			TAB0CCR0 = array_reg[0U];
			status = MD_OK;
			break;
		case 2U:
			TAB0CCR0 = array_reg[0U];
			TAB0CCR1 = array_reg[1U];
			status = MD_OK;
			break;
		default:
			status = MD_ARGERROR;
			break;
	}
	
	return (status);
}

/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */