Ftm_Mcl_Ip.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : DMA,CACHE,TRGMUX,FLEXIO
  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 Ftm_Mcl_Ip.c
  26. *
  27. * @version 1.0.0
  28. *
  29. * @brief AUTOSAR Mcl - Ftm Common driver source file.
  30. * @details
  31. *
  32. * @addtogroup FTM_IP_DRIVER FTM IP Driver
  33. * @{
  34. */
  35. #ifdef __cplusplus
  36. extern "C"{
  37. #endif
  38. /*==================================================================================================
  39. * INCLUDE FILES
  40. * 1) system and project includes
  41. * 2) needed interfaces from external units
  42. * 3) internal and external interfaces from this unit
  43. ==================================================================================================*/
  44. #include "OsIf.h"
  45. #include "Ftm_Mcl_Ip.h"
  46. #include "RegLockMacros.h"
  47. #include "Reg_eSys.h"
  48. #if (STD_ON == FTM_MCL_IP_DEV_ERROR_DETECT)
  49. #include "Devassert.h"
  50. #endif
  51. /*==================================================================================================
  52. * SOURCE FILE VERSION INFORMATION
  53. ==================================================================================================*/
  54. #define FTM_MCL_IP_VENDOR_ID_C 43
  55. #define FTM_MCL_IP_AR_RELEASE_MAJOR_VERSION_C 4
  56. #define FTM_MCL_IP_AR_RELEASE_MINOR_VERSION_C 4
  57. #define FTM_MCL_IP_AR_RELEASE_REVISION_VERSION_C 0
  58. #define FTM_MCL_IP_SW_MAJOR_VERSION_C 1
  59. #define FTM_MCL_IP_SW_MINOR_VERSION_C 0
  60. #define FTM_MCL_IP_SW_PATCH_VERSION_C 0
  61. /*==================================================================================================
  62. * FILE VERSION CHECKS
  63. ==================================================================================================*/
  64. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  65. #if (STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT)
  66. /* Check if source file and RegLockMacros.h file are of the same AUTOSAR version */
  67. #if ((FTM_MCL_IP_AR_RELEASE_MAJOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MAJOR_VERSION) || \
  68. (FTM_MCL_IP_AR_RELEASE_MINOR_VERSION_C != REGLOCKMACROS_AR_RELEASE_MINOR_VERSION))
  69. #error "AutoSar Version Numbers of Ftm_Mcl_Ip.c and RegLockMacros.h are different"
  70. #endif
  71. #endif
  72. #endif
  73. /* Check if source file and Ftm_Mcl_Ip header file are of the same vendor. */
  74. #if (FTM_MCL_IP_VENDOR_ID_C != FTM_MCL_IP_VENDOR_ID_H)
  75. #error "Vendor IDs of Ftm_Mcl_Ip.h and Ftm_Mcl_Ip.h are different."
  76. #endif
  77. /* Check if source file and Ftm_Mcl_Ip header file are of the same AUTOSAR version. */
  78. #if ((FTM_MCL_IP_AR_RELEASE_MAJOR_VERSION_C != FTM_MCL_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  79. (FTM_MCL_IP_AR_RELEASE_MINOR_VERSION_C != FTM_MCL_IP_AR_RELEASE_MINOR_VERSION_H) || \
  80. (FTM_MCL_IP_AR_RELEASE_REVISION_VERSION_C != FTM_MCL_IP_AR_RELEASE_REVISION_VERSION_H))
  81. #error "AUTOSAR version numbers of Ftm_Mcl_Ip.h and Ftm_Mcl_Ip.h are different."
  82. #endif
  83. /* Check if source file and Ftm_Pwm_Ip_Cfg header file are of the same software version */
  84. #if ((FTM_MCL_IP_SW_MAJOR_VERSION_C != FTM_MCL_IP_SW_MAJOR_VERSION_H) || \
  85. (FTM_MCL_IP_SW_MINOR_VERSION_C != FTM_MCL_IP_SW_MINOR_VERSION_H) || \
  86. (FTM_MCL_IP_SW_PATCH_VERSION_C != FTM_MCL_IP_SW_PATCH_VERSION_H))
  87. #error "Software version numbers of Ftm_Mcl_Ip.h and Ftm_Mcl_Ip.h are different."
  88. #endif
  89. /*==================================================================================================
  90. * LOCAL VARIABLES
  91. ==================================================================================================*/
  92. #if (FTM_MCL_SELECT_COMMON_TIMEBASE_API == STD_ON)
  93. #define MCL_START_SEC_CONST_UNSPECIFIED
  94. #include "Mcl_MemMap.h"
  95. /* Table of base addresses for FTM instances. */
  96. static Ftm_Mcl_Ip_BaseType * const ftmBase[] = IP_FTM_BASE_PTRS;
  97. #define MCL_STOP_SEC_CONST_UNSPECIFIED
  98. #include "Mcl_MemMap.h"
  99. #endif /* FTM_MCL_SELECT_COMMON_TIMEBASE_API */
  100. /*==================================================================================================
  101. * LOCAL FUNCTION PROTOTYPES
  102. ==================================================================================================*/
  103. #if (FTM_MCL_SELECT_COMMON_TIMEBASE_API == STD_ON)
  104. #if (STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT)
  105. #define MCL_START_SEC_CODE
  106. #include "Mcl_MemMap.h"
  107. /**
  108. * @brief Enables FTM registers writing in User Mode by configuring REG_PROT
  109. * @details Sets the UAA (User Access Allowed) bit of the FTM IP allowing FTM registers writing in User Mode
  110. *
  111. * @param[in] FtmBaseAddr
  112. *
  113. * @return none
  114. *
  115. * @pre Should be executed in supervisor mode
  116. */
  117. static void Ftm_Mcl_Ip_SetUserAccessAllowed(uint32 FtmBaseAddr);
  118. /*==================================================================================================
  119. * LOCAL FUNCTIONS
  120. ==================================================================================================*/
  121. static void Ftm_Mcl_Ip_SetUserAccessAllowed(uint32 FtmBaseAddr)
  122. {
  123. SET_USER_ACCESS_ALLOWED(FtmBaseAddr, FTM_PROT_MEM_U32);
  124. }
  125. /*==================================================================================================
  126. * LOCAL MACROS
  127. ==================================================================================================*/
  128. #if (defined (MCAL_FTM_REG_PROT_AVAILABLE) && (STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT))
  129. #define Call_Ftm_Mcl_Ip_SetUserAccessAllowed(BaseAddr) OsIf_Trusted_Call1param(Ftm_Mcl_Ip_SetUserAccessAllowed, (BaseAddr))
  130. #else
  131. #define Call_Ftm_Mcl_Ip_SetUserAccessAllowed(BaseAddr) Ftm_Mcl_Ip_SetUserAccessAllowed(BaseAddr)
  132. #endif
  133. #define MCL_STOP_SEC_CODE
  134. #include "Mcl_MemMap.h"
  135. #endif /* STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT */
  136. /*==================================================================================================
  137. GLOBAL FUNCTIONS
  138. ==================================================================================================*/
  139. #define MCL_START_SEC_CODE
  140. #include "Mcl_MemMap.h"
  141. /** @implements Ftm_Mcl_Ip_SelectCommonTimebase_Activity */
  142. void Ftm_Mcl_Ip_SelectCommonTimebase(uint8 instance, uint32 syncList)
  143. {
  144. #if (defined(FTM_MCL_IP_DEV_ERROR_DETECT) && (STD_ON == FTM_MCL_IP_DEV_ERROR_DETECT))
  145. DevAssert(instance < FTM_MCL_IP_NOF_MODULES);
  146. DevAssert((syncList >> FTM_MCL_IP_NOF_MODULES) == (uint16)0U);
  147. #endif
  148. uint8 moduleToSync;
  149. uint32 currentClkSrc;
  150. #if (STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT)
  151. /* User mode. */
  152. Call_Ftm_Mcl_Ip_SetUserAccessAllowed((uint32)ftmBase[instance]);
  153. #endif
  154. for (moduleToSync = 0U; moduleToSync < FTM_MCL_IP_NOF_MODULES; moduleToSync++)
  155. {
  156. /* Get index value for FTM module that need to be synchronized */
  157. if ((uint8)((uint8)syncList & (uint8)(1U << moduleToSync)) == (uint8)(1U << moduleToSync))
  158. {
  159. #if (STD_ON == FTM_MCL_ENABLE_USER_MODE_SUPPORT)
  160. /* User mode. */
  161. Call_Ftm_Mcl_Ip_SetUserAccessAllowed((uint32)ftmBase[moduleToSync]);
  162. #endif
  163. /* Save used clock source */
  164. currentClkSrc = ftmBase[moduleToSync]->SC & FTM_SC_CLKS_MASK;
  165. /* Stop clock */
  166. ftmBase[moduleToSync]->SC &= ~FTM_SC_CLKS_MASK;
  167. /* Set sync bit for the driven module */
  168. ftmBase[moduleToSync]->CONF = (ftmBase[moduleToSync]->CONF & ~(FTM_CONF_GTBEOUT_MASK | FTM_CONF_GTBEEN_MASK)) | \
  169. FTM_CONF_GTBEEN_MASK;
  170. /* Start clock again, this can be done directly because it is write 00 on CLKS bits before. */
  171. ftmBase[moduleToSync]->SC |= currentClkSrc;
  172. /* Clear counter register */
  173. ftmBase[moduleToSync]->CNT = (uint32)0U;
  174. }
  175. }
  176. /* Set global sync bit for the source module */
  177. ftmBase[instance]->CONF |= FTM_CONF_GTBEOUT_MASK;
  178. }
  179. #define MCL_STOP_SEC_CODE
  180. #include "Mcl_MemMap.h"
  181. #endif /* FTM_MCL_SELECT_COMMON_TIMEBASE_API */
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. /** @} */