iLLD_TC27xC  1.0
IfxCpu_CStart0.c
Go to the documentation of this file.
1 /**
2  * \file IfxCpu_Cstart0.c
3  * \brief This file contains the Core startup sequence for Cpu0.
4  * \version iLLD_0_1_0_10
5  * \copyright Copyright (c) 2012 Infineon Technologies AG. All rights reserved.
6  *
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  */
24 /*******************************************************************************
25 ** Includes **
26 *******************************************************************************/
27 #include "Ifx_Cfg.h"
28 #ifndef IFX_CFG_USE_COMPILER_DEFAULT_LINKER
29 #include "Scu/Std/IfxScuWdt.h"
30 #include "Scu/Std/IfxScuCcu.h"
31 #include "Cpu/Std/IfxCpu.h"
33 #include "IfxScu_reg.h"
34 #include "IfxCpu_reg.h"
35 
36 /******************************************************************************/
37 /* Macros */
38 /******************************************************************************/
39 /** \brief Configuration for CpuX enable.
40  *
41  */
42 #ifndef IFX_CFG_CPU_CSTART_ENABLE_TRICORE0
43 # define IFX_CFG_CPU_CSTART_ENABLE_TRICORE0 (1) /**< Cpu0 enabled by default*/
44 #endif
45 #ifndef IFX_CFG_CPU_CSTART_ENABLE_TRICORE1
46 # define IFX_CFG_CPU_CSTART_ENABLE_TRICORE1 (1) /**< Cpu1 enabled by default*/
47 #endif
48 #ifndef IFX_CFG_CPU_CSTART_ENABLE_TRICORE2
49 # define IFX_CFG_CPU_CSTART_ENABLE_TRICORE2 (1) /**< Cpu2 enabled by default*/
50 #endif
51 
52 /** \brief Configuration for cache enable.
53  *
54  */
55 #ifndef IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_PCACHE
56 # define IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_PCACHE (1) /**< Program Cache enabled by default*/
57 #endif
58 #ifndef IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_DCACHE
59 # define IFX_CFG_CPU_CSTART_ENABLE_TRICORE0_DCACHE (1) /**< Data Cache enabled by default*/
60 #endif
61 
62 #ifndef IFXCPU_CSTART_CCU_INIT_HOOK
63 #define IFXCPU_CSTART_CCU_INIT_HOOK() (void)IfxScuCcu_init(&IfxScuCcu_defaultClockConfig); /*The status returned by Ccu init is ignored */
64 #endif
65 
66 /*******************************************************************************
67 ** Imported Function Declarations **
68 *******************************************************************************/
71 
72 IFX_EXTERN void core0_main(void);
73 #if defined(__TASKING__)
74 __asm("\t .extern core0_main");
75 #endif
76 
77 /*******************************************************************************
78 ** Private Constant Definitions **
79 *******************************************************************************/
80 #define IFXCSTART0_PSW_DEFAULT (0x00000980u)
81 #define IFXCSTART0_PCX_O_S_DEFAULT (0xfff00000u)
82 
83 /*********************************************************************************
84 * _start() - startup code
85 *********************************************************************************/
86 void _Core0_start(void)
87 {
88  uint32 pcxi;
89  uint16 cpuWdtPassword = IfxScuWdt_getCpuWatchdogPasswordInline(&MODULE_SCU.WDTCPU[0]);
90 
91  IFX_CFG_CPU_CSTART_PRE_C_INIT_HOOK(0); /*Test Stack, CSA and Cache */
92 
93  /* Load user stack pointer */
94  __setareg(sp, __USTACK(0));
95  __dsync();
96 
97  /* Set the PSW to its reset value in case of a warm start,clear PSW.IS */
99 
100  /* Set the PCXS and PCXO to its reset value in case of a warm start */
101  pcxi = __mfcr(CPU_PCXI);
102  pcxi &= IFXCSTART0_PCX_O_S_DEFAULT; /*0xfff00000; */
103  __mtcr(CPU_PCXI, pcxi);
104 
105  /*enable/disable program cache depending on the configuration */
107 
108  /*enable/disable data cache depending on the configuration */
110 
111  /* Clear the ENDINIT bit in the WDT_CON0 register, inline funtion */
112  IfxScuWdt_clearCpuEndinitInline(&MODULE_SCU.WDTCPU[0], cpuWdtPassword);
113 
114  /* Load Base Address of Trap Vector Table. */
115  __mtcr(CPU_BTV, (uint32)__TRAPTAB(0));
116 
117  /* Load Base Address of Interrupt Vector Table. we will do this later in the program */
118  __mtcr(CPU_BIV, (uint32)__INTTAB(0));
119 
120  /* Load interupt stack pointer. */
121  __mtcr(CPU_ISP, (uint32)__ISTACK(0));
122 
123  IfxScuWdt_setCpuEndinitInline(&MODULE_SCU.WDTCPU[0], cpuWdtPassword);
124 
125  /* initialize SDA base pointers */
126  __setareg(a0, __SDATA1(0));
127  __setareg(a1, __SDATA2(0));
128 
129  /* These to be un commented if A8 and A9 are required to be initialized */
130  __setareg(a8, __SDATA3(0));
131  __setareg(a9, __SDATA4(0));
132  /* Setup the context save area linked list. */
133 
134  IfxCpu_initCSA((uint32 *)__CSA(0), (uint32 *)__CSA_END(0)); /*Initialize the context save area for CPU0 */
135 
136  {
137  /*CPU and safety watchdogs are enabled by default, C initialization functions are not servicing the watchdogs */
138  uint16 safetyWdtPassword = IfxScuWdt_getSafetyWatchdogPassword();
139  IfxScuWdt_disableCpuWatchdog(cpuWdtPassword);
140  IfxScuWdt_disableSafetyWatchdog(safetyWdtPassword);
141 
142  Ifx_C_Init(); /*Initialization of C runtime variables */
143 
144  IfxScuWdt_enableCpuWatchdog(cpuWdtPassword);
145  IfxScuWdt_enableSafetyWatchdog(safetyWdtPassword);
146  }
147 
148  /*Initialize the clock system */
150 
151  /*Start remaining cores */
152 #if (IFX_CFG_CPU_CSTART_ENABLE_TRICORE1 != 0)
153  (void)IfxCpu_startCore(&MODULE_CPU1, (uint32)&_Core1_start); /*The status returned by function call is ignored */
154 #endif
155 #if (IFX_CFG_CPU_CSTART_ENABLE_TRICORE2 != 0)
156  (void)IfxCpu_startCore(&MODULE_CPU2, (uint32)&_Core2_start); /*The status returned by function call is ignored */
157 #endif
158 
159 #if (IFX_CFG_CPU_CSTART_ENABLE_TRICORE0 == 0)
160  /*halt the CPU 0 if it is not needed to be enabled */
162 #endif
163 
164  /*Call main function of Cpu0 */
166 }
167 
168 
169 /******************************************************************************
170  * reset vector address, user section to inform linker to locate the code at 0x8000 0020
171  *****************************************************************************/
172 #if defined(__GNUC__)
173 #pragma section
174 #pragma section ".start" x
175 #endif
176 #if defined(__TASKING__)
177 #pragma protect on
178 #pragma section code "start"
179 #endif
180 #if defined(__DCC__)
181 #pragma section CODE ".start" X
182 #endif
183 
184 void _START(void)
185 {
187 }
188 
189 
190 /* reset the sections defined above, to normal region */
191 #if defined(__GNUC__)
192 #pragma section
193 #endif
194 #if defined(__TASKING__)
195 #pragma protect restore
196 #pragma section code restore
197 #endif
198 #if defined(__DCC__)
199 #pragma section CODE
200 #endif
201 
202 /*******************************************************************************
203 ** Boot Mode Headers **
204 *******************************************************************************/
205 /*Boot Mode Header 0 sections to inform linker to locate them at 0x8000 0000 */
206 #if defined(__GNUC__)
207 #pragma section
208 #pragma section ".bmhd_0" a
209 #endif
210 #if defined(__TASKING__)
211 #pragma protect on
212 #pragma section farrom "bmhd_0"
213 #endif
214 #if defined(__DCC__)
215 #pragma section CONST ".bmhd_0" R
216 #endif
217 /** \brief Boot Mode Header 0
218  * Boot mode header at memory location 0c8000 0000.
219  */
221  0x00000000u, /* STADBM first user code at 0x8000 0020h */
222  0xb3590070u, /* BMI = 0070h BMHDID = B359h */
223  0x00000000u, /* ChkStart */
224  0x00000000u, /* ChkEnd */
225  0x00000000u, /* CRCrange */
226  0x00000000u, /* !CRCrange */
227  0x791eb864u, /* CRChead */
228  0x86e1479bu /* !CRChead */
229 };
230 
231 /*reset the sections defined above */
232 #if defined(__GNUC__)
233 #pragma section
234 #endif
235 #if defined(__TASKING__)
236 #pragma protect restore
237 #pragma section farrom restore
238 #endif
239 #if defined(__DCC__)
240 #pragma section CONST
241 #endif
242 
243 #ifndef IFX_CFG_CPUCSTART_BMI01_NOT_NEEDED
244 /*Boot Mode Header 1 sections to inform linker to locate them at 0x8002 0000 */
245 #if defined(__GNUC__)
246 #pragma section
247 #pragma section ".bmhd_1" a
248 #endif
249 #if defined(__TASKING__)
250 #pragma protect on
251 #pragma section farrom "bmhd_1"
252 #endif
253 #if defined(__DCC__)
254 #pragma section CONST ".bmhd_1" R
255 #endif
256 
257 /** \brief Boot Mode Header 1
258  * Boot mode header at memory location 0c8002 0000.
259  */
261  0x00000000u, /* STADBM first user code at 0x8000 0020h */
262  0xB3590070u, /* BMI = 0070h BMHDID = B359h */
263  0x00000000u, /* ChkStart */
264  0x00000000u, /* ChkEnd */
265  0x00000000u, /* CRCrange */
266  0x00000000u, /* !CRCrange */
267  0x791eb864u, /* CRChead */
268  0x86e1479bu /* !CRChead */
269 };
270 
271 /*reset the sections defined above */
272 #if defined(__GNUC__)
273 #pragma section
274 #endif
275 #if defined(__TASKING__)
276 #pragma protect restore
277 #pragma section farrom restore
278 #endif
279 #if defined(__DCC__)
280 #pragma section CONST
281 #endif
282 #endif /*IFX_CFG_CPUCSTART_BMI01_NOT_NEEDED*/
283 
284 #endif /*#ifndef IFX_CFG_USE_COMPILER_DEFAULT_LINKER */