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