1 /***************************************************************************//**
2 * \file cy_evtgen.h
3 * \version 1.0
4 *
5 * Provides the API declarations of the Event generator driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2016-2022 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_evtgen
27 * \{
28 * This driver provides API functions to configure and use the Event Generator.
29 *
30 * The functions and other declarations used in this driver are in cy_evtgen.h.
31 * You can include cy_pdl.h to get access to all functions
32 * and declarations in the PDL.
33 *
34 ********************************************************************************
35 * \section group_evtgen_glossary Glossary
36 ********************************************************************************
37 * * Structure or Comparator Structure - is the main instance of the Event
38 *   Generator that set of two comparators.
39 * * Comparator - it is a sub-module of Structures for saving value to compare.
40 *
41 ********************************************************************************
42 * \section group_evtgen_solution EVTGEN Solution
43 ********************************************************************************
44 * The Event Generator (EVTGEN) implements event generation - in Active mode,
45 * for interrupts and triggers and in Deep Sleep mode only for interrupts. The
46 * Active functionality interrupt is connected to the CPU interrupt controller.
47 * Active mode triggered events can be used to trigger a specific device functionality
48 * mode (for example, execution of an interrupt handler, a SAR ADC conversion,
49 * and so on) in Active power mode. The Deep Sleep functionality interrupts can
50 * be used to wake up the CPU from the Deep Sleep power mode. The event generator
51 * includes a single counter and a maximum of 16 comparator structures for each
52 * Active and Deep Sleep mode. EVTGEN reduces CPU involvement and thus overall
53 * power consumption and jitters.
54 * \image html evtgen_architecture.png
55 *
56 * EVTGEN consists of two blocks: Active and Deep Sleep mode blocks.
57 * There are 16 comparator structures and one 32-bit counter for each of the
58 * modes which increment with each cycle CLK_REF. Each comparator structure has
59 * an Active and a Deep Sleep comparator. A comparator compares a programmed
60 * comparator value with the current counter value. When the counter value
61 * "passes" (equal) a comparator value, a comparator output is activated.
62 * \image html evtgen_clock_structure.png
63 * The Event Generator implements synchronization between the Active counter
64 * and Deep Sleep counter through ratio control. The ratio value shows the number
65 * of clk_ref_div periods in one clk_lf periods. Event Generator uses Ratio value
66 * to synchronize active counter and Deep Sleep counter with hardware
67 * automatically.
68 *
69 ********************************************************************************
70 * \section group_evtgen_configuration Configuration Considerations
71 ********************************************************************************
72 * The EVTGEN driver configuration can be divided into a number of sequential
73 * steps:
74 * * \ref group_scb_evtgen_config
75 * * \ref group_scb_evtgen_clock
76 * * \ref group_scb_evtgen_intr
77 * * \ref group_scb_evtgen_enable
78 * * \ref group_scb_evtgen_comp_struct_config
79 *
80 * \note
81 * The EVTGEN driver is built on top of the EVTGEN hardware block. The EVTGEN0
82 * instance is used as an example for all code snippets. Modify the code to match
83 * your design.
84 *
85 ********************************************************************************
86 * \subsection group_scb_evtgen_config Configure EVTGEN
87 ********************************************************************************
88 * To set up the EVTGEN driver, provide the configuration parameters in the
89 * \ref cy_stc_evtgen_config_t structure. To initialize the driver, call the
90 * \ref Cy_EvtGen_Init function providing a pointer to the populated
91 * \ref cy_stc_evtgen_config_t structure.
92 *
93 * \snippet evtgen/snippet/main.c EVTGEN_CFG
94 *
95 ********************************************************************************
96 * \subsection group_scb_evtgen_clock Enable Clock Path
97 ********************************************************************************
98 * A clock source must be connected to the EVTGEN block to control time. Enable
99 * High Frequency clock. Use the \ref group_sysclk driver API to do.
100 *
101 * \snippet evtgen/snippet/main.c EVTGEN_CFG_ASSIGN_CLOCK
102 *
103 ********************************************************************************
104 * \subsection group_scb_evtgen_comp_struct_config Configure Comparator Structure
105 ********************************************************************************
106 * To set up the Comparator Structure of the EVTGEN driver, provide the
107 * configuration parameters in the \ref cy_stc_evtgen_struct_config_t structure.
108 * To initialize the Comparator Structure, call the \ref Cy_EvtGen_InitStruct
109 * function providing a pointer to the populated
110 * \ref cy_stc_evtgen_struct_config_t structure.
111 *
112 * \snippet evtgen/snippet/main.c EVTGEN_CFG_COMP_STRUCT
113 *
114 ********************************************************************************
115 * \subsection group_scb_evtgen_intr Configure Interrupt
116 ********************************************************************************
117 * The interrupt is the main operation of EVTGEN. Use it to configure an
118 * interrupt and create the interrupt handle for the selected EVTGEN instance.
119 * Also, enable this interrupt in the NVIC.
120 *
121 * \snippet evtgen/snippet/main.c EVTGEN_INTR_A
122 * \snippet evtgen/snippet/main.c EVTGEN_INTR_B
123 *
124 ********************************************************************************
125 * \subsection group_scb_evtgen_enable Enable EVTGEN
126 ********************************************************************************
127 * Finally, enable the EVTGEN operation by calling \ref Cy_EvtGen_Enable.
128 *
129 * \snippet evtgen/snippet/main.c EVTGEN_ENABLE
130 *
131 * \section group_evtgen_changelog Changelog
132 *
133 * <table class="doxtable">
134 *   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
135 *   <tr>
136 *     <td>1.0</td>
137 *     <td>Initial version</td>
138 *     <td></td>
139 *   </tr>
140 *
141 * \defgroup group_evtgen_macros Macro
142 * \defgroup group_evtgen_functions Functions
143 * \defgroup group_evtgen_data_structures Data structures
144 * \defgroup group_evtgen_enums Enumerated types
145 */
146 
147 #if !defined(CY_EVTGEN_H)
148 #define CY_EVTGEN_H
149 
150 #include <stdint.h>
151 #include <stdbool.h>
152 #include <stddef.h>
153 #include "cy_syslib.h"
154 #include "cy_utils.h"
155 #include "cy_device_headers.h"
156 
157 #ifdef CY_IP_MXEVTGEN
158 
159 #if defined(__cplusplus)
160 extern "C" {
161 #endif
162 
163 /***************************************
164 * Macro definitions
165 ***************************************/
166 /**
167 * \addtogroup group_evtgen_macros
168 * \{
169 */
170 
171 /** Driver major version */
172 #define CY_EVTGEN_DRV_VERSION_MAJOR       1
173 
174 /** Driver minor version */
175 #define CY_EVTGEN_DRV_VERSION_MINOR       0
176 
177 /** EVTGEN driver identifier */
178 #define CY_EVTGEN_ID                      (CY_PDL_DRV_ID(0x4AU))
179 
180 /** EVTGEN driver struct number mask */
181 #define CY_EVTGEN_STRUCTNUM_MASK          0xFU
182 
183 /** \cond */
184 /******************************************************************************
185  * Local definitions
186 *******************************************************************************/
187 /* Macros for conditions used by CY_ASSERT calls */
188 #define CY_EVTGEN_IS_STRUCTNUM_VALID(structNum) ((structNum) < EVTGEN_COMP_STRUCT_NR)
189 #define CY_EVTGEN_IS_MASK_VALID(mask) (0UL == ((mask) & ((uint32_t) ~EVTGEN_INTR_COMP0_Msk)))
190 #define CY_EVTGEN_IS_BASE_VALID(base) ((base) != NULL)
191 #define CY_EVTGEN_IS_DIVIDER_VALID_RANGE(divider) ((divider < 255UL) && (divider > 0UL))
192 /** \endcond */
193 
194 /** \} group_evtgen_macros */
195 
196 /**
197 * \addtogroup group_evtgen_enums
198 * \{
199 */
200 
201 /**
202 * Specifies return values meaning
203 */
204 
205 /** This enum has the return values of the Event generator driver */
206 typedef enum
207 {
208     CY_EVTGEN_SUCCESS    = 0UL,
209     CY_EVTGEN_BAD_PARAM,
210 } cy_en_evtgen_status_t;
211 
212 /**
213 * Returns the state of the Active Counter in the function Cy_EvtGen_GetCounterStatus.
214 */
215 typedef enum
216 {
217     CY_EVTGEN_COUNTER_STATUS_INVALID = 0UL,
218     CY_EVTGEN_COUNTER_STATUS_VALID   = 1UL,
219 } cy_en_evtgen_counter_status_t;
220 
221 /**
222 * Ratio Value Dynamic Mode.
223 * Ratio calculation is based on a weighted average operation.
224 * This enum has the setting weight for calculation.
225 *
226 * \note Small weights coefficients respond more quickly to changes in the number of
227 * clk_ref_div cycles per clk_lf cycle than larger weights coefficients. Use the small
228 * dynamic ratio values in the cause low-precision of the low-frequency clock or in
229 * difficult operating conditions (eg high temperature).
230 */
231 typedef enum
232 {
233     CY_EVTGEN_RATIO_DYNAMIC_MODE0    = 0UL,    /**< new RATIO value = (RATIO + measurement + 1) / 2. */
234     CY_EVTGEN_RATIO_DYNAMIC_MODE1    = 1UL,    /**< new RATIO value = (3*RATIO + measurement + 2) / 4. */
235     CY_EVTGEN_RATIO_DYNAMIC_MODE2    = 2UL,    /**< new RATIO value = (7*RATIO + measurement + 4) / 8. */
236     CY_EVTGEN_RATIO_DYNAMIC_MODE3    = 3UL,    /**< new RATIO value = (15*RATIO + measurement + 8) / 16. */
237     CY_EVTGEN_RATIO_DYNAMIC_MODE4    = 4UL,    /**< new RATIO value = (31*RATIO + measurement + 16) / 32. */
238     CY_EVTGEN_RATIO_DYNAMIC_MODE5    = 5UL,    /**< new RATIO value = (63*RATIO + measurement + 32) / 64. */
239     CY_EVTGEN_RATIO_DYNAMIC_MODE6    = 6UL,    /**< new RATIO value = (127*RATIO + measurement + 64) / 128. */
240     CY_EVTGEN_RATIO_DYNAMIC_MODE7    = 7UL,    /**< new RATIO value = (255*RATIO + measurement + 128) / 256. */
241 } cy_en_evtgen_ratio_dynamic_mode_t;
242 
243 /**
244 * Set Ratio Control Mode
245 */
246 typedef enum
247 {
248     CY_EVTGEN_RATIO_CONTROL_SW    = 0UL,    /**< The ratio value is static and calculated during the initialization of the
249                                             Event Generator. */
250     CY_EVTGEN_RATIO_CONTROL_HW    = 1UL,    /**< Autocalibration continuously measures the number of clk_ref_div cycles
251                                              per clk_lf cycle and combines this new measurement with the current
252                                              RATIO value to calculate the new RATIO value. */
253 } cy_en_evtgen_ratio_control_t;
254 
255 /**
256 * Set Trigger Mode
257 */
258 typedef enum
259 {
260     CY_EVTGEN_LEVEL_SENSITIVE    = 0UL,
261     CY_EVTGEN_EDGE_SENSITIVE,
262 } cy_en_evtgen_struct_trigger_t;
263 
264 /**
265 * Set Work Mode of Comparator Structure
266 */
267 typedef enum
268 {
269     CY_EVTGEN_ACTIVE_FUNCTIONALITY    = 0UL,
270     CY_EVTGEN_DEEPSLEEP_FUNCTIONALITY,
271 } cy_en_evtgen_struct_functionality_t;
272 
273 /** \} group_evtgen_enums */
274 
275 /***************************************
276 * Data Structure definitions
277 ***************************************/
278 
279 /**
280 * \addtogroup group_evtgen_data_structures
281 * \{
282 */
283 
284 /**
285 * Configuration structure to set up the entire EVTGEN to be used with \ref Cy_EvtGen_Init.
286 */
287 typedef struct
288 {
289     uint32_t frequencyRef;                                      /**< Set clock source frequency in Active power mode. */
290     uint32_t frequencyLf;                                       /**< Set clock source frequency in DeepSleep power mode. */
291     uint32_t frequencyTick;                                     /**< Set the EVTGEN customized period.  */
292     cy_en_evtgen_ratio_control_t ratioControlMode;              /**< Set the ratio control mode. */
293     cy_en_evtgen_ratio_dynamic_mode_t ratioValueDynamicMode;    /**< Set the specific dynamic mode. Use only during
294                                                                      CY_EVTGEN_RATIO_CONTROL_HW */
295 }cy_stc_evtgen_config_t;
296 
297 typedef void (* cy_evtgen_handler)(void);   /**< Type of ISR callbacks */
298 
299 /**
300 * Configuration structure to set up the comparator structure of the EVTGEN to be used with
301 * \ref Cy_EvtGen_InitStruct.
302 */
303 typedef struct
304 {
305     cy_en_evtgen_struct_functionality_t functionalitySelection;    /**< Functionality comparator structure */
306     cy_en_evtgen_struct_trigger_t triggerOutEdge;                  /**< Condition for start trigger/interrupt */
307     uint32_t valueActiveComparator;                                /**< Value is used for making period of interrupts/triggers */
308     uint32_t valueDeepSleepComparator;                             /**< Value is used for making period of deepsleep_interrupts */
309 }cy_stc_evtgen_struct_config_t;
310 
311 /** \} group_evtgen_data_structures */
312 
313 
314 /***************************************
315 * Function Prototypes
316 ***************************************/
317 
318 /**
319 * \addtogroup group_evtgen_functions
320 * \{
321 */
322 
323 /*******************************************************************************
324 * Function Name: Cy_EvtGen_Enable
325 ****************************************************************************//**
326 *
327 * Enable the Event Generator.
328 *
329 * \param base
330 * Pointer to structure describing registers
331 *
332 * \note
333 * Check the ratio status \ref Cy_EvtGen_GetRatioStatus after enabling the
334 * Event Generator during hardware control ratio. Set a valid value takes to 625
335 * microseconds.
336 *
337 *******************************************************************************/
Cy_EvtGen_Enable(EVTGEN_Type * base)338 __STATIC_INLINE void Cy_EvtGen_Enable(EVTGEN_Type *base)
339 {
340     base->CTL |= EVTGEN_CTL_ENABLED_Msk;
341 }
342 
343 /*******************************************************************************
344 * Function Name: Cy_EvtGen_Disable
345 ****************************************************************************//**
346 *
347 * Disable event generator
348 *
349 * \param base
350 * Pointer to structure describing registers
351 *
352 *******************************************************************************/
Cy_EvtGen_Disable(EVTGEN_Type * base)353 __STATIC_INLINE void Cy_EvtGen_Disable(EVTGEN_Type *base)
354 {
355     base->CTL = 0UL;
356 }
357 
358 
359 /*******************************************************************************
360 * Function Name: Cy_EvtGen_SetStructInterrupt
361 ****************************************************************************//**
362 *
363 * Set interrupt factor of corresponding structure
364 *
365 * \param base
366 * Pointer to structure describing registers
367 *
368 * \param structNumber
369 * Number of structure. The interrupt factor of that is to be set.
370 * Valid range from 0 to 15.
371 *
372 *******************************************************************************/
Cy_EvtGen_SetStructInterrupt(EVTGEN_Type * base,uint8_t structNumber)373 __STATIC_INLINE void Cy_EvtGen_SetStructInterrupt(EVTGEN_Type *base, uint8_t structNumber)
374 {
375     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
376     base->INTR_SET = _VAL2FLD(EVTGEN_INTR_SET_COMP0, 1UL << (structNumber & CY_EVTGEN_STRUCTNUM_MASK));
377 }
378 
379 
380 /*******************************************************************************
381 * Function Name: Cy_EvtGen_ClearInterrupt
382 ****************************************************************************//**
383 *
384 * Clear the interrupt factor
385 *
386 * \param base
387 * Pointer to structure describing registers
388 *
389 * \param mask
390 * Each bit of this parameter corresponds to each structure factor to be clear
391 *
392 *******************************************************************************/
Cy_EvtGen_ClearInterrupt(EVTGEN_Type * base,uint32_t mask)393 __STATIC_INLINE void Cy_EvtGen_ClearInterrupt(EVTGEN_Type *base, uint32_t mask)
394 {
395     CY_ASSERT_L1(CY_EVTGEN_IS_MASK_VALID(mask));
396     CY_SET_REG32(&base->INTR, mask);
397     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
398     (void) base->INTR;
399 }
400 
401 
402 /*******************************************************************************
403 * Function Name: Cy_EvtGen_ClearStructInterrupt
404 ****************************************************************************//**
405 *
406 * Clear interrupt factor of corresponding structure
407 *
408 * \param base
409 * Pointer to structure describing registers
410 *
411 * \param structNumber
412 * Number of structure. The factor of that is to be clear.
413 * Valid range from 0 to 15.
414 *
415 *******************************************************************************/
Cy_EvtGen_ClearStructInterrupt(EVTGEN_Type * base,uint8_t structNumber)416 __STATIC_INLINE void Cy_EvtGen_ClearStructInterrupt(EVTGEN_Type *base, uint8_t structNumber)
417 {
418     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
419     base->INTR = EVTGEN_INTR_COMP0_Msk & (1UL << structNumber);
420     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
421     (void) base->INTR;
422 }
423 
424 
425 /*******************************************************************************
426 * Function Name: Cy_EvtGen_SetStructInterruptMask
427 ****************************************************************************//**
428 *
429 * Set interrupt mask bit of a corresponding structure
430 *
431 * \param base
432 * Pointer to structure describing registers
433 *
434 * \param structNumber
435 * Number of structure. The mask bit of that is to be set.
436 * Valid range from 0 to 15.
437 *
438 *******************************************************************************/
Cy_EvtGen_SetStructInterruptMask(EVTGEN_Type * base,uint8_t structNumber)439 __STATIC_INLINE void Cy_EvtGen_SetStructInterruptMask(EVTGEN_Type *base, uint8_t structNumber)
440 {
441     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
442     base->INTR_MASK |= EVTGEN_INTR_MASK_COMP0_Msk & (1UL << structNumber);
443 }
444 
445 
446 /*******************************************************************************
447 * Function Name: Cy_EvtGen_GetStructInterrupt
448 ****************************************************************************//**
449 *
450 *  Get interrupt bit of corresponding structure
451 *
452 * \param base
453 * Pointer to structure describing registers
454 *
455 * \param structNumber
456 * Number of structure. The interrupt factor of the structure is to be returned.
457 * Valid range from 0 to 15.
458 *
459 * \return
460 * The interrupt bit
461 *
462 *******************************************************************************/
Cy_EvtGen_GetStructInterrupt(EVTGEN_Type * base,uint8_t structNumber)463 __STATIC_INLINE bool Cy_EvtGen_GetStructInterrupt(EVTGEN_Type *base, uint8_t structNumber)
464 {
465     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
466     return _FLD2BOOL(EVTGEN_INTR_COMP0, (base->INTR & (1UL << structNumber)));
467 }
468 
469 
470 /*******************************************************************************
471 * Function Name: Cy_EvtGen_GetStructInterruptMasked
472 ****************************************************************************//**
473 *
474 * Get interrupt masked bit of corresponding structure
475 *
476 * \param base
477 * Pointer to structure describing registers
478 *
479 * \param structNumber
480 * Number of structure. The masked bit of the structure is to be returned.
481 * Valid range from 0 to 15.
482 *
483 * \return
484 * The interrupt masked bit
485 *
486 *******************************************************************************/
Cy_EvtGen_GetStructInterruptMasked(EVTGEN_Type * base,uint8_t structNumber)487 __STATIC_INLINE bool Cy_EvtGen_GetStructInterruptMasked(EVTGEN_Type *base, uint8_t structNumber)
488 {
489     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
490     return _FLD2BOOL(EVTGEN_INTR_MASKED_COMP0, (base->INTR_MASKED & (1UL << structNumber)));
491 }
492 
493 
494 /*******************************************************************************
495 * Function Name: Cy_EvtGen_SetStructInterruptDeepSleep
496 ****************************************************************************//**
497 *
498 * Set deep sleep interrupt factor of corresponding structure
499 *
500 * \param base
501 * Pointer to structure describing registers
502 *
503 * \param structNumber
504 * Number of structure. The interrupt factor of that is to be set.
505 * Valid range from 0 to 15.
506 *
507 *******************************************************************************/
Cy_EvtGen_SetStructInterruptDeepSleep(EVTGEN_Type * base,uint8_t structNumber)508 __STATIC_INLINE void Cy_EvtGen_SetStructInterruptDeepSleep(EVTGEN_Type *base, uint8_t structNumber)
509 {
510     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
511     base->INTR_DPSLP_SET = _VAL2FLD(EVTGEN_INTR_DPSLP_SET_COMP1, 1UL << structNumber);
512 }
513 
514 
515 /*******************************************************************************
516 * Function Name: Cy_EvtGen_ClearInterruptDeepSleep
517 ****************************************************************************//**
518 *
519 * Clear the deep sleep interrupt factor
520 *
521 * \param base
522 * Pointer to structure describing registers
523 *
524 * \param mask
525 * Each bit of this parameter corresponds to each structure factor to be clear.
526 *
527 *******************************************************************************/
Cy_EvtGen_ClearInterruptDeepSleep(EVTGEN_Type * base,uint32_t mask)528 __STATIC_INLINE void Cy_EvtGen_ClearInterruptDeepSleep(EVTGEN_Type *base, uint32_t mask)
529 {
530     CY_ASSERT_L1(CY_EVTGEN_IS_MASK_VALID(mask));
531     base->INTR_DPSLP = _VAL2FLD(EVTGEN_INTR_DPSLP_COMP1, mask);
532     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
533     (void) base->INTR_DPSLP;
534 }
535 
536 
537 /*******************************************************************************
538 * Function Name: Cy_EvtGen_ClearStructInterruptDeepSleep
539 ****************************************************************************//**
540 *
541 * Clear deep sleep interrupt factor of corresponding structure
542 *
543 * \param base
544 * Pointer to structure describing registers
545 *
546 * \param structNumber
547 * Number of structure. The factor of that is to be clear.
548 * Valid range from 0 to 15.
549 *
550 *******************************************************************************/
Cy_EvtGen_ClearStructInterruptDeepSleep(EVTGEN_Type * base,uint8_t structNumber)551 __STATIC_INLINE void Cy_EvtGen_ClearStructInterruptDeepSleep(EVTGEN_Type *base, uint8_t structNumber)
552 {
553     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
554     base->INTR_DPSLP = _VAL2FLD(EVTGEN_INTR_DPSLP_COMP1, (1UL << structNumber));
555     /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
556     (void) base->INTR_DPSLP;
557 }
558 
559 
560 /*******************************************************************************
561 * Function Name: Cy_EvtGen_SetStructInterruptDeepSleepMask
562 ****************************************************************************//**
563 *
564 * Set deep sleep interrupt mask bit of a corresponding structure
565 *
566 * \param base
567 * Pointer to structure describing registers
568 *
569 * \param structNumber
570 * Number of structure. The deep sleep mask bit of that is to be set.
571 * Valid range from 0 to 15.
572 *
573 *******************************************************************************/
Cy_EvtGen_SetStructInterruptDeepSleepMask(EVTGEN_Type * base,uint8_t structNumber)574 __STATIC_INLINE void Cy_EvtGen_SetStructInterruptDeepSleepMask(EVTGEN_Type *base, uint8_t structNumber)
575 {
576     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
577     base->INTR_DPSLP_MASK |= EVTGEN_INTR_DPSLP_MASK_COMP1_Msk & (1UL << structNumber);
578 }
579 
580 
581 /*******************************************************************************
582 * Function Name: Cy_EvtGen_GetStructInterruptDeepSleep
583 ****************************************************************************//**
584 *
585 * Get deep sleep interrupt bit of corresponding structure.
586 *
587 * \param base
588 * Pointer to structure describing registers.
589 *
590 * \param structNumber
591 * Number of structure. The deep sleep interrupt factor of the structure is to be returned.
592 * Valid range from 0 to 15.
593 *
594 * \return
595 * Returns the interrupt bit.
596 *
597 *******************************************************************************/
Cy_EvtGen_GetStructInterruptDeepSleep(EVTGEN_Type * base,uint8_t structNumber)598 __STATIC_INLINE bool Cy_EvtGen_GetStructInterruptDeepSleep(EVTGEN_Type *base, uint8_t structNumber)
599 {
600     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
601     return _FLD2BOOL(EVTGEN_INTR_DPSLP_COMP1, (base->INTR_DPSLP & (1UL << structNumber)));
602 }
603 
604 
605 /*******************************************************************************
606 * Function Name: Cy_EvtGen_GetStructInterruptDeepSleepMasked
607 ****************************************************************************//**
608 *
609 * Get deep sleep interrupt masked bit of corresponding structure.
610 *
611 * \param base
612 * Pointer to structure describing registers.
613 *
614 * \param structNumber
615 * Number of structure. The deep sleep masked bit of the structure is to be returned.
616 * Valid range from 0 to 15.
617 *
618 * \return
619 * Returns the interrupt masked bit.
620 *
621 *******************************************************************************/
Cy_EvtGen_GetStructInterruptDeepSleepMasked(EVTGEN_Type * base,uint8_t structNumber)622 __STATIC_INLINE bool Cy_EvtGen_GetStructInterruptDeepSleepMasked(EVTGEN_Type *base, uint8_t structNumber)
623 {
624     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNumber));
625     return _FLD2BOOL(EVTGEN_INTR_DPSLP_MASKED_COMP1, (base->INTR_DPSLP_MASKED & (1UL << structNumber)));
626 }
627 
628 
629 /*******************************************************************************
630 * Function Name: Cy_EvtGen_GetComp0Status
631 ****************************************************************************//**
632 *
633 * Get comparator 0 status.
634 *
635 * \param base
636 * Pointer to structure describing registers.
637 *
638 * \return
639 * Returns comparator 0 Status.
640 *
641 *******************************************************************************/
Cy_EvtGen_GetComp0Status(EVTGEN_Type * base)642 __STATIC_INLINE uint32_t Cy_EvtGen_GetComp0Status(EVTGEN_Type *base)
643 {
644     return (uint32_t) _FLD2VAL(EVTGEN_COMP0_STATUS_COMP0_OUT, base->COMP0_STATUS);
645 }
646 
647 
648 /*******************************************************************************
649 * Function Name: Cy_EvtGen_GetComp1Status
650 ****************************************************************************//**
651 *
652 * Get comparator 1 status.
653 *
654 * \param base
655 * Pointer to structure describing registers.
656 *
657 * \return
658 * Returns comparator 1 Status.
659 *
660 *******************************************************************************/
Cy_EvtGen_GetComp1Status(EVTGEN_Type * base)661 __STATIC_INLINE uint32_t Cy_EvtGen_GetComp1Status(EVTGEN_Type *base)
662 {
663     return (uint32_t) _FLD2VAL(EVTGEN_COMP1_STATUS_COMP1_OUT, base->COMP1_STATUS);
664 }
665 
666 
667 /*******************************************************************************
668 * Function Name: Cy_EvtGen_GetCounterStatus
669 ****************************************************************************//**
670 *
671 * Get active counter status.
672 *
673 * \param base
674 * Pointer to structure describing registers.
675 *
676 * \return
677 * Returns counter status.
678 *
679 * \note
680 * If this status is CY_EVTGEN_COUNTER_STATUS_VALID, the counter completed initialization
681 * and is ready to be read.
682 *
683 *******************************************************************************/
Cy_EvtGen_GetCounterStatus(EVTGEN_Type * base)684 __STATIC_INLINE cy_en_evtgen_counter_status_t Cy_EvtGen_GetCounterStatus(EVTGEN_Type *base)
685 {
686     CY_MISRA_DEVIATE_LINE('MISRA C-2012 Rule 10.8','Intentional typecast to cy_en_evtgen_counter_status_t enum.');
687     return (cy_en_evtgen_counter_status_t)(_FLD2VAL(EVTGEN_COUNTER_STATUS_VALID, base->COUNTER_STATUS));
688 }
689 
690 
691 
692 /*******************************************************************************
693 * Function Name: Cy_EvtGen_GetCounterValue
694 ****************************************************************************//**
695 *
696 * Get counter value.
697 *
698 * \param base
699 * Pointer to structure describing registers.
700 *
701 * \return
702 * Returns counter value.
703 *
704 *******************************************************************************/
Cy_EvtGen_GetCounterValue(EVTGEN_Type * base)705 __STATIC_INLINE uint32_t Cy_EvtGen_GetCounterValue(EVTGEN_Type *base)
706 {
707     return (_FLD2VAL(EVTGEN_COUNTER_INT32, base->COUNTER));
708 }
709 
710 /*******************************************************************************
711 * Function Name: Cy_EvtGen_GetRatioStatus
712 ****************************************************************************//**
713 *
714 * Get status ratio value.
715 *
716 * \param base
717 * Pointer to structure describing registers.
718 *
719 * \return
720 * Returns true if ratio value is valid.
721 *
722 *******************************************************************************/
Cy_EvtGen_GetRatioStatus(EVTGEN_Type * base)723 __STATIC_INLINE bool Cy_EvtGen_GetRatioStatus(EVTGEN_Type *base)
724 {
725     return (((_FLD2VAL(EVTGEN_RATIO_CTL_VALID, base->RATIO_CTL)) != 0UL) ? true : false);
726 }
727 
728 /*******************************************************************************
729 * Function Name: Cy_EvtGen_GetCompActiveEnabledStatus
730 ****************************************************************************//**
731 *
732 * Get status active struct comparator enable.
733 *
734 * \param base
735 * Pointer to structure describing registers.
736 *
737 * \param structNum
738 * Structure number for status active comparator enable. Valid range from 0 to 15.
739 *
740 * \return
741 * Returns true if status active struct comparator enabled.
742 *
743 *******************************************************************************/
Cy_EvtGen_GetCompActiveEnabledStatus(EVTGEN_Type * base,uint8_t structNum)744 __STATIC_INLINE bool Cy_EvtGen_GetCompActiveEnabledStatus(EVTGEN_Type *base, uint8_t structNum)
745 {
746     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNum));
747     return (((_FLD2VAL(EVTGEN_COMP_STRUCT_COMP_CTL_COMP0_EN, base->COMP_STRUCT[structNum].COMP_CTL)) != 0UL) ? true : false);
748 }
749 
750 /*******************************************************************************
751 * Function Name: Cy_EvtGen_GetCompDeepSleepEnabledStatus
752 ****************************************************************************//**
753 *
754 * Get status Deep Sleep struct comparator enable.
755 *
756 * \param base
757 * Pointer to structure describing registers.
758 *
759 * \param structNum
760 * Structure number for status Deep Sleep comparator enable. Valid range from 0 to 15.
761 *
762 * \return
763 * Returns true if status Deep Sleep struct comparator enabled.
764 *
765 *******************************************************************************/
Cy_EvtGen_GetCompDeepSleepEnabledStatus(EVTGEN_Type * base,uint8_t structNum)766 __STATIC_INLINE bool Cy_EvtGen_GetCompDeepSleepEnabledStatus(EVTGEN_Type *base, uint8_t structNum)
767 {
768     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNum));
769     return (((_FLD2VAL(EVTGEN_COMP_STRUCT_COMP_CTL_COMP1_EN, base->COMP_STRUCT[structNum].COMP_CTL)) != 0UL) ? true : false);
770 }
771 
772 /*******************************************************************************
773 * Function Name: Cy_EvtGen_IsCompStructEnabled
774 ****************************************************************************//**
775 *
776 * Get status struct comparator enable.
777 *
778 * \param base
779 * Pointer to structure describing registers.
780 *
781 * \param structNum
782 * Structure number for status comparator enable. Valid range from 0 to 15.
783 *
784 * \return
785 * Returns true if status struct comparator enabled.
786 *
787 *******************************************************************************/
Cy_EvtGen_IsCompStructEnabled(EVTGEN_Type * base,uint8_t structNum)788 __STATIC_INLINE bool Cy_EvtGen_IsCompStructEnabled(EVTGEN_Type *base, uint8_t structNum)
789 {
790     CY_ASSERT_L1(CY_EVTGEN_IS_STRUCTNUM_VALID(structNum));
791     return (((_FLD2VAL(EVTGEN_COMP_STRUCT_COMP_CTL_ENABLED, base->COMP_STRUCT[structNum].COMP_CTL)) != 0UL) ? true : false);
792 }
793 
794 cy_en_evtgen_status_t Cy_EvtGen_Init(EVTGEN_Type *base, const cy_stc_evtgen_config_t* config);
795 void Cy_EvtGen_DeInit(EVTGEN_Type *base);
796 cy_en_evtgen_status_t Cy_EvtGen_InitStruct(EVTGEN_Type *base,
797                                                         uint8_t structNum,
798                                                         const cy_stc_evtgen_struct_config_t* configStruct);
799 void Cy_EvtGen_DeinitStruct(EVTGEN_Type *base, uint8_t structNum);
800 void Cy_EvtGen_UpdateActiveCompValue(EVTGEN_Type *base, uint8_t structNum, uint32_t newCompareValue);
801 void Cy_EvtGen_UpdateDeepSleepCompValue(EVTGEN_Type *base, uint8_t structNum, uint32_t newCompareValue);
802 
803 /** \} group_evtgen_functions */
804 
805 #if defined(__cplusplus)
806 }
807 #endif
808 
809 #endif /* #if !defined(CY_EVTGEN_H) */
810 
811 #endif /* if not defined CY_IP_MXEVTGEN */
812 
813 /** \} group_ctb */
814 
815 /* [] END OF FILE */
816