1 /* 2 * Copyright 2020-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 #ifndef OSIF_INTERNAL_H 7 #define OSIF_INTERNAL_H 8 9 /** 10 * @file 11 * @implements OsIf_Internal.h_Artifact 12 * @addtogroup osif_drv 13 * @{ 14 */ 15 16 #ifdef __cplusplus 17 extern "C"{ 18 #endif 19 20 /*================================================================================================== 21 * INCLUDE FILES 22 * 1) system and project includes 23 * 2) needed interfaces from external units 24 * 3) internal and external interfaces from this unit 25 ==================================================================================================*/ 26 #include "StandardTypes.h" 27 #include "Soc_Ips.h" 28 #include "OsIf_Cfg.h" 29 30 #if defined(USING_OS_AUTOSAROS) 31 #include "Os.h" 32 #endif /* defined(USING_OS_AUTOSAROS) */ 33 34 #if defined(USING_OS_ZEPHYR) 35 #include "OsIf_Interrupts.h" 36 #ifdef MCAL_ENABLE_USER_MODE_SUPPORT 37 #include "rtd.h" /* System calls for RTD */ 38 #endif 39 #endif /* defined(USING_OS_ZEPHYR) */ 40 41 #if !defined(USING_OS_AUTOSAROS) 42 #ifdef MCAL_ENABLE_USER_MODE_SUPPORT 43 #if (MCAL_PLATFORM_ARM == MCAL_ARM_MARCH) 44 /* prototypes defined in system.h*/ 45 uint32 Sys_GoToUser_Return(uint32 u32SwitchToSupervisor, uint32 u32returnValue); 46 uint32 Sys_GoToSupervisor(void); 47 uint32 Sys_GoToUser(void); 48 #else 49 /*import inline function for switch context from system.h */ 50 #include "system.h" 51 #endif 52 void Sys_SuspendInterrupts(void); 53 void Sys_ResumeInterrupts(void); 54 #endif /* def MCAL_ENABLE_USER_MODE_SUPPORT */ 55 uint8 Sys_GetCoreID(void); 56 #endif /* !defined(USING_OS_AUTOSAROS) */ 57 58 #if (MCAL_PLATFORM_ARM == MCAL_ARM_AARCH32) || (MCAL_PLATFORM_ARM == MCAL_ARM_RARCH) 59 void Sys_EL1SuspendInterrupts(void); 60 void Sys_EL1ResumeInterrupts(void); 61 #endif 62 /*================================================================================================== 63 * SOURCE FILE VERSION INFORMATION 64 ==================================================================================================*/ 65 #define OSIF_INTERNAL_VENDOR_ID 43 66 #define OSIF_INTERNAL_AR_RELEASE_MAJOR_VERSION 4 67 #define OSIF_INTERNAL_AR_RELEASE_MINOR_VERSION 7 68 #define OSIF_INTERNAL_AR_RELEASE_REVISION_VERSION 0 69 #define OSIF_INTERNAL_SW_MAJOR_VERSION 3 70 #define OSIF_INTERNAL_SW_MINOR_VERSION 0 71 #define OSIF_INTERNAL_SW_PATCH_VERSION 0 72 73 /*================================================================================================== 74 * FILE VERSION CHECKS 75 ==================================================================================================*/ 76 /* Checks against StandardTypes.h */ 77 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 78 #if ((OSIF_INTERNAL_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \ 79 (OSIF_INTERNAL_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION)) 80 #error "AutoSar Version Numbers of OsIf_Internal.h and StandardTypes.h are different" 81 #endif 82 #endif 83 84 /* Checks against Soc_Ips.h */ 85 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 86 #if ((OSIF_INTERNAL_AR_RELEASE_MAJOR_VERSION != SOC_IPS_AR_RELEASE_MAJOR_VERSION) || \ 87 (OSIF_INTERNAL_AR_RELEASE_MINOR_VERSION != SOC_IPS_AR_RELEASE_MINOR_VERSION)) 88 #error "AutoSar Version Numbers of OsIf_Internal.h and Soc_Ips.h are different" 89 #endif 90 #endif 91 92 #if defined(USING_OS_AUTOSAROS) 93 /* Checks against Os.h */ 94 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 95 #if ((OSIF_INTERNAL_AR_RELEASE_MAJOR_VERSION != OS_AR_RELEASE_MAJOR_VERSION) || \ 96 (OSIF_INTERNAL_AR_RELEASE_MINOR_VERSION != OS_AR_RELEASE_MINOR_VERSION)) 97 #error "AutoSar Version Numbers of OsIf_Internal.h and Os.h are different" 98 #endif 99 #endif 100 #endif /* defined(USING_OS_AUTOSAROS) */ 101 102 /*================================================================================================== 103 * CONSTANTS 104 ==================================================================================================*/ 105 106 /*================================================================================================== 107 * DEFINES AND MACROS 108 ==================================================================================================*/ 109 110 /* 111 * OsIf_Trusted_Call* 112 */ 113 #ifdef MCAL_ENABLE_USER_MODE_SUPPORT 114 #if (defined(USING_OS_AUTOSAROS) || defined(USING_OS_ZEPHYR)) 115 #define OsIf_Trusted_Call(name) Call_##name##_TRUSTED() 116 #define OsIf_Trusted_Call1param(name,param) Call_##name##_TRUSTED(param) 117 #define OsIf_Trusted_Call2params(name,param1,param2) Call_##name##_TRUSTED(param1,param2) 118 #define OsIf_Trusted_Call3params(name,param1,param2,param3) Call_##name##_TRUSTED(param1,param2,param3) 119 #define OsIf_Trusted_Call4params(name,param1,param2,param3,param4) Call_##name##_TRUSTED(param1,param2,param3,param4) 120 #define OsIf_Trusted_Call5params(name,param1,param2,param3,param4,param5) Call_##name##_TRUSTED(param1,param2,param3,param4,param5) 121 #define OsIf_Trusted_Call6params(name,param1,param2,param3,param4,param5,param6) Call_##name##_TRUSTED(param1,param2,param3,param4,param5,param6) 122 123 #define OsIf_Trusted_Call_Return(name) Call_##name##_TRUSTED() 124 #define OsIf_Trusted_Call_Return1param(name,param1) Call_##name##_TRUSTED(param1) 125 #define OsIf_Trusted_Call_Return2param(name,param1,param2) Call_##name##_TRUSTED(param1,param2) 126 #define OsIf_Trusted_Call_Return3param(name,param1,param2,param3) Call_##name##_TRUSTED(param1,param2,param3) 127 #define OsIf_Trusted_Call_Return4param(name,param1,param2,param3,param4) Call_##name##_TRUSTED(param1,param2,param3,param4) 128 #define OsIf_Trusted_Call_Return5param(name,param1,param2,param3,param4,param5) Call_##name##_TRUSTED(param1,param2,param3,param4,param5) 129 #define OsIf_Trusted_Call_Return6param(name,param1,param2,param3,param4,param5,param6) Call_##name##_TRUSTED(param1,param2,param3,param4,param5,param6) 130 131 #else /* USING_OS_AUTOSAROS */ 132 /* Baremetal and FreeRTOS */ 133 #define OsIf_Trusted_Call(name) \ 134 ((1UL == Sys_GoToSupervisor()) ? (name(), (void)Sys_GoToUser()) : (name(),(void)0U)) 135 #define OsIf_Trusted_Call1param(name,param) \ 136 ((1UL == Sys_GoToSupervisor()) ? (name(param), (void)Sys_GoToUser()) : (name(param),(void)0U)) 137 #define OsIf_Trusted_Call2params(name,param1,param2) \ 138 ((1UL == Sys_GoToSupervisor()) ? (name(param1,param2), (void)Sys_GoToUser()) : (name(param1,param2),(void)0U)) 139 #define OsIf_Trusted_Call3params(name,param1,param2,param3) \ 140 ((1UL == Sys_GoToSupervisor()) ? (name(param1,param2,param3), (void)Sys_GoToUser()) : (name(param1,param2,param3),(void)0U)) 141 #define OsIf_Trusted_Call4params(name,param1,param2,param3,param4) \ 142 ((1UL == Sys_GoToSupervisor()) ? (name(param1,param2,param3,param4), (void)Sys_GoToUser()) : (name(param1,param2,param3,param4),(void)0U)) 143 #define OsIf_Trusted_Call5params(name,param1,param2,param3,param4,param5) \ 144 ((1UL == Sys_GoToSupervisor()) ? (name(param1,param2,param3,param4,param5), (void)Sys_GoToUser()) : (name(param1,param2,param3,param4,param5),(void)0U)) 145 #define OsIf_Trusted_Call6params(name,param1,param2,param3,param4,param5,param6) \ 146 ((1UL == Sys_GoToSupervisor()) ? (name(param1,param2,param3,param4,param5,param6), (void)Sys_GoToUser()) : (name(param1,param2,param3,param4,param5,param6),(void)0U)) 147 148 #define OsIf_Trusted_Call_Return(name) \ 149 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name()) : Sys_GoToUser_Return(0U, name())) 150 #define OsIf_Trusted_Call_Return1param(name,param) \ 151 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param)) : Sys_GoToUser_Return(0U, name(param))) 152 #define OsIf_Trusted_Call_Return2param(name,param1,param2) \ 153 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param1,param2)) : Sys_GoToUser_Return(0U, name(param1,param2))) 154 #define OsIf_Trusted_Call_Return3param(name,param1,param2,param3) \ 155 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param1,param2,param3)) : Sys_GoToUser_Return(0U, name(param1,param2,param3))) 156 #define OsIf_Trusted_Call_Return4param(name,param1,param2,param3,param4) \ 157 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param1,param2,param3,param4)) : Sys_GoToUser_Return(0U, name(param1,param2,param3,param4))) 158 #define OsIf_Trusted_Call_Return5param(name,param1,param2,param3,param4,param5) \ 159 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param1,param2,param3,param4,param5)) : Sys_GoToUser_Return(0U, name(param1,param2,param3,param4,param5))) 160 #define OsIf_Trusted_Call_Return6param(name,param1,param2,param3,param4,param5,param6) \ 161 ((1UL == Sys_GoToSupervisor()) ? Sys_GoToUser_Return(1U, name(param1,param2,param3,param4,param5,param6)) : Sys_GoToUser_Return(0U, name(param1,param2,param3,param4,param5,param6))) 162 #endif /* USING_OS_AUTOSAROS */ 163 #endif /* MCAL_ENABLE_USER_MODE_SUPPORT */ 164 165 /* 166 * OsIf_GetCoreID 167 */ 168 #ifdef USING_OS_AUTOSAROS 169 #define OsIf_GetCoreID() GetCoreID() 170 #else /* USING_OS_AUTOSAROS */ 171 /* Baremetal and FreeRTOS and ZephyrOS */ 172 #ifdef MCAL_ENABLE_USER_MODE_SUPPORT 173 #define OsIf_GetCoreID() OsIf_Trusted_Call_Return(Sys_GetCoreID) 174 #else 175 /* @implements OsIf_GetCoreID_define */ 176 #define OsIf_GetCoreID() Sys_GetCoreID() 177 #endif 178 #endif 179 180 /* 181 * OsIf_SuspendAllInterrupts 182 * OsIf_ResumeAllInterrupts 183 */ 184 #if (!defined(USING_OS_AUTOSAROS) && !defined(USING_OS_ZEPHYR)) 185 #ifndef MCAL_ENABLE_USER_MODE_SUPPORT /*Bare metal not enable user mode*/ 186 /* Baremetal or FreeRTOS case */ 187 #if (MCAL_PLATFORM_ARM == MCAL_ARM_AARCH64) 188 #define ResumeAllInterrupts() ASM_KEYWORD(" msr DAIFClr,#0x3") 189 #define SuspendAllInterrupts() ASM_KEYWORD(" msr DAIFSet,#0x3") 190 #elif (MCAL_PLATFORM_ARM == MCAL_ARM_AARCH32) || (MCAL_PLATFORM_ARM == MCAL_ARM_RARCH) 191 #define ResumeAllInterrupts() Sys_EL1ResumeInterrupts() 192 #define SuspendAllInterrupts() Sys_EL1SuspendInterrupts() 193 #else 194 #define ResumeAllInterrupts() ASM_KEYWORD(" cpsie i") 195 #define SuspendAllInterrupts() ASM_KEYWORD(" cpsid i") 196 #endif /* MCAL_PLATFORM_ARM == MCAL_ARM_AARCH64 */ 197 #else 198 #if (MCAL_PLATFORM_ARM == MCAL_ARM_AARCH32) || (MCAL_PLATFORM_ARM == MCAL_ARM_RARCH) 199 #define ResumeAllInterrupts() OsIf_Trusted_Call(Sys_EL1ResumeInterrupts) 200 #define SuspendAllInterrupts() OsIf_Trusted_Call(Sys_EL1SuspendInterrupts) 201 #else 202 #define ResumeAllInterrupts() Sys_ResumeInterrupts() 203 #define SuspendAllInterrupts() Sys_SuspendInterrupts() 204 #endif 205 #endif /*MCAL_ENABLE_USER_MODE_SUPPORT */ 206 #elif defined(USING_OS_ZEPHYR) 207 #ifdef MCAL_ENABLE_USER_MODE_SUPPORT 208 #define ResumeAllInterrupts() OsIf_Trusted_Call(OsIf_Interrupts_ResumeAllInterrupts) 209 #define SuspendAllInterrupts() OsIf_Trusted_Call(OsIf_Interrupts_SuspendAllInterrupts) 210 #else 211 #define ResumeAllInterrupts() OsIf_Interrupts_ResumeAllInterrupts() 212 #define SuspendAllInterrupts() OsIf_Interrupts_SuspendAllInterrupts() 213 #endif /* MCAL_ENABLE_USER_MODE_SUPPORT */ 214 #endif /* !defined(USING_OS_AUTOSAROS) && !defined(USING_OS_ZEPHYR) */ 215 216 /* @implements OsIf_SuspendAllInterrupts_define */ 217 #define OsIf_SuspendAllInterrupts() SuspendAllInterrupts() 218 /* @implements OsIf_ResumeAllInterrupts_define */ 219 #define OsIf_ResumeAllInterrupts() ResumeAllInterrupts() 220 221 /* 222 * ISR macro definition 223 */ 224 #ifdef USING_OS_AUTOSAROS 225 /* ISR() macro defined by Autosar OS*/ 226 #else 227 /* Baremetal or FreeRTOS case */ 228 #if defined (USE_SW_VECTOR_MODE) 229 #define ISR(IsrName) void IsrName(void) 230 #else 231 #define ISR(IsrName) INTERRUPT_FUNC void IsrName(void) 232 #endif /* defined (USE_SW_VECTOR_MODE) */ 233 #endif /* USING_OS_AUTOSAROS */ 234 235 /*================================================================================================== 236 * ENUMS 237 ==================================================================================================*/ 238 239 /*================================================================================================== 240 * STRUCTURES AND OTHER TYPEDEFS 241 ==================================================================================================*/ 242 243 /*================================================================================================== 244 * GLOBAL VARIABLE DECLARATIONS 245 ==================================================================================================*/ 246 247 /*================================================================================================== 248 * FUNCTION PROTOTYPES 249 ==================================================================================================*/ 250 251 #ifdef __cplusplus 252 } 253 #endif 254 255 /** @} */ 256 257 #endif /* OSIF_INTERNAL_H */ 258