Clock_Ip_FracDiv.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral :
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file Clock_Ip_FracDiv.c
  26. * @version 1.0.0
  27. *
  28. * @brief CLOCK driver implementations.
  29. * @details CLOCK driver implementations.
  30. *
  31. * @addtogroup CLOCK_DRIVER Clock Ip Driver
  32. * @{
  33. */
  34. #include "Clock_Ip_Private.h"
  35. /*==================================================================================================
  36. SOURCE FILE VERSION INFORMATION
  37. ==================================================================================================*/
  38. #define CLOCK_IP_FRACDIV_VENDOR_ID_C 43
  39. #define CLOCK_IP_FRACDIV_AR_RELEASE_MAJOR_VERSION_C 4
  40. #define CLOCK_IP_FRACDIV_AR_RELEASE_MINOR_VERSION_C 4
  41. #define CLOCK_IP_FRACDIV_AR_RELEASE_REVISION_VERSION_C 0
  42. #define CLOCK_IP_FRACDIV_SW_MAJOR_VERSION_C 1
  43. #define CLOCK_IP_FRACDIV_SW_MINOR_VERSION_C 0
  44. #define CLOCK_IP_FRACDIV_SW_PATCH_VERSION_C 0
  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. /* Check if Clock_Ip_FracDiv.c file and Clock_Ip_Private.h file are of the same Autosar version */
  53. #if ((CLOCK_IP_FRACDIV_AR_RELEASE_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MAJOR_VERSION) || \
  54. (CLOCK_IP_FRACDIV_AR_RELEASE_MINOR_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_MINOR_VERSION) || \
  55. (CLOCK_IP_FRACDIV_AR_RELEASE_REVISION_VERSION_C != CLOCK_IP_PRIVATE_AR_RELEASE_REVISION_VERSION) \
  56. )
  57. #error "AutoSar Version Numbers of Clock_Ip_FracDiv.c and Clock_Ip_Private.h are different"
  58. #endif
  59. /* Check if Clock_Ip_FracDiv.c file and Clock_Ip_Private.h file are of the same Software version */
  60. #if ((CLOCK_IP_FRACDIV_SW_MAJOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MAJOR_VERSION) || \
  61. (CLOCK_IP_FRACDIV_SW_MINOR_VERSION_C != CLOCK_IP_PRIVATE_SW_MINOR_VERSION) || \
  62. (CLOCK_IP_FRACDIV_SW_PATCH_VERSION_C != CLOCK_IP_PRIVATE_SW_PATCH_VERSION) \
  63. )
  64. #error "Software Version Numbers of Clock_Ip_FracDiv.c and Clock_Ip_Private.h are different"
  65. #endif
  66. /* Clock start section code */
  67. #define MCU_START_SEC_CODE
  68. #include "Mcu_MemMap.h"
  69. static void Callback_FracDivEmpty(Clock_Ip_FracDivConfigType const* config);
  70. static clock_dfs_status_t Callback_FracDivEmptyComplete(Clock_Ip_NameType DfsName);
  71. #ifdef DFS_MFI_MFN
  72. static void ResetDfsMfiMfn(Clock_Ip_FracDivConfigType const *config);
  73. static void SetDfsMfiMfn(Clock_Ip_FracDivConfigType const *config);
  74. static clock_dfs_status_t CompleteDfsMfiMfn(Clock_Ip_NameType DfsName);
  75. #endif
  76. /* Clock stop section code */
  77. #define MCU_STOP_SEC_CODE
  78. #include "Mcu_MemMap.h"
  79. /* Clock start constant section data */
  80. #define MCU_START_SEC_CONST_UNSPECIFIED
  81. #include "Mcu_MemMap.h"
  82. const fracDivCallback fracDivCallbacks[FRACTIONAL_DIVIDER_CALLBACKS_COUNT] =
  83. {
  84. {
  85. Callback_FracDivEmpty, /* Reset */
  86. Callback_FracDivEmpty, /* Set */
  87. Callback_FracDivEmptyComplete, /* Complete */
  88. },
  89. #ifdef DFS_MFI_MFN
  90. {
  91. ResetDfsMfiMfn, /* Reset */
  92. SetDfsMfiMfn, /* Set */
  93. CompleteDfsMfiMfn, /* Complete */
  94. },
  95. #endif
  96. };
  97. /* Clock stop constant section data */
  98. #define MCU_STOP_SEC_CONST_UNSPECIFIED
  99. #include "Mcu_MemMap.h"
  100. /* Clock start section code */
  101. #define MCU_START_SEC_CODE
  102. #include "Mcu_MemMap.h"
  103. static void Callback_FracDivEmpty(Clock_Ip_FracDivConfigType const* config)
  104. {
  105. (void)config;
  106. /* No implementation */
  107. }
  108. static clock_dfs_status_t Callback_FracDivEmptyComplete(Clock_Ip_NameType DfsName)
  109. {
  110. (void)DfsName;
  111. /* No implementation */
  112. return STATUS_DFS_NOT_ENABLED;
  113. }
  114. #ifdef DFS_MFI_MFN
  115. static void ResetDfsMfiMfn(Clock_Ip_FracDivConfigType const *config)
  116. {
  117. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  118. uint32 dividerIndex = clockFeatures[config->name][DIVIDER_INDEX];
  119. /* Put this fractional divider in reset state */
  120. dfs[instance]->PORTRESET |= (1UL << dividerIndex);
  121. }
  122. static void SetDfsMfiMfn(Clock_Ip_FracDivConfigType const *config)
  123. {
  124. uint32 instance = clockFeatures[config->name][CLOCK_MODULE_INSTANCE];
  125. uint32 dividerIndex = clockFeatures[config->name][DIVIDER_INDEX];
  126. uint32 integerPart = config->value[0U]; /* Integer part. */
  127. uint32 fractionalPart = config->value[1U]; /* Fractional part. */
  128. uint32 value = 0U;
  129. /* Check whether fractional divider is enabled */
  130. if (0U != config->enable)
  131. {
  132. /* Write the value by which input signal is divided */
  133. value |= DFS_DVPORT_MFN(fractionalPart);
  134. value |= DFS_DVPORT_MFI(integerPart);
  135. dfs[instance]->DVPORT[dividerIndex] = value;
  136. /* Get corresponding port out of reset state */
  137. dfs[instance]->PORTRESET &= ~(1UL << dividerIndex);
  138. }
  139. }
  140. static clock_dfs_status_t CompleteDfsMfiMfn(Clock_Ip_NameType DfsName)
  141. {
  142. boolean TimeoutOccurred = FALSE;
  143. uint32 StartTime;
  144. uint32 ElapsedTime;
  145. uint32 TimeoutTicks;
  146. uint32 DfsPortStatus;
  147. clock_dfs_status_t status = STATUS_DFS_LOCKED;
  148. uint32 instance = clockFeatures[DfsName][CLOCK_MODULE_INSTANCE];
  149. uint32 dividerIndex = clockFeatures[DfsName][DIVIDER_INDEX];
  150. /* Check whether fractional divider is enabled */
  151. if ((dfs[instance]->PORTRESET & (1UL << dividerIndex)) == 0U)
  152. {
  153. ClockStartTimeout(&StartTime, &ElapsedTime, &TimeoutTicks, CLOCK_TIMEOUT_VALUE_US);
  154. /* Wait until this port is locked */
  155. do
  156. {
  157. DfsPortStatus = (((dfs[instance]->PORTSR >> DFS_PORTSR_PORTSTAT_SHIFT) & DFS_PORTSR_PORTSTAT_MASK) & (1UL << dividerIndex));
  158. TimeoutOccurred = ClockTimeoutExpired(&StartTime, &ElapsedTime, TimeoutTicks);
  159. }
  160. while ((DfsPortStatus == 0U) && (FALSE == TimeoutOccurred));
  161. if (FALSE != TimeoutOccurred)
  162. {
  163. status = STATUS_DFS_UNLOCKED;
  164. /* Report timeout error */
  165. ReportClockErrors(CLOCK_IP_REPORT_TIMEOUT_ERROR, DfsName);
  166. }
  167. }
  168. else
  169. {
  170. status = STATUS_DFS_NOT_ENABLED;
  171. }
  172. return status;
  173. }
  174. #endif
  175. /* Clock stop section code */
  176. #define MCU_STOP_SEC_CODE
  177. #include "Mcu_MemMap.h"
  178. /*! @}*/
  179. /*******************************************************************************
  180. * EOF
  181. ******************************************************************************/