1 /*
2  * Copyright 2022 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 #ifndef FSL_ITRC_H_
8 #define FSL_ITRC_H_
9 
10 #include "fsl_common.h"
11 
12 /*!
13  * @addtogroup ITRC
14  * @{
15  */
16 
17 /*! @file */
18 
19 /*******************************************************************************
20  * Definitions
21  *******************************************************************************/
22 
23 /*! @name Driver version */
24 /*! @{ */
25 /*! @brief Defines ITRC driver version 2.0.0.
26  *
27  * Change log:
28  * - Version 2.0.0
29  *   - Initial version.
30  */
31 #define FSL_ITRC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
32 /*! @} */
33 
34 #define ITRC_INPUT_SIGNALS_NUM (22u)
35 
36 /*! @brief ITRC input events. */
37 typedef uint32_t itrc_in_signals_t;
38 #define kITRC_CauTemeprature    0U
39 #define kITRC_PmipTemperature   1U
40 #define kITRC_VddCore           2U
41 #define kITRC_Vdd18             3u
42 #define kITRC_Vdd33             4u
43 #define kITRC_VddCoreGlitch     5u
44 #define kITRC_AnalogSensor      6u
45 #define kITRC_Ahb               7u
46 #define kITRC_Cwd               8u
47 #define kITRC_Css               9u
48 #define kITRC_Pkc               10u
49 #define kITRC_Otp               11u
50 #define kITRC_Prince            12u
51 #define kITRC_ClockGlitch       13u
52 #define kITRC_SecurityIP        14u
53 #define kITRC_Trng              15u
54 #define kITRC_PmipGlitch        16u
55 #define kITRC_PmipVddCoreGlitch 17u
56 #define kITRC_TcpuPll           18u
57 #define kITRC_T3Pll             19u
58 #define kITRC_SwEvent0          20u
59 #define kITRC_SwEvent1          21u
60 
61 /*! @brief ITRC output actions. */
62 typedef uint32_t itrc_out_signals_t;
63 #define kITRC_Irq       16U
64 #define kITRC_ChipReset 17u
65 
66 /*! @brief ITRC lock/unlock. */
67 typedef uint32_t itrc_lock_t;
68 #define  kITRC_Unlock 0U
69 #define  kITRC_Lock   1U
70 
71 /*! @brief ITRC enable/disable. */
72 typedef uint32_t itrc_enable_t;
73 #define kITRC_Enable  0U
74 #define kITRC_Disable 1U
75 
76 #define IN_STATUS0_EVENTS_MASK                                                                       \
77     (ITRC_STATUS0_IN0_STATUS_MASK | ITRC_STATUS0_IN1_STATUS_MASK | ITRC_STATUS0_IN2_STATUS_MASK |    \
78      ITRC_STATUS0_IN3_STATUS_MASK | ITRC_STATUS0_IN4_STATUS_MASK | ITRC_STATUS0_IN5_STATUS_MASK |    \
79      ITRC_STATUS0_IN6_STATUS_MASK | ITRC_STATUS0_IN7_STATUS_MASK | ITRC_STATUS0_IN8_STATUS_MASK |    \
80      ITRC_STATUS0_IN9_STATUS_MASK | ITRC_STATUS0_IN10_STATUS_MASK | ITRC_STATUS0_IN11_STATUS_MASK |  \
81      ITRC_STATUS0_IN12_STATUS_MASK | ITRC_STATUS0_IN13_STATUS_MASK | ITRC_STATUS0_IN14_STATUS_MASK | \
82      ITRC_STATUS0_IN15_STATUS_MASK)
83 
84 #define IN_STATUS1_EVENTS_MASK                                                                       \
85     (ITRC_STATUS1_IN16_STATUS_MASK | ITRC_STATUS1_IN17_STATUS_MASK | ITRC_STATUS1_IN18_STATUS_MASK | \
86      ITRC_STATUS1_IN19_STATUS_MASK | ITRC_STATUS1_IN20_STATUS_MASK | ITRC_STATUS1_IN21_STATUS_MASK)
87 
88 #define OUT_ACTIONS_MASK (ITRC_STATUS0_OUT0_STATUS_MASK | ITRC_STATUS0_OUT1_STATUS_MASK)
89 
90 #ifndef ITRC
91 #define ITRC ITRC0
92 #endif
93 
94 /*******************************************************************************
95  * API
96  *******************************************************************************/
97 
98 extern void ITRC_DriverIRQHandler(void);
99 
100 #if defined(__cplusplus)
101 extern "C" {
102 #endif /* __cplusplus */
103 
104 /*!
105  * @name ITRC Functional Operation
106  * @{
107  */
108 
109 /*!
110  * @brief Set ITRC Action to Event
111  *
112  * This function sets input Event signal to corresponding output Action response signal.
113  *
114  * @param base ITRC peripheral base address
115  * @param out ITRC OUT signal action
116  * @param in ITRC IN signal event
117  * @param lock if set locks INx_SEL configuration. This can be cleared only by PMC Core reset.
118  * @param enable if set input Event will be selected for output Action, otherwise disable (if not already locked).
119  * @return kStatus_Success if success, kStatus_InvalidArgument otherwise
120  */
121 status_t ITRC_SetActionToEvent(
122     ITRC_Type *base, itrc_out_signals_t out, itrc_in_signals_t in, itrc_lock_t lock, itrc_enable_t enable);
123 
124 /*!
125  * @brief Trigger ITRC SW Event 0
126  *
127  * This funciton set SW_EVENT0 register with value !=0 which triggers ITRC SW Event 0.
128  *
129  * @param base ITRC peripheral base address
130  */
131 void ITRC_SetSWEvent0(ITRC_Type *base);
132 
133 /*!
134  * @brief Trigger ITRC SW Event 1
135  *
136  * This funciton set SW_EVENT1 register with value !=0 which triggers ITRC SW Event 1.
137  *
138  * @param base ITRC peripheral base address
139  */
140 void ITRC_SetSWEvent1(ITRC_Type *base);
141 
142 /*!
143  * @brief Get ITRC input event status
144  *
145  * This function returns ITRC status corresponding to provided input event.
146  *
147  * @param base ITRC peripheral base address
148  * @param event represents input event to get from STATUS register
149  * (see ITRC_STATUS_INx)
150  * @return boolean TRUE if corresponding event occured
151  *                 FALSE otherwise
152  */
153 bool ITRC_GetInEventStatus(ITRC_Type *base, itrc_in_signals_t event);
154 
155 /*!
156  * @brief Get ITRC output action status
157  *
158  * This function returns ITRC register output status.
159  *
160  * @param base ITRC peripheral base address
161  * @param action represents output action to get from STATUS register
162  * (see ITRC_STATUS_OUTx)
163  * @return boolean TRUE if corresponding action occured
164  *                 FALSE otherwise
165  */
166 bool ITRC_GetOutActionStatus(ITRC_Type *base, itrc_out_signals_t action);
167 
168 /*!
169  * @brief Clear In ITRC status
170  *
171  * This function clears corresponding ITRC event or action in input STATUS register.
172  *
173  * @param base ITRC peripheral base address
174  * @param event represents input event in STATUS register to be cleared
175  *              (see ITRC_STATUS_INx)
176  * @return kStatus_Success if success, kStatus_InvalidArgument otherwise
177  */
178 status_t ITRC_ClearInEventStatus(ITRC_Type *base, itrc_in_signals_t event);
179 
180 /*!
181  * @brief Clear Out ITRC status
182  *
183  * This function clears corresponding ITRC event or action in output STATUS register.
184  *
185  * @param base ITRC peripheral base address
186  * @param action represents output action in STATUS register to be cleared
187  *               (see OUTx_STATUS)
188  * @return kStatus_Success if success, kStatus_InvalidArgument otherwise
189  */
190 status_t ITRC_ClearOutActionStatus(ITRC_Type *base, itrc_out_signals_t action);
191 
192 /*!
193  * @brief Clear All ITRC status
194  *
195  * This function clears all event and action status.
196  *
197  * @param base ITRC peripheral base address
198  * @return kStatus_Success if success
199  */
200 status_t ITRC_ClearAllStatus(ITRC_Type *base);
201 
202 /*!
203  * @brief Initialize ITRC
204  *
205  * This function initializes ITRC by enabling IRQ.
206  *
207  * @param base ITRC peripheral base address
208  * @param conf ITRC configuration structure
209  * @return Status of the init operation
210  */
211 status_t ITRC_Init(ITRC_Type *base);
212 
213 /*!
214  * @brief Deinitialize ITRC
215  *
216  * This function deinitializes ITRC by disabling IRQ.
217  *
218  * @param base ITRC peripheral base address
219  */
220 void ITRC_Deinit(ITRC_Type *base);
221 
222 /*! @}*/
223 
224 #if defined(__cplusplus)
225 }
226 #endif /* __cplusplus */
227 
228 /*! @}*/ /* end of group itrc */
229 
230 #endif /* FSL_ITRC_H_ */
231