1 /***************************************************************************//**
2 * \file cy_sysfault.c
3 * \version 1.20
4 *
5 * \brief
6 * Provides an API implementation of the SysFault driver.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright (c) (2020-2022), Cypress Semiconductor Corporation (an Infineon company) or
11 * an affiliate of Cypress Semiconductor Corporation.
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 *     http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *******************************************************************************/
26 
27 #include "cy_sysfault.h"
28 
29 #if defined(CY_IP_MXS40FAULT) || defined (CY_IP_MXFAULT)
30 
Cy_SysFault_Init(FAULT_STRUCT_Type * base,cy_stc_SysFault_t * config)31 cy_en_SysFault_status_t  Cy_SysFault_Init(FAULT_STRUCT_Type *base, cy_stc_SysFault_t *config)
32 {
33     if(config != NULL)
34     {
35         FAULT_CTL(base) = _VAL2FLD(FAULT_STRUCT_CTL_TR_EN, config->TriggerEnable) |
36                           _VAL2FLD(FAULT_STRUCT_CTL_OUT_EN, config->OutputEnable) |
37                           _VAL2FLD(FAULT_STRUCT_CTL_RESET_REQ_EN, config->ResetEnable);
38         return CY_SYSFAULT_SUCCESS;
39     }
40     else
41     {
42         return CY_SYSFAULT_BAD_PARAM;
43     }
44 }
45 
46 
Cy_SysFault_ClearStatus(FAULT_STRUCT_Type * base)47 void Cy_SysFault_ClearStatus(FAULT_STRUCT_Type *base)
48 {
49     FAULT_STATUS(base) = 0UL;
50 }
51 
52 
Cy_SysFault_GetErrorSource(FAULT_STRUCT_Type * base)53 cy_en_SysFault_source_t Cy_SysFault_GetErrorSource(FAULT_STRUCT_Type *base)
54 {
55     if(_FLD2VAL(FAULT_STRUCT_STATUS_VALID, FAULT_STATUS(base)) == 1UL)
56     {
57         CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_SysFault_source_t enum.');
58         return((cy_en_SysFault_source_t)(_FLD2VAL(FAULT_STRUCT_STATUS_IDX, FAULT_STATUS(base))));
59     }
60     else
61     {
62         CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_SysFault_source_t enum.');
63         return (cy_en_SysFault_source_t)CY_SYSFAULT_NO_FAULT;
64     }
65 
66 }
67 
68 
Cy_SysFault_GetFaultData(FAULT_STRUCT_Type * base,cy_en_SysFault_Data_t dataSet)69 uint32_t Cy_SysFault_GetFaultData(FAULT_STRUCT_Type *base, cy_en_SysFault_Data_t dataSet)
70 {
71     CY_ASSERT_L3(CY_SYSFAULT_IS_DATA_SET_VALID(dataSet));
72 
73     return _FLD2VAL(FAULT_STRUCT_DATA_DATA, FAULT_DATA(base)[dataSet]);
74 }
75 
76 
Cy_SysFault_GetPendingFault(FAULT_STRUCT_Type * base,cy_en_SysFault_Set_t pendingFault)77 uint32_t Cy_SysFault_GetPendingFault(FAULT_STRUCT_Type *base, cy_en_SysFault_Set_t pendingFault)
78 {
79     CY_ASSERT_L3(CY_SYSFAULT_IS_FAULT_SET_VALID(pendingFault));
80     uint32_t retVal = 0;
81 
82     switch(pendingFault)
83     {
84         case CY_SYSFAULT_SET0:
85         {
86             retVal = _FLD2VAL(FAULT_STRUCT_PENDING0_SOURCE, FAULT_PENDING0(base));
87         }
88         break;
89 
90         case CY_SYSFAULT_SET1:
91         {
92             retVal = _FLD2VAL(FAULT_STRUCT_PENDING1_SOURCE, FAULT_PENDING1(base));
93         }
94         break;
95 
96         case CY_SYSFAULT_SET2:
97         {
98             retVal = _FLD2VAL(FAULT_STRUCT_PENDING1_SOURCE, FAULT_PENDING2(base));
99         }
100         break;
101 
102         default:
103         {
104             CY_ASSERT_L3(0);
105         }
106         break;
107     }
108 
109     return retVal;
110 }
111 
Cy_SysFault_SetMaskByIdx(FAULT_STRUCT_Type * base,cy_en_SysFault_source_t idx)112 void Cy_SysFault_SetMaskByIdx(FAULT_STRUCT_Type *base, cy_en_SysFault_source_t idx)
113 {
114     CY_ASSERT_L3(idx < CY_SYSFAULT_NO_FAULT);
115     CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_SysFault_Set_t enum.');
116     switch(((cy_en_SysFault_Set_t)((uint32_t)idx / 32UL)))
117     {
118         case CY_SYSFAULT_SET0:
119         {
120             FAULT_MASK0(base) |= _VAL2FLD(FAULT_STRUCT_MASK0_SOURCE, (1UL << (uint32_t)idx));
121         }
122         break;
123 
124         case CY_SYSFAULT_SET1:
125         {
126             FAULT_MASK1(base) |= _VAL2FLD(FAULT_STRUCT_MASK1_SOURCE, (1UL << ((uint32_t)idx - 32UL)));
127         }
128         break;
129 
130         case CY_SYSFAULT_SET2:
131         {
132             FAULT_MASK2(base) |= _VAL2FLD(FAULT_STRUCT_MASK2_SOURCE, (1UL << ((uint32_t)idx - 64UL)));
133         }
134         break;
135 
136         default:
137         {
138             CY_ASSERT_L3(0);
139         }
140         break;
141     }
142 }
143 
144 
Cy_SysFault_ClearMaskByIdx(FAULT_STRUCT_Type * base,cy_en_SysFault_source_t idx)145 void  Cy_SysFault_ClearMaskByIdx(FAULT_STRUCT_Type *base, cy_en_SysFault_source_t idx)
146 {
147     CY_ASSERT_L3(idx < CY_SYSFAULT_NO_FAULT);
148     CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_SysFault_Set_t enum.');
149     switch(((cy_en_SysFault_Set_t)((uint32_t)idx / 32UL)))
150     {
151         case CY_SYSFAULT_SET0:
152         {
153             FAULT_MASK0(base) &= ~(1UL << (uint32_t)idx);
154         }
155         break;
156 
157         case CY_SYSFAULT_SET1:
158         {
159             FAULT_MASK1(base) &= ~(1UL << ((uint32_t)idx - 32UL));
160         }
161         break;
162 
163         case CY_SYSFAULT_SET2:
164         {
165             FAULT_MASK2(base) &= ~(1UL << ((uint32_t)idx - 64UL));
166         }
167         break;
168 
169         default:
170         {
171             CY_ASSERT_L3(0);
172         }
173         break;
174     }
175 }
176 
177 
Cy_SysFault_GetInterruptStatus(FAULT_STRUCT_Type * base)178 uint32_t Cy_SysFault_GetInterruptStatus(FAULT_STRUCT_Type *base)
179 {
180     return _FLD2VAL(FAULT_STRUCT_INTR_FAULT, FAULT_INTR(base));
181 }
182 
183 
Cy_SysFault_ClearInterrupt(FAULT_STRUCT_Type * base)184 void Cy_SysFault_ClearInterrupt(FAULT_STRUCT_Type *base)
185 {
186      FAULT_INTR(base) = 1UL;
187 }
188 
189 
Cy_SysFault_SetInterrupt(FAULT_STRUCT_Type * base)190 void Cy_SysFault_SetInterrupt(FAULT_STRUCT_Type *base)
191 {
192     FAULT_INTR_SET(base) = FAULT_STRUCT_INTR_SET_FAULT_Msk;
193 }
194 
195 
Cy_SysFault_SetInterruptMask(FAULT_STRUCT_Type * base)196 void Cy_SysFault_SetInterruptMask(FAULT_STRUCT_Type *base)
197 {
198     FAULT_INTR_MASK(base) = FAULT_STRUCT_INTR_MASK_FAULT_Msk;
199 }
200 
Cy_SysFault_ClearInterruptMask(FAULT_STRUCT_Type * base)201 void Cy_SysFault_ClearInterruptMask(FAULT_STRUCT_Type *base)
202 {
203     FAULT_INTR_MASK(base) &=  ~FAULT_STRUCT_INTR_MASK_FAULT_Msk;
204 }
205 
Cy_SysFault_GetInterruptMask(FAULT_STRUCT_Type * base)206 uint32_t Cy_SysFault_GetInterruptMask(FAULT_STRUCT_Type *base)
207 {
208     return(FAULT_INTR_MASK(base));
209 }
210 
211 
Cy_SysFault_GetInterruptStatusMasked(FAULT_STRUCT_Type * base)212 uint32_t Cy_SysFault_GetInterruptStatusMasked(FAULT_STRUCT_Type *base)
213 {
214     return(FAULT_INTR_MASKED(base));
215 }
216 
217 #endif /* CY_IP_M7CPUSS */
218 /* [] END OF FILE */
219