1 /***********************************************************************************************************************
2 * Copyright [2015-2017] Renesas Electronics Corporation and/or its licensors. All Rights Reserved.
3 *
4 * This file is part of Renesas SynergyTM Software Package (SSP)
5 *
6 * The contents of this file (the "contents") are proprietary and confidential to Renesas Electronics Corporation
7 * and/or its licensors ("Renesas") and subject to statutory and contractual protections.
8 *
9 * This file is subject to a Renesas SSP license agreement. Unless otherwise agreed in an SSP license agreement with
10 * Renesas: 1) you may not use, copy, modify, distribute, display, or perform the contents; 2) you may not use any name
11 * or mark of Renesas for advertising or publicity purposes or in connection with your use of the contents; 3) RENESAS
12 * MAKES NO WARRANTY OR REPRESENTATIONS ABOUT THE SUITABILITY OF THE CONTENTS FOR ANY PURPOSE; THE CONTENTS ARE PROVIDED
13 * "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT; AND 4) RENESAS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, OR
15 * CONSEQUENTIAL DAMAGES, INCLUDING DAMAGES RESULTING FROM LOSS OF USE, DATA, OR PROJECTS, WHETHER IN AN ACTION OF
16 * CONTRACT OR TORT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE CONTENTS. Third-party contents
17 * included in this file may be subject to different terms.
18 **********************************************************************************************************************/
19 /***********************************************************************************************************************
20 * File Name : startup_S128.c
21 * Description : Startup for the S128
22 ***********************************************************************************************************************/
23
24 /***********************************************************************************************************************
25 Includes <System Includes> , "Project Includes"
26 ***********************************************************************************************************************/
27 #include "bsp_api.h"
28
29 /* Only build this file if this board is chosen. */
30 #if defined(BSP_MCU_GROUP_S1JA)
31
32 /***********************************************************************************************************************
33 Macro definitions
34 ***********************************************************************************************************************/
35
36 /***********************************************************************************************************************
37 Typedef definitions
38 ***********************************************************************************************************************/
39 /* Defines function pointers to be used with vector table. */
40 typedef void (* exc_ptr_t)(void);
41
42 /***********************************************************************************************************************
43 Exported global variables (to be accessed by other files)
44 ***********************************************************************************************************************/
45
46 /***********************************************************************************************************************
47 Private global variables and functions
48 ***********************************************************************************************************************/
49 void Reset_Handler(void);
50 void Default_Handler(void);
51 int32_t main(void);
52
53 /***********************************************************************************************************************
54 * Function Name: Reset_Handler
55 * Description : MCU starts executing here out of reset. Main stack pointer is setup already.
56 * Arguments : none
57 * Return Value : none
58 ***********************************************************************************************************************/
Reset_Handler(void)59 void Reset_Handler (void)
60 {
61 /* Initialize system using BSP. */
62 SystemInit();
63
64 /* Call user application. */
65 main();
66
67 while (1)
68 {
69 /* Infinite Loop. */
70 }
71 }
72
73 /***********************************************************************************************************************
74 * Function Name: Default_Handler
75 * Description : Default exception handler.
76 * Arguments : none
77 * Return Value : none
78 ***********************************************************************************************************************/
Default_Handler(void)79 void Default_Handler (void)
80 {
81 /** A error has occurred. The user will need to investigate the cause. Common problems are stack corruption
82 * or use of an invalid pointer.
83 */
84 BSP_CFG_HANDLE_UNRECOVERABLE_ERROR(0);
85 }
86
87 /* Stacks. */
88 /* Main stack */
89 /*LDRA_INSPECTED 219 s - This is an allowed exception to LDRA standard 219 S "User name starts with underscore."*/
90 /*LDRA_INSPECTED 57 D - This global is being initialized at it's declaration below. */
91 static uint8_t g_main_stack[BSP_CFG_STACK_MAIN_BYTES] BSP_ALIGN_VARIABLE_V2(BSP_STACK_ALIGNMENT) BSP_PLACE_IN_SECTION_V2(BSP_SECTION_STACK);
92
93 /* Process stack */
94 #if (BSP_CFG_STACK_PROCESS_BYTES > 0)
95 /*LDRA_INSPECTED 219 s - This is an allowed exception to LDRA standard 219 S "User name starts with underscore."*/
96 /*LDRA_INSPECTED 57 D - This global is being initialized at it's declaration below. */
97 BSP_DONT_REMOVE static uint8_t g_process_stack[BSP_CFG_STACK_PROCESS_BYTES] BSP_ALIGN_VARIABLE_V2(BSP_STACK_ALIGNMENT) \
98 BSP_PLACE_IN_SECTION_V2(BSP_SECTION_STACK);
99 #endif
100
101 /* Heap */
102 #if (BSP_CFG_HEAP_BYTES > 0)
103 /*LDRA_INSPECTED 219 s - This is an allowed exception to LDRA standard 219 S "User name starts with underscore."*/
104 /*LDRA_INSPECTED 57 D - This global is being initialized at it's declaration below. */
105 BSP_DONT_REMOVE static uint8_t g_heap[BSP_CFG_HEAP_BYTES] BSP_ALIGN_VARIABLE_V2(BSP_STACK_ALIGNMENT) \
106 BSP_PLACE_IN_SECTION_V2(BSP_SECTION_HEAP);
107 #endif
108
109 /* All system exceptions in the vector table are weak references to Default_Handler. If the user wishes to handle
110 * these exceptions in their code they should define their own function with the same name.
111 */
112 #if defined(__ICCARM__)
113 #define WEAK_REF_ATTRIBUTE
114
115 #pragma weak HardFault_Handler = Default_Handler
116 #pragma weak MemManage_Handler = Default_Handler
117 #pragma weak BusFault_Handler = Default_Handler
118 #pragma weak UsageFault_Handler = Default_Handler
119 #pragma weak SVC_Handler = Default_Handler
120 #pragma weak DebugMon_Handler = Default_Handler
121 #pragma weak PendSV_Handler = Default_Handler
122 #pragma weak SysTick_Handler = Default_Handler
123 #elif defined(__GNUC__)
124 /*LDRA_INSPECTED 293 S - There is no way to implement a weak reference without using a Non ANSI/ISO construct. */
125 #define WEAK_REF_ATTRIBUTE __attribute__ ((weak, alias("Default_Handler")))
126 #endif
127
128 void NMI_Handler(void); //NMI has many sources and is handled by BSP
129 void HardFault_Handler (void) WEAK_REF_ATTRIBUTE;
130 void MemManage_Handler (void) WEAK_REF_ATTRIBUTE;
131 void BusFault_Handler (void) WEAK_REF_ATTRIBUTE;
132 void UsageFault_Handler (void) WEAK_REF_ATTRIBUTE;
133 void SVC_Handler (void) WEAK_REF_ATTRIBUTE;
134 void DebugMon_Handler (void) WEAK_REF_ATTRIBUTE;
135 void PendSV_Handler (void) WEAK_REF_ATTRIBUTE;
136 void SysTick_Handler (void) WEAK_REF_ATTRIBUTE;
137
138 /* Vector table. */
139 BSP_DONT_REMOVE const exc_ptr_t __Vectors[BSP_CORTEX_VECTOR_TABLE_ENTRIES] BSP_PLACE_IN_SECTION_V2(BSP_SECTION_VECTOR) =
140 {
141 (exc_ptr_t)(&g_main_stack[0] + BSP_CFG_STACK_MAIN_BYTES), /* Initial Stack Pointer */
142 Reset_Handler, /* Reset Handler */
143 NMI_Handler, /* NMI Handler */
144 HardFault_Handler, /* Hard Fault Handler */
145 MemManage_Handler, /* MPU Fault Handler */
146 BusFault_Handler, /* Bus Fault Handler */
147 UsageFault_Handler, /* Usage Fault Handler */
148 0, /* Reserved */
149 0, /* Reserved */
150 0, /* Reserved */
151 0, /* Reserved */
152 SVC_Handler, /* SVCall Handler */
153 DebugMon_Handler, /* Debug Monitor Handler */
154 0, /* Reserved */
155 PendSV_Handler, /* PendSV Handler */
156 SysTick_Handler, /* SysTick Handler */
157 };
158
159 #endif
160