]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Tests/main.c
CoreValidation: Fix Cortex-A builds.
[cmsis] / CMSIS / CoreValidation / Tests / main.c
1 /*----------------------------------------------------------------------------
2  * Name:    main.c
3  *----------------------------------------------------------------------------*/
4
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include "RTE_Components.h"
9 #include  CMSIS_device_header
10
11 #ifdef RTE_Compiler_EventRecorder
12 #include "EventRecorder.h"
13 #endif
14
15 #include "cmsis_cv.h"
16 #include "CV_Report.h"
17
18 //lint -e970 allow using int for main
19
20 int main (void)
21 {
22
23   // System Initialization
24   SystemCoreClockUpdate();
25
26 #ifdef RTE_Compiler_EventRecorder
27   // Initialize and start Event Recorder
28   (void)EventRecorderInitialize(EventRecordError, 1U);
29   (void)EventRecorderEnable(EventRecordAll, 0xFEU, 0xFEU);
30 #endif
31
32   cmsis_cv();
33
34   #ifdef __MICROLIB
35   for(;;) {}
36   #else
37   exit(0);
38   #endif
39 }
40
41 #if defined(__CORTEX_A)
42 #include "irq_ctrl.h"
43
44 #if (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || \
45     (defined ( __GNUC__ ))
46   #define __IRQ __attribute__((interrupt("IRQ")))
47 #elif defined ( __CC_ARM )
48   #define __IRQ __irq
49 #elif defined ( __ICCARM__ )
50   #define __IRQ __irq __arm
51 #else
52   #error "Unsupported compiler!"
53 #endif
54
55
56 __IRQ
57 void IRQ_Handler(void);
58 __IRQ
59 void IRQ_Handler(void) {
60   const IRQn_ID_t irqn = IRQ_GetActiveIRQ();
61   IRQHandler_t const handler = IRQ_GetHandler(irqn);
62   if (handler != NULL) {
63     __enable_irq();
64     handler();
65     __disable_irq();
66   }
67   IRQ_EndOfInterrupt(irqn);
68 }
69
70 __IRQ __NO_RETURN
71 void Undef_Handler (void);
72 __IRQ __NO_RETURN
73 void Undef_Handler (void) {
74   cmsis_cv_abort(__FILENAME__, __LINE__, "Undefined Instruction!");
75   exit(0);
76 }
77
78 __IRQ
79 void SVC_Handler   (void);
80 __IRQ
81 void SVC_Handler   (void) {
82 }
83
84 __IRQ __NO_RETURN
85 void PAbt_Handler  (void);
86 __IRQ __NO_RETURN
87 void PAbt_Handler  (void) {
88   cmsis_cv_abort(__FILENAME__, __LINE__, "Prefetch Abort!");
89   exit(0);
90 }
91
92 __IRQ __NO_RETURN
93 void DAbt_Handler  (void);
94 __IRQ __NO_RETURN
95 void DAbt_Handler  (void) {
96   cmsis_cv_abort(__FILENAME__, __LINE__, "Data Abort!");
97   exit(0);
98 }
99
100 __IRQ
101 void FIQ_Handler   (void);
102 __IRQ
103 void FIQ_Handler   (void) {
104 }
105 #endif
106
107 #if defined(__CORTEX_M)
108 __NO_RETURN
109 void HardFault_Handler(void);
110 __NO_RETURN
111 void HardFault_Handler(void) {
112   cmsis_cv_abort(__FILENAME__, __LINE__, "HardFault!");
113   #ifdef __MICROLIB
114   for(;;) {}
115   #else
116   exit(0);
117   #endif
118 }
119 #endif