1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #ifndef OSIF_H
7 #define OSIF_H
8 
9 /**
10 *   @file
11 *
12 *   @addtogroup osif_drv
13 *   @{
14 */
15 
16 #ifdef __cplusplus
17 extern "C"{
18 #endif
19 
20 
21 /*==================================================================================================
22 *                                          INCLUDE FILES
23 * 1) system and project includes
24 * 2) needed interfaces from external units
25 * 3) internal and external interfaces from this unit
26 ==================================================================================================*/
27 #include "OsIf_Internal.h"
28 #include "OsIf_Cfg.h"
29 
30 /*==================================================================================================
31 *                                 SOURCE FILE VERSION INFORMATION
32 ==================================================================================================*/
33 #define OSIF_VENDOR_ID                    43
34 #define OSIF_AR_RELEASE_MAJOR_VERSION     4
35 #define OSIF_AR_RELEASE_MINOR_VERSION     7
36 #define OSIF_AR_RELEASE_REVISION_VERSION  0
37 #define OSIF_SW_MAJOR_VERSION             2
38 #define OSIF_SW_MINOR_VERSION             0
39 #define OSIF_SW_PATCH_VERSION             0
40 
41 /*==================================================================================================
42 *                                       FILE VERSION CHECKS
43 ==================================================================================================*/
44 /* Check if OsIf.h file and OsIf_Internal.h file are of the same vendor */
45 #if (OSIF_VENDOR_ID != OSIF_INTERNAL_VENDOR_ID)
46     #error "OsIf.h and OsIf_Internal.h have different vendor ids"
47 #endif
48 /* Check if OsIf.h file and OsIf_Internal.h file are of the same Autosar version */
49 #if ((OSIF_AR_RELEASE_MAJOR_VERSION    != OSIF_INTERNAL_AR_RELEASE_MAJOR_VERSION) || \
50      (OSIF_AR_RELEASE_MINOR_VERSION    != OSIF_INTERNAL_AR_RELEASE_MINOR_VERSION) || \
51      (OSIF_AR_RELEASE_REVISION_VERSION != OSIF_INTERNAL_AR_RELEASE_REVISION_VERSION))
52     #error "AUTOSAR Version Numbers of OsIf.h and OsIf_Internal.h are different"
53 #endif
54 /* Check if OsIf.h file and OsIf_Internal.h file are of the same Software version */
55 #if ((OSIF_SW_MAJOR_VERSION != OSIF_INTERNAL_SW_MAJOR_VERSION) || \
56      (OSIF_SW_MINOR_VERSION != OSIF_INTERNAL_SW_MINOR_VERSION) || \
57      (OSIF_SW_PATCH_VERSION != OSIF_INTERNAL_SW_PATCH_VERSION) \
58     )
59     #error "Software Version Numbers of OsIf.h and OsIf_Internal.h are different"
60 #endif
61 
62 /* Check if OsIf.h file and OsIf_Cfg.h file are of the same vendor */
63 #if (OSIF_VENDOR_ID != OSIF_CFG_VENDOR_ID)
64     #error "OsIf.h and OsIf_Cfg.h have different vendor ids"
65 #endif
66 /* Check if OsIf.h file and OsIf_Cfg.h file are of the same Autosar version */
67 #if ((OSIF_AR_RELEASE_MAJOR_VERSION    != OSIF_CFG_AR_RELEASE_MAJOR_VERSION) || \
68      (OSIF_AR_RELEASE_MINOR_VERSION    != OSIF_CFG_AR_RELEASE_MINOR_VERSION) || \
69      (OSIF_AR_RELEASE_REVISION_VERSION != OSIF_CFG_AR_RELEASE_REVISION_VERSION))
70     #error "AUTOSAR Version Numbers of OsIf.h and OsIf_Cfg.h are different"
71 #endif
72 /* Check if OsIf.h file and OsIf_Cfg.h file are of the same Software version */
73 #if ((OSIF_SW_MAJOR_VERSION != OSIF_CFG_SW_MAJOR_VERSION) || \
74      (OSIF_SW_MINOR_VERSION != OSIF_CFG_SW_MINOR_VERSION) || \
75      (OSIF_SW_PATCH_VERSION != OSIF_CFG_SW_PATCH_VERSION) \
76     )
77     #error "Software Version Numbers of OsIf.h and OsIf_Cfg.h are different"
78 #endif
79 
80 /*==================================================================================================
81 *                                            CONSTANTS
82 ==================================================================================================*/
83 
84 /*==================================================================================================
85 *                                       DEFINES AND MACROS
86 ==================================================================================================*/
87 
88 /*==================================================================================================
89 *                                              ENUMS
90 ==================================================================================================*/
91 /*!
92  * @brief OsIf Counter type
93  *
94  * Counter type.
95  *
96  * @detail The dummy counter of Osif is meant as a loop-counter timeout mechanism that requirement no
97  * additional resource (hardware and software). It was meant to replace the typical loop timeout of decrementing
98  * a variable each time the loop was executed until the counter reaches zero. Usage of OsIf replaced these loop counters
99  * within RTD, so the advantage is that these timeouts can be configured to be simple loop counters
100  * (using the dummy counter), not changing the RTD code.
101  */
102 typedef enum
103 {
104     OSIF_COUNTER_DUMMY, /**< dummy counter */
105 #if (OSIF_USE_SYSTEM_TIMER == STD_ON)
106     OSIF_COUNTER_SYSTEM, /**< system counter */
107 #endif /* (OSIF_USE_SYSTEM_TIMER == STD_ON) */
108 #if (OSIF_USE_CUSTOM_TIMER == STD_ON)
109     OSIF_COUNTER_CUSTOM /**< custom counter */
110 #endif /* (OSIF_USE_CUSTOM_TIMER == STD_ON) */
111 } OsIf_CounterType;
112 
113 /*==================================================================================================
114 *                                  STRUCTURES AND OTHER TYPEDEFS
115 ==================================================================================================*/
116 
117 /*==================================================================================================
118 *                                  GLOBAL VARIABLE DECLARATIONS
119 ==================================================================================================*/
120 
121 /*==================================================================================================
122 *                                       FUNCTION PROTOTYPES
123 ==================================================================================================*/
124 #define BASENXP_START_SEC_CODE
125 #include "BaseNXP_MemMap.h"
126 
127 /*!
128  * @brief Initialize OsIf
129  *
130  * This function initializes the OsIf module and should be called during startup, before every
131  * other intialization other than Mcu.
132  *
133  */
134 void OsIf_Init(const void* Config);
135 
136 /*!
137  * @brief Get the current value counter
138  *
139  * This function returns the current value of the counter.
140  *
141  * @param[in] SelectedCounter the type of counter to use
142  * @return the current value of the counter
143  */
144 uint32 OsIf_GetCounter(OsIf_CounterType SelectedCounter);
145 
146 /*!
147  * @brief Get the elapsed value from a reference point
148  *
149  * This function returns the delta time in ticks compared to a reference, and updates the reference.
150  *
151  * @param[inout] CurrentRef reference counter value, updated to current counter value
152  * @param[in] SelectedCounter the type of counter to use
153  * @return the elapsed time
154  */
155 uint32 OsIf_GetElapsed(uint32 * const CurrentRef, OsIf_CounterType SelectedCounter);
156 
157 /*!
158  * @brief Set a new frequency used for time conversion (microseconds to ticks)
159  *
160  * This function stores a new timer frequency used for time conversion computations
161  *
162  * @param[in] Freq the new frequency
163  * @param[in] SelectedCounter the type of counter to use
164  */
165 void OsIf_SetTimerFrequency(uint32 Freq, OsIf_CounterType SelectedCounter);
166 
167 /*!
168  * @brief Convert microseconds to ticks
169  *
170  * This function converts a value from microsecond units to ticks units.
171  *
172  * @param[in] Micros microseconds value
173  * @param[in] SelectedCounter the type of counter to use
174  * @return the equivalent value in ticks
175  */
176 uint32 OsIf_MicrosToTicks(uint32 Micros, OsIf_CounterType SelectedCounter);
177 
178 #define BASENXP_STOP_SEC_CODE
179 #include "BaseNXP_MemMap.h"
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 /** @} */
186 
187 #endif /* OSIF_H */
188