1 /* 2 * Copyright 2020-2023 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 /** 8 * @file 9 * 10 * @addtogroup wkpu_icu_ip WKPU IPL 11 * @{ 12 */ 13 14 #ifdef __cplusplus 15 extern "C"{ 16 #endif 17 18 /*================================================================================================== 19 * INCLUDE FILES 20 * 1) system and project includes 21 * 2) needed interfaces from external units 22 * 3) internal and external interfaces from this unit 23 ==================================================================================================*/ 24 #include "Std_Types.h" 25 #include "Wkpu_Ip.h" 26 #include "Wkpu_Ip_Irq.h" 27 28 #include "SchM_Icu.h" 29 /*================================================================================================== 30 * LOCAL MACROS 31 ==================================================================================================*/ 32 33 #define WKPU_IP_IRQ_VENDOR_ID_C 43 34 #define WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C 4 35 #define WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C 7 36 #define WKPU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C 0 37 #define WKPU_IP_IRQ_SW_MAJOR_VERSION_C 3 38 #define WKPU_IP_IRQ_SW_MINOR_VERSION_C 0 39 #define WKPU_IP_IRQ_SW_PATCH_VERSION_C 0 40 41 /*================================================================================================== 42 * FILE VERSION CHECKS 43 ==================================================================================================*/ 44 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 45 /* Check if header file and Std_Types.h file are of the same Autosar version */ 46 #if ((WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != STD_AR_RELEASE_MAJOR_VERSION) || \ 47 (WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != STD_AR_RELEASE_MINOR_VERSION)) 48 #error "AutoSar Version Numbers of Wkpu_Ip_Irq.c and Std_Types.h are different" 49 #endif 50 /* Check if this header file and SchM_Icu.h file are of the same Autosar version */ 51 #if ((WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != SCHM_ICU_AR_RELEASE_MAJOR_VERSION) || \ 52 (WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != SCHM_ICU_AR_RELEASE_MINOR_VERSION)) 53 #error "AutoSar Version Numbers of Wkpu_Ip_Irq.c and SchM_Icu.h are different" 54 #endif 55 #endif 56 57 /* Check if source file and ICU header file are of the same vendor */ 58 #if (WKPU_IP_IRQ_VENDOR_ID_C != WKPU_IP_VENDOR_ID) 59 #error "Wkpu_Ip_Irq.c and Wkpu_Ip.h have different vendor IDs" 60 #endif 61 /* Check if source file and ICU header file are of the same AutoSar version */ 62 #if ((WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != WKPU_IP_AR_RELEASE_MAJOR_VERSION) || \ 63 (WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != WKPU_IP_AR_RELEASE_MINOR_VERSION) || \ 64 (WKPU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != WKPU_IP_AR_RELEASE_REVISION_VERSION)) 65 #error "AutoSar Version Numbers of Wkpu_Ip_Irq.c and Wkpu_Ip.h are different" 66 #endif 67 /* Check if source file and ICU header file are of the same Software version */ 68 #if ((WKPU_IP_IRQ_SW_MAJOR_VERSION_C != WKPU_IP_SW_MAJOR_VERSION) || \ 69 (WKPU_IP_IRQ_SW_MINOR_VERSION_C != WKPU_IP_SW_MINOR_VERSION) || \ 70 (WKPU_IP_IRQ_SW_PATCH_VERSION_C != WKPU_IP_SW_PATCH_VERSION)) 71 #error "Software Version Numbers of Wkpu_Ip_Irq.c and Wkpu_Ip.h are different" 72 #endif 73 74 /* Check if source file and ICU header file are of the same vendor */ 75 #if (WKPU_IP_IRQ_VENDOR_ID_C != WKPU_IP_IRQ_VENDOR_ID) 76 #error "Wkpu_Ip_Irq.c and Wkpu_Ip_Irq.h have different vendor IDs" 77 #endif 78 /* Check if source file and ICU header file are of the same AutoSar version */ 79 #if ((WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION_C != WKPU_IP_IRQ_AR_RELEASE_MAJOR_VERSION) || \ 80 (WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION_C != WKPU_IP_IRQ_AR_RELEASE_MINOR_VERSION) || \ 81 (WKPU_IP_IRQ_AR_RELEASE_REVISION_VERSION_C != WKPU_IP_IRQ_AR_RELEASE_REVISION_VERSION)) 82 #error "AutoSar Version Numbers of Wkpu_Ip_Irq.c and Wkpu_Ip_Irq.h are different" 83 #endif 84 /* Check if source file and ICU header file are of the same Software version */ 85 #if ((WKPU_IP_IRQ_SW_MAJOR_VERSION_C != WKPU_IP_IRQ_SW_MAJOR_VERSION) || \ 86 (WKPU_IP_IRQ_SW_MINOR_VERSION_C != WKPU_IP_IRQ_SW_MINOR_VERSION) || \ 87 (WKPU_IP_IRQ_SW_PATCH_VERSION_C != WKPU_IP_IRQ_SW_PATCH_VERSION)) 88 #error "Software Version Numbers of Wkpu_Ip_Irq.c and Wkpu_Ip_Irq.h are different" 89 #endif 90 91 /*================================================================================================== 92 * GLOBAL CONSTANTS 93 ==================================================================================================*/ 94 95 /*================================================================================================== 96 * GLOBAL FUNCTIONS 97 ==================================================================================================*/ 98 99 /*================================================================================================== 100 * GLOBAL VARIABLES 101 ==================================================================================================*/ 102 #if (STD_ON == WKPU_IP_USED) 103 104 #define ICU_START_SEC_VAR_CLEARED_UNSPECIFIED 105 #include "Icu_MemMap.h" 106 /* Table of initilized Wkpu channels */ 107 #if !defined(WKPU_DERIVATIVE_SUPPORT_ONLY_NMI) 108 /* Table of initilized WKPU channels */ 109 extern Wkpu_Ip_State Wkpu_Ip_u32ChState[WKPU_IP_NUM_OF_CHANNELS_USED]; 110 #endif /* WKPU_DERIVATIVE_SUPPORT_ONLY_NMI */ 111 #define ICU_STOP_SEC_VAR_CLEARED_UNSPECIFIED 112 #include "Icu_MemMap.h" 113 114 #define ICU_START_SEC_VAR_INIT_8 115 #include "Icu_MemMap.h" 116 /* This array stores the positions in the Wkpu_Ip_u32ChState array of the configured Wkpu channels. */ 117 extern uint8 Wkpu_Ip_IndexInChState[WKPU_IP_NUM_OF_CHANNELS]; 118 #define ICU_STOP_SEC_VAR_INIT_8 119 #include "Icu_MemMap.h" 120 /*================================================================================================== 121 * LOCAL FUNCTION PROTOTYPES 122 ==================================================================================================*/ 123 #define ICU_START_SEC_CODE 124 #include "Icu_MemMap.h" 125 126 #if !defined(WKPU_DERIVATIVE_SUPPORT_ONLY_NMI) 127 128 #if (defined(WKPU_ICU_SINGLE_INTERRUPT) && (WKPU_ICU_SINGLE_INTERRUPT == STD_ON)) 129 static inline void Wkpu_Ip_Callback(uint8 hwChannel); 130 #endif 131 132 #endif /* WKPU_DERIVATIVE_SUPPORT_ONLY_NMI */ 133 134 #if (defined(WKPU_ICU_SINGLE_INTERRUPT) && (WKPU_ICU_SINGLE_INTERRUPT == STD_ON)) 135 136 static inline void Wkpu_Icu_Ip_ProcessSingleInterrupt(void); 137 138 #endif /*defined WKPU_ICU_SINGLE_INTERRUPT*/ 139 140 141 /*================================================================================================== 142 * LOCAL FUNCTIONS 143 ==================================================================================================*/ 144 145 #if (defined(WKPU_ICU_SINGLE_INTERRUPT) && (WKPU_ICU_SINGLE_INTERRUPT == STD_ON)) 146 /*==================================================================================================*/ 147 /** 148 * @brief Wkpu_Icu_Ip_ProcessSingleInterrupt 149 * @details 150 * 151 * @param[in] u8FirstHwChannel - first IRQ HW Channel from the HW group 152 * 153 * @retval None 154 * @implements Wkpu_Ip_ProcessSingleInterrupt_Activity 155 */ Wkpu_Icu_Ip_ProcessSingleInterrupt(void)156static inline void Wkpu_Icu_Ip_ProcessSingleInterrupt(void) 157 { 158 uint8 u8WkpuChannel = 0x0U; 159 uint32 u32ChannelMask = 0x1U; 160 uint32 u32reg_WKPU_WISR = Wkpu_Ip_pBase[0U]->WISR; 161 uint32 u32reg_WKPU_WIER = Wkpu_Ip_pBase[0U]->IRER; 162 163 /* Select which channels will be serviced - only the enabled irq ones*/ 164 u32reg_WKPU_WISR &= u32reg_WKPU_WIER; 165 166 for (u8WkpuChannel = 0; u8WkpuChannel < (uint32)WKPU_IP_NUM_OF_CHANNELS_IN_ONE_REG; u8WkpuChannel++) 167 { 168 if (0x0U != (u32reg_WKPU_WISR & u32ChannelMask)) 169 { 170 /* Clear pending interrupt serviced */ 171 Wkpu_Ip_pBase[0U]->WISR = u32reg_WKPU_WISR & u32ChannelMask; 172 173 Wkpu_Ip_Callback(u8WkpuChannel); 174 } 175 u32ChannelMask <<= (uint32)1U; 176 } 177 178 #ifdef WKPU_IP_64_CH_USED 179 /*Get WKPU32 - WKPU63 interrupt status flag*/ 180 u8WkpuChannel = 0x0U; 181 u32ChannelMask = 0x1U; 182 u32reg_WKPU_WISR = Wkpu_Ip_pBase[0U]->WISR_64; 183 u32reg_WKPU_WIER = Wkpu_Ip_pBase[0U]->IRER_64; 184 185 /* Select which channels will be serviced - only the enabled irq ones*/ 186 u32reg_WKPU_WISR &= u32reg_WKPU_WIER; 187 188 for (u8WkpuChannel = 0; u8WkpuChannel < (uint32)WKPU_IP_NUM_OF_CHANNELS_IN_ONE_REG; u8WkpuChannel++) 189 { 190 if (0x0U != (u32reg_WKPU_WISR & u32ChannelMask)) 191 { 192 /* Clear pending interrupt serviced */ 193 Wkpu_Ip_pBase[0U]->WISR_64 = u32reg_WKPU_WISR & u32ChannelMask; 194 195 Wkpu_Ip_Callback(u8WkpuChannel+ 32U); 196 } 197 u32ChannelMask <<= (uint32)1U; 198 } 199 #endif 200 } 201 #endif /*defined WKPU_ICU_SINGLE_INTERRUPT*/ 202 203 /*================================================================================================== 204 * GLOBAL FUNCTIONS 205 ==================================================================================================*/ 206 207 #if (defined(WKPU_ICU_SINGLE_INTERRUPT) && (WKPU_ICU_SINGLE_INTERRUPT == STD_ON)) 208 /*==================================================================================================*/ 209 /** 210 * @brief Interrupt handler for WKPU channels : 0 to 31 211 * @details Process the interrupt of WKPU channels 0 to 31 for platforms with only one interrupt line 212 * 213 * @remarks This will be defined only if any of WKPU channels 0 to 31 are configured 214 */ 215 /*==================================================================================================*/ ISR(WKPU_EXT_IRQ_SINGLE_ISR)216ISR(WKPU_EXT_IRQ_SINGLE_ISR) 217 { 218 Wkpu_Icu_Ip_ProcessSingleInterrupt(); 219 } 220 #endif /* defined WKPU_ICU_SINGLE_INTERRUPT */ 221 222 #if !defined(WKPU_DERIVATIVE_SUPPORT_ONLY_NMI) 223 224 #if (defined(WKPU_ICU_SINGLE_INTERRUPT) && (WKPU_ICU_SINGLE_INTERRUPT == STD_ON)) Wkpu_Ip_Callback(uint8 hwChannel)225static inline void Wkpu_Ip_Callback(uint8 hwChannel) 226 { 227 if(((boolean)TRUE == Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].chInit) && \ 228 (NULL_PTR != Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].callback)) 229 { 230 Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].callback(Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].callbackParam, FALSE); 231 } 232 else 233 { 234 /* Calling Notification for the IPL channel */ 235 if (((boolean)TRUE == Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].chInit) && \ 236 (NULL_PTR != Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[(uint8)hwChannel]].WkpuChannelNotification) && \ 237 ((boolean)TRUE == Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[hwChannel]].notificationEnable)) 238 { 239 Wkpu_Ip_u32ChState[Wkpu_Ip_IndexInChState[(uint8)hwChannel]].WkpuChannelNotification(); 240 } 241 } 242 } 243 #endif 244 #endif /* WKPU_DERIVATIVE_SUPPORT_ONLY_NMI */ 245 246 #define ICU_STOP_SEC_CODE 247 #include "Icu_MemMap.h" 248 249 #endif /* WKPU_IP_USED */ 250 251 #ifdef __cplusplus 252 } 253 #endif 254 255 /** @} */ 256 257