1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifdef __cplusplus
8 extern "C"{
9 #endif
10 /**
11 *   @file    Trgmux_Ip_HwAcc.c
12 *
13 *   @version 3.0.0
14 *
15 *   @brief   AUTOSAR Mcl - Trgmux Ip driver source file.
16 *   @details
17 *
18 *   @addtogroup TRGMUX_IP_DRIVER TRGMUX IP Driver
19 *   @{
20 */
21 
22 /*==================================================================================================
23 *                                        INCLUDE FILES
24 * 1) system and project includes
25 * 2) needed interfaces from external units
26 * 3) internal and external interfaces from this unit
27 ==================================================================================================*/
28 #include "Trgmux_Ip.h"
29 #include "Trgmux_Ip_HwAcc.h"
30 
31 #if (TRGMUX_IP_IS_AVAILABLE == STD_ON)
32 /*==================================================================================================
33 *                                 SOURCE FILE VERSION INFORMATION
34 ==================================================================================================*/
35 #define TRGMUX_IP_HWACC_VENDOR_ID_C                    43
36 #define TRGMUX_IP_HWACC_MODULE_ID_C                    255
37 #define TRGMUX_IP_HWACC_AR_RELEASE_MAJOR_VERSION_C     4
38 #define TRGMUX_IP_HWACC_AR_RELEASE_MINOR_VERSION_C     7
39 #define TRGMUX_IP_HWACC_AR_RELEASE_REVISION_VERSION_C  0
40 #define TRGMUX_IP_HWACC_SW_MAJOR_VERSION_C             3
41 #define TRGMUX_IP_HWACC_SW_MINOR_VERSION_C             0
42 #define TRGMUX_IP_HWACC_SW_PATCH_VERSION_C             0
43 
44 /**
45 * @page misra_violations MISRA-C:2012 violations
46 */
47 
48 /*==================================================================================================
49                                       FILE VERSION CHECKS
50 ==================================================================================================*/
51 
52 /* Check if Trgmux_Ip_HwAcc.c file and Trgmux_Ip.h file are of the same vendor */
53 #if (TRGMUX_IP_HWACC_VENDOR_ID_C != TRGMUX_IP_VENDOR_ID)
54     #error "Trgmux_Ip_HwAcc.c and Trgmux_Ip.h have different vendor ids"
55 #endif
56 
57 /* Check if Trgmux_Ip_HwAcc.c file and Trgmux_Ip.h file are of the same Autosar version */
58 #if ((TRGMUX_IP_HWACC_AR_RELEASE_MAJOR_VERSION_C != TRGMUX_IP_AR_RELEASE_MAJOR_VERSION) || \
59      (TRGMUX_IP_HWACC_AR_RELEASE_MINOR_VERSION_C != TRGMUX_IP_AR_RELEASE_MINOR_VERSION) || \
60      (TRGMUX_IP_HWACC_AR_RELEASE_REVISION_VERSION_C != TRGMUX_IP_AR_RELEASE_REVISION_VERSION) \
61     )
62     #error "AutoSar Version Numbers of Trgmux_Ip_HwAcc.c and Trgmux_Ip.h are different"
63 #endif
64 
65 /* Check if Trgmux_Ip_HwAcc.c file and Trgmux_Ip.h file are of the same Software version */
66 #if ((TRGMUX_IP_HWACC_SW_MAJOR_VERSION_C != TRGMUX_IP_SW_MAJOR_VERSION) || \
67      (TRGMUX_IP_HWACC_SW_MINOR_VERSION_C != TRGMUX_IP_SW_MINOR_VERSION) || \
68      (TRGMUX_IP_HWACC_SW_PATCH_VERSION_C != TRGMUX_IP_SW_PATCH_VERSION) \
69     )
70     #error "Software Version Numbers of Trgmux_Ip_HwAcc.c and Trgmux_Ip.h are different"
71 #endif
72 
73 /* Check if Trgmux_Ip_HwAcc.c file and Trgmux_Ip_HwAcc.c file are of the same vendor */
74 #if (TRGMUX_IP_HWACC_VENDOR_ID_C != TRGMUX_IP_HWACC_VENDOR_ID)
75     #error "Trgmux_Ip_HwAcc.c and Trgmux_Ip_HwAcc.c have different vendor ids"
76 #endif
77 
78 /* Check if Trgmux_Ip_HwAcc.h file and Trgmux_Ip_HwAcc.c file are of the same Autosar version */
79 #if ((TRGMUX_IP_HWACC_AR_RELEASE_MAJOR_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_MAJOR_VERSION) || \
80      (TRGMUX_IP_HWACC_AR_RELEASE_MINOR_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_MINOR_VERSION) || \
81      (TRGMUX_IP_HWACC_AR_RELEASE_REVISION_VERSION_C != TRGMUX_IP_HWACC_AR_RELEASE_REVISION_VERSION) \
82     )
83     #error "AutoSar Version Numbers of Trgmux_Ip_HwAcc.h and Trgmux_Ip_HwAcc.c are different"
84 #endif
85 
86 /* Check if Trgmux_Ip_HwAcc.h file and Trgmux_Ip_HwAcc.c file are of the same Software version */
87 #if ((TRGMUX_IP_HWACC_SW_MAJOR_VERSION_C != TRGMUX_IP_HWACC_SW_MAJOR_VERSION) || \
88      (TRGMUX_IP_HWACC_SW_MINOR_VERSION_C != TRGMUX_IP_HWACC_SW_MINOR_VERSION) || \
89      (TRGMUX_IP_HWACC_SW_PATCH_VERSION_C != TRGMUX_IP_HWACC_SW_PATCH_VERSION) \
90     )
91     #error "Software Version Numbers of Trgmux_Ip_HwAcc.h and Trgmux_Ip_HwAcc.c are different"
92 #endif
93 
94 /*===============================================================================================
95                                        DEFINES AND MACROS
96 ===============================================================================================*/
97 /* Number of SEL bitfields in one TRGMUX register */
98 #define TRGMUX_IP_REG_SELECTION_NUM         ((uint8)(4U))
99 /* Get the index of the TRGMUX register */
100 #define TRGMUX_IP_REG_IDX(x)                ((uint8)((uint8)(x) / TRGMUX_IP_REG_SELECTION_NUM))
101 /* Get the index of the SEL bitfield inside TRGMUX register */
102 #define TRGMUX_IP_REG_SELECTION_IDX(x)      ((uint8)((uint8)(x) % TRGMUX_IP_REG_SELECTION_NUM))
103 
104 /*==================================================================================================
105  *                                      INLINE FUNCTIONS
106 ==================================================================================================*/
107 #define MCL_START_SEC_CODE
108 #include "Mcl_MemMap.h"
109 
hwAcc_Init(TRGMUX_Type * const pTrgmux,uint8 TrgmuxCount)110 Trgmux_Ip_StatusType hwAcc_Init(TRGMUX_Type * const pTrgmux, uint8 TrgmuxCount)
111 {
112     uint32 RegIdx;
113     uint32 RegValue;
114     Trgmux_Ip_StatusType Status = TRGMUX_IP_STATUS_SUCCESS;
115 
116     for(RegIdx = 0U; RegIdx < TrgmuxCount; RegIdx++)
117     {
118         if(TRGMUX_IP_STATUS_LOCKED != Status)
119         {
120             RegValue = pTrgmux->TRGMUXn[RegIdx] & TRGMUX_TRGMUXn_LK_MASK;
121             if(TRGMUX_TRGMUXn_LK_MASK == RegValue)
122             {
123                 Status = TRGMUX_IP_STATUS_LOCKED;
124             }
125             else
126             {
127                 pTrgmux->TRGMUXn[RegIdx] &= ((~(TRGMUX_TRGMUXn_SEL0_MASK)) | (~(TRGMUX_TRGMUXn_SEL1_MASK)) | (~(TRGMUX_TRGMUXn_SEL2_MASK)) | (~(TRGMUX_TRGMUXn_SEL3_MASK)));
128             }
129         }
130         else
131         {
132             /* Do nothing */
133         }
134     }
135 
136     return Status;
137 }
138 
hwAcc_SetInputForOutput(TRGMUX_Type * const pTrgmux,uint8 Instance,const uint32 Input,const uint32 Output)139 void hwAcc_SetInputForOutput(TRGMUX_Type * const pTrgmux, uint8 Instance, const uint32 Input, const uint32 Output)
140 {
141     uint32 RegValue;
142 
143     /* Set input for output */
144     RegValue = pTrgmux->TRGMUXn[TRGMUX_IP_REG_IDX(Output)];
145     RegValue &= ~((uint32)TRGMUX_TRGMUXn_SEL0_MASK << (TRGMUX_TRGMUXn_SEL1_SHIFT * TRGMUX_IP_REG_SELECTION_IDX(Output)));
146     RegValue |=  ((uint32)Input) << ((uint8)(TRGMUX_TRGMUXn_SEL1_SHIFT * TRGMUX_IP_REG_SELECTION_IDX(Output)));
147     pTrgmux->TRGMUXn[TRGMUX_IP_REG_IDX(Output)] = RegValue;
148     (void)Instance;
149 }
150 
hwAcc_SetLockForOutput(TRGMUX_Type * const pTrgmux,const uint32 Output)151 void hwAcc_SetLockForOutput(TRGMUX_Type * const pTrgmux, const uint32 Output)
152 {
153     /* Set TRGMUX_IP_REG_IDX register value */
154     pTrgmux->TRGMUXn[TRGMUX_IP_REG_IDX(Output)] |= (((uint32)1U) << TRGMUX_TRGMUXn_LK_SHIFT);
155 }
156 
hwAcc_GetLockForOutput(const TRGMUX_Type * const pTrgmux,const uint32 Output)157 boolean hwAcc_GetLockForOutput(const TRGMUX_Type * const pTrgmux, const uint32 Output)
158 {
159     boolean Status;
160     /* Get TRGMUX_IP_REG_IDX register value */
161     if(((pTrgmux->TRGMUXn[TRGMUX_IP_REG_IDX(Output)] & TRGMUX_TRGMUXn_LK_MASK) >> TRGMUX_TRGMUXn_LK_SHIFT) == 1U)
162     {
163         Status = TRUE;
164     }
165     else
166     {
167         Status = FALSE;
168     }
169 
170     return Status;
171 }
172 
173 #define MCL_STOP_SEC_CODE
174 #include "Mcl_MemMap.h"
175 
176 #endif /* TRGMUX_IP_IS_AVAILABLE */
177 
178 /** @} */
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 /*==================================================================================================
185  *                                        END OF FILE
186 ==================================================================================================*/
187