1 /***************************************************************************//**
2 * \file cy_sysfault.h
3 * \version 1.20
4 *
5 * \brief
6 * Provides an API declaration 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 /**
28 * \addtogroup group_sysfault
29 * \{
30 *
31 * The SysFault driver provides an API to configure the Fault reporting structure.
32 * The functions and other declarations used in this driver are in cy_sysfault.h.
33 * You can include cy_pdl.h to get access to all functions and declarations in the PDL.
34 * This driver is only available for CAT1C, CAT1D devices.
35 *
36 * The Fault subsystem contains information about faults that occur in the system.
37 * The fault subsystem captures only faults and it does not take any action to correct it.
38 * The subsystem can cause a reset, give a pulse indication, or trigger another peripheral.
39 * CAT1C, CAT1D uses a centralized fault report structure. The centralized nature allows for a
40 * system-wide consistent handling of faults, which simplifies software development as
41 * follows only a single fault interrupt handler is required. The fault report structure
42 * provides the fault source and additional fault-specific information from a single set
43 * of memory mapped input/output (MMIO) registers, no iterative search is required for
44 * the fault source and fault information.
45 * All pending faults are available from a single set of MMIO registers. Below is the block
46 * diagram.
47 * \image html fault.png
48 *
49 * Fault IP provides fault report structure. Fault report structures capture faults.
50 * The number of fault report structures is specified by a design time configuration
51 * parameter (FAULT_NR). In CAT1C, CAT1D there are two instances of fault structures, each fault
52 * report structure has a dedicated set of MMIO control and status registers and captures
53 * a single fault. A fault report structure provides the fault source and additional fault
54 * specific information from a single set of MMIO registers. The fault structures capture
55 * faults like MPU/SMPU/PPI protection violations, peripheral specific errors, memory
56 * controller specific errors. E.g., SRAM controller ECC errors,
57 * FLASH controller read while program and ECC errors, Processor tightly coupled
58 * memory (TCM) ECC errors.
59 *
60 * System fault will be captured by fault report structures. A fault report structure
61 * provides the fault source and additional fault specific information from a single
62 * set of MMIO registers.
63 * The captured fault information includes:
64 * * A validity bit field that indicates a fault is captured.
65 * * A fault index that identifies the fault source.
66 * * Additional fault information describing fault specifics.
67 *
68 * \section group_sysfault_configuration Configuration Considerations
69 *
70 * Fault configuration includes clearing the existing fault status, enabling fault source,
71 * setting interrupt mask, and fault initialization.
72 * Below is the code snippet for the fault configuration.
73 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
74 *
75 * Once the configured fault occurs, the interrupt handler will be triggered where the
76 * fault information can be captured.
77 * Below is the code snippet that can be part of a interrupt handler.
78 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
79 *
80 * \section group_sysfault_section_more_information More Information
81 *
82 * For more information on the System Fault, refer to the technical reference
83 * manual (TRM).
84 *
85 * \section group_sysfault_changelog Changelog
86 * <table class="doxtable">
87 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
88 *   <tr>
89 *     <td>1.20</td>
90 *     <td>Updated \ref Cy_SysFault_GetErrorSource API and added new macro</td>
91 *     <td>MISRA 10.8 fix and code enhancement</td>
92 *   </tr>
93 *    <tr>
94 *     <td>1.10</td>
95 *     <td>Updated macro related to driver enablement for CAT1C without any functional impact</td>
96 *     <td>Code Enhancement</td>
97 *   </tr>
98 *   <tr>
99 *     <td>1.0</td>
100 *     <td>Initial version</td>
101 *     <td></td>
102 *   </tr>
103 * </table>
104 *
105 * \defgroup group_sysfault_macros Macros
106 * \defgroup group_sysfault_enums Enums
107 * \defgroup group_sysfault_data_structures Data Structures
108 * \defgroup group_sysfault_functions Functions
109 *
110 */
111 
112 #if !defined(CY_SYSFAULT_H)
113 #define CY_SYSFAULT_H
114 
115 #include "cy_device.h"
116 
117 #if defined(CY_IP_MXS40FAULT) || defined (CY_IP_MXFAULT)
118 #include "cy_syslib.h"
119 #include "cy_device_headers.h"
120 
121 #if defined(__cplusplus)
122 extern "C" {
123 #endif
124 
125 #if defined (CY_IP_MXS22SRSS)
126 #define cy_en_SysFault_source_t en_sysfault_source_t
127 #define CY_SYSFAULT_NO_FAULT (((uint8_t)M33SYSCPUSS_RRAMC_MMIO_PC_LOCK_FAULT) + 1U)
128 #endif
129 
130 /*******************************************************************************
131 *       Function Constants
132 *******************************************************************************/
133 
134 /**
135 * \addtogroup group_sysfault_macros
136 * \{
137 */
138 
139 /** Driver major version */
140 #define CY_SYSFAULT_DRV_VERSION_MAJOR    1
141 
142 /** Driver minor version */
143 #define CY_SYSFAULT_DRV_VERSION_MINOR    20
144 
145 /** Driver ID */
146 #define CY_SYSFAULT_ID CY_PDL_DRV_ID     (0x76U)
147 
148 /** \cond INTERNAL */
149 
150 /* Macro to validate parameters in Cy_SysFault_GetFaultData() function */
151 #define CY_SYSFAULT_IS_DATA_SET_VALID(dataSet)     (((dataSet) == CY_SYSFAULT_DATA0) || \
152                                                     ((dataSet) == CY_SYSFAULT_DATA1) || \
153                                                     ((dataSet) == CY_SYSFAULT_DATA2) || \
154                                                     ((dataSet) == CY_SYSFAULT_DATA3))
155 
156 /* Macro to validate parameters in Cy_SysFault_GetPendingFault() function */
157 #define CY_SYSFAULT_IS_FAULT_SET_VALID(pendingFault)  (((pendingFault) == CY_SYSFAULT_SET0) || \
158                                                        ((pendingFault) == CY_SYSFAULT_SET1) || \
159                                                        ((pendingFault) == CY_SYSFAULT_SET2))
160 /** \endcond */
161 
162 
163 /** \} group_sysfault_macros */
164 
165 
166 /**
167 * \addtogroup group_sysfault_enums
168 * \{
169 */
170 
171 /**
172 * SysFault driver error codes
173 */
174 typedef enum
175 {
176     CY_SYSFAULT_SUCCESS   = 0x0UL, /**< Returned successful */
177     CY_SYSFAULT_BAD_PARAM = CY_SYSFAULT_ID | CY_PDL_STATUS_ERROR | 0x1UL, /**< Bad parameter was passed */
178 } cy_en_SysFault_status_t;
179 
180 /**
181 * SysFault pending Fault source set.
182 */
183 typedef enum
184 {
185     CY_SYSFAULT_SET0 = 0UL, /**< Set of Faults in the range of 0-31 Fault ID */
186     CY_SYSFAULT_SET1 = 1UL, /**< Set of Faults in the range of 32-63  Fault ID */
187     CY_SYSFAULT_SET2 = 2UL, /**< Set of Faults in the range of 64-95 Fault ID */
188 } cy_en_SysFault_Set_t;
189 
190 /**
191 * Instances of Fault data register.
192 */
193 typedef enum
194 {
195     CY_SYSFAULT_DATA0 = 0UL, /**< Used to get the Fault data for DATA0 register */
196     CY_SYSFAULT_DATA1=  1UL, /**< Used to get the Fault data for DATA1 register */
197     CY_SYSFAULT_DATA2 = 2UL, /**< Used to get the Fault data for DATA2 register */
198     CY_SYSFAULT_DATA3=  3UL, /**< Used to get the Fault data for DATA3 register */
199 } cy_en_SysFault_Data_t;
200 
201 /** \} group_sysfault_enums */
202 
203 
204 /***************************************
205 *       Configuration Structure
206 ***************************************/
207 
208 /**
209 * \addtogroup group_sysfault_data_structures
210 * \{
211 */
212 
213 /**
214 * Configuration structure for a Fault control register.
215 */
216 typedef struct {
217     bool       TriggerEnable;    /**< Enables the trigger output when it is True */
218     bool       OutputEnable;    /**< Enables the output signal when it is True */
219     bool       ResetEnable;     /**< Enables the Reset request  when it is True */
220 } cy_stc_SysFault_t;
221 
222 
223 /** \} group_sysfault_data_structures */
224 
225 
226 /***************************************
227 *       Function Prototypes
228 ***************************************/
229 
230 /**
231 * \addtogroup group_sysfault_functions
232 * \{
233 */
234 
235 /*******************************************************************************
236 * Function Name: Cy_SysFault_Init
237 ****************************************************************************//**
238 *
239 * \brief
240 * Initializes the SysFault for recording faults.
241 *
242 * \param base
243 * The pointer to a Fault structure instance.
244 *
245 * \param config
246 * The pointer to a Configuration structure.
247 *
248 * \return
249 * Fault status. Refer \ref cy_en_SysFault_status_t
250 *
251 * \funcusage
252 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
253 *
254 *******************************************************************************/
255 cy_en_SysFault_status_t Cy_SysFault_Init(FAULT_STRUCT_Type *base, cy_stc_SysFault_t *config);
256 
257 
258 /*******************************************************************************
259 * Function Name: Cy_SysFault_ClearStatus
260 ****************************************************************************//**
261 *
262 * \brief
263 * Clears status register.
264 *
265 * \param base
266 * The pointer to a Fault structure instance.
267 *
268 * \funcusage
269 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
270 *
271 *******************************************************************************/
272 void Cy_SysFault_ClearStatus(FAULT_STRUCT_Type *base);
273 
274 
275 /*******************************************************************************
276 * Function Name: Cy_SysFault_GetErrorSource
277 ****************************************************************************//**
278 *
279 * \brief
280 * Returns the source of error for the Fault.
281 *
282 * \param  base
283 * The pointer to a Fault structure instance.
284 *
285 * \return
286 * Fault source.
287 *
288 * \funcusage
289 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
290 *
291 *******************************************************************************/
292 cy_en_SysFault_source_t Cy_SysFault_GetErrorSource(FAULT_STRUCT_Type *base);
293 
294 
295 /*******************************************************************************
296 * Function Name: Cy_SysFault_GetFaultData
297 ****************************************************************************//**
298 *
299 * \brief
300 * Returns the Fault information for the provided dataSet.
301 *
302 * \param base
303 * The pointer to a Fault structure instance.
304 *
305 * \param dataSet
306 * Instance of data register.
307 *
308 * \return
309 * Fault information.
310 *
311 * \funcusage
312 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
313 *
314 *******************************************************************************/
315 uint32_t Cy_SysFault_GetFaultData(FAULT_STRUCT_Type *base, cy_en_SysFault_Data_t dataSet);
316 
317 
318 /*******************************************************************************
319 * Function Name: Cy_SysFault_GetPendingFault
320 ****************************************************************************//**
321 *
322 * \brief
323 * Returns the sources of pending fault that are not captured.
324 *
325 * \param base
326 * The pointer to a Fault structure instance.
327 *
328 * \param pendingFault
329 * Instance of PENDING register. PENDING0 returns the occurred pending Faults in the range of 0-31 Fault ID.
330 *
331 * \return
332 * The status of pending Faults.
333 *
334 * \funcusage
335 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_PendingFault
336 *
337 *******************************************************************************/
338 uint32_t Cy_SysFault_GetPendingFault(FAULT_STRUCT_Type *base, cy_en_SysFault_Set_t pendingFault);
339 
340 
341 /*******************************************************************************
342 * Function Name: Cy_SysFault_SetMaskByIdx
343 ****************************************************************************//**
344 *
345 * \brief
346 * Enable the Fault to be captured.
347 *
348 * \param base
349 * The pointer to a Fault structure instance.
350 *
351 * \param idx
352 * The Fault id to be set in the mask register.
353 *
354 * \return
355 * None.
356 *
357 * \funcusage
358 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
359 *
360 *******************************************************************************/
361 void Cy_SysFault_SetMaskByIdx(FAULT_STRUCT_Type *base, cy_en_SysFault_source_t idx);
362 
363 
364 /*******************************************************************************
365 * Function Name: Cy_SysFault_ClearMaskByIdx
366 ****************************************************************************//**
367 *
368 * \brief
369 * Disable the faults to be captured.
370 *
371 * \param base
372 * The pointer to a Fault structure instance.
373 *
374 * \param idx
375 * The fault id to be cleared in the mask register.
376 *
377 * \return
378 * None.
379 *
380 * \funcusage
381 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_PendingFault
382 *
383 *******************************************************************************/
384 void Cy_SysFault_ClearMaskByIdx(FAULT_STRUCT_Type *base, cy_en_SysFault_source_t idx);
385 
386 
387 /*******************************************************************************
388 * Function Name: Cy_SysFault_GetInterruptStatus
389 ****************************************************************************//**
390 *
391 * \brief
392 * Returns the status of the interrupt.
393 *
394 * \param base
395 * The pointer to a Fault structure instance.
396 *
397 * \return
398 * Interrupt status.
399 *
400 * \funcusage
401 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
402 *
403 *******************************************************************************/
404 uint32_t Cy_SysFault_GetInterruptStatus(FAULT_STRUCT_Type *base);
405 
406 
407 /*******************************************************************************
408 * Function Name: Cy_SysFault_ClearInterrupt
409 ****************************************************************************//**
410 *
411 * \brief
412 * Clears Active Interrupt Source.
413 *
414 * \param base
415 * The pointer to a Fault structure instance.
416 *
417 * \return
418 * None.
419 *
420 * \funcusage
421 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
422 *
423 *******************************************************************************/
424 void Cy_SysFault_ClearInterrupt(FAULT_STRUCT_Type *base);
425 
426 
427 /*******************************************************************************
428 * Function Name: Cy_SysFault_SetInterrupt
429 ****************************************************************************//**
430 *
431 * \brief
432 * Triggers an interrupt via a software write.
433 *
434 * \param base
435 * The pointer to a Fault structure instance.
436 *
437 * \return
438 * None.
439 *
440 * \funcusage
441 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
442 *
443 *******************************************************************************/
444 void Cy_SysFault_SetInterrupt(FAULT_STRUCT_Type *base);
445 
446 
447 /*******************************************************************************
448 * Function Name: Cy_SysFault_SetInterruptMask
449 ****************************************************************************//**
450 *
451 * \brief
452 * Sets an interrupt mask.
453 *
454 * \param base
455 * The pointer to a Fault structure instance.
456 *
457 * \return
458 * None.
459 *
460 * \funcusage
461 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Config
462 *
463 *******************************************************************************/
464 void Cy_SysFault_SetInterruptMask(FAULT_STRUCT_Type *base);
465 
466 
467 /*******************************************************************************
468 * Function Name: Cy_SysFault_ClearInterruptMask
469 ****************************************************************************//**
470 *
471 * \brief
472 * Clears an interrupt mask.
473 *
474 * \param base
475 * The pointer to a Fault structure instance.
476 *
477 * \return
478 * None.
479 *
480 * \funcusage
481 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
482 *
483 *******************************************************************************/
484 void Cy_SysFault_ClearInterruptMask(FAULT_STRUCT_Type *base);
485 
486 
487 /*******************************************************************************
488 * Function Name: Cy_SysFault_GetInterruptMask
489 ****************************************************************************//**
490 *
491 * \brief Returns the interrupt mask.
492 *
493 * \param  base
494 * The pointer to a Fault structure instance.
495 *
496 * \return
497 * Interrupt Mask.
498 *
499 * \funcusage
500 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
501 *
502 *******************************************************************************/
503 uint32_t Cy_SysFault_GetInterruptMask(FAULT_STRUCT_Type *base);
504 
505 
506 /*******************************************************************************
507 * Function Name: Cy_SysFault_GetInterruptStatusMasked
508 ****************************************************************************//**
509 *
510 * \brief
511 * Returns whether masked interrupt triggered the interrupt.
512 *
513 * \param base
514 * The pointer to a Fault structure instance.
515 *
516 * \return
517 * Interrupt Mask.
518 *
519 * \funcusage
520 * \snippet sysfault/snippet/main.c snippet_Cy_SysFault_Handle_Fault
521 *
522 *******************************************************************************/
523 uint32_t Cy_SysFault_GetInterruptStatusMasked(FAULT_STRUCT_Type *base);
524 
525 /** \} group_sysfault_functions */
526 
527 
528 #if defined(__cplusplus)
529 }
530 #endif
531 
532 #endif /* CY_IP_M7CPUSS */
533 
534 #endif /* CY_SYSFAULT_H */
535 
536 /** \} group_sysfault */
537 
538 /* [] END OF FILE */
539