Trgmux_Ip.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 Trgmux_Ip.c
  26. *
  27. * @version 1.0.0
  28. *
  29. * @brief AUTOSAR Mcl - Trgmux Ip driver source file.
  30. * @details
  31. *
  32. * @addtogroup TRGMUX_IP_DRIVER TRGMUX IP Driver
  33. * @{
  34. */
  35. /*==================================================================================================
  36. * INCLUDE FILES
  37. * 1) system and project includes
  38. * 2) needed interfaces from external units
  39. * 3) internal and external interfaces from this unit
  40. ==================================================================================================*/
  41. #include "Trgmux_Ip.h"
  42. #include "Trgmux_Ip_HwAcc.h"
  43. #include "SchM_Mcl.h"
  44. #if (TRGMUX_IP_IS_AVAILABLE == STD_ON)
  45. /*==================================================================================================
  46. SOURCE FILE VERSION INFORMATION
  47. ==================================================================================================*/
  48. #define TRGMUX_IP_VENDOR_ID_C 43
  49. #define TRGMUX_IP_AR_RELEASE_MAJOR_VERSION_C 4
  50. #define TRGMUX_IP_AR_RELEASE_MINOR_VERSION_C 4
  51. #define TRGMUX_IP_AR_RELEASE_REVISION_VERSION_C 0
  52. #define TRGMUX_IP_SW_MAJOR_VERSION_C 1
  53. #define TRGMUX_IP_SW_MINOR_VERSION_C 0
  54. #define TRGMUX_IP_SW_PATCH_VERSION_C 0
  55. /**
  56. * @page misra_violations MISRA-C:2012 violations
  57. */
  58. /*==================================================================================================
  59. FILE VERSION CHECKS
  60. ==================================================================================================*/
  61. /* Check if Trgmux_Ip.c file and Trgmux_Ip.h file are of the same vendor */
  62. #if (TRGMUX_IP_VENDOR_ID_C != TRGMUX_IP_VENDOR_ID_H)
  63. #error "Trgmux_Ip.c and Trgmux_Ip.h have different vendor ids"
  64. #endif
  65. /* Check if Trgmux_Ip.c file and Trgmux_Ip.h file are of the same Autosar version */
  66. #if ((TRGMUX_IP_AR_RELEASE_MAJOR_VERSION_C != TRGMUX_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  67. (TRGMUX_IP_AR_RELEASE_MINOR_VERSION_C != TRGMUX_IP_AR_RELEASE_MINOR_VERSION_H) || \
  68. (TRGMUX_IP_AR_RELEASE_REVISION_VERSION_C != TRGMUX_IP_AR_RELEASE_REVISION_VERSION_H) \
  69. )
  70. #error "AutoSar Version Numbers of Trgmux_Ip.c and Trgmux_Ip.h are different"
  71. #endif
  72. /* Check if Trgmux_Ip.c file and Trgmux_Ip.h file are of the same Software version */
  73. #if ((TRGMUX_IP_SW_MAJOR_VERSION_C != TRGMUX_IP_SW_MAJOR_VERSION_H) || \
  74. (TRGMUX_IP_SW_MINOR_VERSION_C != TRGMUX_IP_SW_MINOR_VERSION_H) || \
  75. (TRGMUX_IP_SW_PATCH_VERSION_C != TRGMUX_IP_SW_PATCH_VERSION_H) \
  76. )
  77. #error "Software Version Numbers of Trgmux_Ip.c and Trgmux_Ip.h are different"
  78. #endif
  79. /* Check if Trgmux_Ip.c file and Trgmux_Ip_HwAcc.h file are of the same vendor */
  80. #if (TRGMUX_IP_VENDOR_ID_C != TRGMUX_IP_HWACC_VENDOR_ID_H)
  81. #error "Trgmux_Ip.c and Trgmux_Ip_HwAcc.h have different vendor ids"
  82. #endif
  83. /* Check if Trgmux_Ip.c file and Trgmux_Ip_HwAcc.h file are of the same Autosar version */
  84. #if ((TRGMUX_IP_AR_RELEASE_MAJOR_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_MAJOR_VERSION_H) || \
  85. (TRGMUX_IP_AR_RELEASE_MINOR_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_MINOR_VERSION_H) || \
  86. (TRGMUX_IP_AR_RELEASE_REVISION_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_REVISION_VERSION_H) \
  87. )
  88. #error "AutoSar Version Numbers of Trgmux_Ip.c and Trgmux_Ip_HwAcc.h are different"
  89. #endif
  90. /* Check if Trgmux_Ip.c file and Trgmux_Ip_HwAcc.h file are of the same Software version */
  91. #if ((TRGMUX_IP_SW_MAJOR_VERSION_C != TRGMUX_IP_HWACC_SW_MAJOR_VERSION_H) || \
  92. (TRGMUX_IP_SW_MINOR_VERSION_C != TRGMUX_IP_HWACC_SW_MINOR_VERSION_H) || \
  93. (TRGMUX_IP_SW_PATCH_VERSION_C != TRGMUX_IP_HWACC_SW_PATCH_VERSION_H) \
  94. )
  95. #error "Software Version Numbers of Trgmux_Ip.c and Trgmux_Ip_HwAcc.h are different"
  96. #endif
  97. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  98. /* Check if Trgmux_Ip.c file and SchM_Mcl header file are of the same Autosar version */
  99. #if ((TRGMUX_IP_AR_RELEASE_MAJOR_VERSION_C != SCHM_MCL_AR_RELEASE_MAJOR_VERSION) || \
  100. (TRGMUX_IP_AR_RELEASE_MINOR_VERSION_C != SCHM_MCL_AR_RELEASE_MINOR_VERSION))
  101. #error "AutoSar Version Numbers of Trgmux_Ip.c and SchM_Mcl.h are different"
  102. #endif
  103. #endif
  104. /*==================================================================================================
  105. * GLOBAL VARIABLES
  106. ==================================================================================================*/
  107. #define MCL_START_SEC_CONFIG_DATA_UNSPECIFIED
  108. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  109. #include "Mcl_MemMap.h"
  110. static TRGMUX_Type * const g_paxTrgmuxBaseArray[TRGMUX_INSTANCE_COUNT] = IP_TRGMUX_BASE_PTRS;
  111. #define MCL_STOP_SEC_CONFIG_DATA_UNSPECIFIED
  112. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  113. #include "Mcl_MemMap.h"
  114. #define MCL_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  115. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  116. #include "Mcl_MemMap.h"
  117. /* Pointer to the TRGMUX Initialization Configuration. Based on this configuration pointer,
  118. the TRGMUX Driver obtains all information for the Logic Triggers and corresponding
  119. Triggers Configurations.
  120. The Pointer is loaded when Trgmux_Ip_Init() is called. */
  121. static const Trgmux_Ip_InitType * g_pxTrgmuxInit;
  122. #define MCL_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  123. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  124. #include "Mcl_MemMap.h"
  125. /*==================================================================================================
  126. * GLOBAL FUNCTIONS
  127. ==================================================================================================*/
  128. #define MCL_START_SEC_CODE
  129. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  130. #include "Mcl_MemMap.h"
  131. /*==================================================================================================
  132. * LOCAL MACROS
  133. ==================================================================================================*/
  134. #ifdef MCAL_ENABLE_USER_MODE_SUPPORT
  135. #if (STD_ON == TRGMUX_IP_USER_MODE_SUPPORT_IS_AVAILABLE)
  136. #define Trgmux_Ip_HwAcc_Init(pTrgmux) \
  137. (OsIf_Trusted_Call_Return1param((uint32)hwAcc_Init, pTrgmux))
  138. #define Trgmux_Ip_HwAcc_SetInputForOutput(pTrgmux, Input, Output) \
  139. (OsIf_Trusted_Call3params(hwAcc_SetInputForOutput, pTrgmux, Input, Output))
  140. #define Trgmux_Ip_HwAcc_SetLockForOutput(pTrgmux, Output) \
  141. (OsIf_Trusted_Call2params(hwAcc_SetLockForOutput, pTrgmux, Output))
  142. #define Trgmux_Ip_HwAcc_GetLockForOutput(pTrgmux, Output) \
  143. (OsIf_Trusted_Call_Return2param((uint32)hwAcc_GetLockForOutput, pTrgmux, Output))
  144. #else
  145. #define Trgmux_Ip_HwAcc_Init(pTrgmux) \
  146. (hwAcc_Init(pTrgmux))
  147. #define Trgmux_Ip_HwAcc_SetInputForOutput(pTrgmux, Input, Output) \
  148. (hwAcc_SetInputForOutput(pTrgmux, Input, Output))
  149. #define Trgmux_Ip_HwAcc_SetLockForOutput(pTrgmux, Output) \
  150. (hwAcc_SetLockForOutput(pTrgmux, Output))
  151. #define Trgmux_Ip_HwAcc_GetLockForOutput(pTrgmux, Output) \
  152. (hwAcc_GetLockForOutput(pTrgmux, Output))
  153. #endif /* STD_ON == TRGMUX_IP_USER_MODE_SUPPORT_IS_AVAILABLE */
  154. #else
  155. #define Trgmux_Ip_HwAcc_Init(pTrgmux) \
  156. (hwAcc_Init(pTrgmux))
  157. #define Trgmux_Ip_HwAcc_SetInputForOutput(pTrgmux, Input, Output) \
  158. (hwAcc_SetInputForOutput(pTrgmux, Input, Output))
  159. #define Trgmux_Ip_HwAcc_SetLockForOutput(pTrgmux, Output) \
  160. (hwAcc_SetLockForOutput(pTrgmux, Output))
  161. #define Trgmux_Ip_HwAcc_GetLockForOutput(pTrgmux, Output) \
  162. (hwAcc_GetLockForOutput(pTrgmux, Output))
  163. #endif /* MCAL_ENABLE_USER_MODE_SUPPORT */
  164. Trgmux_Ip_StatusType Trgmux_Ip_Init(const Trgmux_Ip_InitType * const pxTrgmuxInit)
  165. {
  166. TRGMUX_Type * LocTrgmuxBase;
  167. uint32 LocTriggerIdx;
  168. uint32 LocInput;
  169. uint32 LocOutput;
  170. uint8 LocInst;
  171. boolean LocLock;
  172. Trgmux_Ip_StatusType Status = TRGMUX_IP_STATUS_SUCCESS;
  173. TRGMUX_IP_DEV_ASSERT(NULL_PTR != pxTrgmuxInit);
  174. /* Clear register */
  175. LocTrgmuxBase = g_paxTrgmuxBaseArray[TRGMUX_IP_HW_INST_0];
  176. /* Enter exclusive area to protect TRGMUXn */
  177. SchM_Enter_Mcl_MCL_EXCLUSIVE_AREA_19();
  178. #ifdef MCAL_ENABLE_USER_MODE_SUPPORT
  179. #if (STD_ON == TRGMUX_IP_USER_MODE_SUPPORT_IS_AVAILABLE)
  180. if((Std_ReturnType)TRGMUX_IP_STATUS_SUCCESS != Trgmux_Ip_HwAcc_Init(LocTrgmuxBase))
  181. #else
  182. if(TRGMUX_IP_STATUS_SUCCESS != Trgmux_Ip_HwAcc_Init(LocTrgmuxBase))
  183. #endif
  184. #else
  185. if(TRGMUX_IP_STATUS_SUCCESS != Trgmux_Ip_HwAcc_Init(LocTrgmuxBase))
  186. #endif
  187. {
  188. Status = TRGMUX_IP_STATUS_LOCKED;
  189. }
  190. else
  191. {
  192. /* Do nothing */
  193. }
  194. if(TRGMUX_IP_STATUS_LOCKED != Status)
  195. {
  196. /* Set register with configured value */
  197. for(LocTriggerIdx = 0U; LocTriggerIdx < TRGMUX_IP_NOF_CFG_LOGIC_TRIGGERS; LocTriggerIdx++)
  198. {
  199. LocInst = pxTrgmuxInit->paxLogicTrigger[LocTriggerIdx]->HwInstId;
  200. LocOutput = pxTrgmuxInit->paxLogicTrigger[LocTriggerIdx]->Output;
  201. LocInput = pxTrgmuxInit->paxLogicTrigger[LocTriggerIdx]->Input;
  202. LocTrgmuxBase = g_paxTrgmuxBaseArray[LocInst];
  203. Trgmux_Ip_HwAcc_SetInputForOutput(LocTrgmuxBase, LocInput, LocOutput);
  204. }
  205. /* Set register lock */
  206. for(LocTriggerIdx = 0U; LocTriggerIdx < TRGMUX_IP_NOF_CFG_LOGIC_TRIGGERS; LocTriggerIdx++)
  207. {
  208. LocLock = pxTrgmuxInit->paxLogicTrigger[LocTriggerIdx]->Lock;
  209. if(TRUE == LocLock)
  210. {
  211. LocOutput = pxTrgmuxInit->paxLogicTrigger[LocTriggerIdx]->Output;
  212. Trgmux_Ip_HwAcc_SetLockForOutput(LocTrgmuxBase, LocOutput);
  213. }
  214. }
  215. /* Exit exclusive area to protect TRGMUXn */
  216. SchM_Exit_Mcl_MCL_EXCLUSIVE_AREA_19();
  217. g_pxTrgmuxInit = pxTrgmuxInit;
  218. }
  219. else
  220. {
  221. /* Do nothing*/
  222. }
  223. return Status;
  224. }
  225. Trgmux_Ip_StatusType Trgmux_Ip_SetInput(const uint32 LogicTrigger, const uint32 Input)
  226. {
  227. uint32 LocHwInst = g_pxTrgmuxInit->paxLogicTrigger[LogicTrigger]->HwInstId;
  228. uint32 LocOutput = g_pxTrgmuxInit->paxLogicTrigger[LogicTrigger]->Output;
  229. TRGMUX_Type * LocTrgmuxBase = g_paxTrgmuxBaseArray[LocHwInst];
  230. Trgmux_Ip_StatusType Status = TRGMUX_IP_STATUS_SUCCESS;
  231. if(FALSE != Trgmux_Ip_HwAcc_GetLockForOutput(LocTrgmuxBase, LocOutput))
  232. {
  233. Status = TRGMUX_IP_STATUS_LOCKED;
  234. }
  235. if(TRGMUX_IP_STATUS_LOCKED != Status)
  236. {
  237. /* Enter exclusive area to protect TRGMUXn */
  238. SchM_Enter_Mcl_MCL_EXCLUSIVE_AREA_20();
  239. Trgmux_Ip_HwAcc_SetInputForOutput(LocTrgmuxBase, Input, LocOutput);
  240. /* Exit exclusive area to protect TRGMUXn */
  241. SchM_Exit_Mcl_MCL_EXCLUSIVE_AREA_20();
  242. }
  243. else
  244. {
  245. /* Do nothing */
  246. }
  247. return Status;
  248. }
  249. Trgmux_Ip_StatusType Trgmux_Ip_SetLock(const uint32 LogicTrigger)
  250. {
  251. uint32 LocHwInst = g_pxTrgmuxInit->paxLogicTrigger[LogicTrigger]->HwInstId;
  252. uint32 LocOutput = g_pxTrgmuxInit->paxLogicTrigger[LogicTrigger]->Output;
  253. TRGMUX_Type * LocTrgmuxBase = g_paxTrgmuxBaseArray[LocHwInst];
  254. Trgmux_Ip_StatusType Status = TRGMUX_IP_STATUS_SUCCESS;
  255. if(FALSE != Trgmux_Ip_HwAcc_GetLockForOutput(LocTrgmuxBase, LocOutput))
  256. {
  257. Status = TRGMUX_IP_STATUS_LOCKED;
  258. }
  259. if(TRGMUX_IP_STATUS_LOCKED != Status)
  260. {
  261. /* Enter exclusive area to protect TRGMUXn */
  262. SchM_Enter_Mcl_MCL_EXCLUSIVE_AREA_21();
  263. Trgmux_Ip_HwAcc_SetLockForOutput(LocTrgmuxBase, LocOutput);
  264. /* Exit exclusive area to protect TRGMUXn */
  265. SchM_Exit_Mcl_MCL_EXCLUSIVE_AREA_21();
  266. }
  267. else
  268. {
  269. /*Do nothing*/
  270. }
  271. return Status;
  272. }
  273. #define MCL_STOP_SEC_CODE
  274. /* @violates @ref Mcl_Dma_h_REF_1 MISRA 2012 Required Directive 4.10, Precautions shall be taken in order to prevent the contents of a header file being included more than once. */
  275. #include "Mcl_MemMap.h"
  276. #endif /* TRGMUX_IP_IS_AVAILABLE */
  277. /** @} */
  278. /*==================================================================================================
  279. * END OF FILE
  280. ==================================================================================================*/