summaryrefslogtreecommitdiff
path: root/bsp/upd70f3454/drivers/CG_system.c
blob: dc99dc4a9ca61f3bb825ed414e1137df736aa886 (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
/*
*******************************************************************************
* 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_system.c
* Abstract:	This file implements device driver for System 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_system.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
*******************************************************************************
*/
/* Start user code for global. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

void clock_pll_mode(void)
{
	/* CPU operation clock selection */
	/* Set PLL mode. */
	PLLCTL = 0x03;						/* bit 1: CPU clock selection (PLL mode/clock-through mode selection) */
										/* 1: PLL mode, 0: Clock-through mode */
	
	__asm("_loop:	set1	1,0xF82C[r0]");  //__IO_REG8_BIT(  PLLCTL, 0xFFFFF82C,  __READ_WRITE )
	__asm("			tst1	1,0xF82C[r0]");  //__IO_REG8_BIT(  PLLCTL, 0xFFFFF82C,  __READ_WRITE )
	__asm("			bz		_loop");
	
	return;
}

void clock_pcc_mode(void)
{
	/* DMA is forcibly terminated in this sample since DMA transfer must be terminated 
	before data is set to a special register. */
	
	if(TC0 == 0 && E00 == 1){			/* DMA0 transfer judgment */
		INIT0 = 1;						/* DMA0 forcible termination */
	}
	if(TC1 == 0 && E11 == 1){			/* DMA1 transfer judgment */
		INIT1 = 1;						/* DMA1 forcible termination */
	}
	if(TC2 == 0 && E22 == 1){			/* DMA2 transfer judgment */
		INIT2 = 1;						/* DMA2 forcible termination */
	}
	if(TC3 == 0 && E33 == 1){			/* DMA3 transfer judgment */
		INIT3 = 1;						/* DMA3 forcible termination */
	}
	
	/* The PCC register is a special register. Data can be written to this register only in a combination of specific sequences. */
	/* bit 1, bit 0: Clock selection, 11: fxx/8, 10: fxx/4, 01: fxx/2, 00: fxx */
	/* Clock selection: fxx */
	__asm("mov 0x00, r10");				/* Set general-purpose register data to be set to special register. */
	__asm("st.b r10, 0xF1FC[r0]");		/* Write to PRCMD register. */ //__IO_REG8(PRCMD, 0xFFFFF1FC, __WRITE)
	__asm("st.b r10, 0xF828[r0]");		/* Set PCC register. */  //__IO_REG8_BIT(PCC, 0xFFFFF828, __READ_WRITE)
	__asm("nop");						/* Insert five or more NOP instructions. */
	__asm("nop");
	__asm("nop");
	__asm("nop");
	__asm("nop");
	
	return;
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	This function initializes the clock generator module.
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void CLOCK_Init(void)
{
	DI();       						/* Maskable interrupt disabled */
	
	do{
		clock_pll_mode();				/* PLL mode setting function */
		
		clock_pcc_mode();				/* PCC register setting function */
		
	}while(PRERR);						/* Written in correct sequence? */
}

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