]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Layer/App/Validation_Cortex-M/main.c
Update CMSIS-Toolbox to version 2.5.0 (#184)
[cmsis] / CMSIS / CoreValidation / Layer / App / Validation_Cortex-M / 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
35 #if defined (__ARM_FEATURE_CMSE) &&  (__ARM_FEATURE_CMSE == 3U)
36   #include <arm_cmse.h>
37
38   /* Dummy Non-secure callable (entry) function */
39   __attribute__((cmse_nonsecure_entry)) int validationDummy(int x) {
40     return x;
41   }
42 #endif
43
44 int main (void)
45 {
46
47   // System Initialization
48   SystemCoreClockUpdate();
49
50 #ifdef RTE_Compiler_EventRecorder
51   // Initialize and start Event Recorder
52   (void)EventRecorderInitialize(EventRecordError, 1U);
53   (void)EventRecorderEnable(EventRecordAll, 0xFEU, 0xFEU);
54 #endif
55
56   cmsis_cv();
57
58   #ifdef __MICROLIB
59   for(;;) {}
60   #else
61   exit(0);
62   #endif
63 }
64
65 #if defined(__CORTEX_A)
66 #include "irq_ctrl.h"
67
68 #if (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || \
69     (defined ( __GNUC__ ))
70   #define __IRQ __attribute__((interrupt("IRQ")))
71 #elif defined ( __CC_ARM )
72   #define __IRQ __irq
73 #elif defined ( __ICCARM__ )
74   #define __IRQ __irq __arm
75 #else
76   #error "Unsupported compiler!"
77 #endif
78
79
80 __IRQ
81 void IRQ_Handler(void);
82 __IRQ
83 void IRQ_Handler(void) {
84   const IRQn_ID_t irqn = IRQ_GetActiveIRQ();
85   IRQHandler_t const handler = IRQ_GetHandler(irqn);
86   if (handler != NULL) {
87     __enable_irq();
88     handler();
89     __disable_irq();
90   }
91   IRQ_EndOfInterrupt(irqn);
92 }
93
94 __IRQ __NO_RETURN
95 void Undef_Handler (void);
96 __IRQ __NO_RETURN
97 void Undef_Handler (void) {
98   cmsis_cv_abort(__FILENAME__, __LINE__, "Undefined Instruction!");
99   exit(0);
100 }
101
102 __IRQ
103 void SVC_Handler   (void);
104 __IRQ
105 void SVC_Handler   (void) {
106 }
107
108 __IRQ __NO_RETURN
109 void PAbt_Handler  (void);
110 __IRQ __NO_RETURN
111 void PAbt_Handler  (void) {
112   cmsis_cv_abort(__FILENAME__, __LINE__, "Prefetch Abort!");
113   exit(0);
114 }
115
116 __IRQ __NO_RETURN
117 void DAbt_Handler  (void);
118 __IRQ __NO_RETURN
119 void DAbt_Handler  (void) {
120   cmsis_cv_abort(__FILENAME__, __LINE__, "Data Abort!");
121   exit(0);
122 }
123
124 __IRQ
125 void FIQ_Handler   (void);
126 __IRQ
127 void FIQ_Handler   (void) {
128 }
129 #endif
130
131 #if defined(__CORTEX_M)
132 __NO_RETURN
133 void HardFault_Handler(void);
134 __NO_RETURN
135 void HardFault_Handler(void) {
136   cmsis_cv_abort(__FILENAME__, __LINE__, "HardFault!");
137   #ifdef __MICROLIB
138   for(;;) {}
139   #else
140   exit(0);
141   #endif
142 }
143 #endif