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
28 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
29 /* Defines the Hw Timer functions to be implemented in OS-specific environments */
30 #include "OsIf_Timer_System.h"
31 #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
32
33 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
34 /* API functions to be implemented by user */
35 #include "OsIf_Timer_Custom.h"
36 #endif /* (OSIF_USE_CUSTOM_TIMER == STD_ON) */
37
38 /*==================================================================================================
39 * SOURCE FILE VERSION INFORMATION
40 ==================================================================================================*/
41 #define OSIF_TIMER_VENDOR_ID_C 43
42 #define OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C 4
43 #define OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C 7
44 #define OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C 0
45 #define OSIF_TIMER_SW_MAJOR_VERSION_C 3
46 #define OSIF_TIMER_SW_MINOR_VERSION_C 0
47 #define OSIF_TIMER_SW_PATCH_VERSION_C 0
48
49 /*==================================================================================================
50 * FILE VERSION CHECKS
51 ==================================================================================================*/
52 /* Checks against OsIf.h */
53 #if (OSIF_TIMER_VENDOR_ID_C != OSIF_VENDOR_ID)
54 #error "OsIf_Timer.c and OsIf.h have different vendor ids"
55 #endif
56 #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_AR_RELEASE_MAJOR_VERSION) || \
57 (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_AR_RELEASE_MINOR_VERSION) || \
58 (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_AR_RELEASE_REVISION_VERSION))
59 #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf.h are different"
60 #endif
61 #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_SW_MAJOR_VERSION) || \
62 (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_SW_MINOR_VERSION) || \
63 (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_SW_PATCH_VERSION) \
64 )
65 #error "Software Version Numbers of OsIf_Timer.c and OsIf.h are different"
66 #endif
67
68 /* Checks against OsIf_Cfg.h */
69 #if (OSIF_TIMER_VENDOR_ID_C != OSIF_CFG_VENDOR_ID)
70 #error "OsIf_Timer.c and OsIf_Cfg.h have different vendor ids"
71 #endif
72 #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_AR_RELEASE_MAJOR_VERSION) || \
73 (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_AR_RELEASE_MINOR_VERSION) || \
74 (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_AR_RELEASE_REVISION_VERSION))
75 #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Cfg.h are different"
76 #endif
77 #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_CFG_SW_MAJOR_VERSION) || \
78 (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_CFG_SW_MINOR_VERSION) || \
79 (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_CFG_SW_PATCH_VERSION) \
80 )
81 #error "Software Version Numbers of OsIf_Timer.c and OsIf_Cfg.h are different"
82 #endif
83
84 /* Checks against OsIf_Cfg_TypesDef.h */
85 #if (OSIF_TIMER_VENDOR_ID_C != OSIF_CFG_TYPESDEF_VENDOR_ID)
86 #error "OsIf_Timer.c and OsIf_Cfg_TypesDef.h have different vendor ids"
87 #endif
88 #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MAJOR_VERSION) || \
89 (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_MINOR_VERSION) || \
90 (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_CFG_TYPESDEF_AR_RELEASE_REVISION_VERSION))
91 #error "AUTOSAR Version Numbers of OsIf_Timer_System.c and OsIf_Cfg_TypesDef.h are different"
92 #endif
93 #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MAJOR_VERSION) || \
94 (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_CFG_TYPESDEF_SW_MINOR_VERSION) || \
95 (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_CFG_TYPESDEF_SW_PATCH_VERSION) \
96 )
97 #error "Software Version Numbers of OsIf_Timer.c and OsIf_Cfg_TypesDef.h are different"
98 #endif
99
100 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
101 /* Checks against OsIf_Timer_System.h */
102 #if (OSIF_TIMER_VENDOR_ID_C != OSIF_TIMER_SYSTEM_VENDOR_ID)
103 #error "OsIf_Timer.c and OsIf_Timer_System.h have different vendor ids"
104 #endif
105 #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MAJOR_VERSION) || \
106 (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_MINOR_VERSION) || \
107 (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_SYSTEM_AR_RELEASE_REVISION_VERSION))
108 #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Timer_System.h are different"
109 #endif
110 #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MAJOR_VERSION) || \
111 (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_TIMER_SYSTEM_SW_MINOR_VERSION) || \
112 (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_TIMER_SYSTEM_SW_PATCH_VERSION) \
113 )
114 #error "Software Version Numbers of OsIf_Timer.c and OsIf_Timer_System.h are different"
115 #endif
116 #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
117
118 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
119 /* Checks against OsIf_Timer_Custom.h */
120 #if (OSIF_TIMER_VENDOR_ID_C != OSIF_TIMER_CUSTOM_VENDOR_ID)
121 #error "OsIf_Timer.c and OsIf_Timer_Custom.h have different vendor ids"
122 #endif
123 #if ((OSIF_TIMER_AR_RELEASE_MAJOR_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_MAJOR_VERSION) || \
124 (OSIF_TIMER_AR_RELEASE_MINOR_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_MINOR_VERSION) || \
125 (OSIF_TIMER_AR_RELEASE_REVISION_VERSION_C != OSIF_TIMER_CUSTOM_AR_RELEASE_REVISION_VERSION))
126 #error "AUTOSAR Version Numbers of OsIf_Timer.c and OsIf_Timer_Custom.h are different"
127 #endif
128 #if ((OSIF_TIMER_SW_MAJOR_VERSION_C != OSIF_TIMER_CUSTOM_SW_MAJOR_VERSION) || \
129 (OSIF_TIMER_SW_MINOR_VERSION_C != OSIF_TIMER_CUSTOM_SW_MINOR_VERSION) || \
130 (OSIF_TIMER_SW_PATCH_VERSION_C != OSIF_TIMER_CUSTOM_SW_PATCH_VERSION) \
131 )
132 #error "Software Version Numbers of OsIf_Timer.c and OsIf_Timer_Custom.h are different"
133 #endif
134 #endif /* (OSIF_USE_CUSTOM_TIMER == STD_ON) */
135
136 /*==================================================================================================
137 * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
138 ==================================================================================================*/
139
140 /*==================================================================================================
141 * LOCAL MACROS
142 ==================================================================================================*/
143
144 /*==================================================================================================
145 * LOCAL CONSTANTS
146 ==================================================================================================*/
147
148 /*==================================================================================================
149 * LOCAL VARIABLES
150 ==================================================================================================*/
151
152 /*==================================================================================================
153 * GLOBAL CONSTANTS
154 ==================================================================================================*/
155
156 /*==================================================================================================
157 * GLOBAL VARIABLES
158 ==================================================================================================*/
159
160 /*==================================================================================================
161 * LOCAL FUNCTION PROTOTYPES
162 ==================================================================================================*/
163 #define BASENXP_START_SEC_CODE
164 #include "BaseNXP_MemMap.h"
165
166 static inline uint32 OsIf_Timer_Dummy_GetCounter(void);
167 static inline uint32 OsIf_Timer_Dummy_GetElapsed(const uint32 * const CurrentRef);
168 static inline void OsIf_Timer_Dummy_SetTimerFrequency(uint32 Freq);
169 static inline uint32 OsIf_Timer_Dummy_MicrosToTicks(uint32 Micros);
170
171 #define BASENXP_STOP_SEC_CODE
172 #include "BaseNXP_MemMap.h"
173 /*==================================================================================================
174 * LOCAL FUNCTIONS
175 ==================================================================================================*/
176 #define BASENXP_START_SEC_CODE
177 #include "BaseNXP_MemMap.h"
178
179 /* OsIf_Timer_Dummy_GetCounter_Activity */
OsIf_Timer_Dummy_GetCounter(void)180 static inline uint32 OsIf_Timer_Dummy_GetCounter(void)
181 {
182 return 0u;
183 }
184
185 /* OsIf_Timer_Dummy_GetElapsed_Activity */
OsIf_Timer_Dummy_GetElapsed(const uint32 * const CurrentRef)186 static inline uint32 OsIf_Timer_Dummy_GetElapsed(const uint32 * const CurrentRef)
187 {
188 (void)CurrentRef;
189 return 1u;
190 }
191
192 /* OsIf_Timer_Dummy_SetTimerFrequency_Activity */
OsIf_Timer_Dummy_SetTimerFrequency(uint32 Freq)193 static inline void OsIf_Timer_Dummy_SetTimerFrequency(uint32 Freq)
194 {
195 (void)Freq;
196 }
197
198 /* OsIf_Timer_Dummy_MicrosToTicks_Activity */
OsIf_Timer_Dummy_MicrosToTicks(uint32 Micros)199 static inline uint32 OsIf_Timer_Dummy_MicrosToTicks(uint32 Micros)
200 {
201 return Micros;
202 }
203
204 #define BASENXP_STOP_SEC_CODE
205 #include "BaseNXP_MemMap.h"
206 /*==================================================================================================
207 * GLOBAL FUNCTIONS
208 ==================================================================================================*/
209 #define BASENXP_START_SEC_CODE
210 #include "BaseNXP_MemMap.h"
211
212 /* @implements OsIf_Init_Activity */
OsIf_Init(const void * Config)213 void OsIf_Init(const void* Config)
214 {
215
216 #if (STD_ON == OSIF_DEV_ERROR_DETECT)
217 if (Config != NULL_PTR)
218 {
219 #if defined(USING_OS_AUTOSAROS)
220 (void)Det_ReportError(OSIF_MODULE_ID, OSIF_DRIVER_INSTANCE, OSIF_SID_INIT, OSIF_E_INIT_FAILED);
221 #else
222 OSIF_DEV_ASSERT(FALSE);
223 #endif
224 }
225 #else
226 (void)Config;
227 #endif
228
229 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
230 OsIf_Timer_System_Init();
231 #endif
232 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
233 OsIf_Timer_Custom_Init();
234 #endif
235 }
236
237 /* @implements OsIf_GetCounter_Activity */
OsIf_GetCounter(OsIf_CounterType SelectedCounter)238 uint32 OsIf_GetCounter(OsIf_CounterType SelectedCounter)
239 {
240 uint32 Value = 0u;
241 switch (SelectedCounter){
242 case OSIF_COUNTER_DUMMY:
243 Value = OsIf_Timer_Dummy_GetCounter();
244 break;
245 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
246 case OSIF_COUNTER_SYSTEM:
247 Value = OsIf_Timer_System_GetCounter();
248 break;
249 #endif
250 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
251 case OSIF_COUNTER_CUSTOM:
252 Value = OsIf_Timer_Custom_GetCounter();
253 break;
254 #endif
255 default: /* impossible */ break;
256 }
257 return Value;
258 }
259
260
261 /* @implements OsIf_GetElapsed_Activity */
OsIf_GetElapsed(uint32 * const CurrentRef,OsIf_CounterType SelectedCounter)262 uint32 OsIf_GetElapsed(uint32 * const CurrentRef, OsIf_CounterType SelectedCounter)
263 {
264 uint32 Value = 0u;
265 switch (SelectedCounter){
266 case OSIF_COUNTER_DUMMY:
267 Value = OsIf_Timer_Dummy_GetElapsed(CurrentRef);
268 break;
269 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
270 case OSIF_COUNTER_SYSTEM:
271 Value = OsIf_Timer_System_GetElapsed(CurrentRef);
272 break;
273 #endif
274 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
275 case OSIF_COUNTER_CUSTOM:
276 Value = OsIf_Timer_Custom_GetElapsed(CurrentRef);
277 break;
278 #endif
279 default: /* impossible */ break;
280 }
281 return Value;
282 }
283
284
285 /* @implements OsIf_SetTimerFrequency_Activity */
OsIf_SetTimerFrequency(uint32 Freq,OsIf_CounterType SelectedCounter)286 void OsIf_SetTimerFrequency(uint32 Freq, OsIf_CounterType SelectedCounter)
287 {
288 switch (SelectedCounter){
289 case OSIF_COUNTER_DUMMY:
290 OsIf_Timer_Dummy_SetTimerFrequency(Freq);
291 break;
292 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
293 case OSIF_COUNTER_SYSTEM:
294 OsIf_Timer_System_SetTimerFrequency(Freq);
295 break;
296 #endif
297 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
298 case OSIF_COUNTER_CUSTOM:
299 OsIf_Timer_Custom_SetTimerFrequency(Freq);
300 break;
301 #endif
302 default: /* impossible */ break;
303 }
304 }
305
306 /* @implements OsIf_MicrosToTicks_Activity */
OsIf_MicrosToTicks(uint32 Micros,OsIf_CounterType SelectedCounter)307 uint32 OsIf_MicrosToTicks(uint32 Micros, OsIf_CounterType SelectedCounter)
308 {
309 uint32 Value = 0u;
310 switch (SelectedCounter){
311 case OSIF_COUNTER_DUMMY:
312 Value = OsIf_Timer_Dummy_MicrosToTicks(Micros);
313 break;
314 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
315 case OSIF_COUNTER_SYSTEM:
316 Value = OsIf_Timer_System_MicrosToTicks(Micros);
317 break;
318 #endif
319 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
320 case OSIF_COUNTER_CUSTOM:
321 Value = OsIf_Timer_Custom_MicrosToTicks(Micros);
322 break;
323 #endif
324 default: /* impossible */ break;
325 }
326 return Value;
327 }
328
329 #define BASENXP_STOP_SEC_CODE
330 #include "BaseNXP_MemMap.h"
331
332 #ifdef __cplusplus
333 }
334 #endif
335
336 /** @} */
337