1 /*
2  * Copyright 2021-2022 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    0.9.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                0
42 #define CLOCK_IP_SW_MINOR_VERSION                9
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 /*!
194  * @brief Clears status flags for a monitor clock.
195  *
196  * This function clears status flags for a monitor clock.
197  *
198  * @param[in] ClockName  Clock Name.
199  *
200  * @return void
201  */
202 void Clock_Ip_ClearClockMonitorStatus(Clock_Ip_NameType ClockName);
203 
204 /*!
205  * @brief Returns the clock monitor status.
206  *
207  * This function returns status of the clock monitor: undefined, lower, higher, in range.
208  * This function returns undefined status if this function is called when corresponding
209  * cmu is not enabled.
210  *
211  * @return Status.  Cmu status
212  */
213 Clock_Ip_CmuStatusType Clock_Ip_GetClockMonitorStatus(Clock_Ip_NameType ClockName);
214 
215 /*!
216  * @brief Disables a clock monitor.
217  *
218  * This function disables a clock monitor.
219  *
220  * @param[in] ClockName  Clock Name.
221  *
222  * @return void
223  */
224 void Clock_Ip_DisableClockMonitor(Clock_Ip_NameType ClockName);
225 
226 /*!
227  * @brief Disables clock for a peripheral.
228  *
229  * This function disables clock for a peripheral.
230  *
231  * @param[in] ClockName  Clock Name.
232  *
233  * @return void
234  */
235 void Clock_Ip_DisableModuleClock(Clock_Ip_NameType ClockName);
236 
237 /*!
238  * @brief Enables clock for a peripheral.
239  *
240  * This function enables clock for a peripheral.
241  *
242  * @param[in] ClockName  Clock Name.
243  *
244  * @return void
245  */
246 void Clock_Ip_EnableModuleClock(Clock_Ip_NameType ClockName);
247 
248 
249 #if (defined(CLOCK_IP_ENABLE_USER_MODE_SUPPORT))
250   #if (STD_ON == CLOCK_IP_ENABLE_USER_MODE_SUPPORT)
251 void Clock_Ip_SetUserAccessAllowed(void);
252   #endif
253 #endif
254 
255 
256 #if (defined(CLOCK_IP_GET_FREQUENCY_API))
257   #if (CLOCK_IP_GET_FREQUENCY_API == STD_ON)
258 
259 
260  /*!
261  * @brief Gets the clock frequency for a specific clock name.
262  *
263  * This function checks the current clock configurations and then calculates
264  * the clock frequency for a specific clock name defined in Clock_Ip_NameType.
265  * Clock modules must be properly configured before using this function.
266  * See features.h for supported clock names for different chip families.
267  * The returned value is in Hertz. If frequency is required for a peripheral and the
268  * module is not clocked, then 0 Hz frequency is returned.
269  *
270  * @param[in] ClockName Clock names defined in Clock_Ip_NameType
271  * @return frequency    Returned clock frequency value in Hertz
272  */
273 uint32 Clock_Ip_GetClockFrequency(Clock_Ip_NameType ClockName);
274   #endif
275 #endif
276 
277 
278 /* Clock stop section code */
279 #define MCU_STOP_SEC_CODE
280 
281 #include "Mcu_MemMap.h"
282 
283 #if defined(__cplusplus)
284 }
285 #endif /* __cplusplus*/
286 
287 /*! @}*/
288 
289 #endif /* CLOCK_IP_H */
290 
291