1 /***********************************************************************************************************************
\r
3 * This software is supplied by Renesas Electronics Corporation and is only
\r
4 * intended for use with Renesas products. No other uses are authorized. This
\r
5 * software is owned by Renesas Electronics Corporation and is protected under
\r
6 * all applicable laws, including copyright laws.
\r
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
\r
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
\r
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
\r
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
\r
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
\r
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
\r
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
\r
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
\r
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
\r
16 * Renesas reserves the right, without notice, to make changes to this software
\r
17 * and to discontinue the availability of this software. By using this software,
\r
18 * you agree to the additional terms and conditions found by accessing the
\r
20 * http://www.renesas.com/disclaimer
\r
22 * Copyright (C) 2014 Renesas Electronics Corporation. All rights reserved.
\r
23 ***********************************************************************************************************************/
\r
24 /***********************************************************************************************************************
\r
25 * System Name : RZ/T1 Init program
\r
26 * File Name : loader_init2.c
\r
28 * Device : R7S910018
\r
29 * Abstract : Loader program 2
\r
30 * Tool-Chain : GNUARM-NONEv14.02-EABI
\r
32 * H/W Platform : Renesas Starter Kit for RZ/T1(Preliminary)
\r
33 * Description : Initialise the peripheral settings of RZ/T1
\r
35 ***********************************************************************************************************************/
\r
36 /***********************************************************************************************************************
\r
37 * History : DD.MM.YYYY Version Description
\r
38 * : 21.05.2015 1.00 First Release
\r
39 ***********************************************************************************************************************/
\r
42 /***********************************************************************************************************************
\r
43 Includes <System Includes> , "Project Includes"
\r
44 ***********************************************************************************************************************/
\r
46 #include "iodefine.h"
\r
47 #include "r_cg_cgc.h"
\r
48 #include "r_cg_mpc.h"
\r
49 #include "r_system.h"
\r
50 #include "r_reset.h"
\r
51 #include "r_atcm_init.h"
\r
52 #include "r_typedefs.h"
\r
55 /***********************************************************************************************************************
\r
57 ***********************************************************************************************************************/
\r
59 /***********************************************************************************************************************
\r
61 ***********************************************************************************************************************/
\r
63 /***********************************************************************************************************************
\r
64 Private variables and functions
\r
65 ***********************************************************************************************************************/
\r
66 static void reset_check (void);
\r
67 static void cpg_init (void);
\r
69 /***********************************************************************************************************************
\r
70 Imported global variables and functions (from other files)
\r
71 ***********************************************************************************************************************/
\r
72 extern void main(void);
\r
73 extern void set_low_vec(void);
\r
74 extern void cache_init(void);
\r
76 /***********************************************************************************************************************
\r
77 Exported global variables and functions (to be accessed by other files)
\r
78 ***********************************************************************************************************************/
\r
79 void loader_init2 (void);
\r
81 /***********************************************************************************************************************
\r
82 * Function Name : loader_init2
\r
83 * Description : Initialise system by loader program 2
\r
85 * Return Value : none
\r
86 ***********************************************************************************************************************/
\r
87 void loader_init2 (void)
\r
89 /* Check the reset source */
\r
92 /* Set CPU clock and LOCO clock */
\r
95 /* Set ATCM access wait to 1-wait with optimisation */
\r
96 /* Caution: ATCM_WAIT_0 is permitted if CPUCLK = 150MHz or 300MHz.
\r
97 ATCM_WAIT_1_OPT is permitted if CPUCLK = 450MHz or 600MHz.*/
\r
98 R_ATCM_WaitSet(ATCM_WAIT_1_OPT);
\r
100 /* Initialise I1, D1 Cache and MPU setting */
\r
103 /* Set RZ/T1 to Low-vector (SCTLR.V = 0) */
\r
106 /* Jump to _main() */
\r
111 /***********************************************************************************************************************
\r
112 End of function loader_init2
\r
113 ***********************************************************************************************************************/
\r
115 /***********************************************************************************************************************
\r
116 * Function Name : reset_check
\r
117 * Description : Check the reset source and execute the each sequence.
\r
118 * When error source number 35 is generated, set P77 pin to High.
\r
120 * Return Value : none
\r
121 ***********************************************************************************************************************/
\r
122 static void reset_check(void)
\r
124 volatile uint8_t result=0;
\r
125 volatile uint32_t dummy=0;
\r
127 UNUSED_VARIABLE(result);
\r
128 UNUSED_VARIABLE(dummy);
\r
130 /* Check the reset status flag and execute the each sequence */
\r
131 if (RST_SOURCE_ECM == SYSTEM.RSTSR0.LONG)
\r
133 /* Enable writing to the RSTSR0 register */
\r
134 r_rst_write_enable();
\r
136 /* Clear reset factor flag */
\r
137 SYSTEM.RSTSR0.LONG = 0x00000000;
\r
139 /* Disable writing to the RSTSR0 register */
\r
140 r_rst_write_disable();
\r
142 /* Please coding the User program */
\r
146 /* Software reset 1 is generated */
\r
147 else if (RST_SOURCE_SWR1 == SYSTEM.RSTSR0.LONG)
\r
149 /* Clear reset status flag */
\r
150 /* Enable writing to the RSTSR0 register */
\r
151 r_rst_write_enable();
\r
153 /* Clear reset factor flag */
\r
154 SYSTEM.RSTSR0.LONG = 0x00000000;
\r
156 /* Disable writing to the RSTSR0 register */
\r
157 r_rst_write_disable();
\r
159 /* Please coding the User program */
\r
162 else if (RST_SOURCE_RES == SYSTEM.RSTSR0.LONG) // RES# pin reset is generated
\r
164 /* Clear reset status flag */
\r
166 /* Enable writing to the RSTSR0 register */
\r
167 r_rst_write_enable();
\r
169 /* Clear reset factor flag */
\r
170 SYSTEM.RSTSR0.LONG = 0x00000000;
\r
172 /* Disable writing to the RSTSR0 register */
\r
173 r_rst_write_disable();
\r
175 /* Please add user code */
\r
179 /* Any reset is not generated */
\r
182 /* Please add user code */
\r
187 /***********************************************************************************************************************
\r
188 End of function reset_check
\r
189 ***********************************************************************************************************************/
\r
191 /***********************************************************************************************************************
\r
192 * Function Name : cpg_init
\r
193 * Description : Set CPU clock and LOCO clock by CPG function
\r
195 * Return Value : none
\r
196 ***********************************************************************************************************************/
\r
197 static void cpg_init(void)
\r
199 volatile uint32_t dummy=0;
\r
201 UNUSED_VARIABLE(dummy);
\r
203 /* Enables writing to the registers related to CPG function */
\r
204 R_CPG_WriteEnable();
\r
206 /* Enables LOCO clock operation */
\r
207 SYSTEM.LOCOCR.BIT.LCSTP = CPG_LOCO_ENABLE;
\r
209 /* Set CPUCLK to 450MHz, and dummy read at three times */
\r
210 SYSTEM.PLL1CR.LONG = CPG_CPUCLK_450_MHz;
\r
211 dummy = SYSTEM.PLL1CR.LONG;
\r
212 dummy = SYSTEM.PLL1CR.LONG;
\r
213 dummy = SYSTEM.PLL1CR.LONG;
\r
215 /* Enables PLL1 operation */
\r
216 SYSTEM.PLL1CR2.LONG = CPG_PLL1_ON;
\r
218 /* Disables writing to the registers related to CPG function */
\r
219 R_CPG_WriteDisable();
\r
221 /* Wait about 100us for PLL1 (and LOCO) stabilisation */
\r
224 /* Enables writing to the registers related to CPG function */
\r
225 R_CPG_WriteEnable();
\r
227 /* Selects the PLL1 as clock source */
\r
228 SYSTEM.SCKCR2.LONG = CPG_SELECT_PLL1;
\r
230 /* Disables writing to the registers related to CPG function */
\r
231 R_CPG_WriteDisable();
\r
235 /***********************************************************************************************************************
\r
236 End of function cpg_init
\r
237 ***********************************************************************************************************************/
\r