1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /**
8  *   @file       Emios_Mcl_Ip.h
9  *
10  *   @version    3.0.0
11  *
12  *   @brief      AUTOSAR Mcl - Emios Common driver header file.
13  *
14  *   @addtogroup EMIOS_IP_DRIVER EMIOS IP Driver
15  *   @{
16  */
17 
18 #ifndef EMIOS_MCL_IP_H
19 #define EMIOS_MCL_IP_H
20 
21 #ifdef __cplusplus
22 extern "C"{
23 #endif
24 
25 /*==================================================================================================
26 *                                        INCLUDE FILES
27 * 1) system and project includes
28 * 2) needed interfaces from external units
29 * 3) internal and external interfaces from this unit
30 ==================================================================================================*/
31 #include "OsIf.h"
32 
33 #include "StandardTypes.h"
34 #include "Emios_Mcl_Ip_Cfg.h"
35 
36 #if (STD_ON == EMIOS_MCL_IP_DEV_ERROR_DETECT)
37 #include "Devassert.h"
38 #endif
39 
40 /*==================================================================================================
41 *                               HEADER FILE VERSION INFORMATION
42 ==================================================================================================*/
43 #define EMIOS_MCL_IP_VENDOR_ID                    43
44 #define EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION     4
45 #define EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION     7
46 #define EMIOS_MCL_IP_AR_RELEASE_REVISION_VERSION  0
47 #define EMIOS_MCL_IP_SW_MAJOR_VERSION             3
48 #define EMIOS_MCL_IP_SW_MINOR_VERSION             0
49 #define EMIOS_MCL_IP_SW_PATCH_VERSION             0
50 
51 /*==================================================================================================
52 *                                      FILE VERSION CHECKS
53 ==================================================================================================*/
54 #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
55 /* Check if header file and StandardTypes.h are of the same AUTOSAR version */
56 #if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION != STD_AR_RELEASE_MAJOR_VERSION) || \
57      (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION != STD_AR_RELEASE_MINOR_VERSION))
58     #error "AUTOSAR Version Numbers of Emios_Mcl_Ip.h and StandardTypes.h are different"
59 #endif
60 
61 /* Check if header file and OsIf.h are of the same AUTOSAR version */
62 #if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION != OSIF_AR_RELEASE_MAJOR_VERSION) || \
63      (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION != OSIF_AR_RELEASE_MINOR_VERSION))
64     #error "AUTOSAR Version Numbers of Emios_Mcl_Ip.h and OsIf.h are different"
65 #endif
66 
67 #if (STD_ON == EMIOS_MCL_IP_DEV_ERROR_DETECT)
68 /* Check if header file and Devassert.h are of the same AUTOSAR version */
69 #if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
70      (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION != DEVASSERT_AR_RELEASE_MINOR_VERSION))
71     #error "AUTOSAR Version Numbers of Emios_Mcl_Ip.h and Devassert.h are different"
72 #endif
73 #endif /*(STD_ON == EMIOS_MCL_IP_DEV_ERROR_DETECT)*/
74 #endif /*DISABLE_MCAL_INTERMODULE_ASR_CHECK*/
75 
76 /* Check if header file and Emios_Mcl_Ip_Cfg header file are of the same vendor. */
77 #if (EMIOS_MCL_IP_VENDOR_ID != EMIOS_MCL_IP_CFG_VENDOR_ID)
78     #error "Vendor IDs of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
79 #endif
80 
81 /* Check if header file and Emios_Mcl_Ip_Cfg header file are of the same AUTOSAR version. */
82 #if ((EMIOS_MCL_IP_AR_RELEASE_MAJOR_VERSION    != EMIOS_MCL_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
83      (EMIOS_MCL_IP_AR_RELEASE_MINOR_VERSION    != EMIOS_MCL_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
84      (EMIOS_MCL_IP_AR_RELEASE_REVISION_VERSION != EMIOS_MCL_IP_CFG_AR_RELEASE_REVISION_VERSION))
85     #error "AUTOSAR version numbers of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
86 #endif
87 
88 /* Check if header file and Emios_Pwm_Ip_Cfg header file are of the same software version */
89 #if ((EMIOS_MCL_IP_SW_MAJOR_VERSION != EMIOS_MCL_IP_CFG_SW_MAJOR_VERSION) || \
90      (EMIOS_MCL_IP_SW_MINOR_VERSION != EMIOS_MCL_IP_CFG_SW_MINOR_VERSION) || \
91      (EMIOS_MCL_IP_SW_PATCH_VERSION != EMIOS_MCL_IP_CFG_SW_PATCH_VERSION))
92     #error "Software version numbers of Emios_Mcl_Ip.h and Emios_Mcl_Ip_Cfg.h are different."
93 #endif
94 
95 /*==================================================================================================
96 *                                          CONSTANTS
97 ==================================================================================================*/
98 
99 /*==================================================================================================
100 *                                      DEFINES AND MACROS
101 ==================================================================================================*/
102 
103 /*==================================================================================================
104 *                                            ENUMS
105 ==================================================================================================*/
106 
107 /*==================================================================================================
108 *                                 STRUCTURES AND OTHER TYPEDEFS
109 ==================================================================================================*/
110 
111 /*==================================================================================================
112 *                                GLOBAL VARIABLE DECLARATIONS
113 ==================================================================================================*/
114 
115 /*==================================================================================================
116 *                                    FUNCTION PROTOTYPES
117 ==================================================================================================*/
118 #define MCL_START_SEC_CODE
119 #include "Mcl_MemMap.h"
120 
121 /**
122  * @brief   Emios start channel function.
123  * @details This function is called separately for each EMIOS hw channel in order to enable it.
124  *
125  * @param[in] Instance    Instance of EMIOS used.
126  * @param[in] HwChannel EMIOS hardware channel used.
127  */
128 void Emios_Mcl_Ip_EnableChannel(uint8 Instance, uint8 HwChannel);
129 
130 /**
131  * @brief   Emios stop channel function.
132  * @details This function is called separately for each EMIOS hw channel in order to disable it.
133  *
134  * @param[in] Instance    Instance of EMIOS used.
135  * @param[in] HwChannel EMIOS hardware channel used.
136  */
137 void Emios_Mcl_Ip_DisableChannel(uint8 Instance, uint8 HwChannel);
138 
139 /**
140  * @brief The function shall enable the output update for the corresponding channel.
141  *
142  * @param[in] Instance    Instance of EMIOS used.
143  * @param[in] ChannelMask EMIOS channel mask used to enable the output update.
144  *                        This mask should be on 32 bits.
145  *                        0x00000001U <- First channel will be affected
146  *                          ^      ^
147  *                          |      |
148  *                         MSB    LSB
149  *                        0x00FFFFFFU <- All channels will be affected
150  *                                       (EMIOS instance has only 24 channels)
151  */
152 void Emios_Mcl_Ip_ComparatorTransferEnable(uint8 Instance, uint32 ChannelMask);
153 
154 /**
155  * @brief The function shall disable the output update for the corresponding channel.
156  *
157  * @param[in] Instance    Instance of EMIOS used.
158  * @param[in] ChannelMask EMIOS channel mask used to disable the output update.
159  *                        This mask should be on 32 bits.
160  *                        0x00000001U <- First channel will be affected
161  *                          ^      ^
162  *                          |      |
163  *                         MSB    LSB
164  *                        0x00FFFFFFU <- All channels will be affected
165  *                                       (EMIOS instance has only 24 channels)
166  */
167 void Emios_Mcl_Ip_ComparatorTransferDisable(uint8 Instance, uint32 ChannelMask);
168 
169 /**
170  * @brief This function shall reset all the register used to initialize a channel as a masterbus. The
171  * API should reset to POR values all registers used for configuring the common part of EMIOS IP.
172  *
173  * @param[in] Instance  Instance of EMIOS used.
174  * @return Emios_Ip_CommonStatusType
175  */
176 Emios_Ip_CommonStatusType Emios_Mcl_Ip_Deinit(uint8 Instance);
177 
178 /**
179  * @brief The API should configure the common part of EMIOS IP to be used by any driver implementation
180  *        with EMIOS support (ex:  ICU, PWM, GPT, OCU)
181  *
182  * @param[in] Instance   Instance of EMIOS used.
183  * @param[in] ConfigPtr  EMIOS instance specific configuration.
184  * @return Emios_Ip_CommonStatusType
185  */
186 Emios_Ip_CommonStatusType Emios_Mcl_Ip_Init(uint8 Instance, const Emios_Mcl_Ip_ConfigType *const ConfigPtr);
187 
188 /**
189  * @brief   Allow the user to specify the number of bus reload events skipped.
190  *
191  * @details Reload Signal Output Delay Interval
192  *          Specifies the delay interval, in counter bus reload events, between each assertion of AS1-BS1 reload in
193  *          MC and MCB modes.
194  *              00000b - Every event
195  *              00001b - Every 2nd event
196  *              00010b - Every 3rd event
197  *              . . .
198  *              11111b - Every 32nd event
199  *
200  * @param HwInstance Instance of EMIOS used.
201  * @param HwChannel  EMIOS hardware channel used.
202  * @param Interval
203  */
204 void Emios_Mcl_Ip_SetReloadInterval(uint8 HwInstance, uint8 HwChannel, uint8 Interval);
205 
206 /**
207  * @brief Change the period on active/intialized EMIOS counter(master) bus.
208  *
209  * @param HwInstance Instance of EMIOS used.
210  * @param HwChannel  EMIOS hardware channel used.
211  *
212  * @return boolean Status of operation.
213  */
214 boolean Emios_Mcl_Ip_ValidateChannel(uint8 HwInstance, uint8 HwChannel);
215 
216 /**
217  * @brief
218  *
219  * @param HwInstance  Instance of EMIOS used.
220  * @param HwChannel  EMIOS hardware channel used.
221  * @param Period     Period
222  * @return Emios_Ip_CommonStatusType
223  */
224 Emios_Ip_CommonStatusType Emios_Mcl_Ip_SetCounterBusPeriod(uint8 HwInstance, uint8 HwChannel, uint32 Period);
225 
226 /**
227  * @brief  Get period of counter bus channels
228  *
229  * @param Instance  Instance of EMIOS used.
230  * @param Channel   EMIOS hardware channel used.
231  * @return The period value of Counter Bus channels
232  */
233 #if (STD_ON == EMIOS_MCL_IP_24BITS_TIMER_WIDTH)
234 uint32 Emios_Mcl_Ip_GetCounterBusPeriod(uint8 Instance, uint8 Channel);
235 #else
236 uint16 Emios_Mcl_Ip_GetCounterBusPeriod(uint8 Instance, uint8 Channel);
237 #endif
238 
239 #if (STD_ON == EMIOS_IP_MULTICORE_IS_AVAILABLE)
240 /**
241  * @brief
242  *
243  * @param HwInstance
244  * @return boolean
245  */
246 boolean Emios_Mcl_Ip_ValidateMultiCoreInit(uint8 HwInstance);
247 #endif /* STD_ON == EMIOS_IP_MULTICORE_IS_AVAILABLE */
248 
249 /**
250  * @brief  Configure Global Timebase
251  * @details This function enables or disables the GTBE bit of the EMIOS->MCR register of an addressed eMIOS instance.
252  *
253  * @param[in] Instance  Instance of EMIOS used.
254  * @param[in] Value   STD_ON to set bit and STD_OFF to reset bit.
255  * @return void
256  */
257 void Emios_Mcl_Ip_ConfigureGlobalTimebase(uint8 Instance, uint8 Value);
258 
259 #define MCL_STOP_SEC_CODE
260 #include "Mcl_MemMap.h"
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 /** @} */
267 
268 #endif /* EMIOS_MCL_IP_H */
269