1 /***************************************************************************//**
2 * \file cy_lvd_ht.h
3 * \version 1.10
4 *
5 * The header file of the LVD HT driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2017-2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25 /**
26 * \addtogroup group_lvd_ht
27 * \{
28 * The LVD HT driver provides an API to manage the Low Voltage Detection HT block.
29 *
30 * The functions and other declarations used in this driver are in cy_lvd_ht.h.
31 * You can include cy_pdl.h to get access to all functions
32 * and declarations in the PDL.
33 *
34 * The LVD block provides a status of currently observed VDDD voltage
35 * and triggers an interrupt or fault when the observed voltage crosses an adjusted
36 * threshold.
37 *
38 * \section group_lvd_ht_configuration_considerations Configuration Considerations
39 * To set up an LVD, configure the voltage threshold by the
40 * \ref Cy_LVD_HT_SetThreshold function, ensure that the LVD block itself and LVD
41 * interrupt are disabled (by the \ref Cy_LVD_HT_Disable and
42 * \ref Cy_LVD_HT_ClearInterruptMask functions correspondingly) before changing the
43 * threshold to prevent propagating a false interrupt.
44 * Then configure interrupts by the \ref Cy_LVD_HT_SetInterruptConfig function, do
45 * not forget to initialize an interrupt handler (the interrupt source number
46 * is srss_interrupt_IRQn).
47 * Then enable LVD by the \ref Cy_LVD_HT_Enable function, then wait for at least 25us
48 * to get the circuit stabilized and clear the possible false interrupts by the
49 * \ref Cy_LVD_HT_ClearInterrupt, and finally the LVD interrupt can be enabled by
50 * the \ref Cy_LVD_HT_SetInterruptMask function.
51 *
52 * Note : If an LVD is required in Deep Sleep mode, then \ref Cy_LVD_HT_DeepSleepEnable
53 * should be used to enable LVD during Deep Sleep.
54 *
55 * \section group_lvd_ht_more_information More Information
56 * See the LVD chapter of the device technical reference manual (TRM).
57 *
58 * \section group_lvd_ht_changelog Changelog
59 * <table class="doxtable">
60 * <tr><th>Version</th><th>Changes</th><th>Reason of Change</th></tr>
61 * <tr>
62 * <td>1.10</td>
63 * <td>Added support for TRAVEO™ II Body Entry devices.<br>
64 * Changed pre-processor logic so SRSS version 2 is grouped with version 3 instead of version 1.</td>
65 * <td>Code enhancement and support for new devices.</td>
66 * </tr>
67 * <tr>
68 * <td>1.0</td>
69 * <td>Initial Version</td>
70 * <td></td>
71 * </tr>
72 * </table>
73 *
74 * \defgroup group_lvd_ht_macros Macros
75 * \defgroup group_lvd_ht_functions Functions
76 * \{
77 * \defgroup group_lvd_ht_functions_syspm_callback Low Power Callback
78 * \}
79 * \defgroup group_lvd_ht_enums Enumerated Types
80 */
81
82
83 #if !defined(CY_LVD_HT_H)
84 #define CY_LVD_HT_H
85
86 #include "cy_device.h"
87
88 #if (defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2))
89
90 #include "cy_pra.h"
91 #include "cy_syspm.h"
92
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96
97 /** \addtogroup group_lvd_ht_macros
98 * \{
99 */
100
101 /** The driver major version */
102 #define CY_LVD_HT_DRV_VERSION_MAJOR 1
103
104 /** The driver minor version */
105 #define CY_LVD_HT_DRV_VERSION_MINOR 10
106
107 /** The LVD driver identifier */
108 #define CY_LVD_HT_ID (CY_PDL_DRV_ID(0x78U))
109
110
111 /** \} group_lvd_ht_macros */
112
113
114 /** \addtogroup group_lvd_ht_enums
115 * \{
116 */
117
118 /**
119 * LVD Selection.
120 */
121 typedef enum
122 {
123 CY_LVD_HT_SELECT_LVD_1 = 0x1u, /**<Select HT LVD-1 */
124 CY_LVD_HT_SELECT_LVD_2 = 0x2u, /**<Select HT LVD-2 */
125 } cy_en_lvd_ht_select_t;
126
127 /**
128 * LVD reference voltage select.
129 */
130 typedef enum
131 {
132 CY_LVD_HT_THRESHOLD_2_8_V = 0x0U, /**<Select LVD reference voltage: 2.8V */
133 CY_LVD_HT_THRESHOLD_2_9_V = 0x1U, /**<Select LVD reference voltage: 2.9V */
134 CY_LVD_HT_THRESHOLD_3_0_V = 0x2U, /**<Select LVD reference voltage: 3.0V */
135 CY_LVD_HT_THRESHOLD_3_1_V = 0x3U, /**<Select LVD reference voltage: 3.1V */
136 CY_LVD_HT_THRESHOLD_3_2_V = 0x4U, /**<Select LVD reference voltage: 3.2V */
137 CY_LVD_HT_THRESHOLD_3_3_V = 0x5U, /**<Select LVD reference voltage: 3.3V */
138 CY_LVD_HT_THRESHOLD_3_4_V = 0x6U, /**<Select LVD reference voltage: 3.4V */
139 CY_LVD_HT_THRESHOLD_3_5_V = 0x7U, /**<Select LVD reference voltage: 3.5V */
140 CY_LVD_HT_THRESHOLD_3_6_V = 0x8U, /**<Select LVD reference voltage: 3.6V */
141 CY_LVD_HT_THRESHOLD_3_7_V = 0x9U, /**<Select LVD reference voltage: 3.7V */
142 CY_LVD_HT_THRESHOLD_3_8_V = 0xAU, /**<Select LVD reference voltage: 3.8V */
143 CY_LVD_HT_THRESHOLD_3_9_V = 0xBU, /**<Select LVD reference voltage: 3.9V */
144 CY_LVD_HT_THRESHOLD_4_0_V = 0xCU, /**<Select LVD reference voltage: 4.0V */
145 CY_LVD_HT_THRESHOLD_4_1_V = 0xDU, /**<Select LVD reference voltage: 4.1V */
146 CY_LVD_HT_THRESHOLD_4_2_V = 0xEU, /**<Select LVD reference voltage: 4.2V */
147 CY_LVD_HT_THRESHOLD_4_3_V = 0xFU, /**<Select LVD reference voltage: 4.3V */
148 CY_LVD_HT_THRESHOLD_4_4_V = 0x10U, /**<Select LVD reference voltage: 4.4V */
149 CY_LVD_HT_THRESHOLD_4_5_V = 0x11U, /**<Select LVD reference voltage: 4.5V */
150 CY_LVD_HT_THRESHOLD_4_6_V = 0x12U, /**<Select LVD reference voltage: 4.6V */
151 CY_LVD_HT_THRESHOLD_4_7_V = 0x13U, /**<Select LVD reference voltage: 4.7V */
152 CY_LVD_HT_THRESHOLD_4_8_V = 0x14U, /**<Select LVD reference voltage: 4.8V */
153 CY_LVD_HT_THRESHOLD_4_9_V = 0x15U, /**<Select LVD reference voltage: 4.9V */
154 CY_LVD_HT_THRESHOLD_5_0_V = 0x16U, /**<Select LVD reference voltage: 5.0V */
155 CY_LVD_HT_THRESHOLD_5_1_V = 0x17U, /**<Select LVD reference voltage: 5.1V */
156 CY_LVD_HT_THRESHOLD_5_2_V = 0x18U, /**<Select LVD reference voltage: 5.2V */
157 CY_LVD_HT_THRESHOLD_5_3_V = 0x19U, /**<Select LVD reference voltage: 5.3V */
158 } cy_en_lvd_ht_tripsel_t;
159
160 /**
161 * LVD interrupt configuration select.
162 */
163 typedef enum
164 {
165 CY_LVD_HT_INTR_DISABLE = 0x0U, /**<Select LVD interrupt: disabled */
166 CY_LVD_HT_INTR_RISING = 0x1U, /**<Select LVD interrupt: rising edge */
167 CY_LVD_HT_INTR_FALLING = 0x2U, /**<Select LVD interrupt: falling edge */
168 CY_LVD_HT_INTR_BOTH = 0x3U, /**<Select LVD interrupt: both edges */
169 } cy_en_lvd_ht_intr_config_t;
170
171 /**
172 * LVD Action
173 */
174 typedef enum
175 {
176 CY_LVD_HT_ACTION_INTERRUPT = 0x0U, /**<Select LVD Action : Interrupt */
177 CY_LVD_HT_ACTION_FAULT = 0x1U, /**<Select LVD Action : Fault */
178 } cy_en_lvd_ht_action_config_t;
179
180 /**
181 * LVD output status.
182 */
183 typedef enum
184 {
185 CY_LVD_HT_STATUS_BELOW = 0x0U, /**<The voltage is below the threshold */
186 CY_LVD_HT_STATUS_ABOVE = 0x1U, /**<The voltage is above the threshold */
187 } cy_en_lvd_ht_status_t;
188
189 /** \} group_lvd_ht_enums */
190
191 /** \cond internal */
192 /* Macros for conditions used by CY_ASSERT calls */
193 #define CY_LVD_HT_CHECK_TRIPSEL(threshold) (((threshold) == CY_LVD_HT_THRESHOLD_2_8_V) || \
194 ((threshold) == CY_LVD_HT_THRESHOLD_2_9_V) || \
195 ((threshold) == CY_LVD_HT_THRESHOLD_3_0_V) || \
196 ((threshold) == CY_LVD_HT_THRESHOLD_3_1_V) || \
197 ((threshold) == CY_LVD_HT_THRESHOLD_3_2_V) || \
198 ((threshold) == CY_LVD_HT_THRESHOLD_3_3_V) || \
199 ((threshold) == CY_LVD_HT_THRESHOLD_3_4_V) || \
200 ((threshold) == CY_LVD_HT_THRESHOLD_3_5_V) || \
201 ((threshold) == CY_LVD_HT_THRESHOLD_3_6_V) || \
202 ((threshold) == CY_LVD_HT_THRESHOLD_3_7_V) || \
203 ((threshold) == CY_LVD_HT_THRESHOLD_3_8_V) || \
204 ((threshold) == CY_LVD_HT_THRESHOLD_3_9_V) || \
205 ((threshold) == CY_LVD_HT_THRESHOLD_4_0_V) || \
206 ((threshold) == CY_LVD_HT_THRESHOLD_4_1_V) || \
207 ((threshold) == CY_LVD_HT_THRESHOLD_4_2_V) || \
208 ((threshold) == CY_LVD_HT_THRESHOLD_4_3_V) || \
209 ((threshold) == CY_LVD_HT_THRESHOLD_4_4_V) || \
210 ((threshold) == CY_LVD_HT_THRESHOLD_4_5_V) || \
211 ((threshold) == CY_LVD_HT_THRESHOLD_4_6_V) || \
212 ((threshold) == CY_LVD_HT_THRESHOLD_4_7_V) || \
213 ((threshold) == CY_LVD_HT_THRESHOLD_4_8_V) || \
214 ((threshold) == CY_LVD_HT_THRESHOLD_4_9_V) || \
215 ((threshold) == CY_LVD_HT_THRESHOLD_5_0_V) || \
216 ((threshold) == CY_LVD_HT_THRESHOLD_5_1_V) || \
217 ((threshold) == CY_LVD_HT_THRESHOLD_5_2_V) || \
218 ((threshold) == CY_LVD_HT_THRESHOLD_5_3_V))
219
220 #define CY_LVD_HT_CHECK_INTR_CFG(intrCfg) (((intrCfg) == CY_LVD_HT_INTR_DISABLE) || \
221 ((intrCfg) == CY_LVD_HT_INTR_RISING) || \
222 ((intrCfg) == CY_LVD_HT_INTR_FALLING) || \
223 ((intrCfg) == CY_LVD_HT_INTR_BOTH))
224
225 #define CY_LVD_HT_CHECK_ACTION_CFG(actionCfg) (((actionCfg) == CY_LVD_HT_ACTION_INTERRUPT) || \
226 ((actionCfg) == CY_LVD_HT_ACTION_FAULT))
227
228 #define CY_LVD_HT_CHECK_LVD_SELECT(lvdNum) (((lvdNum) == CY_LVD_HT_SELECT_LVD_1) || \
229 ((lvdNum) == CY_LVD_HT_SELECT_LVD_2))
230
231 /** \endcond */
232
233 /**
234 * \addtogroup group_lvd_ht_functions
235 * \{
236 */
237 __STATIC_INLINE void Cy_LVD_HT_Enable(cy_en_lvd_ht_select_t lvdNum);
238 __STATIC_INLINE void Cy_LVD_HT_Disable(cy_en_lvd_ht_select_t lvdNum);
239 __STATIC_INLINE void Cy_LVD_HT_SetThreshold(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_tripsel_t threshold);
240 __STATIC_INLINE cy_en_lvd_ht_status_t Cy_LVD_HT_GetStatus(cy_en_lvd_ht_select_t lvdNum);
241 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptStatus(cy_en_lvd_ht_select_t lvdNum);
242 __STATIC_INLINE void Cy_LVD_HT_ClearInterrupt(cy_en_lvd_ht_select_t lvdNum);
243 __STATIC_INLINE void Cy_LVD_HT_SetInterrupt(cy_en_lvd_ht_select_t lvdNum);
244 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptMask(cy_en_lvd_ht_select_t lvdNum);
245 __STATIC_INLINE void Cy_LVD_HT_SetInterruptMask(cy_en_lvd_ht_select_t lvdNum);
246 __STATIC_INLINE void Cy_LVD_HT_ClearInterruptMask(cy_en_lvd_ht_select_t lvdNum);
247 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptStatusMasked(cy_en_lvd_ht_select_t lvdNum);
248 __STATIC_INLINE void Cy_LVD_HT_SetInterruptConfig(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_intr_config_t lvdInterruptConfig);
249 __STATIC_INLINE void Cy_LVD_HT_DeepSleepEnable(cy_en_lvd_ht_select_t lvdNum);
250 __STATIC_INLINE void Cy_LVD_HT_DeepSleepDisable(cy_en_lvd_ht_select_t lvdNum);
251 __STATIC_INLINE void Cy_LVD_HT_SetActionConfig(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_action_config_t lvdActionConfig);
252 __STATIC_INLINE cy_en_lvd_ht_action_config_t Cy_LVD_HT_GetActionConfig(cy_en_lvd_ht_select_t lvdNum);
253 __STATIC_INLINE bool Cy_LVD_HT_IsDeepSleepEnabled(cy_en_lvd_ht_select_t lvdNum);
254
255 /** \addtogroup group_lvd_ht_functions_syspm_callback
256 * The driver supports SysPm callback for Deep Sleep transition.
257 * \{
258 */
259 cy_en_syspm_status_t Cy_LVD_HT_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams, cy_en_syspm_callback_mode_t mode);
260 /** \} */
261
262 /*******************************************************************************
263 * Function Name: Cy_LVD_HT_Enable
264 ****************************************************************************//**
265 *
266 * Enables the output of the LVD block when the VDDD voltage crosses the
267 * threshold.
268 * See the Configuration Considerations section for details.
269 *
270 * \param lvdNum
271 * Selects the LVD, \ref cy_en_lvd_ht_select_t
272 *
273 *******************************************************************************/
Cy_LVD_HT_Enable(cy_en_lvd_ht_select_t lvdNum)274 __STATIC_INLINE void Cy_LVD_HT_Enable(cy_en_lvd_ht_select_t lvdNum)
275 {
276 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
277
278 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
279 {
280 SRSS_PWR_LVD_CTL |= SRSS_PWR_LVD_CTL_HVLVD1_EN_HT_Msk;
281 }
282 else
283 {
284 SRSS_PWR_LVD_CTL2 |= SRSS_PWR_LVD_CTL2_HVLVD2_EN_HT_Msk;
285 }
286 }
287
288
289 /*******************************************************************************
290 * Function Name: Cy_LVD_HT_Disable
291 ****************************************************************************//**
292 *
293 * Disables a particular LVD. A low voltage detection interrupt is disabled.
294 *
295 * \param lvdNum
296 * Selects the LVD, \ref cy_en_lvd_ht_select_t
297 *
298 *******************************************************************************/
Cy_LVD_HT_Disable(cy_en_lvd_ht_select_t lvdNum)299 __STATIC_INLINE void Cy_LVD_HT_Disable(cy_en_lvd_ht_select_t lvdNum)
300 {
301 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
302
303 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
304 {
305 SRSS_PWR_LVD_CTL &= (uint32_t) ~SRSS_PWR_LVD_CTL_HVLVD1_EN_HT_Msk;
306 }
307 else
308 {
309 SRSS_PWR_LVD_CTL2 &= (uint32_t) ~SRSS_PWR_LVD_CTL2_HVLVD2_EN_HT_Msk;
310 }
311 }
312
313
314 /*******************************************************************************
315 * Function Name: Cy_LVD_HT_SetThreshold
316 ****************************************************************************//**
317 *
318 * Sets a threshold for monitoring the VDDD voltage.
319 * To prevent propagating a false interrupt, before changing the threshold
320 * ensure that the LVD block itself and LVD interrupt are disabled by the
321 * \ref Cy_LVD_HT_Disable and \ref Cy_LVD_HT_ClearInterruptMask functions
322 * correspondingly.
323 *
324 * \param lvdNum
325 * Selects the LVD, \ref cy_en_lvd_ht_select_t
326 *
327 * \param threshold
328 * Threshold selection for Low Voltage Detect circuit, \ref cy_en_lvd_ht_tripsel_t.
329 *
330 *******************************************************************************/
Cy_LVD_HT_SetThreshold(cy_en_lvd_ht_select_t lvdNum,cy_en_lvd_ht_tripsel_t threshold)331 __STATIC_INLINE void Cy_LVD_HT_SetThreshold(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_tripsel_t threshold)
332 {
333 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
334 CY_ASSERT_L3(CY_LVD_HT_CHECK_TRIPSEL(threshold));
335
336 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
337 {
338 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_TRIPSEL_HT, threshold);
339 }
340 else
341 {
342 SRSS_PWR_LVD_CTL2 = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL2, SRSS_PWR_LVD_CTL2_HVLVD2_TRIPSEL_HT, threshold);
343 }
344 }
345
346
347 /*******************************************************************************
348 * Function Name: Cy_LVD_HT_GetStatus
349 ****************************************************************************//**
350 *
351 * Returns the status of selected LVD.
352 * SRSS LVD Status Register (PWR_LVD_STATUS).
353 *
354 * \param lvdNum
355 * Selects the LVD, \ref cy_en_lvd_ht_select_t
356 *
357 * \return LVD status, \ref cy_en_lvd_ht_status_t.
358 *
359 *******************************************************************************/
Cy_LVD_HT_GetStatus(cy_en_lvd_ht_select_t lvdNum)360 __STATIC_INLINE cy_en_lvd_ht_status_t Cy_LVD_HT_GetStatus(cy_en_lvd_ht_select_t lvdNum)
361 {
362 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
363
364 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
365 {
366 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','SRSS_PWR_LVD_STATUS_HVLVD1_OUT_Msk extracts only 1 bit value');
367 return ((cy_en_lvd_ht_status_t) _FLD2VAL(SRSS_PWR_LVD_STATUS_HVLVD1_OUT, SRSS_PWR_LVD_STATUS));
368 }
369 else
370 {
371 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','SRSS_PWR_LVD_STATUS2_HVLVD2_OUT_Msk extracts only 1 bit value');
372 return ((cy_en_lvd_ht_status_t) _FLD2VAL(SRSS_PWR_LVD_STATUS2_HVLVD2_OUT, SRSS_PWR_LVD_STATUS2));
373
374 }
375 }
376
377
378 /*******************************************************************************
379 * Function Name: Cy_LVD_HT_GetInterruptStatus
380 ****************************************************************************//**
381 *
382 * Returns the status of selected LVD's interrupt.
383 * SRSS Interrupt Register (SRSS_INTR).
384 *
385 * \param lvdNum
386 * Selects the LVD, \ref cy_en_lvd_ht_select_t
387 *
388 * \return SRSS Interrupt status
389 *
390 *******************************************************************************/
Cy_LVD_HT_GetInterruptStatus(cy_en_lvd_ht_select_t lvdNum)391 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptStatus(cy_en_lvd_ht_select_t lvdNum)
392 {
393 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
394
395 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
396 {
397 return (SRSS_SRSS_INTR & SRSS_SRSS_INTR_HVLVD1_Msk);
398 }
399 else
400 {
401 return (SRSS_SRSS_INTR & SRSS_SRSS_INTR_HVLVD2_Msk);
402 }
403 }
404
405
406 /*******************************************************************************
407 * Function Name: Cy_LVD_HT_ClearInterrupt
408 ****************************************************************************//**
409 *
410 * Clears LVD interrupt.
411 * SRSS Interrupt Register (SRSS_INTR).
412 *
413 * \param lvdNum
414 * Selects the LVD, \ref cy_en_lvd_ht_select_t
415 *
416 *******************************************************************************/
Cy_LVD_HT_ClearInterrupt(cy_en_lvd_ht_select_t lvdNum)417 __STATIC_INLINE void Cy_LVD_HT_ClearInterrupt(cy_en_lvd_ht_select_t lvdNum)
418 {
419 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
420
421 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
422 {
423 SRSS_SRSS_INTR = SRSS_SRSS_INTR_HVLVD1_Msk;
424 }
425 else
426 {
427 SRSS_SRSS_INTR = SRSS_SRSS_INTR_HVLVD2_Msk;
428 }
429 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
430 (void) SRSS_SRSS_INTR;
431 }
432
433
434 /*******************************************************************************
435 * Function Name: Cy_LVD_HT_SetInterrupt
436 ****************************************************************************//**
437 *
438 * Triggers the device to generate interrupt for LVD.
439 * SRSS Interrupt Set Register (SRSS_INTR_SET).
440 *
441 * \param lvdNum
442 * Selects the LVD, \ref cy_en_lvd_ht_select_t
443 *
444 *******************************************************************************/
Cy_LVD_HT_SetInterrupt(cy_en_lvd_ht_select_t lvdNum)445 __STATIC_INLINE void Cy_LVD_HT_SetInterrupt(cy_en_lvd_ht_select_t lvdNum)
446 {
447 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
448
449 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
450 {
451 SRSS_SRSS_INTR_SET |= SRSS_SRSS_INTR_SET_HVLVD1_Msk;
452 }
453 else
454 {
455 SRSS_SRSS_INTR_SET |= SRSS_SRSS_INTR_SET_HVLVD2_Msk;
456 }
457 }
458
459
460 /*******************************************************************************
461 * Function Name: Cy_LVD_HT_GetInterruptMask
462 ****************************************************************************//**
463 *
464 * Returns the mask value of LVD interrupts.
465 * SRSS Interrupt Mask Register (SRSS_INTR_MASK).
466 *
467 * \param lvdNum
468 * Selects the LVD, \ref cy_en_lvd_ht_select_t
469 *
470 * \return SRSS Interrupt Mask value
471 *
472 *******************************************************************************/
Cy_LVD_HT_GetInterruptMask(cy_en_lvd_ht_select_t lvdNum)473 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptMask(cy_en_lvd_ht_select_t lvdNum)
474 {
475 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
476
477 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
478 {
479 return (SRSS_SRSS_INTR_MASK & SRSS_SRSS_INTR_MASK_HVLVD1_Msk);
480 }
481 else
482 {
483 return (SRSS_SRSS_INTR_MASK & SRSS_SRSS_INTR_MASK_HVLVD2_Msk);
484 }
485 }
486
487
488 /*******************************************************************************
489 * Function Name: Cy_LVD_HT_SetInterruptMask
490 ****************************************************************************//**
491 *
492 * Enables LVD interrupts.
493 * Sets the LVD interrupt mask in the SRSS_INTR_MASK register.
494 *
495 * \param lvdNum
496 * Selects the LVD, \ref cy_en_lvd_ht_select_t
497 *
498 *******************************************************************************/
Cy_LVD_HT_SetInterruptMask(cy_en_lvd_ht_select_t lvdNum)499 __STATIC_INLINE void Cy_LVD_HT_SetInterruptMask(cy_en_lvd_ht_select_t lvdNum)
500 {
501 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
502
503 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
504 {
505 SRSS_SRSS_INTR_MASK |= SRSS_SRSS_INTR_MASK_HVLVD1_Msk;
506 }
507 else
508 {
509 SRSS_SRSS_INTR_MASK |= SRSS_SRSS_INTR_MASK_HVLVD2_Msk;
510 }
511 }
512
513
514 /*******************************************************************************
515 * Function Name: Cy_LVD_HT_ClearInterruptMask
516 ****************************************************************************//**
517 *
518 * Disables LVD interrupts.
519 * Clears the LVD interrupt mask in the SRSS_INTR_MASK register.
520 *
521 * \param lvdNum
522 * Selects the LVD, \ref cy_en_lvd_ht_select_t
523 *
524 *******************************************************************************/
Cy_LVD_HT_ClearInterruptMask(cy_en_lvd_ht_select_t lvdNum)525 __STATIC_INLINE void Cy_LVD_HT_ClearInterruptMask(cy_en_lvd_ht_select_t lvdNum)
526 {
527 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
528
529 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
530 {
531 SRSS_SRSS_INTR_MASK &= (uint32_t) ~SRSS_SRSS_INTR_MASK_HVLVD1_Msk;
532 }
533 else
534 {
535 SRSS_SRSS_INTR_MASK &= (uint32_t) ~SRSS_SRSS_INTR_MASK_HVLVD2_Msk;
536 }
537 }
538
539
540 /*******************************************************************************
541 * Function Name: Cy_LVD_HT_GetInterruptStatusMasked
542 ****************************************************************************//**
543 *
544 * Returns the masked interrupt status which is a bitwise AND between the
545 * interrupt status and interrupt mask registers.
546 * SRSS Interrupt Masked Register (SRSS_INTR_MASKED).
547 *
548 * \param lvdNum
549 * Selects the LVD, \ref cy_en_lvd_ht_select_t
550 *
551 * \return SRSS Interrupt Masked value
552 *
553 *******************************************************************************/
Cy_LVD_HT_GetInterruptStatusMasked(cy_en_lvd_ht_select_t lvdNum)554 __STATIC_INLINE uint32_t Cy_LVD_HT_GetInterruptStatusMasked(cy_en_lvd_ht_select_t lvdNum)
555 {
556 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
557
558 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
559 {
560 return (SRSS_SRSS_INTR_MASKED & SRSS_SRSS_INTR_MASK_HVLVD1_Msk);
561 }
562 else
563 {
564 return (SRSS_SRSS_INTR_MASKED & SRSS_SRSS_INTR_MASK_HVLVD2_Msk);
565 }
566 }
567
568
569 /*******************************************************************************
570 * Function Name: Cy_LVD_HT_SetInterruptConfig
571 ****************************************************************************//**
572 *
573 * Sets a configuration for specified LVD interrupt.
574 * HVLVD Configuration Register (PWR_LVD_CTL or PWR_LVD_CTL2).
575 *
576 * \param lvdNum
577 * Selects the LVD, \ref cy_en_lvd_ht_select_t
578 *
579 * \param lvdInterruptConfig \ref cy_en_lvd_ht_intr_config_t.
580 *
581 *******************************************************************************/
Cy_LVD_HT_SetInterruptConfig(cy_en_lvd_ht_select_t lvdNum,cy_en_lvd_ht_intr_config_t lvdInterruptConfig)582 __STATIC_INLINE void Cy_LVD_HT_SetInterruptConfig(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_intr_config_t lvdInterruptConfig)
583 {
584 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
585 CY_ASSERT_L3(CY_LVD_HT_CHECK_INTR_CFG(lvdInterruptConfig));
586
587 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
588 {
589 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_EDGE_SEL, lvdInterruptConfig);
590 }
591 else
592 {
593 SRSS_PWR_LVD_CTL2 = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL2, SRSS_PWR_LVD_CTL2_HVLVD2_EDGE_SEL, lvdInterruptConfig);
594 }
595 }
596
597 /*******************************************************************************
598 * Function Name: Cy_LVD_HT_SetActionConfig
599 ****************************************************************************//**
600 *
601 * Sets a action configuration after LVD block reaches threshold.
602 *
603 * \param lvdNum
604 * Selects the LVD, \ref cy_en_lvd_ht_select_t
605 *
606 * \param lvdActionConfig \ref cy_en_lvd_ht_action_config_t.
607 *
608 *******************************************************************************/
Cy_LVD_HT_SetActionConfig(cy_en_lvd_ht_select_t lvdNum,cy_en_lvd_ht_action_config_t lvdActionConfig)609 __STATIC_INLINE void Cy_LVD_HT_SetActionConfig(cy_en_lvd_ht_select_t lvdNum, cy_en_lvd_ht_action_config_t lvdActionConfig)
610 {
611 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
612 CY_ASSERT_L3(CY_LVD_HT_CHECK_ACTION_CFG(lvdActionConfig));
613
614 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
615 {
616 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_ACTION, lvdActionConfig);
617 }
618 else
619 {
620 SRSS_PWR_LVD_CTL2 = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL2, SRSS_PWR_LVD_CTL2_HVLVD2_ACTION, lvdActionConfig);
621 }
622 }
623
624 /*******************************************************************************
625 * Function Name: Cy_LVD_HT_GetActionConfig
626 ****************************************************************************//**
627 *
628 * Gets the action configured after LVD reaches threshold.
629 *
630 * \param lvdNum
631 * Selects the LVD, \ref cy_en_lvd_ht_select_t
632 *
633 * \return \ref cy_en_lvd_ht_action_config_t
634 *
635 *******************************************************************************/
Cy_LVD_HT_GetActionConfig(cy_en_lvd_ht_select_t lvdNum)636 __STATIC_INLINE cy_en_lvd_ht_action_config_t Cy_LVD_HT_GetActionConfig(cy_en_lvd_ht_select_t lvdNum)
637 {
638 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
639
640 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
641 {
642 return (((SRSS_PWR_LVD_CTL & SRSS_PWR_LVD_CTL_HVLVD1_ACTION_Msk) != 0UL) ? CY_LVD_HT_ACTION_FAULT : CY_LVD_HT_ACTION_INTERRUPT);
643 }
644 else
645 {
646 return (((SRSS_PWR_LVD_CTL2 & SRSS_PWR_LVD_CTL2_HVLVD2_ACTION_Msk) != 0UL) ? CY_LVD_HT_ACTION_FAULT : CY_LVD_HT_ACTION_INTERRUPT);
647 }
648 }
649
650 /*******************************************************************************
651 * Function Name: Cy_LVD_HT_DeepSleepEnable
652 ****************************************************************************//**
653 *
654 * Enables selected LVD block during Deep Sleep.
655 *
656 * \param lvdNum
657 * Selects the LVD, \ref cy_en_lvd_ht_select_t
658 *
659 * \note
660 * For enabling, call this API before the system enters first DEEPSLEEP entry,
661 * else if we enable in the second or subsequent DEEPSLEEP entries then it might
662 * not wake the system from DEEPSLEEP through LVD.
663 *
664 *******************************************************************************/
Cy_LVD_HT_DeepSleepEnable(cy_en_lvd_ht_select_t lvdNum)665 __STATIC_INLINE void Cy_LVD_HT_DeepSleepEnable(cy_en_lvd_ht_select_t lvdNum)
666 {
667 CY_ASSERT_L3(CY_LVD_HT_CHECK_LVD_SELECT(lvdNum));
668
669 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
670 {
671 SRSS_PWR_LVD_CTL |= SRSS_PWR_LVD_CTL_HVLVD1_DPSLP_EN_HT_Msk;
672 }
673 else
674 {
675 SRSS_PWR_LVD_CTL2 |= SRSS_PWR_LVD_CTL2_HVLVD2_DPSLP_EN_HT_Msk;
676 }
677 }
678
679
680 /*******************************************************************************
681 * Function Name: Cy_LVD_HT_DeepSleepDisable
682 ****************************************************************************//**
683 *
684 * Disables selected LVD block during Deep Sleep.
685 *
686 * \param lvdNum
687 * Selects the LVD, \ref cy_en_lvd_ht_select_t
688 *
689 * \note
690 * After Cy_LVD_HT_DeepSleepDisable call, you have to reinitialize LVD according
691 * to recommended LVD Init sequence, else it might not wake the system from
692 * DEEPSLEEP through LVD after calling Cy_LVD_HT_DeepSleepEnable.
693 *
694 *******************************************************************************/
Cy_LVD_HT_DeepSleepDisable(cy_en_lvd_ht_select_t lvdNum)695 __STATIC_INLINE void Cy_LVD_HT_DeepSleepDisable(cy_en_lvd_ht_select_t lvdNum)
696 {
697 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
698 {
699 SRSS_PWR_LVD_CTL &= (uint32_t) ~SRSS_PWR_LVD_CTL_HVLVD1_DPSLP_EN_HT_Msk;
700 }
701 else
702 {
703 SRSS_PWR_LVD_CTL2 &= (uint32_t) ~SRSS_PWR_LVD_CTL2_HVLVD2_DPSLP_EN_HT_Msk;
704 }
705 }
706
707 /*******************************************************************************
708 * Function Name: Cy_LVD_HT_IsDeepSleepEnabled
709 ****************************************************************************//**
710 *
711 * Checks if LVD HT is enabled during Deep Sleep or not.
712 *
713 * \param lvdNum
714 * Selects the LVD, \ref cy_en_lvd_ht_select_t
715 *
716 * \return - True if LVD HT is enabled during Deep Sleep, otherwise False.
717 *
718 *******************************************************************************/
Cy_LVD_HT_IsDeepSleepEnabled(cy_en_lvd_ht_select_t lvdNum)719 __STATIC_INLINE bool Cy_LVD_HT_IsDeepSleepEnabled(cy_en_lvd_ht_select_t lvdNum)
720 {
721 if(lvdNum == CY_LVD_HT_SELECT_LVD_1)
722 {
723 return (((SRSS_PWR_LVD_CTL & SRSS_PWR_LVD_CTL_HVLVD1_DPSLP_EN_HT_Msk) != 0UL) ? true : false);
724 }
725 else
726 {
727 return (((SRSS_PWR_LVD_CTL2 & SRSS_PWR_LVD_CTL2_HVLVD2_DPSLP_EN_HT_Msk) != 0UL) ? true : false);
728 }
729 }
730
731
732 /** \} group_lvd_ht_functions */
733
734 #ifdef __cplusplus
735 }
736 #endif
737
738 #endif /* CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2) */
739
740 #endif /* CY_LVD_HT_H */
741
742 /** \} group_lvd_ht */
743
744
745 /* [] END OF FILE */
746