1 /* 2 * Copyright 2021-2022 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef STM_IP_H 8 #define STM_IP_H 9 10 /** 11 * @file Stm_Ip.h 12 * 13 * @addtogroup stm_ip Stm IPL 14 * 15 * @{ 16 */ 17 18 #ifdef __cplusplus 19 extern "C"{ 20 #endif 21 22 /*================================================================================================== 23 * INCLUDE FILES 24 * 1) system and project includes 25 * 2) needed interfaces from external units 26 * 3) internal and external interfaces from this unit 27 ==================================================================================================*/ 28 #include "Stm_Ip_Types.h" 29 #include "Stm_Ip_Cfg.h" 30 #include "OsIf.h" 31 #if STM_IP_DEV_ERROR_DETECT == STD_ON 32 #include "Devassert.h" 33 #endif 34 #if (STM_IP_ENABLE_USER_MODE_SUPPORT == STD_ON) 35 #include "Reg_eSys.h" 36 #endif 37 #include "SchM_Gpt.h" 38 /*================================================================================================== 39 * SOURCE FILE VERSION INFORMATION 40 ==================================================================================================*/ 41 /** 42 * @internal 43 * @brief Defines used for file version checks 44 */ 45 #define STM_IP_VENDOR_ID 43 46 #define STM_IP_AR_RELEASE_MAJOR_VERSION 4 47 #define STM_IP_AR_RELEASE_MINOR_VERSION 7 48 #define STM_IP_AR_RELEASE_REVISION_VERSION 0 49 #define STM_IP_SW_MAJOR_VERSION 0 50 #define STM_IP_SW_MINOR_VERSION 9 51 #define STM_IP_SW_PATCH_VERSION 0 52 53 54 /*================================================================================================== 55 * FILE VERSION CHECKS 56 ==================================================================================================*/ 57 #if (STM_IP_VENDOR_ID != STM_IP_TYPES_VENDOR_ID) 58 #error "Stm_Ip.h and Stm_Ip_Types.h have different vendor ids" 59 #endif 60 /* Check if header file and Gpt header file are of the same Autosar version */ 61 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != STM_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \ 62 (STM_IP_AR_RELEASE_MINOR_VERSION != STM_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \ 63 (STM_IP_AR_RELEASE_REVISION_VERSION != STM_IP_TYPES_AR_RELEASE_REVISION_VERSION) \ 64 ) 65 #error "AutoSar Version Numbers of Stm_Ip.h and Stm_Ip_Types.h are different" 66 #endif 67 /* Check if source file and GPT header file are of the same Software version */ 68 #if ((STM_IP_SW_MAJOR_VERSION != STM_IP_TYPES_SW_MAJOR_VERSION) || \ 69 (STM_IP_SW_MINOR_VERSION != STM_IP_TYPES_SW_MINOR_VERSION) || \ 70 (STM_IP_SW_PATCH_VERSION != STM_IP_TYPES_SW_PATCH_VERSION) \ 71 ) 72 #error "Software Version Numbers of Stm_Ip.h and Stm_Ip_Types.h are different" 73 #endif 74 75 #if (STM_IP_VENDOR_ID != STM_IP_VENDOR_ID_CFG) 76 #error "Stm_Ip.h and Stm_Ip_Cfg.h have different vendor ids" 77 #endif 78 /* Check if STM_IP header file and STM_IP_Cfg header file are of the same Autosar version */ 79 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != STM_IP_AR_RELEASE_MAJOR_VERSION_CFG) || \ 80 (STM_IP_AR_RELEASE_MINOR_VERSION != STM_IP_AR_RELEASE_MINOR_VERSION_CFG) || \ 81 (STM_IP_AR_RELEASE_REVISION_VERSION != STM_IP_AR_RELEASE_REVISION_VERSION_CFG) \ 82 ) 83 #error "AutoSar Version Numbers of Stm_Ip.h and Stm_Ip_Cfg.h are different" 84 #endif 85 /* Check if Stm_Ip file and Stm_Ip_Cfg header file are of the same Software version */ 86 #if ((STM_IP_SW_MAJOR_VERSION != STM_IP_SW_MAJOR_VERSION_CFG) || \ 87 (STM_IP_SW_MINOR_VERSION != STM_IP_SW_MINOR_VERSION_CFG) || \ 88 (STM_IP_SW_PATCH_VERSION != STM_IP_SW_PATCH_VERSION_CFG) \ 89 ) 90 #error "Software Version Numbers of Stm_Ip.h and Stm_Ip_Cfg.h are different" 91 #endif 92 93 94 #if (STM_IP_ENABLE_USER_MODE_SUPPORT == STD_ON) 95 /* Check if header file and StandardTypes.h file are of the same Autosar version */ 96 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 97 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != REG_ESYS_AR_RELEASE_MAJOR_VERSION) || \ 98 (STM_IP_AR_RELEASE_MINOR_VERSION != REG_ESYS_AR_RELEASE_MINOR_VERSION)) 99 #error "AutoSar Version Numbers of Stm_Ip.h and Reg_eSys.h are different" 100 #endif 101 #endif 102 #endif 103 104 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 105 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != SCHM_GPT_AR_RELEASE_MAJOR_VERSION) || \ 106 (STM_IP_AR_RELEASE_MINOR_VERSION != SCHM_GPT_AR_RELEASE_MINOR_VERSION)) 107 #error "AutoSar Version Numbers of Stm_Ip.h and SchM_Gpt.h are different" 108 #endif 109 /* Check if this header file and OsIf.h file are of the same Autosar version */ 110 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \ 111 (STM_IP_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION)) 112 #error "AutoSar Version Numbers of Stm_Ip.h and OsIf.h are different" 113 #endif 114 #endif 115 116 #if STM_IP_DEV_ERROR_DETECT == STD_ON 117 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK 118 #if ((STM_IP_AR_RELEASE_MAJOR_VERSION != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \ 119 (STM_IP_AR_RELEASE_MINOR_VERSION != DEVASSERT_AR_RELEASE_MINOR_VERSION)) 120 #error "AutoSar Version Numbers of Stm_Ip.h and Devassert.h are different" 121 #endif 122 #endif 123 #endif 124 /*================================================================================================== 125 * CONSTANT-LIKE DEFINES 126 ==================================================================================================*/ 127 128 /*================================================================================================== 129 * FUNCTION-LIKE DEFINES(MACROS) 130 ==================================================================================================*/ 131 #if (STM_IP_USED == STD_ON) 132 133 /*================================================================================================== 134 * ENUMS 135 ==================================================================================================*/ 136 137 /*================================================================================================== 138 * STRUCTURES AND OTHER TYPEDEFS 139 ==================================================================================================*/ 140 141 /*================================================================================================== 142 * GLOBAL VARIABLE DECLARATIONS 143 ==================================================================================================*/ 144 /** 145 * @internal 146 * @brief MemMap section 147 */ 148 #define GPT_START_SEC_VAR_CLEARED_32 149 #include "Gpt_MemMap.h" 150 151 extern uint32 Stm_Ip_u32TargetValue[STM_INSTANCE_COUNT][STM_CHANNEL_COUNT]; 152 #if ((defined STM_0_ISR_USED) || (defined STM_1_ISR_USED) || (defined STM_2_ISR_USED) || (defined STM_3_ISR_USED) || \ 153 (defined STM_4_ISR_USED) || (defined STM_5_ISR_USED) || (defined STM_6_ISR_USED) || (defined STM_7_ISR_USED) || \ 154 (defined STM_8_ISR_USED) || (defined STM_9_ISR_USED) || (defined STM_10_ISR_USED) || (defined STM_11_ISR_USED) || \ 155 (defined STM_12_ISR_USED)|| (defined SMU_STM_0_ISR_USED) || (defined SMU_STM_2_ISR_USED) || \ 156 (defined CE_STM_0_ISR_USED) || (defined CE_STM_1_ISR_USED) || (defined CE_STM_2_ISR_USED) || \ 157 (defined RTU0_STM_0_ISR_USED) || (defined RTU0_STM_1_ISR_USED) || (defined RTU0_STM_2_ISR_USED) || (defined RTU0_STM_3_ISR_USED) || \ 158 (defined RTU1_STM_0_ISR_USED) || (defined RTU1_STM_1_ISR_USED) || (defined RTU1_STM_2_ISR_USED) || (defined RTU1_STM_3_ISR_USED)) 159 extern uint32 Stm_Ip_u32NextTargetValue[STM_INSTANCE_COUNT][STM_CHANNEL_COUNT]; 160 #endif 161 162 /** 163 * @internal 164 * @brief MemMap section 165 */ 166 #define GPT_STOP_SEC_VAR_CLEARED_32 167 #include "Gpt_MemMap.h" 168 169 /*================================================================================================== 170 * FUNCTION PROTOTYPES 171 ==================================================================================================*/ 172 /** 173 * @internal 174 * @brief MemMap section 175 */ 176 #define GPT_START_SEC_CODE 177 #include "Gpt_MemMap.h" 178 179 uint32 Stm_Ip_GetInterruptFlag(uint8 instance, uint8 channel); 180 extern STM_Type * const stmBase[STM_INSTANCE_COUNT]; 181 /*================================================================================================*/ 182 /** 183 * @brief Function Name : Stm_Ip_Init 184 * @details Initializes the STM instance. This functions is called for each STM hw Instance and: 185 * - sets the counter value 186 * - configures the freeze mode 187 * - sets the prescaler value 188 * - enables the STM counter 189 * 190 * @param[in] instance STM hw instance number 191 * @param[in] configPtr Pointer to a selected configuration structure 192 * @return void 193 * @pre The data structure including the configuration set required for initializing the GPT driver 194 */ 195 void Stm_Ip_Init(uint8 instance, const Stm_Ip_InstanceConfigType *configPtr); 196 /*================================================================================================*/ 197 /** 198 * @brief Function Name : Stm_Ip_InitChannel 199 * @details Initializes the STM channels. This functions is called for each STM hw channel and: 200 * - disables hw channel 201 * - clears interrupt clear 202 * - sets compare value to 0 203 * - initializes the state sructure for common process interrupt 204 * 205 * @param[in] instance STM hw instance number 206 * @param[in] configPtr Pointer to a selected configuration structure 207 * @return void 208 * @pre The data structure including the configuration set required for initializing the GPT driver 209 */ 210 void Stm_Ip_InitChannel(uint8 instance, const Stm_Ip_ChannelConfigType *configPtr); 211 /*================================================================================================*/ 212 /** 213 * @brief Function Name : Stm_Ip_Deinit 214 * @details De-Initializes the STM module. This functions is called for each STM hw instance and: 215 * - resets all channels to default 216 * - sets to default prescaler bits 217 * - disables the STM counter 218 * 219 * @param[in] instance STM hw instance number 220 * @return void 221 * @pre The data structure including the configuration set required for initializing the GPT driver. 222 */ 223 void Stm_Ip_Deinit(uint8 instance); 224 /*================================================================================================*/ 225 /** 226 * @brief Function Name : Stm_Ip_StartCounting 227 * @details This function is called for starting the Stm timer channel 228 * - reads the current counter register value and sets the compare register to the sum of 229 * counter register value plus the timeout value 230 * - enables the STM channel 231 * 232 * @param[in] instance STM hw instance number 233 * @param[in] channel Stm channel 234 * @param[in] compareValue Compare value 235 * @return void 236 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel. 237 */ 238 void Stm_Ip_StartCounting(uint8 instance, uint8 channel, uint32 compareValue); 239 /*================================================================================================*/ 240 #if STM_IP_ABSOLUTE_COUNTING_API == STD_ON 241 /** 242 * @brief Function Name : Stm_Ip_StartCountingAbsolute 243 * @details This function is called for starting the Stm timer channel 244 * - sets the compare value without adding the current counter value to the timeout value 245 * - enables the STM channel 246 * 247 * @param[in] instance STM hw instance number 248 * @param[in] channel Stm channel 249 * @param[in] compareValue Compare value 250 * @return void 251 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel. 252 * @implements Stm_Ip_StartCountingAbsolute_Activity 253 */ 254 void Stm_Ip_StartCountingAbsolute(uint8 instance, uint8 channel, uint32 compareValue); 255 #endif 256 /*================================================================================================*/ 257 /** 258 * @brief Function Name : Stm_Ip_StartTimer 259 * @details This function is called for setting a new start counter value and enables the STM counter: 260 * - sets the new counter value 261 * - enables the STM counter 262 * 263 * @param[in] instance Stm hw instance 264 * @param[in] startValue counter value 265 * @return void 266 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel. 267 * 268 */ 269 void Stm_Ip_StartTimer(uint8 instance, uint32 startValue); 270 /*================================================================================================*/ 271 /** 272 * @brief Function Name : Stm_Ip_StopTimer 273 * @details Gpt driver function for stopping the Stm counter. 274 * - disables the STM counter 275 * 276 * @param[in] instance Stm hw instance 277 * @return void 278 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel. 279 */ 280 void Stm_Ip_StopTimer(uint8 instance); 281 /*================================================================================================*/ 282 /** 283 * @brief Function Name : Stm_Ip_EnableChannel 284 * @details Enables the channel selected. 285 * 286 * @param[in] instance Stm hw instance 287 * @param[in] channel Stm hw channel 288 * @return void 289 * @pre The driver needs to be initialized. 290 */ 291 void Stm_Ip_EnableChannel(uint8 instance, uint8 channel); 292 /*================================================================================================*/ 293 /** 294 * @brief Function Name : Stm_Ip_DisableChannel 295 * @details Disables the channel selected. 296 * 297 * @param[in] instance Stm hw instance 298 * @param[in] channel Stm hw channel 299 * @return void 300 * @pre The driver needs to be initialized. 301 */ 302 void Stm_Ip_DisableChannel(uint8 instance, uint8 channel); 303 /*================================================================================================*/ 304 /** 305 * @brief Function Name : Stm_Ip_GetCounterValue 306 * @details Gets the counter value. 307 * 308 * @param[in] instance Stm hw instance 309 * 310 * @return currentCounterValue current counter value 311 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel. 312 */ 313 uint32 Stm_Ip_GetCounterValue(uint8 instance); 314 /*================================================================================================*/ 315 /** 316 * @brief Function Name : Stm_Ip_GetCompareValue 317 * @details Gets the compare value for selected channel 318 * 319 * @param[in] instance Stm hw instance 320 * @param[in] channel Stm hw channel 321 * 322 * @return currentCompareValue compare value for selected channel 323 * @pre The driver needs to be initialized. 324 */ 325 uint32 Stm_Ip_GetCompareValue(uint8 instance, uint8 channel); 326 /*================================================================================================*/ 327 #if (STM_IP_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON) 328 /** 329 * @brief The function changes the Stm compare register value. 330 * @details This function: 331 * - Write next timeout to local variable 332 * 333 * @param[in] instance Stm hw instance 334 * @param[in] channel Channel 335 * @param[in] value Channel timeout value 336 * @return void 337 * @pre The driver needs to be initialized. 338 */ 339 void Stm_Ip_ChangeNextTimeoutValue(uint8 instance, uint8 channel, uint32 value); 340 #endif 341 /*================================================================================================*/ 342 #if (STM_IP_SET_CLOCK_MODE == STD_ON) 343 /** 344 * @brief The function changes the STM prescaler value. 345 * @details This function sets the STM prescaler based on the input mode. 346 * 347 * @param[in] instance Stm hw instance 348 * @param[in] clockMode STM_IP_CLOCKMODE_NORMAL or STM_IP_CLOCKMODE_ALTERNATE 349 * 350 * @return void 351 * @pre The driver needs to be initialized. On/Off by the configuration parameter: GPT_DUAL_CLOCK_MODE 352 * @implements Stm_Ip_SetClockMode_Activity 353 */ 354 void Stm_Ip_SetClockMode(uint8 instance, Stm_Ip_ClockModeType clockMode); 355 #endif 356 /*================================================================================================*/ 357 /** 358 * @brief This function sets the STM prescaler, freeze bit and enables counter 359 * @details This function start counting with predefined values(like a free running timer) 360 * 361 * @param[in] instance Stm hw instance 362 * @param[in] prescaler Prescaler value 363 * @param[in] freezeEnable Freeze value 364 * @return void 365 * @pre The driver needs to be initialized 366 * @implements 367 */ 368 void Stm_Ip_PredefCounting(uint8 instance, uint8 prescaler, boolean freezeEnable); 369 370 /** 371 * @internal 372 * @brief MemMap section 373 */ 374 #define GPT_STOP_SEC_CODE 375 #include "Gpt_MemMap.h" 376 377 #endif /* STM_IP_USED == STD_ON */ 378 379 #ifdef __cplusplus 380 } 381 #endif 382 /** @} */ 383 #endif/*STM_IP_H*/ 384