1 /* 2 * Copyright 2020-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 /** 7 * @file Mcal.h 8 * @implements Mcal.h_Artifact 9 * @version 3.0.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 3 59 #define MCAL_SW_MINOR_VERSION 0 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_S32K3XX_ 115 116 /** 117 * @brief Compiler abstraction for the intrinsic wait instruction. 118 */ 119 #define EXECUTE_WAIT() ASM_KEYWORD(" wfi"); 120 /** 121 * @brief Compiler abstraction for MCAL Fault Injection tests 122 */ 123 #ifdef MCAL_ENABLE_FAULT_INJECTION 124 125 #define MCAL_PUT_IN_QUOTES(x) #x 126 127 #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label::)) 128 #else 129 130 #define MCAL_FAULT_INJECTION_POINT(label) 131 #endif 132 133 #endif /* #ifdef _GREENHILLS_C_S32K3XX_ */ 134 135 /**************************************** Wind River Diab *****************************************/ 136 #ifdef _DIABDATA_C_S32K3XX_ 137 138 /** 139 * @brief Compiler abstraction for the intrinsic wait instruction. 140 */ 141 #define EXECUTE_WAIT() ASM_KEYWORD(" wfi"); 142 /** 143 * @brief Compiler abstraction for MCAL Fault Injection tests 144 */ 145 #ifdef MCAL_ENABLE_FAULT_INJECTION 146 147 #define MCAL_PUT_IN_QUOTES(x) #x 148 149 #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:)) 150 #else 151 152 #define MCAL_FAULT_INJECTION_POINT(label) 153 #endif 154 155 #endif /* #ifdef _DIABDATA_C_S32K3XX_ */ 156 157 /*************************************** CodeWarrior **********************************************/ 158 #ifdef _CODEWARRIOR_C_S32K3XX_ 159 160 /** 161 * @brief Compiler abstraction for the intrinsic wait instruction. 162 */ 163 #define EXECUTE_WAIT() ASM_KEYWORD (" opword 0x7C00007C"); 164 #endif /* #ifdef _CODEWARRIOR_C_S32K3XX_ */ 165 166 /*************************************** HighTec **********************************************/ 167 #ifdef _HITECH_C_S32K3XX_ 168 /** 169 * @brief Compiler abstraction for the intrinsic wait instruction. 170 */ 171 #define EXECUTE_WAIT() ASM_KEYWORD(" wait"); 172 #endif /* #ifdef _HITECH_C_S32K3XX_ */ 173 /**************************************** Linaro *********************************************/ 174 #ifdef _LINARO_C_S32K3XX_ 175 /** 176 * @brief Compiler abstraction for the intrinsic wait instruction. 177 */ 178 #define EXECUTE_WAIT() ASM_KEYWORD(" wfi"); 179 /** 180 * @brief Compiler abstraction for MCAL Fault Injection tests 181 */ 182 #ifdef MCAL_ENABLE_FAULT_INJECTION 183 184 #define MCAL_PUT_IN_QUOTES(x) #x 185 186 #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:)) 187 #else 188 189 #define MCAL_FAULT_INJECTION_POINT(label) 190 #endif 191 192 #endif /* #ifdef _LINARO_C_S32K3XX_ */ 193 194 /**************************************** DS5 *********************************************/ 195 #ifdef _ARM_DS5_C_S32K3XX_ 196 /** 197 * @brief Compiler abstraction for the intrinsic wait instruction. 198 */ 199 #define EXECUTE_WAIT() ASM_KEYWORD(" wfi"); 200 /** 201 * @brief Compiler abstraction for MCAL Fault Injection tests 202 */ 203 #ifdef MCAL_ENABLE_FAULT_INJECTION 204 205 #define MCAL_PUT_IN_QUOTES(x) #x 206 207 #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:)) 208 #else 209 210 #define MCAL_FAULT_INJECTION_POINT(label) 211 #endif 212 213 #endif /* #ifdef _ARM_DS5_C_S32K3XX_ */ 214 /**************************************** IAR *********************************************/ 215 #ifdef _IAR_C_S32K3XX_ 216 /** 217 * @brief Compiler abstraction for the "Put in Quotes". 218 */ 219 #define MCAL_PUT_IN_QUOTES(x) #x 220 /** 221 * @brief Compiler abstraction for the "Double Put in Quotes" - Used by VAL_ALIGN. 222 */ 223 #define MCAL_PUT_IN_QUOTES1(x) MCAL_PUT_IN_QUOTES(x) 224 225 /** 226 * @brief Compiler abstraction for the intrinsic wait instruction. 227 */ 228 #define EXECUTE_WAIT() ASM_KEYWORD(" wfi"); 229 /** 230 * @brief Compiler abstraction for MCAL Fault Injection tests 231 */ 232 #ifdef MCAL_ENABLE_FAULT_INJECTION 233 234 #define MCAL_FAULT_INJECTION_POINT(label) ASM_KEYWORD(MCAL_PUT_IN_QUOTES(label:)) 235 #else 236 237 #define MCAL_FAULT_INJECTION_POINT(label) 238 #endif 239 240 #endif /* #ifdef _IAR_C_S32K3XX_ */ 241 242 /* check that the compiler used is supported (otherwise some defines might not exist) */ 243 #ifndef _GREENHILLS_C_S32K3XX_ 244 #ifndef _DIABDATA_C_S32K3XX_ 245 #ifndef _CODEWARRIOR_C_S32K3XX_ 246 #ifndef _HITECH_C_S32K3XX_ 247 #ifndef _LINARO_C_S32K3XX_ 248 #ifndef _ARM_DS5_C_S32K3XX_ 249 #ifndef _IAR_C_S32K3XX_ 250 #error "Unsupported compiler. Compiler abstraction needs to be updated to use this compiler." 251 #endif 252 #endif 253 #endif 254 #endif 255 #endif 256 #endif 257 #endif 258 #if (MCAL_PLATFORM_ARM == MCAL_ARM_AARCH64) 259 /** 260 * @brief Data Synchronization Barrier (DSB) completes when all instructions before this instruction complete 261 */ 262 #define MCAL_DATA_SYNC_BARRIER() ASM_KEYWORD("dsb sy":::"memory") 263 /** 264 * @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. 265 */ 266 #define MCAL_INSTRUCTION_SYNC_BARRIER() ASM_KEYWORD("isb":::"memory") 267 #else 268 /** 269 * @brief Data Synchronization Barrier (DSB) completes when all instructions before this instruction complete 270 */ 271 #define MCAL_DATA_SYNC_BARRIER() ASM_KEYWORD(" DSB") 272 273 /** 274 * @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. 275 */ 276 #define MCAL_INSTRUCTION_SYNC_BARRIER() ASM_KEYWORD(" ISB") 277 #endif 278 279 #if defined(MCAL_PLATFORM_ARM_M4) || defined(MCAL_PLATFORM_ARM_M4F) 280 #if !defined(USING_OS_AUTOSAROS) 281 #define EXIT_INTERRUPT() MCAL_DATA_SYNC_BARRIER() /* DSB sy full system */ 282 #else 283 #define EXIT_INTERRUPT() 284 #endif /* !defined(USING_OS_AUTOSAROS) */ 285 #else 286 #define EXIT_INTERRUPT() 287 #endif 288 289 /*================================================================================================== 290 * ENUMS 291 ==================================================================================================*/ 292 293 /*================================================================================================== 294 * STRUCTURES AND OTHER TYPEDEFS 295 ==================================================================================================*/ 296 /** 297 * @brief Typedef for DEM error management implemented by MCAL drivers 298 */ 299 typedef struct 300 { 301 uint32 state; /**< enabling/disabling the DEM error: Active=STD_ON/ Inactive=STD_OFF */ 302 uint32 id ; /**< ID of DEM error (0 if STD_OFF)*/ 303 }Mcal_DemErrorType; 304 /*================================================================================================== 305 * GLOBAL VARIABLE DECLARATIONS 306 ==================================================================================================*/ 307 308 /*================================================================================================== 309 * FUNCTION PROTOTYPES 310 ==================================================================================================*/ 311 312 #ifdef __cplusplus 313 } 314 #endif 315 316 #endif /* #ifndef MCAL_H */ 317 318 /** @} */ 319