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