1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef CLOCK_IP_H
8 #define CLOCK_IP_H
9 
10 /**
11 *   @file    Clock_Ip.h
12 *   @version    3.0.0
13 *
14 *   @brief   CLOCK IP driver header file.
15 *   @details CLOCK IP driver header file.
16 *
17 *   @addtogroup CLOCK_DRIVER Clock Ip Driver
18 *   @{
19 */
20 
21 
22 #if defined(__cplusplus)
23 extern "C"{
24 #endif
25 
26 /*==================================================================================================
27 *                                          INCLUDE FILES
28 * 1) system and project includes
29 * 2) needed interfaces from external units
30 * 3) internal and external interfaces from this unit
31 ==================================================================================================*/
32 #include "Clock_Ip_Types.h"
33 #include "Clock_Ip_Cfg.h"
34 /*==================================================================================================
35 *                               SOURCE FILE VERSION INFORMATION
36 ==================================================================================================*/
37 #define CLOCK_IP_VENDOR_ID                       43
38 #define CLOCK_IP_AR_RELEASE_MAJOR_VERSION        4
39 #define CLOCK_IP_AR_RELEASE_MINOR_VERSION        7
40 #define CLOCK_IP_AR_RELEASE_REVISION_VERSION     0
41 #define CLOCK_IP_SW_MAJOR_VERSION                3
42 #define CLOCK_IP_SW_MINOR_VERSION                0
43 #define CLOCK_IP_SW_PATCH_VERSION                0
44 
45 /*==================================================================================================
46 *                                      FILE VERSION CHECKS
47 ==================================================================================================*/
48 /* Check if Clock_Ip.h file and Clock_Ip_Types.h file have same versions */
49 #if (CLOCK_IP_VENDOR_ID  != CLOCK_IP_TYPES_VENDOR_ID)
50     #error "Clock_Ip.h and Clock_Ip_Types.h have different vendor IDs"
51 #endif
52 
53 /* Check if Clock_Ip.h file and Clock_Ip_Types.h file are of the same Autosar version */
54 #if ((CLOCK_IP_AR_RELEASE_MAJOR_VERSION    != CLOCK_IP_TYPES_AR_RELEASE_MAJOR_VERSION) || \
55      (CLOCK_IP_AR_RELEASE_MINOR_VERSION    != CLOCK_IP_TYPES_AR_RELEASE_MINOR_VERSION) || \
56      (CLOCK_IP_AR_RELEASE_REVISION_VERSION != CLOCK_IP_TYPES_AR_RELEASE_REVISION_VERSION))
57     #error "AutoSar Version Numbers of Clock_Ip.h and Clock_Ip_Types.h are different"
58 #endif
59 
60 /* Check if Clock_Ip.h file and Clock_Ip_Types.h file are of the same Software version */
61 #if ((CLOCK_IP_SW_MAJOR_VERSION != CLOCK_IP_TYPES_SW_MAJOR_VERSION) || \
62      (CLOCK_IP_SW_MINOR_VERSION != CLOCK_IP_TYPES_SW_MINOR_VERSION) || \
63      (CLOCK_IP_SW_PATCH_VERSION != CLOCK_IP_TYPES_SW_PATCH_VERSION))
64     #error "Software Version Numbers of Clock_Ip.h and Clock_Ip_Types.h are different"
65 #endif
66 
67 /* Check if Clock_Ip.h file and Clock_Ip_Cfg.h file have same versions */
68 #if (CLOCK_IP_VENDOR_ID  != CLOCK_IP_CFG_VENDOR_ID)
69     #error "Clock_Ip.h and Clock_Ip_Cfg.h have different vendor IDs"
70 #endif
71 
72 /* Check if Clock_Ip.h file and Clock_Ip_Cfg.h file are of the same Autosar version */
73 #if ((CLOCK_IP_AR_RELEASE_MAJOR_VERSION    != CLOCK_IP_CFG_AR_RELEASE_MAJOR_VERSION) || \
74      (CLOCK_IP_AR_RELEASE_MINOR_VERSION    != CLOCK_IP_CFG_AR_RELEASE_MINOR_VERSION) || \
75      (CLOCK_IP_AR_RELEASE_REVISION_VERSION != CLOCK_IP_CFG_AR_RELEASE_REVISION_VERSION))
76     #error "AutoSar Version Numbers of Clock_Ip.h and Clock_Ip_Cfg.h are different"
77 #endif
78 
79 /* Check if Clock_Ip.h file and Clock_Ip_Cfg.h file are of the same Software version */
80 #if ((CLOCK_IP_SW_MAJOR_VERSION != CLOCK_IP_CFG_SW_MAJOR_VERSION) || \
81      (CLOCK_IP_SW_MINOR_VERSION != CLOCK_IP_CFG_SW_MINOR_VERSION) || \
82      (CLOCK_IP_SW_PATCH_VERSION != CLOCK_IP_CFG_SW_PATCH_VERSION))
83     #error "Software Version Numbers of Clock_Ip.h and Clock_Ip_Cfg.h are different"
84 #endif
85 /*==================================================================================================
86 *                                            CONSTANTS
87 ==================================================================================================*/
88 
89 /*==================================================================================================
90 *                                       DEFINES AND MACROS
91 ==================================================================================================*/
92 
93 /*==================================================================================================
94 *                                              ENUMS
95 ==================================================================================================*/
96 
97 /*==================================================================================================
98 *                                  STRUCTURES AND OTHER TYPEDEFS
99 ==================================================================================================*/
100 
101 /*==================================================================================================
102 *                                  GLOBAL VARIABLE DECLARATIONS
103 ==================================================================================================*/
104 
105 /*==================================================================================================
106 *                                       FUNCTION PROTOTYPES
107 ==================================================================================================*/
108 
109 /* Clock start section code */
110 #define MCU_START_SEC_CODE
111 
112 #include "Mcu_MemMap.h"
113 
114 
115 /*!
116  * @brief Set clock configuration according to pre-defined structure.
117  *
118  * This function sets system to target clock configuration; It sets the
119  * clock modules registers for clock mode change.
120  *
121  * @param[in] Config  Pointer to configuration structure.
122  *
123  * @return void
124  *
125  * @note If external clock is used in the target mode, please make sure it is
126  * enabled, for example, if the external oscillator is used, please setup correctly.
127  */
128 Clock_Ip_StatusType Clock_Ip_Init(Clock_Ip_ClockConfigType const * Config);
129 
130 /*!
131  * @brief Set the PLL and other MCU specific clock options.
132  *
133  * This function initializes the PLL and other MCU specific clock options.
134  * The clock configuration parameters are provided via the configuration structure.
135  *
136  * This function shall start the PLL lock procedure (if PLL
137  * shall be initialized) and shall return without waiting until the PLL is locked.
138  *
139  * @param[in] Config  Pointer to configuration structure.
140  *
141  * @return void
142  */
143 void Clock_Ip_InitClock(Clock_Ip_ClockConfigType const * Config);
144 
145 /*!
146  * @brief Returns the lock status of the PLL.
147  *
148  * This function returns status of the PLL: undefined, unlocked or locked.
149  * This function returns undefined status if this function is called prior
150  * to calling of the function Clock_Ip_InitClock
151  *
152  * @return Status.  Pll lock status
153  */
154 Clock_Ip_PllStatusType Clock_Ip_GetPllStatus(void);
155 
156 /*!
157  * @brief Activates the PLL in MCU clock distribution.
158  *
159  * This function activates the PLL clock to
160  * the MCU clock distribution.
161  *
162  * This function removes the current clock source
163  * (for example internal oscillator clock) from MCU clock distribution.
164  *
165  * Application layer calls this function after the status of the PLL has been detected as
166  * locked by the function Clock_Ip_GetPllStatus.
167  *
168  * The function Clock_Ip_DistributePll shall return without affecting
169  * the MCU hardware if the PLL clock has been automatically activated by the MCU
170  * hardware.
171  *
172  * @return void
173  */
174 void Clock_Ip_DistributePll(void);
175 
176 
177 
178 /*!
179  * @brief Install a clock notifications callback
180  *
181  * This function installs a callback for
182  * reporting notifications from clock driver
183  *
184  *
185  * @param[in] Clock_Ip_NotificationsCallbackType  notifications callback
186  *
187  * @return void
188  *
189  * @implements Clock_Ip_InstallNotificationsCallback_Activity
190  */
191 void Clock_Ip_InstallNotificationsCallback(Clock_Ip_NotificationsCallbackType Callback);
192 /*!
193  * @brief Disables a clock monitor.
194  *
195  * This function disables a clock monitor.
196  *
197  * @param[in] ClockName  Clock Name.
198  *
199  * @return void
200  */
201 void Clock_Ip_DisableClockMonitor(Clock_Ip_NameType ClockName);
202 /*!
203  * @brief Disables clock for a peripheral.
204  *
205  * This function disables clock for a peripheral.
206  *
207  * @param[in] ClockName  Clock Name.
208  *
209  * @return void
210  */
211 void Clock_Ip_DisableModuleClock(Clock_Ip_NameType ClockName);
212 
213 /*!
214  * @brief Enables clock for a peripheral.
215  *
216  * This function enables clock for a peripheral.
217  *
218  * @param[in] ClockName  Clock Name.
219  *
220  * @return void
221  */
222 void Clock_Ip_EnableModuleClock(Clock_Ip_NameType ClockName);
223 
224 
225 #if (defined(CLOCK_IP_ENABLE_USER_MODE_SUPPORT))
226   #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
227 void Clock_Ip_SetUserAccessAllowed(void);
228   #endif
229 #endif
230 
231 
232 #if (defined(CLOCK_IP_GET_FREQUENCY_API))
233   #if (CLOCK_IP_GET_FREQUENCY_API == STD_ON)
234 
235 
236  /*!
237  * @brief Gets the clock frequency for a specific clock name.
238  *
239  * This function checks the current clock configurations and then calculates
240  * the clock frequency for a specific clock name defined in Clock_Ip_NameType.
241  * Clock modules must be properly configured before using this function.
242  * See features.h for supported clock names for different chip families.
243  * The returned value is in Hertz. If frequency is required for a peripheral and the
244  * module is not clocked, then 0 Hz frequency is returned.
245  *
246  * @param[in] ClockName Clock names defined in Clock_Ip_NameType
247  * @return frequency    Returned clock frequency value in Hertz
248  */
249 uint32 Clock_Ip_GetClockFrequency(Clock_Ip_NameType ClockName);
250   #endif
251 #endif
252 
253 
254 #ifdef CLOCK_IP_HAS_FIRC_STDBY_CLOCK_DISABLE
255 /*!
256  * @brief Disables FIRC in STANDBY mode.
257  *
258  * @param[in] void.
259  *
260  * @return void
261  */
262 void Clock_Ip_DisableFircInStandby(void);
263 #endif
264 
265 
266 #ifdef CLOCK_IP_HAS_FIRC_STDBY_CLOCK_ENABLE
267 /*!
268  * @brief Enables FIRC in STANDBY mode.
269  *
270  * @param[in] void.
271  *
272  * @return void
273  */
274 void Clock_Ip_EnableFircInStandby(void);
275 #endif
276 
277 
278 #ifdef CLOCK_IP_HAS_SIRC_STDBY_CLOCK_DISABLE
279 /*!
280  * @brief Disables SIRC in STANDBY mode.
281  *
282  * @param[in] void.
283  *
284  * @return void
285  */
286 void Clock_Ip_DisableSircInStandby(void);
287 #endif
288 
289 
290 #ifdef CLOCK_IP_HAS_SIRC_STDBY_CLOCK_ENABLE
291 /*!
292  * @brief Enables SIRC in STANDBY mode.
293  *
294  * @param[in] void.
295  *
296  * @return void
297  */
298 void Clock_Ip_EnableSircInStandby(void);
299 #endif
300 
301 
302 /* Clock stop section code */
303 #define MCU_STOP_SEC_CODE
304 
305 #include "Mcu_MemMap.h"
306 
307 #if defined(__cplusplus)
308 }
309 #endif /* __cplusplus*/
310 
311 /*! @}*/
312 
313 #endif /* CLOCK_IP_H */
314 
315