1 /*
2 * Copyright 2021-2023 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 1
50 #define STM_IP_SW_MINOR_VERSION 0
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 Reg_eSys.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[GPT_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 defined(RTU2_STM_0_ISR_USED) || defined(RTU2_STM_1_ISR_USED) || defined(RTU2_STM_2_ISR_USED) || defined(RTU2_STM_3_ISR_USED) || \
160 defined(RTU3_STM_0_ISR_USED) || defined(RTU3_STM_1_ISR_USED) || defined(RTU3_STM_2_ISR_USED) || defined(RTU3_STM_3_ISR_USED) || \
161 defined(CRS_STM_0_ISR_USED) || \
162 defined(RTU0_COS_STM_0_CH_0_ISR_USED) || defined(RTU0_COS_STM_0_CH_1_ISR_USED) || defined(RTU0_COS_STM_0_CH_2_ISR_USED) || defined(RTU0_COS_STM_0_CH_3_ISR_USED) || \
163 defined(RTU0_COS_STM_1_CH_0_ISR_USED) || defined(RTU0_COS_STM_1_CH_1_ISR_USED) || defined(RTU0_COS_STM_1_CH_2_ISR_USED) || defined(RTU0_COS_STM_1_CH_3_ISR_USED) || \
164 defined(RTU0_COS_STM_2_CH_0_ISR_USED) || defined(RTU0_COS_STM_2_CH_1_ISR_USED) || defined(RTU0_COS_STM_2_CH_2_ISR_USED) || defined(RTU0_COS_STM_2_CH_3_ISR_USED) || \
165 defined(RTU0_COS_STM_3_CH_0_ISR_USED) || defined(RTU0_COS_STM_3_CH_1_ISR_USED) || defined(RTU0_COS_STM_3_CH_2_ISR_USED) || defined(RTU0_COS_STM_3_CH_3_ISR_USED) || \
166 defined(RTU1_COS_STM_0_CH_0_ISR_USED) || defined(RTU1_COS_STM_0_CH_1_ISR_USED) || defined(RTU1_COS_STM_0_CH_2_ISR_USED) || defined(RTU1_COS_STM_0_CH_3_ISR_USED) || \
167 defined(RTU1_COS_STM_1_CH_0_ISR_USED) || defined(RTU1_COS_STM_1_CH_1_ISR_USED) || defined(RTU1_COS_STM_1_CH_2_ISR_USED) || defined(RTU1_COS_STM_1_CH_3_ISR_USED) || \
168 defined(RTU1_COS_STM_2_CH_0_ISR_USED) || defined(RTU1_COS_STM_2_CH_1_ISR_USED) || defined(RTU1_COS_STM_2_CH_2_ISR_USED) || defined(RTU1_COS_STM_2_CH_3_ISR_USED) || \
169 defined(RTU1_COS_STM_3_CH_0_ISR_USED) || defined(RTU1_COS_STM_3_CH_1_ISR_USED) || defined(RTU1_COS_STM_3_CH_2_ISR_USED) || defined(RTU1_COS_STM_3_CH_3_ISR_USED) || \
170 defined(RTU2_COS_STM_0_CH_0_ISR_USED) || defined(RTU2_COS_STM_0_CH_1_ISR_USED) || defined(RTU2_COS_STM_0_CH_2_ISR_USED) || defined(RTU2_COS_STM_0_CH_3_ISR_USED) || \
171 defined(RTU2_COS_STM_1_CH_0_ISR_USED) || defined(RTU2_COS_STM_1_CH_1_ISR_USED) || defined(RTU2_COS_STM_1_CH_2_ISR_USED) || defined(RTU2_COS_STM_1_CH_3_ISR_USED) || \
172 defined(RTU2_COS_STM_2_CH_0_ISR_USED) || defined(RTU2_COS_STM_2_CH_1_ISR_USED) || defined(RTU2_COS_STM_2_CH_2_ISR_USED) || defined(RTU2_COS_STM_2_CH_3_ISR_USED) || \
173 defined(RTU2_COS_STM_3_CH_0_ISR_USED) || defined(RTU2_COS_STM_3_CH_1_ISR_USED) || defined(RTU2_COS_STM_3_CH_2_ISR_USED) || defined(RTU2_COS_STM_3_CH_3_ISR_USED) || \
174 defined(RTU3_COS_STM_0_CH_0_ISR_USED) || defined(RTU3_COS_STM_0_CH_1_ISR_USED) || defined(RTU3_COS_STM_0_CH_2_ISR_USED) || defined(RTU3_COS_STM_0_CH_3_ISR_USED) || \
175 defined(RTU3_COS_STM_1_CH_0_ISR_USED) || defined(RTU3_COS_STM_1_CH_1_ISR_USED) || defined(RTU3_COS_STM_1_CH_2_ISR_USED) || defined(RTU3_COS_STM_1_CH_3_ISR_USED) || \
176 defined(RTU3_COS_STM_2_CH_0_ISR_USED) || defined(RTU3_COS_STM_2_CH_1_ISR_USED) || defined(RTU3_COS_STM_2_CH_2_ISR_USED) || defined(RTU3_COS_STM_2_CH_3_ISR_USED) || \
177 defined(RTU3_COS_STM_3_CH_0_ISR_USED) || defined(RTU3_COS_STM_3_CH_1_ISR_USED) || defined(RTU3_COS_STM_3_CH_2_ISR_USED) || defined(RTU3_COS_STM_3_CH_3_ISR_USED) )
178 extern uint32 Stm_Ip_u32NextTargetValue[GPT_STM_INSTANCE_COUNT][STM_CHANNEL_COUNT];
179 #endif
180
181 /**
182 * @internal
183 * @brief MemMap section
184 */
185 #define GPT_STOP_SEC_VAR_CLEARED_32
186 #include "Gpt_MemMap.h"
187
188
189 #define GPT_START_SEC_CONST_UNSPECIFIED
190 #include "Gpt_MemMap.h"
191
192 /** @brief Table of base addresses for STM instances. */
193 extern STM_Type * const stmBase[];
194
195 #define GPT_STOP_SEC_CONST_UNSPECIFIED
196 #include "Gpt_MemMap.h"
197
198 /*==================================================================================================
199 * FUNCTION PROTOTYPES
200 ==================================================================================================*/
201 /**
202 * @internal
203 * @brief MemMap section
204 */
205 #define GPT_START_SEC_CODE
206 #include "Gpt_MemMap.h"
207
208 /**
209 * @brief
210 * Function Name : Stm_Ip_GetInterruptStatusFlag
211 * Description : Get the state of Channel Interrupt Status Flag (CIF): channel interrupt registers (CIR0 - CIR3)
212 *
213 * @param[in] instance STM hw instance number
214 * @param[in] channel STM hw channel number
215 *
216 * @return TRUE if a Channel Interrupt has occurred, FALSE otherwise
217 * @pre The driver needs to be initialized.
218 */
Stm_Ip_GetInterruptStatusFlag(uint8 instance,uint8 channel)219 static inline boolean Stm_Ip_GetInterruptStatusFlag(uint8 instance, uint8 channel)
220 {
221 return (0U != (stmBase[instance]->CHANNEL[channel].CIR & STM_CIR_CIF_MASK)) ? TRUE : FALSE;
222 }
223
224 /*================================================================================================*/
225 /**
226 * @brief Function Name : Stm_Ip_Init
227 * @details Initializes the STM instance. This functions is called for each STM hw Instance and:
228 * - sets the counter value
229 * - configures the freeze mode
230 * - sets the prescaler value
231 * - enables the STM counter
232 *
233 * @param[in] instance STM hw instance number
234 * @param[in] configPtr Pointer to a selected configuration structure
235 * @return void
236 * @pre The data structure including the configuration set required for initializing the GPT driver
237 */
238 void Stm_Ip_Init(uint8 instance, const Stm_Ip_InstanceConfigType *configPtr);
239 /*================================================================================================*/
240 /**
241 * @brief Function Name : Stm_Ip_InitChannel
242 * @details Initializes the STM channels. This functions is called for each STM hw channel and:
243 * - disables hw channel
244 * - clears interrupt clear
245 * - sets compare value to 0
246 * - initializes the state sructure for common process interrupt
247 *
248 * @param[in] instance STM hw instance number
249 * @param[in] configPtr Pointer to a selected configuration structure
250 * @return void
251 * @pre The data structure including the configuration set required for initializing the GPT driver
252 */
253 void Stm_Ip_InitChannel(uint8 instance, const Stm_Ip_ChannelConfigType *configPtr);
254 /*================================================================================================*/
255 /**
256 * @brief Function Name : Stm_Ip_Deinit
257 * @details De-Initializes the STM module. This functions is called for each STM hw instance and:
258 * - resets all channels to default
259 * - sets to default prescaler bits
260 * - disables the STM counter
261 *
262 * @param[in] instance STM hw instance number
263 * @return void
264 * @pre The data structure including the configuration set required for initializing the GPT driver.
265 */
266 void Stm_Ip_Deinit(uint8 instance);
267 /*================================================================================================*/
268 /**
269 * @brief Function Name : Stm_Ip_StartCounting
270 * @details This function is called for starting the Stm timer channel
271 * - reads the current counter register value and sets the compare register to the sum of
272 * counter register value plus the timeout value
273 * - enables the STM channel
274 *
275 * @param[in] instance STM hw instance number
276 * @param[in] channel Stm channel
277 * @param[in] compareValue Compare value
278 * @return void
279 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel.
280 */
281 void Stm_Ip_StartCounting(uint8 instance, uint8 channel, uint32 compareValue);
282 /*================================================================================================*/
283 #if STM_IP_ABSOLUTE_COUNTING_API == STD_ON
284 /**
285 * @brief Function Name : Stm_Ip_StartCountingAbsolute
286 * @details This function is called for starting the Stm timer channel
287 * - sets the compare value without adding the current counter value to the timeout value
288 * - enables the STM channel
289 *
290 * @param[in] instance STM hw instance number
291 * @param[in] channel Stm channel
292 * @param[in] compareValue Compare value
293 * @return void
294 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel.
295 * @implements Stm_Ip_StartCountingAbsolute_Activity
296 */
297 void Stm_Ip_StartCountingAbsolute(uint8 instance, uint8 channel, uint32 compareValue);
298 #endif
299 /*================================================================================================*/
300 /**
301 * @brief Function Name : Stm_Ip_StartTimer
302 * @details This function is called for setting a new start counter value and enables the STM counter:
303 * - sets the new counter value
304 * - enables the STM counter
305 *
306 * @param[in] instance Stm hw instance
307 * @param[in] startValue counter value
308 * @return void
309 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel.
310 *
311 */
312 void Stm_Ip_StartTimer(uint8 instance, uint32 startValue);
313 /*================================================================================================*/
314 /**
315 * @brief Function Name : Stm_Ip_StopTimer
316 * @details Gpt driver function for stopping the Stm counter.
317 * - disables the STM counter
318 *
319 * @param[in] instance Stm hw instance
320 * @return void
321 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel.
322 */
323 void Stm_Ip_StopTimer(uint8 instance);
324 /*================================================================================================*/
325 /**
326 * @brief Function Name : Stm_Ip_EnableChannel
327 * @details Enables the channel selected.
328 *
329 * @param[in] instance Stm hw instance
330 * @param[in] channel Stm hw channel
331 * @return void
332 * @pre The driver needs to be initialized.
333 */
334 void Stm_Ip_EnableChannel(uint8 instance, uint8 channel);
335 /*================================================================================================*/
336 /**
337 * @brief Function Name : Stm_Ip_DisableChannel
338 * @details Disables the channel selected.
339 *
340 * @param[in] instance Stm hw instance
341 * @param[in] channel Stm hw channel
342 * @return void
343 * @pre The driver needs to be initialized.
344 */
345 void Stm_Ip_DisableChannel(uint8 instance, uint8 channel);
346 /*================================================================================================*/
347 /**
348 * @brief Function Name : Stm_Ip_GetCounterValue
349 * @details Gets the counter value.
350 *
351 * @param[in] instance Stm hw instance
352 *
353 * @return currentCounterValue current counter value
354 * @pre The driver needs to be initialized. This function is called for starting the STM timer channel.
355 */
356 uint32 Stm_Ip_GetCounterValue(uint8 instance);
357 /*================================================================================================*/
358 /**
359 * @brief Function Name : Stm_Ip_GetCompareValue
360 * @details Gets the compare value for selected channel
361 *
362 * @param[in] instance Stm hw instance
363 * @param[in] channel Stm hw channel
364 *
365 * @return currentCompareValue compare value for selected channel
366 * @pre The driver needs to be initialized.
367 */
368 uint32 Stm_Ip_GetCompareValue(uint8 instance, uint8 channel);
369 /*================================================================================================*/
370 #if (STM_IP_CHANGE_NEXT_TIMEOUT_VALUE == STD_ON)
371 /**
372 * @brief The function changes the Stm compare register value.
373 * @details This function:
374 * - Write next timeout to local variable
375 *
376 * @param[in] instance Stm hw instance
377 * @param[in] channel Channel
378 * @param[in] value Channel timeout value
379 * @return void
380 * @pre The driver needs to be initialized.
381 */
382 void Stm_Ip_ChangeNextTimeoutValue(uint8 instance, uint8 channel, uint32 value);
383 #endif
384 /*================================================================================================*/
385 #if (STM_IP_SET_CLOCK_MODE == STD_ON)
386 /**
387 * @brief The function changes the STM prescaler value.
388 * @details This function sets the STM prescaler based on the input mode.
389 *
390 * @param[in] instance Stm hw instance
391 * @param[in] clockMode STM_IP_CLOCKMODE_NORMAL or STM_IP_CLOCKMODE_ALTERNATE
392 *
393 * @return void
394 * @pre The driver needs to be initialized. On/Off by the configuration parameter: GPT_DUAL_CLOCK_MODE
395 * @implements Stm_Ip_SetClockMode_Activity
396 */
397 void Stm_Ip_SetClockMode(uint8 instance, Stm_Ip_ClockModeType clockMode);
398 #endif
399 /*================================================================================================*/
400 /**
401 * @brief This function sets the STM prescaler, freeze bit and enables counter
402 * @details This function start counting with predefined values(like a free running timer)
403 *
404 * @param[in] instance Stm hw instance
405 * @param[in] prescaler Prescaler value
406 * @param[in] freezeEnable Freeze value
407 * @return void
408 * @pre The driver needs to be initialized
409 * @implements
410 */
411 void Stm_Ip_PredefCounting(uint8 instance, uint8 prescaler, boolean freezeEnable);
412
413 /**
414 * @internal
415 * @brief MemMap section
416 */
417 #define GPT_STOP_SEC_CODE
418 #include "Gpt_MemMap.h"
419
420 #endif /* STM_IP_USED == STD_ON */
421
422 #ifdef __cplusplus
423 }
424 #endif
425 /** @} */
426 #endif/*STM_IP_H*/
427