1 /* 2 * Copyright 2021-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 /** 7 * @file Compiler.h 8 * @implements Compiler.h_Artifact 9 * @version 1.0.0 10 * 11 * @brief AUTOSAR BaseNXP - SWS Compiler abstraction 12 * @details The file Compiler.h provides macros for the encapsulation of definitions and 13 * declarations. 14 * This file contains sample code only. It is not part of the production code deliverables 15 * 16 * @addtogroup BASENXP_COMPONENT 17 * @{ 18 */ 19 20 /** 21 * @requirements COMPILER047 22 */ 23 #ifndef COMPILER_H 24 #define COMPILER_H 25 26 #ifdef __cplusplus 27 extern "C"{ 28 #endif 29 30 /*================================================================================================== 31 * INCLUDE FILES 32 * 1) system and project includes 33 * 2) needed interfaces from external units 34 * 3) internal and external interfaces from this unit 35 ==================================================================================================*/ 36 #include "Compiler_Cfg.h" 37 #include "CompilerDefinition.h" 38 39 /*================================================================================================== 40 * SOURCE FILE VERSION INFORMATION 41 ==================================================================================================*/ 42 /** 43 * @brief Parameters that shall be published within the compiler abstraction header file and also in 44 the module's description file. 45 @{ 46 */ 47 #define COMPILER_VENDOR_ID 43 48 #define COMPILER_AR_RELEASE_MAJOR_VERSION 4 49 #define COMPILER_AR_RELEASE_MINOR_VERSION 7 50 #define COMPILER_AR_RELEASE_REVISION_VERSION 0 51 #define COMPILER_SW_MAJOR_VERSION 1 52 #define COMPILER_SW_MINOR_VERSION 0 53 #define COMPILER_SW_PATCH_VERSION 0 54 /**@}*/ 55 /*================================================================================================== 56 * FILE VERSION CHECKS 57 ==================================================================================================*/ 58 59 /*================================================================================================== 60 * CONSTANTS 61 ==================================================================================================*/ 62 63 /*================================================================================================== 64 * DEFINES AND MACROS 65 ==================================================================================================*/ 66 67 /** 68 * @brief The memory class AUTOMATIC shall be provided as empty definition, used for the declaration 69 * of local pointers. 70 */ 71 #define AUTOMATIC 72 73 /** 74 * @brief The memory class TYPEDEF shall be provided as empty definition. This memory class shall be 75 * used within type definitions, where no memory qualifier can be specified. This can be 76 * necessary for defining pointer types, with e.g. P2VAR, where the macros require two 77 * parameters. First parameter can be specified in the type definition (distance to the memory 78 * location referenced by the pointer), but the second one (memory allocation of the pointer 79 * itself) cannot be defined at this time. Hence memory class TYPEDEF shall be applied. 80 */ 81 #define TYPEDEF 82 83 /** 84 * @brief The compiler abstraction shall provide the NULL_PTR define with a void pointer to zero 85 * definition. 86 */ 87 #define NULL_PTR ((void *)0) 88 89 /**************************************** Green Hills *********************************************/ 90 #ifdef _GREENHILLS_C_S32ZE_ 91 /* Prototypes for intrinsic functions */ 92 /** 93 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 94 * inline. 95 */ 96 #define INLINE __inline 97 98 /** 99 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 100 * keyword inline in functions with "static" scope 101 */ 102 #define LOCAL_INLINE static __inline 103 104 /** 105 * @brief Compiler abstraction for specifying an interrupt handler. 106 */ 107 #define INTERRUPT_FUNC __interrupt 108 109 /** 110 * @brief Compiler abstraction for the asm keyword. 111 */ 112 #define ASM_KEYWORD __asm 113 114 /** 115 * @brief Compiler abstraction for the asm keyword. 116 */ 117 #define ASMV_KEYWORD __asm volatile 118 119 /** 120 * @brief Compiler abstraction for the data alignment 121 */ 122 #define ALIGNED_VARS_START(sec_name, align) 123 /** 124 * @brief Compiler abstraction for the data alignment 125 */ 126 #define VAR_ALIGN(v, size) __attribute__(( aligned(size) )) v; 127 /** 128 * @brief Compiler abstraction for the data alignment 129 */ 130 #define ALIGNED_VARS_STOP() 131 /** 132 * @brief Compiler abstraction for the packed qualifier 133 */ 134 #define PACKED __packed 135 136 #endif /* #ifdef _GREENHILLS_C_S32ZE_ */ 137 138 /**************************************** Wind River Diab *****************************************/ 139 #ifdef _DIABDATA_C_S32ZE_ 140 /* Prototypes for intrinsic functions */ 141 /** 142 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 143 * inline. 144 */ 145 #define INLINE inline __attribute__((always_inline)) 146 147 /** 148 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 149 * keyword inline in functions with "static" scope 150 */ 151 #define LOCAL_INLINE static inline __attribute__((always_inline)) 152 153 /** 154 * @brief Compiler abstraction for specifying an interrupt handler. Diab version 7 and above use clang 155 */ 156 #ifdef __clang__ 157 #define INTERRUPT_FUNC __attribute__((interrupt)) 158 #else 159 #define INTERRUPT_FUNC __interrupt__ 160 #endif /* __clang__*/ 161 162 /** 163 * @brief Compiler abstraction for the asm keyword. 164 */ 165 #define ASM_KEYWORD __asm 166 167 /** 168 * @brief Compiler abstraction for the asm keyword. 169 */ 170 #define ASMV_KEYWORD __asm volatile 171 172 /** 173 * @brief Compiler abstraction for the data alignment 174 */ 175 #define ALIGNED_VARS_START(sec_name, align) 176 /** 177 * @brief Compiler abstraction for the data alignment 178 */ 179 #define VAR_ALIGN(v, size) __attribute__(( aligned(size) )) v; 180 /** 181 * @brief Compiler abstraction for the data alignment 182 */ 183 #define ALIGNED_VARS_STOP() 184 /** 185 * @brief Compiler abstraction for the packed qualifier 186 */ 187 #define PACKED __attribute__((packed)) 188 189 #endif /* #ifdef _DIABDATA_C_S32ZE_ */ 190 191 /*************************************** CodeWarrior **********************************************/ 192 #ifdef _CODEWARRIOR_C_S32ZE_ 193 /* Prototypes for intrinsic functions */ 194 /** 195 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 196 * inline. 197 */ 198 #define INLINE inline 199 200 /** 201 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 202 * keyword inline in functions with "static" scope 203 */ 204 #define LOCAL_INLINE static inline 205 206 /** 207 * @brief Compiler abstraction for specifying an interrupt handler. 208 */ 209 #define INTERRUPT_FUNC __declspec(interrupt nowarn) 210 211 /** 212 * @brief Compiler abstraction for the asm keyword. 213 */ 214 #define ASM_KEYWORD asm 215 216 /** 217 * @brief Compiler abstraction for the data alignment 218 */ 219 #define ALIGNED_VARS_START(sec_name, align) 220 /** 221 * @brief Compiler abstraction for the data alignment 222 */ 223 #define VAR_ALIGN(v, size) v __attribute__(( aligned(size) )); 224 /** 225 * @brief Compiler abstraction for the data alignment 226 */ 227 #define ALIGNED_VARS_STOP() 228 /** 229 * @brief Compiler abstraction for the packed qualifier 230 */ 231 #define PACKED __packed 232 233 #endif /* #ifdef _CODEWARRIOR_C_S32ZE_ */ 234 235 /*************************************** HighTec **********************************************/ 236 #ifdef _HITECH_C_S32ZE_ 237 /* Prototypes for intrinsic functions */ 238 /** 239 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 240 * inline. 241 */ 242 #define INLINE __inline 243 244 /** 245 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 246 * keyword inline in functions with "static" scope 247 */ 248 #define LOCAL_INLINE static __inline 249 250 /** 251 * @brief Compiler abstraction for specifying an interrupt handler. 252 */ 253 #define INTERRUPT_FUNC __attribute__((interrupt)); 254 255 /** 256 * @brief Compiler abstraction for the asm keyword. 257 */ 258 #define ASM_KEYWORD __asm 259 260 /** 261 * @brief Compiler abstraction for the data alignment 262 */ 263 #define ALIGNED_VARS_START(sec_name, align) 264 /** 265 * @brief Compiler abstraction for the data alignment 266 */ 267 #define VAR_ALIGN(v, size) __attribute__(( aligned(size) )) v; 268 /** 269 * @brief Compiler abstraction for the data alignment 270 */ 271 #define ALIGNED_VARS_STOP() 272 273 #endif /* #ifdef _HITECH_C_S32ZE_ */ 274 275 /**************************************** Linaro *********************************************/ 276 #ifdef _LINARO_C_S32ZE_ 277 /* Prototypes for intrinsic functions */ 278 /** 279 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 280 * inline. 281 */ 282 #define INLINE inline __attribute__((always_inline)) 283 284 /** 285 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 286 * keyword inline in functions with "static" scope 287 */ 288 #define LOCAL_INLINE static inline __attribute__((always_inline)) 289 290 /** 291 * @brief Compiler abstraction for specifying an interrupt handler. 292 */ 293 #define INTERRUPT_FUNC 294 295 /** 296 * @brief Compiler abstraction for the asm keyword. 297 */ 298 #define ASM_KEYWORD __asm__ 299 /** 300 * @brief Compiler abstraction for the asm keyword. 301 */ 302 #define ASMV_KEYWORD __asm__ volatile 303 304 /** 305 * @brief Compiler abstraction for the data alignment 306 */ 307 #define ALIGNED_VARS_START(sec_name, align) 308 /** 309 * @brief Compiler abstraction for the data alignment 310 */ 311 #define VAR_ALIGN(v, size) __attribute__(( aligned(size) )) v; 312 /** 313 * @brief Compiler abstraction for the data alignment 314 */ 315 #define ALIGNED_VARS_STOP() 316 /** 317 * @brief Compiler abstraction for the packed qualifier 318 */ 319 #define PACKED __attribute__((__packed__)) 320 321 #endif /* #ifdef _LINARO_C_S32ZE_ */ 322 /**************************************** DS5 *************************************************/ 323 #ifdef _ARM_DS5_C_S32ZE_ 324 /* Prototypes for intrinsic functions */ 325 /** 326 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 327 * inline. 328 */ 329 #define INLINE __inline 330 331 /** 332 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 333 * keyword inline in functions with "static" scope 334 */ 335 #define LOCAL_INLINE static __inline 336 337 /** 338 * @brief Compiler abstraction for specifying an interrupt handler. 339 */ 340 #define INTERRUPT_FUNC 341 /** 342 * @brief Compiler abstraction for the asm keyword. 343 */ 344 #define ASM_KEYWORD __asm 345 346 /** 347 * @brief Compiler abstraction for the data alignment 348 */ 349 #define ALIGNED_VARS_START(sec_name, align) 350 /** 351 * @brief Compiler abstraction for the data alignment 352 */ 353 #define VAR_ALIGN(v, size) __align(size) v; 354 /** 355 * @brief Compiler abstraction for the data alignment 356 */ 357 #define ALIGNED_VARS_STOP() 358 /** 359 * @brief Compiler abstraction for the packed qualifier 360 */ 361 #define PACKED __packed 362 363 #endif /* #ifdef _ARM_DS5_C_S32ZE_ */ 364 365 /**************************************** IAR *************************************************/ 366 #ifdef _IAR_C_S32ZE_ 367 /* Prototypes for intrinsic functions */ 368 /** 369 * @brief The compiler abstraction shall provide the INLINE define for abstraction of the keyword 370 * inline. 371 */ 372 #define INLINE inline __attribute__((always_inline)) 373 374 /** 375 * @brief The compiler abstraction shall provide the LOCAL_INLINE define for abstraction of the 376 * keyword inline in functions with "static" scope 377 */ 378 #define LOCAL_INLINE static inline __attribute__((always_inline)) 379 380 /** 381 * @brief Compiler abstraction for specifying an interrupt handler. 382 */ 383 #define INTERRUPT_FUNC 384 385 /** 386 * @brief Compiler abstraction for the asm keyword. 387 */ 388 #define ASM_KEYWORD __asm 389 /** 390 * @brief Compiler abstraction for the asm keyword. 391 */ 392 #define ASMV_KEYWORD __asm volatile 393 394 /** 395 * @brief Compiler abstraction for the data alignment 396 */ 397 #define ALIGNED_VARS_START(sec_name, align) 398 /** 399 * @brief Compiler abstraction for the data alignment 400 */ 401 #define VAR_ALIGN(v, size) _Pragma(MCAL_PUT_IN_QUOTES1(data_alignment=size)) \ 402 v; 403 /** 404 * @brief Compiler abstraction for the data alignment 405 */ 406 #define ALIGNED_VARS_STOP() 407 /** 408 * @brief Compiler abstraction for the packed qualifier 409 */ 410 #define PACKED __packed 411 412 #endif /* #ifdef _IAR_C_S32ZE_ */ 413 414 415 /** 416 * @brief The compiler abstraction shall define the FUNC macro for the declaration and definition of 417 * functions, that ensures correct syntax of function declarations as required by a specific 418 * compiler. 419 */ 420 #define FUNC(rettype, memclass) rettype 421 422 /** 423 * @brief The compiler abstraction shall define the P2VAR macro for the declaration and definition of 424 * pointers in RAM, pointing to variables. 425 */ 426 #define P2VAR(ptrtype, memclass, ptrclass) ptrtype * 427 428 /** 429 * @brief The compiler abstraction shall define the P2CONST macro for the declaration and definition 430 * of pointers in RAM pointing to constants. 431 */ 432 #define P2CONST(ptrtype, memclass, ptrclass) const ptrtype * 433 434 /** 435 * @brief The compiler abstraction shall define the CONSTP2VAR macro for the declaration and 436 * definition of constant pointers accessing variables. 437 */ 438 #define CONSTP2VAR(ptrtype, memclass, ptrclass) ptrtype * const 439 440 /** 441 * @brief The compiler abstraction shall define the CONSTP2CONST macro for the declaration and 442 * definition of constant pointers accessing constants. 443 */ 444 #define CONSTP2CONST(ptrtype, memclass, ptrclass) const ptrtype * const 445 446 /** 447 * @brief The compiler abstraction shall define the P2FUNC macro for the type definition of pointers 448 * to functions. 449 */ 450 #define P2FUNC(rettype, ptrclass, fctname) rettype (*fctname) 451 452 /** 453 * @brief The compiler abstraction shall define the CONST macro for the declaration and definition of 454 * constants. 455 */ 456 #define CONST(consttype, memclass) const consttype 457 458 /** 459 * @brief The compiler abstraction shall define the VAR macro for the declaration and definition of 460 * variables. 461 */ 462 #define VAR(vartype, memclass) vartype 463 464 465 /** 466 * @brief The compiler abstraction for const pointer to function. 467 */ 468 #define CONSTP2FUNC(rettype, ptrclass, fctname) rettype (* const fctname) 469 470 471 /** 472 * @brief The compiler abstraction shall define the FUNC_P2CONST macro for the declaration and 473 * definition of functions returning a pointer to a constant 474 */ 475 #define FUNC_P2CONST(rettype, ptrclass, memclass) const ptrclass rettype * memclass 476 477 /** 478 * @brief The compiler abstraction shall define the FUNC_P2VAR macro for the declaration and 479 * definition of functions returning a pointer to a variable. 480 */ 481 #define FUNC_P2VAR(rettype, ptrclass, memclass) ptrclass rettype * memclass 482 483 /** 484 * @brief Compiler abstraction for allocating variables to nocache section 485 */ 486 #ifdef CONFIG_NOCACHE_MEMORY 487 #ifdef __ZEPHYR__ 488 #include <zephyr/toolchain.h> 489 #else 490 #ifndef STRINGIFY 491 #define STRINGIFY(x) #x 492 #endif /* STRINGIFY */ 493 #endif /* __ZEPHYR__ */ 494 #define VAR_SEC_NOCACHE(name) __attribute__((section(".nocache." STRINGIFY(name)))) 495 #else 496 #define VAR_SEC_NOCACHE(name) 497 #endif /* CONFIG_NOCACHE_MEMORY */ 498 499 /*================================================================================================== 500 * ENUMS 501 ==================================================================================================*/ 502 503 /*================================================================================================== 504 * STRUCTURES AND OTHER TYPEDEFS 505 ==================================================================================================*/ 506 507 /*================================================================================================== 508 * GLOBAL VARIABLE DECLARATIONS 509 ==================================================================================================*/ 510 511 /*================================================================================================== 512 * FUNCTION PROTOTYPES 513 ==================================================================================================*/ 514 515 #ifdef __cplusplus 516 } 517 #endif 518 519 #endif /* #ifndef COMPILER_H */ 520 521 /** @} */ 522