1 /*
2 * Copyright 2021-2023 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 /**
7 * @file Clock_Ip_FracDiv.c
8 * @version 1.0.0
9 *
10 * @brief CLOCK driver implementations.
11 * @details CLOCK driver implementations.
12 *
13 * @addtogroup CLOCK_DRIVER Clock Ip Driver
14 * @{
15 */
16
17
18 #ifdef __cplusplus
19 extern "C"{
20 #endif
21
22
23 /*==================================================================================================
24 * INCLUDE FILES
25 * 1) system and project includes
26 * 2) needed interfaces from external units
27 * 3) internal and external interfaces from this unit
28 ==================================================================================================*/
29
30
31
32 #include "Clock_Ip_Private.h"
33
34 /*==================================================================================================
35 SOURCE FILE VERSION INFORMATION
36 ==================================================================================================*/
37 #define CLOCK_IP_FRACDIV_VENDOR_ID_C 43
38 #define CLOCK_IP_FRACDIV_AR_RELEASE_MAJOR_VERSION_C 4
39 #define CLOCK_IP_FRACDIV_AR_RELEASE_MINOR_VERSION_C 7
40 #define CLOCK_IP_FRACDIV_AR_RELEASE_REVISION_VERSION_C 0
41 #define CLOCK_IP_FRACDIV_SW_MAJOR_VERSION_C 1
42 #define CLOCK_IP_FRACDIV_SW_MINOR_VERSION_C 0
43 #define CLOCK_IP_FRACDIV_SW_PATCH_VERSION_C 0
44
45 /*==================================================================================================
46 * FILE VERSION CHECKS
47 ==================================================================================================*/
48 /* Check if Clock_Ip_FracDiv.c file and Clock_Ip_Private.h file are of the same vendor */
49 #if (CLOCK_IP_FRACDIV_VENDOR_ID_C != CLOCK_IP_PRIVATE_VENDOR_ID)
50 #error "Clock_Ip_FracDiv.c and Clock_Ip_Private.h have different vendor ids"
51 #endif
52
53 /* Check if Clock_Ip_FracDiv.c file and Clock_Ip_Private.h file are of the same Autosar version */
54 #if ((CLOCK_IP_FRACDIV_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
55 (CLOCK_IP_FRACDIV_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
56 (CLOCK_IP_FRACDIV_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
57 )
58 #error "AutoSar Version Numbers of Clock_Ip_FracDiv.c and Clock_Ip_Private.h are different"
59 #endif
60
61 /* Check if Clock_Ip_FracDiv.c file and Clock_Ip_Private.h file are of the same Software version */
62 #if ((CLOCK_IP_FRACDIV_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
63 (CLOCK_IP_FRACDIV_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
64 (CLOCK_IP_FRACDIV_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
65 )
66 #error "Software Version Numbers of Clock_Ip_FracDiv.c and Clock_Ip_Private.h are different"
67 #endif
68
69 /*==================================================================================================
70 * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
71 ==================================================================================================*/
72
73 /*==================================================================================================
74 * LOCAL MACROS
75 ==================================================================================================*/
76
77 /*==================================================================================================
78 * LOCAL CONSTANTS
79 ==================================================================================================*/
80
81 /*==================================================================================================
82 * LOCAL VARIABLES
83 ==================================================================================================*/
84
85 /*==================================================================================================
86 * GLOBAL CONSTANTS
87 ==================================================================================================*/
88
89 /*==================================================================================================
90 * GLOBAL VARIABLES
91 ==================================================================================================*/
92
93 /*==================================================================================================
94 * LOCAL FUNCTION PROTOTYPES
95 ==================================================================================================*/
96 /* Clock start section code */
97 #define MCU_START_SEC_CODE
98
99 #include "Mcu_MemMap.h"
100
101 static void Clock_Ip_CallbackFracDivEmpty(Clock_Ip_FracDivConfigType const* Config);
102 static Clock_Ip_DfsStatusType Clock_Ip_CallbackFracDivEmptyComplete(Clock_Ip_NameType DfsName);
103 #ifdef CLOCK_IP_DFS_MFI_MFN
104 static void Clock_Ip_ResetDfsMfiMfn(Clock_Ip_FracDivConfigType const *Config);
105 static void Clock_Ip_SetDfsMfiMfn(Clock_Ip_FracDivConfigType const *Config);
106 static Clock_Ip_DfsStatusType Clock_Ip_CompleteDfsMfiMfn(Clock_Ip_NameType DfsName);
107 #endif
108
109 /* Clock stop section code */
110 #define MCU_STOP_SEC_CODE
111
112 #include "Mcu_MemMap.h"
113 /*==================================================================================================
114 * LOCAL FUNCTIONS
115 ==================================================================================================*/
116 /* Clock start section code */
117 #define MCU_START_SEC_CODE
118
119 #include "Mcu_MemMap.h"
120
Clock_Ip_CallbackFracDivEmpty(Clock_Ip_FracDivConfigType const * Config)121 static void Clock_Ip_CallbackFracDivEmpty(Clock_Ip_FracDivConfigType const* Config)
122 {
123 (void)Config;
124 /* No implementation */
125 }
126
Clock_Ip_CallbackFracDivEmptyComplete(Clock_Ip_NameType DfsName)127 static Clock_Ip_DfsStatusType Clock_Ip_CallbackFracDivEmptyComplete(Clock_Ip_NameType DfsName)
128 {
129 (void)DfsName;
130 /* No implementation */
131 return STATUS_DFS_NOT_ENABLED;
132 }
133
134 #ifdef CLOCK_IP_DFS_MFI_MFN
Clock_Ip_ResetDfsMfiMfn(Clock_Ip_FracDivConfigType const * Config)135 static void Clock_Ip_ResetDfsMfiMfn(Clock_Ip_FracDivConfigType const *Config)
136 {
137
138 uint32 Instance = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_MODULE_INSTANCE];
139 uint32 DividerIndex = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_DIVIDER_INDEX];
140
141 /* Put this fractional divider in reset state */
142 Clock_Ip_apxDfs[Instance]->PORTRESET |= (1UL << DividerIndex);
143 }
Clock_Ip_SetDfsMfiMfn(Clock_Ip_FracDivConfigType const * Config)144 static void Clock_Ip_SetDfsMfiMfn(Clock_Ip_FracDivConfigType const *Config)
145 {
146
147 uint32 Instance;
148 uint32 DividerIndex;
149 uint32 IntegerPart; /* Integer part. */
150 uint32 FractionalPart; /* Fractional part. */
151
152 uint32 Value = 0U;
153
154 if (NULL_PTR != Config)
155 {
156 Instance = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_MODULE_INSTANCE];
157 DividerIndex = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_DIVIDER_INDEX];
158 IntegerPart = Config->Value[0U];
159 FractionalPart = Config->Value[1U];
160
161 /* Check whether fractional divider is enabled */
162 if (0U != Config->Enable)
163 {
164 /* Write the value by which input signal is divided */
165 Value |= DFS_DVPORT_MFN(FractionalPart);
166 Value |= DFS_DVPORT_MFI(IntegerPart);
167 Clock_Ip_apxDfs[Instance]->DVPORT[DividerIndex] = Value;
168
169 /* Get corresponding port out of reset state */
170 Clock_Ip_apxDfs[Instance]->PORTRESET &= ~(1UL << DividerIndex);
171 }
172 }
173 }
Clock_Ip_CompleteDfsMfiMfn(Clock_Ip_NameType DfsName)174 static Clock_Ip_DfsStatusType Clock_Ip_CompleteDfsMfiMfn(Clock_Ip_NameType DfsName)
175 {
176 boolean TimeoutOccurred = FALSE;
177 uint32 StartTime;
178 uint32 ElapsedTime;
179 uint32 TimeoutTicks;
180 uint32 DfsPortStatus;
181
182 Clock_Ip_DfsStatusType Status = STATUS_DFS_LOCKED;
183
184 uint32 Instance = Clock_Ip_au8ClockFeatures[DfsName][CLOCK_IP_MODULE_INSTANCE];
185 uint32 DividerIndex = Clock_Ip_au8ClockFeatures[DfsName][CLOCK_IP_DIVIDER_INDEX];
186
187 /* Check whether fractional divider is enabled */
188 if (0U == (Clock_Ip_apxDfs[Instance]->PORTRESET & (1UL << DividerIndex)))
189 {
190 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
191 /* Wait until this port is locked */
192 do
193 {
194 DfsPortStatus = (((Clock_Ip_apxDfs[Instance]->PORTSR >> DFS_PORTSR_PORTSTAT_SHIFT) & DFS_PORTSR_PORTSTAT_MASK) & (1UL << DividerIndex));
195 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
196 }
197 while ((0U == DfsPortStatus) && (FALSE == TimeoutOccurred));
198
199 if (FALSE != TimeoutOccurred)
200 {
201 Status = STATUS_DFS_UNLOCKED;
202 /* Report timeout error */
203 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, DfsName);
204 }
205 }
206 else
207 {
208 Status = STATUS_DFS_NOT_ENABLED;
209 }
210
211 return Status;
212 }
213
214
215 #endif
216
217 /* Clock stop section code */
218 #define MCU_STOP_SEC_CODE
219
220 #include "Mcu_MemMap.h"
221
222 /*==================================================================================================
223 * GLOBAL FUNCTIONS
224 ==================================================================================================*/
225 /*==================================================================================================
226 * GLOBAL CONSTANTS
227 ==================================================================================================*/
228 /* Clock start constant section data */
229 #define MCU_START_SEC_CONST_UNSPECIFIED
230
231 #include "Mcu_MemMap.h"
232
233 const Clock_Ip_FracDivCallbackType Clock_Ip_axFracDivCallbacks[CLOCK_IP_FRACTIONAL_DIVIDER_CALLBACKS_COUNT] =
234 {
235 {
236 Clock_Ip_CallbackFracDivEmpty, /* Reset */
237 Clock_Ip_CallbackFracDivEmpty, /* Set */
238 Clock_Ip_CallbackFracDivEmptyComplete, /* Complete */
239 },
240 #ifdef CLOCK_IP_DFS_MFI_MFN
241 {
242 Clock_Ip_ResetDfsMfiMfn, /* Reset */
243 Clock_Ip_SetDfsMfiMfn, /* Set */
244 Clock_Ip_CompleteDfsMfiMfn, /* Complete */
245 },
246 #endif
247 };
248
249 /* Clock stop constant section data */
250 #define MCU_STOP_SEC_CONST_UNSPECIFIED
251
252 #include "Mcu_MemMap.h"
253
254 #ifdef __cplusplus
255 }
256 #endif
257
258 /** @} */
259