1 /***************************************************************************//**
2 * \file cy_lvd.h
3 * \version 1.80
4 *
5 * The header file of the LVD driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright (c) (2017-2022), Cypress Semiconductor Corporation (an Infineon company) or
10 * an affiliate of Cypress Semiconductor Corporation.
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25
26 /**
27 * \addtogroup group_lvd
28 * \{
29 * The LVD driver provides an API to manage the Low Voltage Detection block.
30 *
31 * The functions and other declarations used in this driver are in cy_lvd.h.
32 * You can include cy_pdl.h to get access to all functions
33 * and declarations in the PDL.
34 *
35 * The LVD block provides a status of currently observed VDDD voltage
36 * and triggers an interrupt when the observed voltage crosses an adjusted
37 * threshold.
38 *
39 * \section group_lvd_configuration_considerations Configuration Considerations
40 * To set up an LVD, configure the voltage threshold by the
41 * \ref Cy_LVD_SetThreshold function, ensure that the LVD block itself and LVD
42 * interrupt are disabled (by the \ref Cy_LVD_Disable and
43 * \ref Cy_LVD_ClearInterruptMask functions correspondingly) before changing the
44 * threshold to prevent propagating a false interrupt.
45 * Then configure interrupts by the \ref Cy_LVD_SetInterruptConfig function, do
46 * not forget to initialize an interrupt handler (the interrupt source number
47 * is srss_interrupt_IRQn).
48 * Then enable LVD by the \ref Cy_LVD_Enable function, then wait for at least 20us
49 * to get the circuit stabilized and clear the possible false interrupts by the
50 * \ref Cy_LVD_ClearInterrupt, and finally the LVD interrupt can be enabled by
51 * the \ref Cy_LVD_SetInterruptMask function.
52 *
53 * For example:
54 * \snippet lvd/snippet/main.c Cy_LVD_Snippet
55 *
56 * Note that the LVD circuit is available only in Low Power and Ultra Low Power
57 * modes. If an LVD is required in Deep Sleep mode, then the device
58 * should be configured to periodically wake up from Deep Sleep using a
59 * Deep Sleep wakeup source. This makes sure a LVD check is performed during
60 * Low Power or Ultra Low Power modes.
61 *
62 * \section group_lvd_more_information More Information
63 * See the LVD chapter of the device technical reference manual (TRM).
64 *
65 * \section group_lvd_changelog Changelog
66 * <table class="doxtable">
67 * <tr><th>Version</th><th>Changes</th><th>Reason of Change</th></tr>
68 * <tr>
69 * <td>1.80</td>
70 * <td>Added new APIs \ref Cy_LVD_SetActionConfig, \ref Cy_LVD_GetActionConfig
71 * - Added enum \ref cy_en_lvd_action_config_t.</td>
72 * <td>LVD set and get config APIs added.</td>
73 * </tr>
74 * <tr>
75 * <td>1.70</td>
76 * <td>Added support for TRAVEO™ II Body Entry devices.<br>
77 * Changed pre-processor logic so SRSS version 2 is grouped with version 3 instead of version 1.</td>
78 * <td>Code enhancement and support for new devices.</td>
79 * </tr>
80 * <tr>
81 * <td>1.60</td>
82 * <td>Added CAT1D device support.</td>
83 * <td>Added support for CAT1D family of devices.</td>
84 * </tr>
85 * <tr>
86 * <td rowspan="2">1.50</td>
87 * <td>Added CAT1B device support.</td>
88 * <td>Added support for CAT1B family of devices.</td>
89 * </tr>
90 * <tr>
91 * <td>New APIs Added
92 * * Cy_LVD_GetSourceVoltage()
93 * * Cy_LVD_SetSourceVoltage()
94 * </td>
95 * <td>Added new APIs to set and get the source voltage.</td>
96 * </tr>
97 * <tr>
98 * <td>1.40</td>
99 * <td>Added new device support.</td>
100 * <td>Added new family of devices.</td>
101 * </tr>
102 * <tr>
103 * <td>1.30</td>
104 * <td>Fixed/documented MISRA 2012 violations.</td>
105 * <td>MISRA 2012 compliance.</td>
106 * </tr>
107 * <tr>
108 * <td>1.20</td>
109 * <td>
110 Updated the following functions for the PSoC 64 devices:
111 \ref Cy_LVD_Enable, \ref Cy_LVD_Disable, \ref Cy_LVD_SetThreshold,
112 \ref Cy_LVD_ClearInterrupt, \ref Cy_LVD_SetInterrupt,
113 \ref Cy_LVD_SetInterruptMask, \ref Cy_LVD_ClearInterruptMask, and
114 \ref Cy_LVD_SetInterruptConfig.
115 </td>
116 * <td>Added PSoC 64 device support.</td>
117 * </tr>
118 * <tr>
119 * <td rowspan="2">1.10</td>
120 * <td>Flattened the organization of the driver source code into the single
121 * source directory and the single include directory.
122 * </td>
123 * <td>Driver library directory-structure simplification.</td>
124 * </tr>
125 * <tr>
126 * <td>Added register access layer. Use register access macros instead
127 * of direct register access using dereferenced pointers.</td>
128 * <td>Makes register access device-independent, so that the PDL does
129 * not need to be recompiled for each supported part number.</td>
130 * </tr>
131 * <tr>
132 * <td>1.0.1</td>
133 * <td>Added Low Power Callback section</td>
134 * <td>Documentation update and clarification</td>
135 * </tr>
136 * <tr>
137 * <td>1.0</td>
138 * <td>Initial Version</td>
139 * <td></td>
140 * </tr>
141 * </table>
142 *
143 * \defgroup group_lvd_macros Macros
144 * \defgroup group_lvd_functions Functions
145 * \{
146 * \defgroup group_lvd_functions_syspm_callback Low Power Callback
147 * \}
148 * \defgroup group_lvd_enums Enumerated Types
149 */
150
151
152 #if !defined(CY_LVD_H)
153 #define CY_LVD_H
154
155 #include "cy_device.h"
156
157 #if defined (CY_IP_MXS40SSRSS) || (defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION == 1)) || defined (CY_IP_MXS22SRSS)
158
159 #include "cy_pra.h"
160 #include "cy_syspm.h"
161
162 #ifdef __cplusplus
163 extern "C" {
164 #endif
165
166 /** \addtogroup group_lvd_macros
167 * \{
168 */
169
170 /** The driver major version */
171 #define CY_LVD_DRV_VERSION_MAJOR 1
172
173 /** The driver minor version */
174 #define CY_LVD_DRV_VERSION_MINOR 80
175
176 /** The LVD driver identifier */
177 #define CY_LVD_ID (CY_PDL_DRV_ID(0x39U))
178
179 #if defined (CY_IP_MXS40SRSS)
180 /**
181 * \note
182 * These macros are available for CAT1A devices.
183 **/
184
185 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatus(),
186 \ref Cy_LVD_ClearInterrupt() */
187 #define CY_LVD_SRSS_INTR_HVLVD1_MASK (SRSS_SRSS_INTR_HVLVD1_Msk)
188
189 /** Interrupt mask for \ref Cy_LVD_SetInterrupt() */
190 #define CY_LVD_SRSS_INTR_SET_HVLVD1_MASK (SRSS_SRSS_INTR_SET_HVLVD1_Msk)
191
192 /** Interrupt mask for \ref Cy_LVD_GetInterruptMask(),
193 \ref Cy_LVD_SetInterruptMask() and
194 \ref Cy_LVD_ClearInterruptMask() */
195 #define CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK (SRSS_SRSS_INTR_MASK_HVLVD1_Msk)
196
197 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatusMasked() */
198 #define CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK (SRSS_SRSS_INTR_MASKED_HVLVD1_Msk)
199
200 /** Enable mask for \ref Cy_LVD_Enable() and /ref Cy_LVD_Disable() */
201 #define CY_LVD_SRSS_PWR_LVD_CTL_HVLVD_EN_Msk (SRSS_PWR_LVD_CTL_HVLVD1_EN_Msk)
202
203 #endif
204
205 #if defined (CY_IP_MXS40SSRSS)
206 /**
207 * \note
208 * These macros are available for devices having MXS40SSRSS IP.
209 **/
210
211 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatus(),
212 \ref Cy_LVD_ClearInterrupt() */
213 #define CY_LVD_SRSS_INTR_HVLVD1_MASK (SRSS_SRSS_AINTR_HVLVD1_Msk)
214
215 /** Interrupt mask for \ref Cy_LVD_SetInterrupt() */
216 #define CY_LVD_SRSS_INTR_SET_HVLVD1_MASK (SRSS_SRSS_AINTR_SET_HVLVD1_Msk)
217
218 /** Interrupt mask for \ref Cy_LVD_GetInterruptMask(),
219 \ref Cy_LVD_SetInterruptMask() and
220 \ref Cy_LVD_ClearInterruptMask() */
221 #define CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK (SRSS_SRSS_AINTR_MASK_HVLVD1_Msk)
222
223 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatusMasked() */
224 #define CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK (SRSS_SRSS_AINTR_MASKED_HVLVD1_Msk)
225
226 /** Enable mask for \ref Cy_LVD_Enable() and /ref Cy_LVD_Disable() */
227 #define CY_LVD_SRSS_PWR_LVD_CTL_HVLVD_EN_Msk (SRSS_PWR_LVD_CTL_HVLVD1_EN_Msk)
228
229 #endif
230
231 #if defined (CY_IP_MXS22SRSS)
232 /**
233 * \note
234 * These macros are available for devices having MXS22SRSS IP.
235 **/
236
237 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatus(),
238 \ref Cy_LVD_ClearInterrupt() */
239 #define CY_LVD_SRSS_INTR_HVLVD1_MASK (SRSS_SRSS_AINTR_HVLVD_Msk)
240
241 /** Interrupt mask for \ref Cy_LVD_SetInterrupt() */
242 #define CY_LVD_SRSS_INTR_SET_HVLVD1_MASK (SRSS_SRSS_AINTR_SET_HVLVD_Msk)
243
244 /** Interrupt mask for \ref Cy_LVD_GetInterruptMask(),
245 \ref Cy_LVD_SetInterruptMask() and
246 \ref Cy_LVD_ClearInterruptMask() */
247 #define CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK (SRSS_SRSS_AINTR_MASK_HVLVD_Msk)
248
249 /** Interrupt mask for \ref Cy_LVD_GetInterruptStatusMasked() */
250 #define CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK (SRSS_SRSS_AINTR_MASKED_HVLVD_Msk)
251
252 /** Enable mask for \ref Cy_LVD_Enable() and /ref Cy_LVD_Disable() */
253 #define CY_LVD_SRSS_PWR_LVD_CTL_HVLVD_EN_Msk (SRSS_PWR_LVD_CTL_HVLVD_EN_Msk)
254 #endif
255
256
257 /** \} group_lvd_macros */
258
259
260 /** \addtogroup group_lvd_enums
261 * \{
262 */
263
264
265 /**
266 * LVD reference voltage select.
267 */
268 #if defined (CY_IP_MXS22SRSS)
269 typedef enum
270 {
271 CY_LVD_THRESHOLD_2_75_V = 0x0U, /**<Select LVD reference voltage: 2.75V */
272 CY_LVD_THRESHOLD_2_85_V = 0x1U, /**<Select LVD reference voltage: 2.85V */
273 CY_LVD_THRESHOLD_2_95_V = 0x2U, /**<Select LVD reference voltage: 2.95V */
274 CY_LVD_THRESHOLD_3_05_V = 0x3U, /**<Select LVD reference voltage: 3.05V */
275 CY_LVD_THRESHOLD_3_15_V = 0x4U, /**<Select LVD reference voltage: 3.15V */
276 } cy_en_lvd_tripsel_t;
277 #else
278 typedef enum
279 {
280 CY_LVD_THRESHOLD_1_2_V = 0x0U, /**<Select LVD reference voltage: 1.2V */
281 CY_LVD_THRESHOLD_1_4_V = 0x1U, /**<Select LVD reference voltage: 1.4V */
282 CY_LVD_THRESHOLD_1_6_V = 0x2U, /**<Select LVD reference voltage: 1.6V */
283 CY_LVD_THRESHOLD_1_8_V = 0x3U, /**<Select LVD reference voltage: 1.8V */
284 CY_LVD_THRESHOLD_2_0_V = 0x4U, /**<Select LVD reference voltage: 2.0V */
285 CY_LVD_THRESHOLD_2_1_V = 0x5U, /**<Select LVD reference voltage: 2.1V */
286 CY_LVD_THRESHOLD_2_2_V = 0x6U, /**<Select LVD reference voltage: 2.2V */
287 CY_LVD_THRESHOLD_2_3_V = 0x7U, /**<Select LVD reference voltage: 2.3V */
288 CY_LVD_THRESHOLD_2_4_V = 0x8U, /**<Select LVD reference voltage: 2.4V */
289 CY_LVD_THRESHOLD_2_5_V = 0x9U, /**<Select LVD reference voltage: 2.5V */
290 CY_LVD_THRESHOLD_2_6_V = 0xAU, /**<Select LVD reference voltage: 2.6V */
291 CY_LVD_THRESHOLD_2_7_V = 0xBU, /**<Select LVD reference voltage: 2.7V */
292 CY_LVD_THRESHOLD_2_8_V = 0xCU, /**<Select LVD reference voltage: 2.8V */
293 CY_LVD_THRESHOLD_2_9_V = 0xDU, /**<Select LVD reference voltage: 2.9V */
294 CY_LVD_THRESHOLD_3_0_V = 0xEU, /**<Select LVD reference voltage: 3.0V */
295 CY_LVD_THRESHOLD_3_1_V = 0xFU /**<Select LVD reference voltage: 3.1V */
296 } cy_en_lvd_tripsel_t;
297 #endif
298 /**
299 * LVD interrupt configuration select.
300 */
301 typedef enum
302 {
303 CY_LVD_INTR_DISABLE = 0x0U, /**<Select LVD interrupt: disabled */
304 CY_LVD_INTR_RISING = 0x1U, /**<Select LVD interrupt: rising edge */
305 CY_LVD_INTR_FALLING = 0x2U, /**<Select LVD interrupt: falling edge */
306 CY_LVD_INTR_BOTH = 0x3U, /**<Select LVD interrupt: both edges */
307 } cy_en_lvd_intr_config_t;
308
309 /**
310 * LVD output status.
311 */
312 typedef enum
313 {
314 CY_LVD_STATUS_BELOW = 0x0U, /**<The voltage is below the threshold */
315 CY_LVD_STATUS_ABOVE = 0x1U, /**<The voltage is above the threshold */
316 } cy_en_lvd_status_t;
317
318 /**
319 * LVD Voltage Source.
320 */
321 typedef enum
322 {
323 CY_LVD_SOURCE_VDDD = 0x0U, /**<Selects VDDD */
324 CY_LVD_SOURCE_AMUXBUSA = 0x1U, /**<Selects AMUXBUSA*/
325 CY_LVD_SOURCE_RES = 0x2U, /**<Reserved */
326 CY_LVD_SOURCE_VDDIO = 0x3U, /**<Selects VDDIO, Currently Reserved , Selects VDDD */
327 CY_LVD_SOURCE_AMUXBUSB = 0x4U, /**<Selects AMUXBUSB*/
328 } cy_en_lvd_source_t;
329
330 /**
331 * LVD Action
332 */
333 typedef enum
334 {
335 CY_LVD_ACTION_INTERRUPT = 0x0U, /**<Select LVD Action : Interrupt */
336 CY_LVD_ACTION_FAULT = 0x1U, /**<Select LVD Action : Fault */
337 } cy_en_lvd_action_config_t;
338
339 /** \} group_lvd_enums */
340
341 /** \cond internal */
342 /* Macros for conditions used by CY_ASSERT calls */
343 #if defined (CY_IP_MXS22SRSS)
344 #define CY_LVD_CHECK_TRIPSEL(threshold) (((threshold) == CY_LVD_THRESHOLD_2_75_V) || \
345 ((threshold) == CY_LVD_THRESHOLD_2_85_V) || \
346 ((threshold) == CY_LVD_THRESHOLD_2_95_V) || \
347 ((threshold) == CY_LVD_THRESHOLD_3_05_V) || \
348 ((threshold) == CY_LVD_THRESHOLD_3_15_V))
349
350 #else
351 #define CY_LVD_CHECK_TRIPSEL(threshold) (((threshold) == CY_LVD_THRESHOLD_1_2_V) || \
352 ((threshold) == CY_LVD_THRESHOLD_1_4_V) || \
353 ((threshold) == CY_LVD_THRESHOLD_1_6_V) || \
354 ((threshold) == CY_LVD_THRESHOLD_1_8_V) || \
355 ((threshold) == CY_LVD_THRESHOLD_2_0_V) || \
356 ((threshold) == CY_LVD_THRESHOLD_2_1_V) || \
357 ((threshold) == CY_LVD_THRESHOLD_2_2_V) || \
358 ((threshold) == CY_LVD_THRESHOLD_2_3_V) || \
359 ((threshold) == CY_LVD_THRESHOLD_2_4_V) || \
360 ((threshold) == CY_LVD_THRESHOLD_2_5_V) || \
361 ((threshold) == CY_LVD_THRESHOLD_2_6_V) || \
362 ((threshold) == CY_LVD_THRESHOLD_2_7_V) || \
363 ((threshold) == CY_LVD_THRESHOLD_2_8_V) || \
364 ((threshold) == CY_LVD_THRESHOLD_2_9_V) || \
365 ((threshold) == CY_LVD_THRESHOLD_3_0_V) || \
366 ((threshold) == CY_LVD_THRESHOLD_3_1_V))
367 #endif
368 #define CY_LVD_CHECK_INTR_CFG(intrCfg) (((intrCfg) == CY_LVD_INTR_DISABLE) || \
369 ((intrCfg) == CY_LVD_INTR_RISING) || \
370 ((intrCfg) == CY_LVD_INTR_FALLING) || \
371 ((intrCfg) == CY_LVD_INTR_BOTH))
372
373 /* Added for backward Compatibility */
374 #define CY_LVD_INTR (CY_LVD_SRSS_INTR_HVLVD1_MASK)
375
376 #define CY_LVD_CHECK_ACTION_CFG(actionCfg) (((actionCfg) == CY_LVD_ACTION_INTERRUPT) || \
377 ((actionCfg) == CY_LVD_ACTION_FAULT))
378
379 /** \endcond */
380
381 /**
382 * \addtogroup group_lvd_functions
383 * \{
384 */
385 __STATIC_INLINE void Cy_LVD_Enable(void);
386 __STATIC_INLINE void Cy_LVD_Disable(void);
387 __STATIC_INLINE void Cy_LVD_SetThreshold(cy_en_lvd_tripsel_t threshold);
388 __STATIC_INLINE cy_en_lvd_status_t Cy_LVD_GetStatus(void);
389 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptStatus(void);
390 __STATIC_INLINE void Cy_LVD_ClearInterrupt(void);
391 __STATIC_INLINE void Cy_LVD_SetInterrupt(void);
392 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptMask(void);
393 __STATIC_INLINE void Cy_LVD_SetInterruptMask(void);
394 __STATIC_INLINE void Cy_LVD_ClearInterruptMask(void);
395 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptStatusMasked(void);
396 __STATIC_INLINE void Cy_LVD_SetInterruptConfig(cy_en_lvd_intr_config_t lvdInterruptConfig);
397 #if defined (CY_IP_MXS40SSRSS)
398 __STATIC_INLINE uint32_t Cy_LVD_GetSourceVoltage(void);
399 __STATIC_INLINE void Cy_LVD_SetSourceVoltage(cy_en_lvd_source_t source);
400 #endif
401
402 /** \addtogroup group_lvd_functions_syspm_callback
403 * The driver supports SysPm callback for Deep Sleep transition.
404 * \{
405 */
406 cy_en_syspm_status_t Cy_LVD_DeepSleepCallback(cy_stc_syspm_callback_params_t * callbackParams, cy_en_syspm_callback_mode_t mode);
407 /** \} */
408
409 /*******************************************************************************
410 * Function Name: Cy_LVD_Enable
411 ****************************************************************************//**
412 *
413 * Enables the output of the LVD block when the VDDD voltage is
414 * at or below the threshold.
415 * See the Configuration Considerations section for details.
416 *
417 *******************************************************************************/
Cy_LVD_Enable(void)418 __STATIC_INLINE void Cy_LVD_Enable(void)
419 {
420 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
421 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_EN, 1U);
422 #else
423 SRSS_PWR_LVD_CTL |= CY_LVD_SRSS_PWR_LVD_CTL_HVLVD_EN_Msk;
424 #endif
425 }
426
427
428 /*******************************************************************************
429 * Function Name: Cy_LVD_Disable
430 ****************************************************************************//**
431 *
432 * Disables the LVD block. A low voltage detection interrupt is disabled.
433 *
434 *******************************************************************************/
Cy_LVD_Disable(void)435 __STATIC_INLINE void Cy_LVD_Disable(void)
436 {
437 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
438 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_EN, 0U);
439 #else
440 SRSS_PWR_LVD_CTL &= (uint32_t) ~CY_LVD_SRSS_PWR_LVD_CTL_HVLVD_EN_Msk;
441 #endif
442 }
443
444
445 /*******************************************************************************
446 * Function Name: Cy_LVD_SetThreshold
447 ****************************************************************************//**
448 *
449 * Sets a threshold for monitoring the VDDD voltage.
450 * To prevent propagating a false interrupt, before changing the threshold
451 * ensure that the LVD block itself and LVD interrupt are disabled by the
452 * \ref Cy_LVD_Disable and \ref Cy_LVD_ClearInterruptMask functions
453 * correspondingly.
454 *
455 * \param threshold
456 * Threshold selection for Low Voltage Detect circuit, \ref cy_en_lvd_tripsel_t.
457 *
458 *******************************************************************************/
Cy_LVD_SetThreshold(cy_en_lvd_tripsel_t threshold)459 __STATIC_INLINE void Cy_LVD_SetThreshold(cy_en_lvd_tripsel_t threshold)
460 {
461 CY_ASSERT_L3(CY_LVD_CHECK_TRIPSEL(threshold));
462
463 #if CY_CPU_CORTEX_M4 && defined (CY_DEVICE_SECURE)
464 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_TRIPSEL, threshold);
465 #elif defined (CY_IP_MXS22SRSS)
466 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD_TRIPSEL, threshold);
467 #else
468 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_TRIPSEL, threshold);
469 #endif
470 }
471
472
473 /*******************************************************************************
474 * Function Name: Cy_LVD_GetStatus
475 ****************************************************************************//**
476 *
477 * Returns the status of LVD.
478 * SRSS LVD Status Register (PWR_LVD_STATUS).
479 *
480 * \return LVD status, \ref cy_en_lvd_status_t.
481 *
482 *******************************************************************************/
Cy_LVD_GetStatus(void)483 __STATIC_INLINE cy_en_lvd_status_t Cy_LVD_GetStatus(void)
484 {
485 #if defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION >= 2)
486 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','SRSS_PWR_LVD_STATUS_HVLVD1_OK_Msk extracts only 1 bit value');
487 return ((cy_en_lvd_status_t) _FLD2VAL(SRSS_PWR_LVD_STATUS_HVLVD1_OUT, SRSS_PWR_LVD_STATUS));
488 #elif defined (CY_IP_MXS22SRSS)
489 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','SRSS_PWR_LVD_STATUS_HVLVD_OK_Msk extracts only 1 bit value');
490 return ((cy_en_lvd_status_t) _FLD2VAL(SRSS_PWR_LVD_STATUS_HVLVD_OK, SRSS_PWR_LVD_STATUS));
491 #else
492 CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','SRSS_PWR_LVD_STATUS_HVLVD1_OK_Msk extracts only 1 bit value');
493 return ((cy_en_lvd_status_t) _FLD2VAL(SRSS_PWR_LVD_STATUS_HVLVD1_OK, SRSS_PWR_LVD_STATUS));
494 #endif
495 }
496
497
498 /*******************************************************************************
499 * Function Name: Cy_LVD_GetInterruptStatus
500 ****************************************************************************//**
501 *
502 * Returns the status of LVD interrupt.
503 * SRSS Interrupt Register (SRSS_INTR).
504 *
505 * \return SRSS Interrupt status, \ref CY_LVD_SRSS_INTR_HVLVD1_MASK.
506 *
507 *******************************************************************************/
Cy_LVD_GetInterruptStatus(void)508 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptStatus(void)
509 {
510 #if defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
511 return (SRSS_SRSS_AINTR & CY_LVD_SRSS_INTR_HVLVD1_MASK);
512 #else
513 return (SRSS_SRSS_INTR & CY_LVD_SRSS_INTR_HVLVD1_MASK);
514 #endif
515 }
516
517
518 /*******************************************************************************
519 * Function Name: Cy_LVD_ClearInterrupt
520 ****************************************************************************//**
521 *
522 * Clears LVD interrupt.
523 * SRSS Interrupt Register (SRSS_INTR).
524 *
525 *******************************************************************************/
Cy_LVD_ClearInterrupt(void)526 __STATIC_INLINE void Cy_LVD_ClearInterrupt(void)
527 {
528 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
529 CY_PRA_REG32_SET(CY_PRA_INDX_SRSS_SRSS_INTR, CY_LVD_SRSS_INTR_HVLVD1_MASK);
530 #elif defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
531 SRSS_SRSS_AINTR = CY_LVD_SRSS_INTR_HVLVD1_MASK;
532 #else
533 SRSS_SRSS_INTR = CY_LVD_SRSS_INTR_HVLVD1_MASK;
534 #endif
535 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
536 #if defined (CY_IP_MXS40SSRSS)
537 (void) SRSS_SRSS_AINTR;
538 #else
539 (void) SRSS_SRSS_INTR;
540 #endif
541 }
542
543
544 /*******************************************************************************
545 * Function Name: Cy_LVD_SetInterrupt
546 ****************************************************************************//**
547 *
548 * Triggers the device to generate interrupt for LVD.
549 * SRSS Interrupt Set Register (SRSS_INTR_SET).
550 *
551 *******************************************************************************/
Cy_LVD_SetInterrupt(void)552 __STATIC_INLINE void Cy_LVD_SetInterrupt(void)
553 {
554 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
555 CY_PRA_REG32_SET(CY_PRA_INDX_SRSS_SRSS_INTR_SET, CY_LVD_SRSS_INTR_SET_HVLVD1_MASK);
556 #elif defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
557 SRSS_SRSS_AINTR_SET = CY_LVD_SRSS_INTR_SET_HVLVD1_MASK;
558 #else
559 SRSS_SRSS_INTR_SET = CY_LVD_SRSS_INTR_SET_HVLVD1_MASK;
560 #endif
561 }
562
563
564 /*******************************************************************************
565 * Function Name: Cy_LVD_GetInterruptMask
566 ****************************************************************************//**
567 *
568 * Returns the mask value of LVD interrupts.
569 * SRSS Interrupt Mask Register (SRSS_INTR_MASK).
570 *
571 * \return SRSS Interrupt Mask value, \ref CY_LVD_SRSS_INTR_HVLVD1_MASK.
572 *
573 *******************************************************************************/
Cy_LVD_GetInterruptMask(void)574 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptMask(void)
575 {
576 #if defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
577 return (SRSS_SRSS_AINTR_MASK & CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK);
578 #else
579 return (SRSS_SRSS_INTR_MASK & CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK);
580 #endif
581 }
582
583
584 /*******************************************************************************
585 * Function Name: Cy_LVD_SetInterruptMask
586 ****************************************************************************//**
587 *
588 * Enables LVD interrupts.
589 * Sets the LVD interrupt mask in the SRSS_INTR_MASK register.
590 *
591 *******************************************************************************/
Cy_LVD_SetInterruptMask(void)592 __STATIC_INLINE void Cy_LVD_SetInterruptMask(void)
593 {
594 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
595 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_SRSS_INTR_MASK, SRSS_SRSS_INTR_MASK_HVLVD1, 1U);
596 #elif defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
597 SRSS_SRSS_AINTR_MASK |= CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK;
598 #else
599 SRSS_SRSS_INTR_MASK |= CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK;
600 #endif
601 }
602
603
604 /*******************************************************************************
605 * Function Name: Cy_LVD_ClearInterruptMask
606 ****************************************************************************//**
607 *
608 * Disables LVD interrupts.
609 * Clears the LVD interrupt mask in the SRSS_INTR_MASK register.
610 *
611 *******************************************************************************/
Cy_LVD_ClearInterruptMask(void)612 __STATIC_INLINE void Cy_LVD_ClearInterruptMask(void)
613 {
614 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
615 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_SRSS_INTR_MASK, SRSS_SRSS_INTR_MASK_HVLVD1, 0U);
616 #elif defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
617 SRSS_SRSS_AINTR_MASK &= (uint32_t) ~CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK;
618 #else
619 SRSS_SRSS_INTR_MASK &= (uint32_t) ~CY_LVD_SRSS_INTR_MASK_HVLVD1_MASK;
620 #endif
621 }
622
623
624 /*******************************************************************************
625 * Function Name: Cy_LVD_GetInterruptStatusMasked
626 ****************************************************************************//**
627 *
628 * Returns the masked interrupt status which is a bitwise AND between the
629 * interrupt status and interrupt mask registers.
630 * SRSS Interrupt Masked Register (SRSS_INTR_MASKED).
631 *
632 * \return SRSS Interrupt Masked value, \ref CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK.
633 *
634 *******************************************************************************/
Cy_LVD_GetInterruptStatusMasked(void)635 __STATIC_INLINE uint32_t Cy_LVD_GetInterruptStatusMasked(void)
636 {
637 #if defined (CY_IP_MXS40SSRSS) || defined (CY_IP_MXS22SRSS)
638 return (SRSS_SRSS_AINTR_MASKED & CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK);
639 #else
640 return (SRSS_SRSS_INTR_MASKED & CY_LVD_SRSS_INTR_MASKED_HVLVD1_MASK);
641 #endif
642 }
643
644
645 /*******************************************************************************
646 * Function Name: Cy_LVD_SetInterruptConfig
647 ****************************************************************************//**
648 *
649 * Sets a configuration for LVD interrupt.
650 * SRSS Interrupt Configuration Register (SRSS_INTR_CFG).
651 *
652 * \param lvdInterruptConfig \ref cy_en_lvd_intr_config_t.
653 *
654 *******************************************************************************/
Cy_LVD_SetInterruptConfig(cy_en_lvd_intr_config_t lvdInterruptConfig)655 __STATIC_INLINE void Cy_LVD_SetInterruptConfig(cy_en_lvd_intr_config_t lvdInterruptConfig)
656 {
657 CY_ASSERT_L3(CY_LVD_CHECK_INTR_CFG(lvdInterruptConfig));
658
659 #if defined (CY_IP_MXS40SRSS)
660 #if CY_CPU_CORTEX_M4 && defined(CY_DEVICE_SECURE)
661 CY_PRA_REG32_CLR_SET(CY_PRA_INDX_SRSS_SRSS_INTR_CFG, SRSS_SRSS_INTR_CFG_HVLVD1_EDGE_SEL, lvdInterruptConfig);
662 #else
663 #if (CY_IP_MXS40SRSS_VERSION == 1)
664 SRSS_SRSS_INTR_CFG = _CLR_SET_FLD32U(SRSS_SRSS_INTR_CFG, SRSS_SRSS_INTR_CFG_HVLVD1_EDGE_SEL, lvdInterruptConfig);
665 #else
666 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_EDGE_SEL, lvdInterruptConfig);
667 #endif
668 #endif
669 #endif
670
671 #if defined (CY_IP_MXS40SSRSS)
672 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD1_EDGE_SEL, lvdInterruptConfig);
673 #endif
674
675 #if defined (CY_IP_MXS22SRSS)
676 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD_EDGE_SEL, lvdInterruptConfig);
677 #endif
678
679 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
680 (void) lvdInterruptConfig;
681 }
682
683 #if defined (CY_IP_MXS22SRSS) || defined (CY_DOXYGEN)
684 /*******************************************************************************
685 * Function Name: Cy_LVD_SetActionConfig
686 ****************************************************************************//**
687 *
688 * Sets a action configuration after LVD block reaches threshold.
689 *
690 * \param lvdActionConfig \ref cy_en_lvd_action_config_t.
691 *
692 * \note
693 * This API is available only for CAT1D devices.
694 *
695 *******************************************************************************/
Cy_LVD_SetActionConfig(cy_en_lvd_action_config_t lvdActionConfig)696 __STATIC_INLINE void Cy_LVD_SetActionConfig(cy_en_lvd_action_config_t lvdActionConfig)
697 {
698 CY_ASSERT_L3(CY_LVD_CHECK_ACTION_CFG(lvdActionConfig));
699
700 SRSS_PWR_LVD_CTL = _CLR_SET_FLD32U(SRSS_PWR_LVD_CTL, SRSS_PWR_LVD_CTL_HVLVD_ACTION, lvdActionConfig);
701 }
702
703 /*******************************************************************************
704 * Function Name: Cy_LVD_GetActionConfig
705 ****************************************************************************//**
706 *
707 * Gets the action configured after LVD reaches threshold.
708 *
709 * \return \ref cy_en_lvd_action_config_t
710 *
711 * \note
712 * This API is available only for CAT1D devices.
713 *
714 *******************************************************************************/
Cy_LVD_GetActionConfig(void)715 __STATIC_INLINE cy_en_lvd_action_config_t Cy_LVD_GetActionConfig(void)
716 {
717 return (((SRSS_PWR_LVD_CTL & SRSS_PWR_LVD_CTL_HVLVD_ACTION_Msk) != 0UL) ? CY_LVD_ACTION_FAULT : CY_LVD_ACTION_INTERRUPT);
718 }
719 #endif
720
721 #if defined (CY_IP_MXS40SSRSS) || defined (CY_DOXYGEN)
722
723 /*******************************************************************************
724 * Function Name: Cy_LVD_GetSourceVoltage
725 ****************************************************************************//**
726 *
727 * Returns the index of the source selected
728 *
729 * \return LVD source index, \ref cy_en_lvd_source_t.
730 *
731 * \note
732 * This API is available only for CAT1B devices.
733 *
734 *******************************************************************************/
Cy_LVD_GetSourceVoltage(void)735 __STATIC_INLINE uint32_t Cy_LVD_GetSourceVoltage(void)
736 {
737 return (SRSS_PWR_LVD_CTL & SRSS_PWR_LVD_CTL_HVLVD1_SRCSEL_Msk);
738 }
739
740
741 /*******************************************************************************
742 * Function Name: Cy_LVD_SetSourceVoltage
743 ****************************************************************************//**
744 *
745 * Selects the source voltage for LVD.
746 *
747 * \param source \ref cy_en_lvd_source_t.
748 *
749 * \note
750 * This API is available only for CAT1B devices.
751 *
752 *******************************************************************************/
Cy_LVD_SetSourceVoltage(cy_en_lvd_source_t source)753 __STATIC_INLINE void Cy_LVD_SetSourceVoltage(cy_en_lvd_source_t source)
754 {
755 CY_UNUSED_PARAMETER(source); /* Suppress a compiler warning about unused variables */
756 SRSS_PWR_LVD_CTL |= SRSS_PWR_LVD_CTL_HVLVD1_SRCSEL_Msk;
757 }
758 #endif
759
760 /** \} group_lvd_functions */
761
762 #ifdef __cplusplus
763 }
764 #endif
765
766 #endif /* (CY_IP_MXS40SSRSS) || (defined (CY_IP_MXS40SRSS) && (CY_IP_MXS40SRSS_VERSION < 3)) || defined (CY_IP_MXS22SRSS) */
767
768 #endif /* CY_LVD_H */
769
770 /** \} group_lvd */
771
772
773 /* [] END OF FILE */
774