]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Layer/App/Validation_Cortex-A/main.c
Add new compiler macros:
[cmsis] / CMSIS / CoreValidation / Layer / App / Validation_Cortex-A / main.c
1 /*
2  * Copyright (C) 2022 ARM Limited or its affiliates. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include "RTE_Components.h"
23 #include  CMSIS_device_header
24
25 #ifdef RTE_Compiler_EventRecorder
26 #include "EventRecorder.h"
27 #endif
28
29 #include "cmsis_cv.h"
30 #include "CV_Report.h"
31
32 //lint -e970 allow using int for main
33
34 int main (void)
35 {
36
37   // System Initialization
38   SystemCoreClockUpdate();
39
40 #ifdef RTE_Compiler_EventRecorder
41   // Initialize and start Event Recorder
42   (void)EventRecorderInitialize(EventRecordError, 1U);
43   (void)EventRecorderEnable(EventRecordAll, 0xFEU, 0xFEU);
44 #endif
45
46   cmsis_cv();
47
48   #ifdef __MICROLIB
49   for(;;) {}
50   #else
51   exit(0);
52   #endif
53 }
54
55 #if defined(__CORTEX_A)
56 #include "irq_ctrl.h"
57
58 #if (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || \
59     (defined ( __GNUC__ ))
60   #define __IRQ __attribute__((interrupt("IRQ")))
61 #elif defined ( __CC_ARM )
62   #define __IRQ __irq
63 #elif defined ( __ICCARM__ )
64   #define __IRQ __irq __arm
65 #else
66   #error "Unsupported compiler!"
67 #endif
68
69
70 __IRQ
71 void IRQ_Handler(void);
72 __IRQ
73 void IRQ_Handler(void) {
74   const IRQn_ID_t irqn = IRQ_GetActiveIRQ();
75   IRQHandler_t const handler = IRQ_GetHandler(irqn);
76   if (handler != NULL) {
77     __enable_irq();
78     handler();
79     __disable_irq();
80   }
81   IRQ_EndOfInterrupt(irqn);
82 }
83
84 __IRQ __NO_RETURN
85 void Undef_Handler (void);
86 __IRQ __NO_RETURN
87 void Undef_Handler (void) {
88   cmsis_cv_abort(__FILENAME__, __LINE__, "Undefined Instruction!");
89   exit(0);
90 }
91
92 __IRQ
93 void SVC_Handler   (void);
94 __IRQ
95 void SVC_Handler   (void) {
96 }
97
98 __IRQ __NO_RETURN
99 void PAbt_Handler  (void);
100 __IRQ __NO_RETURN
101 void PAbt_Handler  (void) {
102   cmsis_cv_abort(__FILENAME__, __LINE__, "Prefetch Abort!");
103   exit(0);
104 }
105
106 __IRQ __NO_RETURN
107 void DAbt_Handler  (void);
108 __IRQ __NO_RETURN
109 void DAbt_Handler  (void) {
110   cmsis_cv_abort(__FILENAME__, __LINE__, "Data Abort!");
111   exit(0);
112 }
113
114 __IRQ
115 void FIQ_Handler   (void);
116 __IRQ
117 void FIQ_Handler   (void) {
118 }
119 #endif
120
121 #if defined(__CORTEX_M)
122 __NO_RETURN
123 void HardFault_Handler(void);
124 __NO_RETURN
125 void HardFault_Handler(void) {
126   cmsis_cv_abort(__FILENAME__, __LINE__, "HardFault!");
127   #ifdef __MICROLIB
128   for(;;) {}
129   #else
130   exit(0);
131   #endif
132 }
133 #endif