1 /*
2 * Copyright 2020-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 /**
8 * @file
9 *
10 * @addtogroup osif_drv
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 "OsIf.h"
25 #include "OsIf_Cfg.h"
26 #include "OsIf_Cfg_TypesDef.h"
27 #include "OsIf_Timer_System.h"
28
29 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
30
31 #if defined(USING_OS_AUTOSAROS)
32 #include "Os.h"
33 #elif defined(USING_OS_FREERTOS)
34 #include "FreeRTOSConfig.h"
35 #elif defined(USING_OS_ZEPHYR)
36 #include <zephyr/kernel.h>
37 #else
38 /* Baremetal, make sure USING_OS_BAREMETAL is defined */
39 #ifndef USING_OS_BAREMETAL
40 #define USING_OS_BAREMETAL
41 #endif /* ifndef USING_OS_BAREMETAL */
42 #endif /* defined(USING_OS_AUTOSAROS) */
43
44 /* Timer specific includes to define:
45 - OsIf_Timer_System_Internal_Init
46 - OsIf_Timer_System_Internal_GetCounter
47 - OsIf_Timer_System_Internal_GetElapsed
48 */
49 #if defined(OSIF_USE_SYSTICK)
50 #if (OSIF_USE_SYSTICK == STD_ON)
51 #include "OsIf_Timer_System_Internal_Systick.h"
52 #endif /* OSIF_USE_SYSTICK == STD_ON */
53 #endif /* defined(OSIF_USE_SYSTICK) */
54
55 #if defined(OSIF_USE_GENERICTIMER)
56 #if (OSIF_USE_GENERICTIMER == STD_ON)
57 #include "OsIf_Timer_System_Internal_GenericTimer.h"
58 #endif /* OSIF_USE_GENERICTIMER == STD_ON */
59 #endif /* defined(OSIF_USE_GENERICTIMER) */
60
61 /*==================================================================================================
62 * SOURCE FILE VERSION INFORMATION
63 ==================================================================================================*/
64 #define OSIF_TIMER_SYSTEM_VENDOR_ID_C 43
65 #define OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C 4
66 #define OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C 7
67 #define OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C 0
68 #define OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C 3
69 #define OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C 0
70 #define OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C 0
71
72 /*==================================================================================================
73 * FILE VERSION CHECKS
74 ==================================================================================================*/
75 /* Checks against OsIf.h */
76 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_VENDOR_ID)
77 #error "OsIf_Timer_System.c and OsIf.h have different vendor ids"
78 #endif
79 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
80 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) || \
81 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_AR_RELEASE_REVISION_VERSION))
82 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf.h are different"
83 #endif
84 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_SW_MAJOR_VERSION) || \
85 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_SW_MINOR_VERSION) || \
86 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_SW_PATCH_VERSION) \
87 )
88 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf.h are different"
89 #endif
90
91 /* Checks against OsIf_Cfg.h */
92 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_CFG_VENDOR_ID)
93 #error "OsIf_Timer_System.c and OsIf_Cfg.h have different vendor ids"
94 #endif
95 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_AR_RELEASE_MAJOR_VERSION) || \
96 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_AR_RELEASE_MINOR_VERSION) || \
97 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_AR_RELEASE_REVISION_VERSION))
98 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Cfg.h are different"
99 #endif
100 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_CFG_SW_MAJOR_VERSION) || \
101 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_CFG_SW_MINOR_VERSION) || \
102 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_CFG_SW_PATCH_VERSION) \
103 )
104 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf_Cfg.h are different"
105 #endif
106
107 /* Checks against OsIf_Cfg_TypesDef.h */
108 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_CFG_TYPESDEF_VENDOR_ID)
109 #error "OsIf_Timer_System.c and OsIf_Cfg_TypesDef.h have different vendor ids"
110 #endif
111 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MAJOR_VERSION) || \
112 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MINOR_VERSION) || \
113 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_REVISION_VERSION))
114 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Cfg_TypesDef.h are different"
115 #endif
116 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MAJOR_VERSION) || \
117 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MINOR_VERSION) || \
118 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_CFG_TYPESDEF_SW_PATCH_VERSION) \
119 )
120 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf_Cfg_TypesDef.h are different"
121 #endif
122
123 /* Checks against OsIf_Timer_System.h */
124 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_TIMER_SYSTEM_VENDOR_ID)
125 #error "OsIf_Timer_System.c and OsIf_Timer_System.h have different vendor ids"
126 #endif
127 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION) || \
128 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION) || \
129 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION))
130 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System.h are different"
131 #endif
132 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION) || \
133 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MINOR_VERSION) || \
134 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_TIMER_SYSTEM_SW_PATCH_VERSION) \
135 )
136 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System.h are different"
137 #endif
138
139 #if defined(OSIF_USE_SYSTICK)
140 #if (OSIF_USE_SYSTICK == STD_ON)
141 /* Checks against OsIf_Timer_System_Internal_Systick.h */
142 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_VENDOR_ID)
143 #error "OsIf_Timer_System.c and OsIf_Timer_System_Internal_Systick.h have different vendor ids"
144 #endif
145 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_AR_RELEASE_MAJOR_VERSION) || \
146 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_AR_RELEASE_MINOR_VERSION) || \
147 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_AR_RELEASE_REVISION_VERSION))
148 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System_Internal_Systick.h are different"
149 #endif
150 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_SW_MAJOR_VERSION) || \
151 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_SW_MINOR_VERSION) || \
152 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_TIMER_SYSTEM_INTERNAL_SYSTICK_SW_PATCH_VERSION) \
153 )
154 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System_Internal_Systick.h are different"
155 #endif
156 #endif /* OSIF_USE_SYSTICK == STD_ON */
157 #endif /* defined(OSIF_USE_SYSTICK) */
158
159 #if defined(OSIF_USE_GENERICTIMER)
160 #if OSIF_USE_GENERICTIMER == STD_ON
161 /* Checks against OsIf_Timer_System_Internal_GenericTimer.h */
162 #if (OSIF_TIMER_SYSTEM_VENDOR_ID_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_VENDOR_ID)
163 #error "OsIf_Timer_System.c and OsIf_Timer_System_Internal_GenericTimer.h have different vendor ids"
164 #endif
165 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_AR_RELEASE_MAJOR_VERSION) || \
166 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_AR_RELEASE_MINOR_VERSION) || \
167 (OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_AR_RELEASE_REVISION_VERSION))
168 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System_Internal_GenericTimer.h are different"
169 #endif
170 #if ((OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_SW_MAJOR_VERSION) || \
171 (OSIF_TIMER_SYSTEM_SW_MINOR_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_SW_MINOR_VERSION) || \
172 (OSIF_TIMER_SYSTEM_SW_PATCH_VERSION_C != OSIF_TIMER_SYS_INTER_GENERICTIMER_SW_PATCH_VERSION) \
173 )
174 #error "Software Version Numbers of OsIf_Timer_System.c and OsIf_Timer_System_Internal_GenericTimer.h are different"
175 #endif
176 #endif /* OSIF_USE_GENERICTIMER == STD_ON */
177 #endif /* defined(OSIF_USE_GENERICTIMER) */
178
179 #if defined(USING_OS_AUTOSAROS)
180 /* Checks against Os.h */
181 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
182 #if ((OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION_C != OS_AR_RELEASE_MAJOR_VERSION) || \
183 (OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION_C != OS_AR_RELEASE_MINOR_VERSION))
184 #error "AutoSar Version Numbers of OsIf_Timer_System.c and Os.h are different"
185 #endif
186 #endif
187 #endif /* defined(USING_OS_AUTOSAROS) */
188
189 /*==================================================================================================
190 * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
191 ==================================================================================================*/
192
193 /*==================================================================================================
194 * LOCAL MACROS
195 ==================================================================================================*/
196 #if (STD_ON == OSIF_ENABLE_USER_MODE_SUPPORT)
197 #define Trusted_OsIf_Timer_System_Internal_Init(Freq) OsIf_Trusted_Call1param(OsIf_Timer_System_Internal_Init, (Freq))
198 #define Trusted_OsIf_Timer_System_Internal_GetCounter() OsIf_Trusted_Call_Return(OsIf_Timer_System_Internal_GetCounter)
199 #define Trusted_OsIf_Timer_System_Internal_GetElapsed(CurrentRef) OsIf_Trusted_Call_Return1param(OsIf_Timer_System_Internal_GetElapsed, (CurrentRef))
200 #define Trusted_k_cycle_get_32() OsIf_Trusted_Call_Return(k_cycle_get_32)
201 #else
202 #define Trusted_OsIf_Timer_System_Internal_Init(Freq) OsIf_Timer_System_Internal_Init(Freq)
203 #define Trusted_OsIf_Timer_System_Internal_GetCounter() OsIf_Timer_System_Internal_GetCounter()
204 #define Trusted_OsIf_Timer_System_Internal_GetElapsed(CurrentRef) OsIf_Timer_System_Internal_GetElapsed(CurrentRef)
205 #define Trusted_k_cycle_get_32() k_cycle_get_32()
206 #endif
207
208 #if STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT
209 #define OsIfCoreID() (OsIf_GetCoreID())
210 #else
211 #define OsIfCoreID() (0U)
212 #endif
213 /*==================================================================================================
214 * LOCAL CONSTANTS
215 ==================================================================================================*/
216
217 /*==================================================================================================
218 * LOCAL VARIABLES
219 ==================================================================================================*/
220 #if STD_ON == OSIF_DEV_ERROR_DETECT
221 #define BASENXP_START_SEC_VAR_CLEARED_BOOLEAN
222 #include "BaseNXP_MemMap.h"
223
224 static boolean OsIf_abMdlInit[OSIF_MAX_COREIDX_SUPPORTED];
225
226 #define BASENXP_STOP_SEC_VAR_CLEARED_BOOLEAN
227 #include "BaseNXP_MemMap.h"
228 #endif /* STD_ON == OSIF_DEV_ERROR_DETECT */
229
230 #if (defined(USING_OS_AUTOSAROS) || (STD_ON == OSIF_DEV_ERROR_DETECT))
231 #define BASENXP_START_SEC_VAR_CLEARED_UNSPECIFIED
232 #include "BaseNXP_MemMap.h"
233
234 static const OsIf_ConfigType *OsIf_apxInternalCfg[OSIF_MAX_COREIDX_SUPPORTED];
235
236 #define BASENXP_STOP_SEC_VAR_CLEARED_UNSPECIFIED
237 #include "BaseNXP_MemMap.h"
238 #endif /* (defined(USING_OS_AUTOSAROS) || (STD_ON == OSIF_DEV_ERROR_DETECT)) */
239
240 #define BASENXP_START_SEC_VAR_CLEARED_32
241 #include "BaseNXP_MemMap.h"
242
243 static uint32 OsIf_au32InternalFrequencies[OSIF_MAX_COREIDX_SUPPORTED];
244
245 #define BASENXP_STOP_SEC_VAR_CLEARED_32
246 #include "BaseNXP_MemMap.h"
247 /*==================================================================================================
248 * GLOBAL CONSTANTS
249 ==================================================================================================*/
250
251 /*==================================================================================================
252 * GLOBAL VARIABLES
253 ==================================================================================================*/
254 #define BASENXP_START_SEC_CONFIG_DATA_UNSPECIFIED
255 #include "BaseNXP_MemMap.h"
256
257 extern const OsIf_ConfigType *const OsIf_apxPredefinedConfig[OSIF_MAX_COREIDX_SUPPORTED];
258
259 #define BASENXP_STOP_SEC_CONFIG_DATA_UNSPECIFIED
260 #include "BaseNXP_MemMap.h"
261 /*==================================================================================================
262 * LOCAL FUNCTION PROTOTYPES
263 ==================================================================================================*/
264
265 /*==================================================================================================
266 * LOCAL FUNCTIONS
267 ==================================================================================================*/
268
269 /*==================================================================================================
270 * GLOBAL FUNCTIONS
271 ==================================================================================================*/
272 #define BASENXP_START_SEC_CODE
273 #include "BaseNXP_MemMap.h"
274
OsIf_Timer_System_Init(void)275 void OsIf_Timer_System_Init(void)
276 {
277 uint32 CoreId = OsIfCoreID();
278
279 #if (STD_ON == OSIF_DEV_ERROR_DETECT)
280 #if (STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT)
281 if ((CoreId >= OSIF_MAX_COREIDX_SUPPORTED) || (NULL_PTR == OsIf_apxPredefinedConfig[CoreId]))
282 #else
283 if (NULL_PTR == OsIf_apxPredefinedConfig[CoreId])
284 #endif
285 {
286 #if defined(USING_OS_AUTOSAROS)
287 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_INIT, OSIF_E_INV_CORE_IDX);
288 #else
289 OSIF_DEV_ASSERT(FALSE);
290 #endif
291 }
292 else
293 {
294 OsIf_abMdlInit[CoreId] = TRUE;
295 #endif
296
297 #if (defined(USING_OS_AUTOSAROS) || (STD_ON == OSIF_DEV_ERROR_DETECT))
298 OsIf_apxInternalCfg[CoreId] = OsIf_apxPredefinedConfig[CoreId];
299 #endif
300 #if (!defined(USING_OS_FREERTOS) && !defined(USING_OS_ZEPHYR))
301 OsIf_au32InternalFrequencies[CoreId] = OsIf_apxPredefinedConfig[CoreId]->counterFrequency;
302 #endif
303
304 #if defined(USING_OS_FREERTOS)
305 /* FreeRTOS */
306 OsIf_au32InternalFrequencies[CoreId] = configCPU_CLOCK_HZ;
307 #elif defined(USING_OS_ZEPHYR)
308 /* ZephyrOS */
309 OsIf_au32InternalFrequencies[CoreId] = sys_clock_hw_cycles_per_sec();
310 #elif defined(USING_OS_BAREMETAL)
311 /* Baremetal */
312 Trusted_OsIf_Timer_System_Internal_Init(OsIf_au32InternalFrequencies[CoreId]);
313 #endif
314 #if (STD_ON == OSIF_DEV_ERROR_DETECT)
315 }
316 #endif
317 }
318
319
OsIf_Timer_System_GetCounter(void)320 uint32 OsIf_Timer_System_GetCounter(void)
321 {
322 uint32 Counter = 0u;
323 uint32 CoreId = OsIfCoreID();
324
325 #if STD_ON == OSIF_DEV_ERROR_DETECT
326 if (TRUE != OsIf_abMdlInit[CoreId])
327 {
328 #if defined(USING_OS_AUTOSAROS)
329 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_GETCOUNTER, OSIF_E_UNINIT);
330 #else
331 OSIF_DEV_ASSERT(FALSE);
332 #endif
333 }
334 #if (STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT)
335 else if ((CoreId >= OSIF_MAX_COREIDX_SUPPORTED) || (NULL_PTR == OsIf_apxInternalCfg[CoreId]))
336 #else
337 else if (NULL_PTR == OsIf_apxInternalCfg[CoreId])
338 #endif
339 {
340 #if defined(USING_OS_AUTOSAROS)
341 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_GETCOUNTER, OSIF_E_INV_CORE_IDX);
342 #else
343 OSIF_DEV_ASSERT(FALSE);
344 #endif
345 }
346 else
347 {
348 #endif /* OSIF_DEV_ERROR_DETECT */
349
350 #if defined(USING_OS_AUTOSAROS)
351 StatusType Status;
352 TickType value;
353 Status = GetCounterValue(OsIf_apxInternalCfg[CoreId]->counterId, &value);
354 OSIF_DEV_ASSERT(Status == E_OK);
355 Counter = (uint32)value;
356 #elif defined(USING_OS_ZEPHYR)
357 /* ZephyrOS */
358 (void)CoreId;
359 Counter = Trusted_k_cycle_get_32();
360 #elif defined(USING_OS_FREERTOS) || defined(USING_OS_BAREMETAL)
361 /* FreeRTOS and Baremetal*/
362 (void)CoreId;
363 Counter = Trusted_OsIf_Timer_System_Internal_GetCounter();
364 #endif
365
366 #if STD_ON == OSIF_DEV_ERROR_DETECT
367 }
368 #endif
369
370 return Counter;
371 }
372
373
OsIf_Timer_System_GetElapsed(uint32 * const CurrentRef)374 uint32 OsIf_Timer_System_GetElapsed(uint32 * const CurrentRef)
375 {
376 uint32 Elapsed = 0u;
377 uint32 CoreId = OsIfCoreID();
378
379 #if STD_ON == OSIF_DEV_ERROR_DETECT
380 if (TRUE != OsIf_abMdlInit[CoreId])
381 {
382 #if defined(USING_OS_AUTOSAROS)
383 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_GETELAPSED, OSIF_E_UNINIT);
384 #else
385 OSIF_DEV_ASSERT(FALSE);
386 #endif
387 }
388 #if (STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT)
389 else if ((CoreId >= OSIF_MAX_COREIDX_SUPPORTED) || (NULL_PTR == OsIf_apxInternalCfg[CoreId]))
390 #else
391 else if (NULL_PTR == OsIf_apxInternalCfg[CoreId])
392 #endif
393 {
394 #if defined(USING_OS_AUTOSAROS)
395 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_GETELAPSED, OSIF_E_INV_CORE_IDX);
396 #else
397 OSIF_DEV_ASSERT(FALSE);
398 #endif
399 }
400 else
401 {
402 #endif /* OSIF_DEV_ERROR_DETECT */
403
404 #if defined(USING_OS_AUTOSAROS)
405 TickType ElapsedTickType;
406 StatusType Status;
407 Status = GetElapsedValue(OsIf_apxInternalCfg[CoreId]->counterId, (TickType*)CurrentRef, &ElapsedTickType);
408 OSIF_DEV_ASSERT(Status == E_OK);
409 Elapsed = (uint32)ElapsedTickType;
410 #elif defined(USING_OS_ZEPHYR)
411 /* No need for additional logic. The hardware clock is represented as a 32-bit counter */
412 uint32 CurrentVal = Trusted_k_cycle_get_32();
413 Elapsed = CurrentVal - *CurrentRef;
414 *CurrentRef = CurrentVal;
415 (void)CoreId;
416 #elif defined(USING_OS_FREERTOS) || defined(USING_OS_BAREMETAL)
417 /* FreeRTOS and Baremetal*/
418 (void)CoreId;
419 Elapsed = Trusted_OsIf_Timer_System_Internal_GetElapsed(CurrentRef);
420 #endif
421
422 #if STD_ON == OSIF_DEV_ERROR_DETECT
423 }
424 #endif
425
426 return Elapsed;
427 }
428
429
OsIf_Timer_System_SetTimerFrequency(uint32 Freq)430 void OsIf_Timer_System_SetTimerFrequency(uint32 Freq)
431 {
432 uint32 CoreId = OsIfCoreID();
433 #if STD_ON == OSIF_DEV_ERROR_DETECT
434
435 if (TRUE != OsIf_abMdlInit[CoreId])
436 {
437 #if defined(USING_OS_AUTOSAROS)
438 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_SETTIMERFREQ, OSIF_E_UNINIT);
439 #else
440 OSIF_DEV_ASSERT(FALSE);
441 #endif
442 }
443 #if (STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT)
444 else if ((CoreId >= OSIF_MAX_COREIDX_SUPPORTED) || (NULL_PTR == OsIf_apxInternalCfg[CoreId]))
445 #else
446 else if (NULL_PTR == OsIf_apxInternalCfg[CoreId])
447 #endif
448 {
449 #if defined(USING_OS_AUTOSAROS)
450 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_SETTIMERFREQ, OSIF_E_INV_CORE_IDX);
451 #else
452 OSIF_DEV_ASSERT(FALSE);
453 #endif
454 }
455 else
456 {
457 #endif /* OSIF_DEV_ERROR_DETECT */
458
459 #if defined(USING_OS_AUTOSAROS)
460 (void)CoreId;
461 (void)Freq;
462 #elif defined(USING_OS_ZEPHYR)
463 (void)CoreId;
464 (void)Freq;
465 /* As of 2.6.0: "The frequency of this counter is required to be steady over time" */
466 #elif defined(USING_OS_FREERTOS) || defined(USING_OS_BAREMETAL)
467 /* FreeRTOS and Baremetal*/
468 OsIf_au32InternalFrequencies[CoreId] = Freq;
469 #endif
470
471 #if STD_ON == OSIF_DEV_ERROR_DETECT
472 }
473 #endif
474 }
475
476
OsIf_Timer_System_MicrosToTicks(uint32 Micros)477 uint32 OsIf_Timer_System_MicrosToTicks(uint32 Micros)
478 {
479 uint64 interim;
480 uint32 ticks = 0u;
481 uint32 CoreId = OsIfCoreID();
482
483 #if STD_ON == OSIF_DEV_ERROR_DETECT
484 if (TRUE != OsIf_abMdlInit[CoreId])
485 {
486 #if defined(USING_OS_AUTOSAROS)
487 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_US2TICKS, OSIF_E_UNINIT);
488 #else
489 OSIF_DEV_ASSERT(FALSE);
490 #endif
491 }
492 #if (STD_ON == OSIF_ENABLE_MULTICORE_SUPPORT)
493 else if ((CoreId >= OSIF_MAX_COREIDX_SUPPORTED) || (NULL_PTR == OsIf_apxInternalCfg[CoreId]))
494 #else
495 else if (NULL_PTR == OsIf_apxInternalCfg[CoreId])
496 #endif
497 {
498 #if defined(USING_OS_AUTOSAROS)
499 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_US2TICKS, OSIF_E_INV_CORE_IDX);
500 #else
501 OSIF_DEV_ASSERT(FALSE);
502 #endif
503 }
504 else
505 {
506 #endif /* OSIF_DEV_ERROR_DETECT */
507
508 interim = Micros * (uint64)OsIf_au32InternalFrequencies[CoreId];
509 interim /= 1000000u;
510 OSIF_DEV_ASSERT(interim <= 0xFFFFFFFFu); /* check that computed value fits in 32 bits */
511 ticks = (uint32)(interim & 0xFFFFFFFFu);
512
513 #if STD_ON == OSIF_DEV_ERROR_DETECT
514 }
515 #endif
516
517 return ticks;
518 }
519
520 #define BASENXP_STOP_SEC_CODE
521 #include "BaseNXP_MemMap.h"
522
523 #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
524
525 #ifdef __cplusplus
526 }
527 #endif
528
529 /** @} */
530