1 /*
2  * Copyright 2021-2022 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 /**
7 *   @file           Mcal.h
8 *   @implements     Mcal.h_Artifact
9 *   @version 0.9.0
10 *
11 *   @brief   AUTOSAR BaseNXP - SWS Compiler abstraction specific for MCAL.
12 *   @details The file Mcal.h provides MCAL specific macros used for compiler abstraction.
13 *
14 *
15 *   @addtogroup BASENXP_COMPONENT
16 *   @{
17 */
18 
19 
20 #ifndef MCAL_H
21 #define MCAL_H
22 
23 #ifdef __cplusplus
24 extern "C"{
25 #endif
26 
27 /*==================================================================================================
28 *                                        INCLUDE FILES
29 * 1) system and project includes
30 * 2) needed interfaces from external units
31 * 3) internal and external interfaces from this unit
32 ==================================================================================================*/
33 /*
34 * @file        Mcal.h
35 * @brief Include compiler abstraction
36 */
37 #include "Compiler.h"
38 /*
39 * @file        Mcal.h
40 * @brief Include standard types
41 */
42 #include "StandardTypes.h"
43 
44 #include "Soc_Ips.h"
45 
46 #include "Reg_eSys.h"
47 
48 #include "OsIf_Internal.h"
49 
50 /*==================================================================================================
51 *                              SOURCE FILE VERSION INFORMATION
52 ==================================================================================================*/
53 #define MCAL_VENDOR_ID                    43
54 #define MCAL_MODULE_ID                    0
55 #define MCAL_AR_RELEASE_MAJOR_VERSION     4
56 #define MCAL_AR_RELEASE_MINOR_VERSION     7
57 #define MCAL_AR_RELEASE_REVISION_VERSION  0
58 #define MCAL_SW_MAJOR_VERSION             0
59 #define MCAL_SW_MINOR_VERSION             9
60 #define MCAL_SW_PATCH_VERSION             0
61 
62 /*==================================================================================================
63 *                                     FILE VERSION CHECKS
64 ==================================================================================================*/
65 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
66     /* Check if source file and Compiler.h header file are of the same Autosar version */
67     #if ((MCAL_AR_RELEASE_MAJOR_VERSION != COMPILER_AR_RELEASE_MAJOR_VERSION) || \
68          (MCAL_AR_RELEASE_MINOR_VERSION != COMPILER_AR_RELEASE_MINOR_VERSION))
69         #error "AutoSar Version Numbers of Mcal.h and Compiler.h are different"
70     #endif
71 #endif
72 
73 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
74     /* Check if source file and StandardTypes.h header file are of the same Autosar version */
75     #if ((MCAL_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
76          (MCAL_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
77         #error "AutoSar Version Numbers of Mcal.h and StandardTypes.h are different"
78     #endif
79 #endif
80 
81 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
82     /* Check if source file and StandardTypes.h header file are of the same Autosar version */
83     #if ((MCAL_AR_RELEASE_MAJOR_VERSION != REG_ESYS_AR_RELEASE_MAJOR_VERSION) || \
84          (MCAL_AR_RELEASE_MINOR_VERSION != REG_ESYS_AR_RELEASE_MINOR_VERSION))
85         #error "AutoSar Version Numbers of Mcal.h and Reg_eSys.h are different"
86     #endif
87 #endif
88 
89 /* Check if source file and Soc_Ips.h header file have same versions */
90 #if (MCAL_VENDOR_ID  != SOC_IPS_VENDOR_ID)
91 #error "Soc_Ips.h and Mcal.h have different vendor IDs"
92 #endif
93 
94 /* Check if source file and Soc_Ips.h header file are of the same Autosar version */
95 #if ((MCAL_AR_RELEASE_MAJOR_VERSION != SOC_IPS_AR_RELEASE_MAJOR_VERSION) || \
96      (MCAL_AR_RELEASE_MINOR_VERSION != SOC_IPS_AR_RELEASE_MINOR_VERSION))
97     #error "AutoSar Version Numbers of Mcal.h and Soc_Ips.h are different"
98 #endif
99 
100 #if ((MCAL_SW_MAJOR_VERSION != SOC_IPS_SW_MAJOR_VERSION) || \
101      (MCAL_SW_MINOR_VERSION != SOC_IPS_SW_MINOR_VERSION) || \
102      (MCAL_SW_PATCH_VERSION != SOC_IPS_SW_PATCH_VERSION))
103     #error "Software Version Numbers of Soc_Ips.h and Mcal.h are different"
104 #endif
105 /*==================================================================================================
106 *                                         CONSTANTS
107 ==================================================================================================*/
108 
109 /*==================================================================================================
110 *                                      DEFINES AND MACROS
111 ==================================================================================================*/
112 
113 /**************************************** Green Hills *********************************************/
114 #ifdef _GREENHILLS_C_S32ZE_
115 
116     /**
117     * @brief Compiler abstraction for the intrinsic wait instruction.
118     */
119     #define EXECUTE_WAIT()  \
120                 do  \
121                 {   \
122                     OsIf_ResumeAllInterrupts();  \
123                     ASM_KEYWORD("  wfi");   \
124                     OsIf_SuspendAllInterrupts(); \
125                 } while (0)
126     /**
127      * @brief Compiler abstraction for MCAL Fault Injection tests
128     */
129     #ifdef MCAL_ENABLE_FAULT_INJECTION
130 
131         #define MCAL_PUT_IN_QUOTES(x) #x
132 
133         #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label::))
134     #else
135 
136         #define MCAL_FAULT_INJECTION_POINT(label)
137     #endif
138 
139 #endif /* #ifdef _GREENHILLS_C_S32ZE_ */
140 
141 /**************************************** Wind River Diab *****************************************/
142 #ifdef _DIABDATA_C_S32ZE_
143 
144     /**
145     * @brief Compiler abstraction for the intrinsic wait instruction.
146     */
147     #define EXECUTE_WAIT()  \
148                 do  \
149                 {   \
150                     OsIf_ResumeAllInterrupts();              \
151                     ASM_KEYWORD(" wfi");  \
152                     OsIf_SuspendAllInterrupts();             \
153                 } while (0)
154     /**
155      * @brief Compiler abstraction for MCAL Fault Injection tests
156     */
157     #ifdef MCAL_ENABLE_FAULT_INJECTION
158 
159         #define MCAL_PUT_IN_QUOTES(x) #x
160 
161         #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:))
162     #else
163 
164         #define MCAL_FAULT_INJECTION_POINT(label)
165     #endif
166 
167 #endif /* #ifdef _DIABDATA_C_S32ZE_ */
168 
169 /*************************************** CodeWarrior **********************************************/
170 #ifdef _CODEWARRIOR_C_S32ZE_
171 
172     /**
173     * @brief Compiler abstraction for the intrinsic wait instruction.
174     */
175     #define EXECUTE_WAIT()  \
176                 do  \
177                 {   \
178                     OsIf_ResumeAllInterrupts();                  \
179                     ASM_KEYWORD (" opword 0x7C00007C");     \
180                     OsIf_SuspendAllInterrupts();                 \
181                 } while (0)
182 #endif /* #ifdef _CODEWARRIOR_C_S32ZE_ */
183 
184 /*************************************** Cosmic ***************************************************/
185 #ifdef _COSMIC_C_S32ZE_
186     /**
187     * @brief Compiler abstraction for the asm keyword.
188     */
189     #define ASM_PUBLIC_LABEL(label)  _asm("\txdef\t" #label "\n" #label ":")
190 
191     /**
192     * @brief Compiler abstraction for the intrinsic wait instruction.
193     */
194     #define EXECUTE_WAIT()  \
195                 do  \
196                 {   \
197                     OsIf_ResumeAllInterrupts();                  \
198                     ASM_KEYWORD (" dc.l 0x7C00007C");       \
199                     OsIf_SuspendAllInterrupts();                 \
200                 } while (0)
201 
202 #endif /* #ifdef _COSMIC_C_S32ZE_ */
203 
204 /*************************************** HighTec **********************************************/
205 #ifdef _HITECH_C_S32ZE_
206     /**
207     * @brief Compiler abstraction for the intrinsic wait instruction.
208     */
209     #define EXECUTE_WAIT()  \
210                 do  \
211                 {   \
212                     OsIf_ResumeAllInterrupts();                  \
213                     ASM_KEYWORD("  wait");                  \
214                     OsIf_SuspendAllInterrupts();                 \
215                 } while (0)
216 #endif /* #ifdef _HITECH_C_S32ZE_ */
217 /**************************************** Linaro *********************************************/
218 #ifdef _LINARO_C_S32ZE_
219     /**
220     * @brief Compiler abstraction for the intrinsic wait instruction.
221     */
222     #define EXECUTE_WAIT()  \
223                 do  \
224                 {   \
225                     OsIf_ResumeAllInterrupts();                  \
226                     ASM_KEYWORD("  wfi");                   \
227                     OsIf_SuspendAllInterrupts();                 \
228                 } while (0)
229     /**
230      * @brief Compiler abstraction for MCAL Fault Injection tests
231     */
232     #ifdef MCAL_ENABLE_FAULT_INJECTION
233 
234         #define MCAL_PUT_IN_QUOTES(x) #x
235 
236         #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:))
237     #else
238 
239         #define MCAL_FAULT_INJECTION_POINT(label)
240     #endif
241 
242 #endif /* #ifdef _LINARO_C_S32ZE_ */
243 
244 /**************************************** DS5 *********************************************/
245 #ifdef _ARM_DS5_C_S32ZE_
246     /**
247     * @brief Compiler abstraction for the intrinsic wait instruction.
248     */
249     #define EXECUTE_WAIT()  \
250                 do  \
251                 {   \
252                     OsIf_ResumeAllInterrupts();                  \
253                     ASM_KEYWORD("  wfi");                   \
254                     OsIf_SuspendAllInterrupts();                 \
255                 } while (0)
256     /**
257      * @brief Compiler abstraction for MCAL Fault Injection tests
258     */
259     #ifdef MCAL_ENABLE_FAULT_INJECTION
260 
261         #define MCAL_PUT_IN_QUOTES(x) #x
262 
263         #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:))
264     #else
265 
266         #define MCAL_FAULT_INJECTION_POINT(label)
267     #endif
268 
269 #endif /* #ifdef _ARM_DS5_C_S32ZE_ */
270 /**************************************** IAR *********************************************/
271 #ifdef _IAR_C_S32ZE_
272     /**
273     * @brief Compiler abstraction for the "Put in Quotes".
274     */
275     #define MCAL_PUT_IN_QUOTES(x) #x
276     /**
277     * @brief Compiler abstraction for the "Double Put in Quotes" - Used by VAL_ALIGN.
278     */
279     #define MCAL_PUT_IN_QUOTES1(x) MCAL_PUT_IN_QUOTES(x)
280 
281     /**
282     * @brief Compiler abstraction for the intrinsic wait instruction.
283     */
284     #define EXECUTE_WAIT()  \
285                 do  \
286                 {   \
287                     OsIf_ResumeAllInterrupts();                  \
288                     ASM_KEYWORD("  wfi");                   \
289                     OsIf_SuspendAllInterrupts();                 \
290                 } while (0)
291     /**
292      * @brief Compiler abstraction for MCAL Fault Injection tests
293     */
294     #ifdef MCAL_ENABLE_FAULT_INJECTION
295 
296         #define MCAL_FAULT_INJECTION_POINT(label)   ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:))
297     #else
298 
299         #define MCAL_FAULT_INJECTION_POINT(label)
300     #endif
301 
302 #endif /* #ifdef _IAR_C_S32ZE_ */
303 
304 /* check that the compiler used is supported (otherwise some defines might not exist) */
305 #ifndef _GREENHILLS_C_S32ZE_
306     #ifndef _DIABDATA_C_S32ZE_
307         #ifndef _CODEWARRIOR_C_S32ZE_
308             #ifndef _COSMIC_C_S32ZE_
309                 #ifndef _HITECH_C_S32ZE_
310                     #ifndef _LINARO_C_S32ZE_
311                         #ifndef _ARM_DS5_C_S32ZE_
312                             #ifndef _IAR_C_S32ZE_
313                                 #error "Unsupported compiler. Compiler abstraction needs to be updated to use this compiler."
314                             #endif
315                         #endif
316                     #endif
317                 #endif
318             #endif
319         #endif
320     #endif
321 #endif
322 #if (MCAL_PLATFORM_ARM  == MCAL_ARM_AARCH64)
323 /**
324 * @brief Data Synchronization Barrier (DSB) completes when all instructions before this instruction complete
325 */
326 #define MCAL_DATA_SYNC_BARRIER()  ASM_KEYWORD("dsb sy":::"memory")
327 /**
328 * @brief  flushes the pipeline in the processor, so that all instructions following the ISB are fetched from cache or memory, after the ISB has been completed.
329 */
330 #define MCAL_INSTRUCTION_SYNC_BARRIER()  ASM_KEYWORD("isb":::"memory")
331 #else
332 /**
333 * @brief Data Synchronization Barrier (DSB) completes when all instructions before this instruction complete
334 */
335 #define MCAL_DATA_SYNC_BARRIER()  ASM_KEYWORD(" DSB")
336 
337 /**
338 * @brief  flushes the pipeline in the processor, so that all instructions following the ISB are fetched from cache or memory, after the ISB has been completed.
339 */
340 #define MCAL_INSTRUCTION_SYNC_BARRIER()  ASM_KEYWORD(" ISB")
341 #endif
342 
343 #if defined(MCAL_PLATFORM_ARM_M4) || defined(MCAL_PLATFORM_ARM_M4F)
344     #if !defined(USING_OS_AUTOSAROS)
345         #define EXIT_INTERRUPT()  MCAL_DATA_SYNC_BARRIER()   /* DSB sy full system */
346     #else
347         #define EXIT_INTERRUPT()
348     #endif /* !defined(USING_OS_AUTOSAROS) */
349 #else
350     #define EXIT_INTERRUPT()
351 #endif
352 
353 /*==================================================================================================
354 *                                             ENUMS
355 ==================================================================================================*/
356 
357 /*==================================================================================================
358 *                                 STRUCTURES AND OTHER TYPEDEFS
359 ==================================================================================================*/
360 /**
361 * @brief Typedef for DEM error management implemented by MCAL drivers
362 */
363 typedef struct
364 {
365     uint32 state;   /**< enabling/disabling the DEM error: Active=STD_ON/ Inactive=STD_OFF */
366     uint32 id ;     /**< ID of DEM error (0 if STD_OFF)*/
367 }Mcal_DemErrorType;
368 /*==================================================================================================
369 *                                 GLOBAL VARIABLE DECLARATIONS
370 ==================================================================================================*/
371 
372 /*==================================================================================================
373 *                                     FUNCTION PROTOTYPES
374 ==================================================================================================*/
375 
376 #ifdef __cplusplus
377 }
378 #endif
379 
380 #endif /* #ifndef MCAL_H */
381 
382 /** @} */
383