1 /*
2 * Copyright 2021-2022 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 /**
7 * @file Clock_Ip_FracDiv.c
8 * @version 0.9.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 0
42 #define CLOCK_IP_FRACDIV_SW_MINOR_VERSION_C 9
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 = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_MODULE_INSTANCE];
148 uint32 DividerIndex = Clock_Ip_au8ClockFeatures[Config->Name][CLOCK_IP_DIVIDER_INDEX];
149
150 uint32 IntegerPart = Config->Value[0U]; /* Integer part. */
151 uint32 FractionalPart = Config->Value[1U]; /* Fractional part. */
152
153 uint32 Value = 0U;
154
155 /* Check whether fractional divider is enabled */
156 if (0U != Config->Enable)
157 {
158 /* Write the value by which input signal is divided */
159 Value |= DFS_DVPORT_MFN(FractionalPart);
160 Value |= DFS_DVPORT_MFI(IntegerPart);
161 Clock_Ip_apxDfs[Instance]->DVPORT[DividerIndex] = Value;
162
163 /* Get corresponding port out of reset state */
164 Clock_Ip_apxDfs[Instance]->PORTRESET &= ~(1UL << DividerIndex);
165 }
166 }
Clock_Ip_CompleteDfsMfiMfn(Clock_Ip_NameType DfsName)167 static Clock_Ip_DfsStatusType Clock_Ip_CompleteDfsMfiMfn(Clock_Ip_NameType DfsName)
168 {
169 boolean TimeoutOccurred = FALSE;
170 uint32 StartTime;
171 uint32 ElapsedTime;
172 uint32 TimeoutTicks;
173 uint32 DfsPortStatus;
174
175 Clock_Ip_DfsStatusType Status = STATUS_DFS_LOCKED;
176
177 uint32 Instance = Clock_Ip_au8ClockFeatures[DfsName][CLOCK_IP_MODULE_INSTANCE];
178 uint32 DividerIndex = Clock_Ip_au8ClockFeatures[DfsName][CLOCK_IP_DIVIDER_INDEX];
179
180 /* Check whether fractional divider is enabled */
181 if (0U == (Clock_Ip_apxDfs[Instance]->PORTRESET & (1UL << DividerIndex)))
182 {
183 Clock_Ip_StartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_IP_TIMEOUT_VALUE_US);
184 /* Wait until this port is locked */
185 do
186 {
187 DfsPortStatus = (((Clock_Ip_apxDfs[Instance]->PORTSR >> DFS_PORTSR_PORTSTAT_SHIFT) & DFS_PORTSR_PORTSTAT_MASK) & (1UL << DividerIndex));
188 TimeoutOccurred = Clock_Ip_TimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
189 }
190 while ((0U == DfsPortStatus) && (FALSE == TimeoutOccurred));
191
192 if (FALSE != TimeoutOccurred)
193 {
194 Status = STATUS_DFS_UNLOCKED;
195 /* Report timeout error */
196 Clock_Ip_ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, DfsName);
197 }
198 }
199 else
200 {
201 Status = STATUS_DFS_NOT_ENABLED;
202 }
203
204 return Status;
205 }
206
207
208 #endif
209
210 /* Clock stop section code */
211 #define MCU_STOP_SEC_CODE
212
213 #include "Mcu_MemMap.h"
214
215 /*==================================================================================================
216 * GLOBAL FUNCTIONS
217 ==================================================================================================*/
218 /*==================================================================================================
219 * GLOBAL CONSTANTS
220 ==================================================================================================*/
221 /* Clock start constant section data */
222 #define MCU_START_SEC_CONST_UNSPECIFIED
223
224 #include "Mcu_MemMap.h"
225
226 const Clock_Ip_FracDivCallbackType Clock_Ip_axFracDivCallbacks[CLOCK_IP_FRACTIONAL_DIVIDER_CALLBACKS_COUNT] =
227 {
228 {
229 Clock_Ip_CallbackFracDivEmpty, /* Reset */
230 Clock_Ip_CallbackFracDivEmpty, /* Set */
231 Clock_Ip_CallbackFracDivEmptyComplete, /* Complete */
232 },
233 #ifdef CLOCK_IP_DFS_MFI_MFN
234 {
235 Clock_Ip_ResetDfsMfiMfn, /* Reset */
236 Clock_Ip_SetDfsMfiMfn, /* Set */
237 Clock_Ip_CompleteDfsMfiMfn, /* Complete */
238 },
239 #endif
240 };
241
242 /* Clock stop constant section data */
243 #define MCU_STOP_SEC_CONST_UNSPECIFIED
244
245 #include "Mcu_MemMap.h"
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 /** @} */
252