1 /***************************************************************************//**
2 * \file cy_ctdac.h
3 * \version 2.0.2
4 *
5 * Header file for the CTDAC 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_ctdac
27 * \{
28 * The CTDAC driver provides APIs to configure the 12-bit Continuous-Time DAC.
29 *
30 * The functions and other declarations used in this driver are in cy_ctdac.h.
31 * You can include cy_pdl.h to get access to all functions
32 * and declarations in the PDL.
33 *
34 * - 12-bit continuous time output
35 * - 2 us settling time for a 25 pF load when output buffered through Opamp0 of \ref group_ctb "CTB"
36 * - Can be enabled in Deep Sleep power mode
37 * - Selectable voltage reference:
38 * - VDDA
39 * - Internal analog reference buffered through Opamp1 of \ref group_ctb "CTB"
40 * - External reference buffered through Opamp1 of \ref group_ctb "CTB"
41 * - Selectable output paths:
42 * - Direct DAC output to a pin
43 * - Buffered DAC output through Opamp0 of \ref group_ctb "CTB"
44 * - Sample and hold output path through Opamp0 of \ref group_ctb "CTB"
45 * - Selectable input modes:
46 * - Unsigned 12-bit mode
47 * - Virtual signed 12-bit mode
48 * - Configurable update rate using clock or strobe signal
49 * - Double buffered DAC voltage control register
50 * - Interrupt and DMA trigger on DAC buffer empty
51 * - Configurable as PGA along with Opamp1 of the \ref group_ctb "CTB"
52 *
53 * The CTDAC generates a 12-bit DAC output voltage from the reference.
54 * The DAC reference can come from VDDA or from any signal buffered through Opamp0
55 * of the CTB. This can be an external signal through a GPIO or from the internal
56 * AREF. The CTDAC is closely integrated with the CTB block,
57 * which provides easy buffering of the DAC output voltage,
58 * buffered input reference voltage, and sample and hold for the DAC output.
59 * The CTDAC control interface provides control of the DAC output through CPU or DMA.
60 * This includes a double-buffered DAC voltage control register, clock input for programmable
61 * update rate, interrupt on DAC buffer empty, and trigger to DMA.
62 *
63 * \image html ctdac_block_diagram.png
64 * \image latex ctdac_block_diagram.png
65 *
66 * The CTDAC has two switches, CO6 for configuring the output path and
67 * CVD for the reference source.
68 *
69 * \image html ctdac_switches.png
70 * \image latex ctdac_switches.png
71 *
72 * \section group_ctdac_init Initialization
73 *
74 * Configure the CTDAC hardware block by calling \ref Cy_CTDAC_Init.
75 * The base address of the CTDAC hardware can be found in the device-specific header file.
76 * If the buffers in the CTB are used for the reference source or the output,
77 * initialize the CTB hardware block. After both blocks are initialized,
78 * enable the CTB block before enabling the CTDAC block.
79 *
80 * The driver also provides a \ref Cy_CTDAC_FastInit function for fast and easy initialization of the CTDAC.
81 * The driver has pre-defined configuration structures for the four combinations of the reference and output buffers.
82 *
83 * - \ref Cy_CTDAC_Fast_VddaRef_UnbufferedOut
84 * - \ref Cy_CTDAC_Fast_VddaRef_BufferedOut
85 * - \ref Cy_CTDAC_Fast_OA1Ref_UnbufferedOut
86 * - \ref Cy_CTDAC_Fast_OA1Ref_BufferedOut
87 *
88 * After initialization, call \ref Cy_CTDAC_Enable to enable the hardware.
89 *
90 * \section group_ctdac_updatemode Update Modes
91 * The CTDAC contains two registers:
92 * -# CTDAC_VAL
93 *
94 * For direct firmware writes to update the current DAC value immediately.
95 * This register is written with \ref Cy_CTDAC_SetValue.
96 * -# CTDAC_VAL_NXT
97 *
98 * For buffered writes to update the DAC value at a
99 * periodic rate or with a strobe trigger input.
100 * This register is written with \ref Cy_CTDAC_SetValueBuffered.
101 *
102 * The update mode is
103 * selected during initialization with the \ref cy_stc_ctdac_config_t.updateMode.
104 * Four of these modes require a dedicated clock resource and the driver
105 * can configure the clock during initialization (see \ref cy_stc_ctdac_config_t).
106 *
107 * Three of these modes use a strobe signal through the digital signal interface (DSI).
108 * This allows control of the buffered update timing from an external source, for example, by another
109 * chip peripheral or from an off-chip source.
110 *
111 * \subsection group_ctdac_updatemode_direct_write Direct write
112 *
113 * In this mode, the user writes directly into the CTDAC_VAL register
114 * using \ref Cy_CTDAC_SetValue. The action of writing to this register
115 * will update the DAC output. This mode does not generate an interrupt
116 * or trigger signal.
117 * In this mode, a clock must not be configured. Additionally, calling \ref
118 * Cy_CTDAC_SetValueBuffered does not update the DAC output.
119 *
120 * \image html ctdac_update_mode_direct_write.png
121 * \image latex ctdac_update_mode_direct_write.png
122 *
123 * \subsection group_ctdac_updatemode_buffered_write Buffered write
124 *
125 * In this mode, the user writes to the CTDAC_VAL_NXT register using
126 * \ref Cy_CTDAC_SetValueBuffered. The rising edge of the clock
127 * will update the DAC output and generate the interrupt and trigger signals.
128 *
129 * Whenever data is transferred from the CTDAC_VAL_NXT register,
130 * an interrupt is asserted the same time as the trigger. But while
131 * the trigger is automatically cleared after two PeriClk cycles, the
132 * user must clear the interrupt with \ref Cy_CTDAC_ClearInterrupt.
133 *
134 * \image html ctdac_update_mode_buffered_write.png
135 * \image latex ctdac_update_mode_buffered_write.png
136 *
137 * \subsection group_ctdac_updatemode_strobe_edge_sync Strobe edge sync
138 *
139 * In this mode, the user writes to the CTDAC_VAL_NXT register using
140 * \ref Cy_CTDAC_SetValueBuffered.
141 * Each rising edge of the DSI strobe input enables
142 * one subsequent update from the next rising edge of the clock. The DSI
143 * input must remain high for two PeriClk cycles and go low for
144 * another two PeriClk cycles to allow for the next update.
145 * This restricts the DSI strobe input frequency to the PeriClk frequency divided by four.
146 *
147 * \image html ctdac_update_mode_strobe_edge_sync.png
148 * \image latex ctdac_update_mode_strobe_edge_sync.png
149 *
150 * \subsection group_ctdac_updatemode_strobe_edge_immediate Strobe edge immediate
151 *
152 * In this mode, the user writes to the CTDAC_VAL_NXT register using
153 * \ref Cy_CTDAC_SetValueBuffered.
154 * The clock resource is used but set to a logic high.
155 * Therefore, each rising edge of the DSI strobe input immediately
156 * updates the DAC output.
157 *
158 * \image html ctdac_update_mode_strobe_edge_immediate.png
159 * \image latex ctdac_update_mode_strobe_edge_immediate.png
160 *
161 * \subsection group_ctdac_updatemode_strobe_level Strobe level
162 *
163 * In this mode, the user writes to the CTDAC_VAL_NXT register using
164 * \ref Cy_CTDAC_SetValueBuffered.
165 * The DSI strobe input acts as a hardware enable signal.
166 * While the DSI strobe input is high, the mode behaves
167 * like the Buffered write mode. When the DSI strobe input is low,
168 * updates are disabled.
169 *
170 * \image html ctdac_update_mode_strobe_level.png
171 * \image latex ctdac_update_mode_strobe_level.png
172 *
173 * \section group_ctdac_dacmode DAC Modes
174 *
175 * The format of code stored in the CTDAC_VAL register can either be unsigned
176 * or signed two's complemented.
177 * Only the first 12 bits of the register are used by the DAC so there is
178 * no need for sign extension. With the signed format, the DAC decodes
179 * the code in the register by adding 0x800.
180 * The DAC can output the register value or the register value plus 1 (see \ref Cy_CTDAC_SetOutputMode).
181 *
182 * <table class="doxtable">
183 * <tr>
184 * <th>12-bit unsigned code</th>
185 * <th>12-bit two's complement signed code</th>
186 * <th>Vout (for \ref CY_CTDAC_OUTPUT_VALUE )</th>
187 * <th>Vout (for \ref CY_CTDAC_OUTPUT_VALUE_PLUS1 )</th>
188 * </tr>
189 * <tr>
190 * <td>0x000</td>
191 * <td>0x800</td>
192 * <td>0</td>
193 * <td>Vref/4096</td>
194 * </tr>
195 * <tr>
196 * <td>0x800</td>
197 * <td>0x000</td>
198 * <td>0.5 * Vref</td>
199 * <td>Vref * 2049 / 4096</td>
200 * </tr>
201 * <tr>
202 * <td>0xFFF</td>
203 * <td>0x7FF</td>
204 * <td>Vref * 4095 / 4096</td>
205 * <td>Vref</td>
206 * </tr>
207 * </table>
208 *
209 * The expressions in the above table are based on an unbuffered DAC output.
210 * When the output is buffered, the input and output range of the buffer will affect the
211 * output voltage. See \ref group_ctb_opamp_range in the CTB driver for more information.
212 *
213 * \section group_ctdac_trigger Interrupts and Trigger
214 *
215 * When data from the CTDAC_VAL_NXT is transferred to the CTDAC_VAL register,
216 * an interrupt and trigger output are generated. The trigger output can be
217 * used with a DMA block to update the CTDAC value register at high speeds without any CPU intervention.
218 * Alternatively, the interrupt output can be used when DMA is not available
219 * to update the CTDAC value register, but at a slower speed.
220 *
221 * Recall with the \ref group_ctdac_updatemode, the interrupt and trigger output are available in all modes except
222 * \ref group_ctdac_updatemode_direct_write.
223 *
224 * \subsection group_ctdac_dma_trigger DMA Trigger
225 *
226 * The CTDAC trigger output signal can be routed to a DMA block using the \ref group_trigmux
227 * to trigger an update to the CTDAC_VAL_NXT register.
228 * When making the required \ref Cy_TrigMux_Connect calls, use the pre-defined enums, TRIG14_IN_PASS_TR_CTDAC_EMPTY
229 * and TRIGGER_TYPE_PASS_TR_CTDAC_EMPTY.
230 *
231 * \subsection group_ctdac_handling_interrupts Handling Interrupts
232 *
233 * The following code snippet demonstrates how to implement a routine to handle the interrupt.
234 * The routine gets called when any CTDAC on the device generates an interrupt.
235 *
236 * \snippet ctdac/snippet/main.c SNIPPET_CTDAC_ISR
237 *
238 * The following code snippet demonstrates how to configure and enable the interrupt.
239 *
240 * \snippet ctdac/snippet/main.c SNIPPET_CTDAC_INTR_SETUP
241 *
242 * \snippet ctdac/snippet/main.c CTDAC_SNIPPET_DMA_TRIGGER
243 *
244 * \section group_ctdac_deglitch Deglitch
245 *
246 * The hardware has the ability to deglitch the output value every time it is updated.
247 * This prevents small glitches in the DAC output during an update to propagate to
248 * the pin or opamp input. When deglitch is enabled, a switch on the output path
249 * is forced open for a configurable number of PeriClk cycles. This deglitch time
250 * is calculated as:
251 *
252 * (DEGLITCH_CNT + 1) / PERI_CLOCK_FREQ
253 *
254 * The optimal and recommended deglitch time is 700 ns. Call \ref Cy_CTDAC_SetDeglitchCycles to set DEGLITCH_CNT.
255 *
256 * There are two switches used for deglitching.
257 * - Switch COS in the CTB between the DAC output and the Opamp0 input
258 * - Switch CO6 in the CTDAC between the DAC output and external pin
259 *
260 * Call \ref Cy_CTDAC_SetDeglitchMode to set the deglitch path. Match this with the output buffer selection.
261 * If the output is buffered through the CTB, select \ref CY_CTDAC_DEGLITCHMODE_BUFFERED.
262 * If the output is unbuffered to a direct pin, select \ref CY_CTDAC_DEGLITCHMODE_UNBUFFERED.
263 *
264 * \note
265 * If deglitching is enabled, the hardware does not force the deglitch switches into a closed
266 * state during Deep Sleep mode. Therefore, there is a chance that the device enters
267 * Deep Sleep mode while the hardware is deglitching and the switches on the output path remain open.
268 * To ensure the DAC will operate properly in Deep Sleep when enabled, make sure to
269 * register the \ref Cy_CTDAC_DeepSleepCallback before entering Deep Sleep mode.
270 *
271 * \section group_ctdac_sample_hold Sample and Hold
272 *
273 * When buffering the DAC output, the CTB has a Sample and Hold (SH) feature that can be used for saving power.
274 * The DAC output voltage is retained on an internal capacitor for a duration of time while the
275 * DAC output can be turned off. The DAC hardware needs to be turned on in a periodic fashion
276 * to recharge the hold capacitor. This feature is firmware controlled using a sequence of function calls.
277 * See \ref Cy_CTB_DACSampleAndHold in the \ref group_ctb_sample_hold "CTB" driver.
278 *
279 * The hold time depends on the supply and reference voltages. The following hold times are based on the
280 * time it takes for the buffered output to change by 1 LSB.
281 *
282 * - Hold time = 750 us @ Vref = VDDA , VDDA = 1.7 V
283 * - Hold time = 525 us @ Vref = VDDA , VDDA = 3.6 V
284 * - Hold time = 200 us @ Vref = 1.2 V, VDDA = 3.6 V
285 *
286 * \section group_ctdac_low_power Low Power Support
287 *
288 * The CTDAC driver provides a callback function to handle power mode transitions.
289 * If the CTDAC is configured for Deep Sleep operation and \ref group_ctdac_deglitch "deglitching" is enabled,
290 * the callback \ref Cy_CTDAC_DeepSleepCallback must be registered before calling
291 * \ref Cy_SysPm_CpuEnterDeepSleep.
292 * Refer to \ref group_syspm driver for more information about power mode transitions and
293 * callback registration.
294 *
295 * \section group_ctdac_more_information More Information
296 *
297 * Refer to the technical reference manual (TRM) and the device datasheet.
298 *
299 * \section group_ctdac_changelog Changelog
300 * <table class="doxtable">
301 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
302 * <tr>
303 * <td>2.0.2</td>
304 * <td>Minor documentation updates.</td>
305 * <td>Documented MISRA 2012 violations. Updated Cy_CTDAC_ConfigureClock()
306 * function parameters description. </td>
307 * </tr>
308 * <tr>
309 * <td>2.0.1</td>
310 * <td>Minor documentation updates.</td>
311 * <td>Documentation enhancement.</td>
312 * </tr>
313 * <tr>
314 * <td rowspan="2">2.0</td>
315 * <td>Flattened the organization of the driver source code into the single
316 * source directory and the single include directory.
317 * </td>
318 * <td>Driver library directory-structure simplification.</td>
319 * </tr>
320 * <tr>
321 * <td>Added register access layer. Use register access macros instead
322 * of direct register access using dereferenced pointers.</td>
323 * <td>Makes register access device-independent, so that the PDL does
324 * not need to be recompiled for each supported part number.</td>
325 * </tr>
326 * <tr>
327 * <td>1.0.1</td>
328 * <td>Added low power support section. Minor documentation edits.</td>
329 * <td>Documentation update and clarification</td>
330 * </tr>
331 * <tr>
332 * <td>1.0</td>
333 * <td>Initial version</td>
334 * <td></td>
335 * </tr>
336 * </table>
337 *
338 * \defgroup group_ctdac_macros Macros
339 * \defgroup group_ctdac_functions Functions
340 * \{
341 * \defgroup group_ctdac_functions_init Initialization Functions
342 * \defgroup group_ctdac_functions_basic Basic Configuration Functions
343 * \defgroup group_ctdac_functions_switches Switch Control Functions
344 * \defgroup group_ctdac_functions_interrupts Interrupt Functions
345 * \defgroup group_ctdac_functions_syspm_callback Low Power Callback
346 * \}
347 * \defgroup group_ctdac_globals Global Variables
348 * \defgroup group_ctdac_data_structures Data Structures
349 * \defgroup group_ctdac_enums Enumerated Types
350 */
351
352 #if !defined(CY_CTDAC_H)
353 #define CY_CTDAC_H
354
355 #include "cy_device.h"
356 #ifdef CY_IP_MXS40PASS_CTDAC
357
358 #include <stdint.h>
359 #include <stdbool.h>
360 #include <stddef.h>
361 #include "cy_syspm.h"
362 #include "cy_syslib.h"
363 #include "cy_sysclk.h"
364
365 #if defined(__cplusplus)
366 extern "C" {
367 #endif
368
369 CY_MISRA_DEVIATE_BLOCK_START('MISRA C-2012 Rule 11.3', 13, \
370 'CTDAC_Type will typecast to either CTDAC_V1_Type or CTDAC_V2_Type but not both on PDL initialization based on the target device at compile time.')
371
372 /** \addtogroup group_ctdac_macros
373 * \{
374 */
375
376 /** Driver major version */
377 #define CY_CTDAC_DRV_VERSION_MAJOR 2
378
379 /** Driver minor version */
380 #define CY_CTDAC_DRV_VERSION_MINOR 0
381
382 /** CTDAC driver identifier */
383 #define CY_CTDAC_ID CY_PDL_DRV_ID(0x19u)
384
385 #define CY_CTDAC_DEINIT (0uL) /**< De-init value for CTDAC registers */
386 #define CY_CTDAC_UNSIGNED_MID_CODE_VALUE (0x800uL) /**< Middle code value for unsigned values */
387 #define CY_CTDAC_UNSIGNED_MAX_CODE_VALUE (0xFFFuL) /**< Maximum code value for unsigned values */
388 #define CY_CTDAC_FAST_CLKCFG_TYPE CY_SYSCLK_DIV_8_BIT /**< Clock divider type for quick clock setup */
389 #define CY_CTDAC_FAST_CLKCFG_NUM (0uL) /**< Clock divider number for quick clock setup */
390 #define CY_CTDAC_FAST_CLKCFG_DIV (99uL) /**< Clock divider integer value for quick clock setup. Divides PERI clock by 100. */
391
392 /** \cond INTERNAL */
393 #define CY_CTDAC_DEINT_CTDAC_SW (CTDAC_CTDAC_SW_CLEAR_CTDD_CVD_Msk | CTDAC_CTDAC_SW_CLEAR_CTDO_CO6_Msk) /**< Mask for de-initializing the CTDAC switch control register */
394 #define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV (0uL) /**< Clock divider value for the Strobe Edge Immediate update mode */
395 #define CY_CTDAC_STROBE_EDGE_IMMEDIATE_DIV_FRAC (0uL) /**< Clock fractional divider value for the Strobe Edge Immediate update mode */
396 #define CY_CTDAC_DEGLITCH_CYCLES_MAX (63uL)
397
398 /**< Macros for conditions used by CY_ASSERT calls */
399 #define CY_CTDAC_REFSOURCE(source) (((source) == CY_CTDAC_REFSOURCE_EXTERNAL) || ((source) == CY_CTDAC_REFSOURCE_VDDA))
400 #define CY_CTDAC_FORMAT(mode) (((mode) == CY_CTDAC_FORMAT_UNSIGNED) || ((mode) == CY_CTDAC_FORMAT_SIGNED))
401 #define CY_CTDAC_UPDATE(mode) ((mode) <= CY_CTDAC_UPDATE_STROBE_LEVEL)
402 #define CY_CTDAC_DEGLITCH(mode) (((mode) == CY_CTDAC_DEGLITCHMODE_NONE) \
403 || ((mode) == CY_CTDAC_DEGLITCHMODE_UNBUFFERED) \
404 || ((mode) == CY_CTDAC_DEGLITCHMODE_BUFFERED) \
405 || ((mode) == CY_CTDAC_DEGLITCHMODE_BOTH))
406 #define CY_CTDAC_OUTPUTMODE(mode) (((mode) == CY_CTDAC_OUTPUT_HIGHZ) \
407 || ((mode) == CY_CTDAC_OUTPUT_VALUE) \
408 || ((mode) == CY_CTDAC_OUTPUT_VALUE_PLUS1) \
409 || ((mode) == CY_CTDAC_OUTPUT_VSSA) \
410 || ((mode) == CY_CTDAC_OUTPUT_VREF))
411 #define CY_CTDAC_OUTPUTBUFFER(buffer) (((buffer) == CY_CTDAC_OUTPUT_UNBUFFERED) || ((buffer) == CY_CTDAC_OUTPUT_BUFFERED))
412 #define CY_CTDAC_DEEPSLEEP(deepSleep) (((deepSleep) == CY_CTDAC_DEEPSLEEP_DISABLE) || ((deepSleep) == CY_CTDAC_DEEPSLEEP_ENABLE))
413 #define CY_CTDAC_DEGLITCHCYCLES(cycles) ((cycles) <= CY_CTDAC_DEGLITCH_CYCLES_MAX)
414 #define CY_CTDAC_SWITCHMASK(mask) ((mask) <= (uint32_t) (CY_CTDAC_SWITCH_CVD_MASK | CY_CTDAC_SWITCH_CO6_MASK))
415 #define CY_CTDAC_SWITCHSTATE(state) (((state) == CY_CTDAC_SWITCH_OPEN) || ((state) == CY_CTDAC_SWITCH_CLOSE))
416 #define CY_CTDAC_INTRMASK(mask) (((mask) == 0uL) || ((mask) == 1uL))
417 /** \endcond */
418
419 /** \} group_ctdac_macros */
420
421 /***************************************
422 * Enumerated Types
423 ***************************************/
424
425 /**
426 * \addtogroup group_ctdac_enums
427 * \{
428 */
429
430 /**
431 * Configure the mode for how the DAC value is updated.
432 * All the modes require a CTDAC clock except for \ref group_ctdac_updatemode_direct_write.
433 */
434 typedef enum {
435 CY_CTDAC_UPDATE_DIRECT_WRITE = 0uL, /**< DAC value is updated with a direct write by calling to \ref Cy_CTDAC_SetValue */
436 CY_CTDAC_UPDATE_BUFFERED_WRITE = 1uL, /**< DAC value stored with \ref Cy_CTDAC_SetValueBuffered is updated on the next CTDAC clock edge */
437 CY_CTDAC_UPDATE_STROBE_EDGE_SYNC = 2uL, /**< DAC value stored with \ref Cy_CTDAC_SetValueBuffered is updated on the next CTDAC clock edge after a rising edge of the strobe */
438 CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE = 3uL, /**< DAC value stored with \ref Cy_CTDAC_SetValueBuffered is updated on the rising edge of the strobe input */
439 CY_CTDAC_UPDATE_STROBE_LEVEL = 4uL /**< DAC value stored with \ref Cy_CTDAC_SetValueBuffered is updated on every CTDAC clock edge while the strobe line is high */
440 }cy_en_ctdac_update_t;
441
442 /**
443 * Configure the format in which the DAC value register is decoded.
444 */
445 typedef enum {
446 CY_CTDAC_FORMAT_UNSIGNED = 0uL, /**< Unsigned 12-bit DAC. No value decoding */
447 CY_CTDAC_FORMAT_SIGNED = 1uL << CTDAC_CTDAC_CTRL_CTDAC_MODE_Pos /**< Virtual signed. Add 0x800 to the 12-bit DAC value */
448 }cy_en_ctdac_format_t;
449
450 /**
451 * Enable or disable the CTDAC hardware during Deep Sleep.
452 */
453 typedef enum {
454 CY_CTDAC_DEEPSLEEP_DISABLE = 0uL, /**< DAC is disabled during Deep Sleep power mode */
455 CY_CTDAC_DEEPSLEEP_ENABLE = CTDAC_CTDAC_CTRL_DEEPSLEEP_ON_Msk /**< DAC remains enabled during Deep Sleep power mode */
456 }cy_en_ctdac_deep_sleep_t;
457
458 /**
459 * Configure the output state of the CTDAC.
460 */
461 typedef enum {
462 CY_CTDAC_OUTPUT_HIGHZ = 0uL, /**< DAC output is tri-state */
463 CY_CTDAC_OUTPUT_VALUE = CTDAC_CTDAC_CTRL_OUT_EN_Msk, /**< DAC Output is enabled and drives the programmed value */
464 CY_CTDAC_OUTPUT_VALUE_PLUS1 = CTDAC_CTDAC_CTRL_OUT_EN_Msk \
465 | CTDAC_CTDAC_CTRL_CTDAC_RANGE_Msk, /**< DAC Output enabled and drives the programmed value plus 1 */
466 CY_CTDAC_OUTPUT_VSSA = CTDAC_CTDAC_CTRL_DISABLED_MODE_Msk, /**< Output is pulled to Vssa through a 1.1 MOhm (typ) resistor */
467 CY_CTDAC_OUTPUT_VREF = CTDAC_CTDAC_CTRL_DISABLED_MODE_Msk \
468 | CTDAC_CTDAC_CTRL_CTDAC_RANGE_Msk /**< Output is pulled to Vref through a 1.1 MOhm (typ) resistor */
469 }cy_en_ctdac_output_mode_t;
470
471 /**
472 * Configure the deglitch mode. See the \ref group_ctdac_deglitch section for
473 * more information on how deglitching works.
474 */
475 typedef enum {
476 CY_CTDAC_DEGLITCHMODE_NONE = 0uL, /**< Disable deglitch */
477 CY_CTDAC_DEGLITCHMODE_UNBUFFERED = CTDAC_CTDAC_CTRL_DEGLITCH_CO6_Msk, /**< Deglitch through the CO6 switch */
478 CY_CTDAC_DEGLITCHMODE_BUFFERED = CTDAC_CTDAC_CTRL_DEGLITCH_COS_Msk, /**< Deglitch through the CTB COS switch */
479 CY_CTDAC_DEGLITCHMODE_BOTH = CTDAC_CTDAC_CTRL_DEGLITCH_COS_Msk \
480 | CTDAC_CTDAC_CTRL_DEGLITCH_CO6_Msk /**< Deglitch through both CO6 and CTB COS switches */
481 }cy_en_ctdac_deglitch_t;
482
483 /**
484 * Configure the reference source for the CTDAC
485 *
486 * The CVD switch is closed when Vdda is the reference source.
487 */
488 typedef enum {
489 CY_CTDAC_REFSOURCE_EXTERNAL = 0uL, /**< Use an external source from Opamp1 of the CTB as the reference. CVD switch is open. */
490 CY_CTDAC_REFSOURCE_VDDA = 1uL /**< Use Vdda as the reference. CVD switch is closed. */
491 }cy_en_ctdac_ref_source_t;
492
493 /** Configure the output to be buffered or unbuffered
494 *
495 * The CO6 switch is closed when the output is unbuffered to Pin 6 of the CTDAC port.
496 * See the device datasheet for the CTDAC port.
497 */
498 typedef enum {
499 CY_CTDAC_OUTPUT_BUFFERED = 0uL, /**< Buffer the output through the CTB OA0 */
500 CY_CTDAC_OUTPUT_UNBUFFERED = 1uL /**< Send output to a direct pin */
501 }cy_en_ctdac_output_buffer_t;
502
503 /** Switch state, either open or closed, to be used in \ref Cy_CTDAC_SetAnalogSwitch. */
504 typedef enum
505 {
506 CY_CTDAC_SWITCH_OPEN = 0uL, /**< Open the switch */
507 CY_CTDAC_SWITCH_CLOSE = 1uL /**< Close the switch */
508 }cy_en_ctdac_switch_state_t;
509
510 /** Switch mask to be used in \ref Cy_CTDAC_SetAnalogSwitch */
511 typedef enum
512 {
513 CY_CTDAC_SWITCH_CVD_MASK = CTDAC_CTDAC_SW_CTDD_CVD_Msk, /**< Switch for the reference source, Vdda or external */
514 CY_CTDAC_SWITCH_CO6_MASK = CTDAC_CTDAC_SW_CTDO_CO6_Msk /**< Switch for the output, buffered or direct */
515 }cy_en_ctdac_switches_t;
516
517 /** Return states for \ref Cy_CTDAC_Init, \ref Cy_CTDAC_DeInit, and \ref Cy_CTDAC_FastInit */
518 typedef enum {
519 CY_CTDAC_SUCCESS = 0x00uL, /**< Initialization completed successfully */
520 CY_CTDAC_BAD_PARAM = CY_CTDAC_ID | CY_PDL_STATUS_ERROR | 0x01uL /**< Input pointers were NULL and Initialization could not be completed */
521 }cy_en_ctdac_status_t;
522
523 /** \} group_ctdac_enums */
524
525 /***************************************
526 * Configuration Structures
527 ***************************************/
528
529 /**
530 * \addtogroup group_ctdac_data_structures
531 * \{
532 */
533
534 /** Configuration structure to set up the entire CTDAC block to be used with \ref Cy_CTDAC_Init
535 */
536 typedef struct
537 {
538 cy_en_ctdac_ref_source_t refSource; /**< Reference source: Vdda or externally through Opamp1 of CTB */
539 cy_en_ctdac_format_t formatMode; /**< Format of DAC value: signed or unsigned */
540 cy_en_ctdac_update_t updateMode; /**< Update mode: direct or buffered writes or hardware, edge or level */
541 cy_en_ctdac_deglitch_t deglitchMode; /**< Deglitch mode: disabled, buffered, unbuffered, or both */
542 cy_en_ctdac_output_mode_t outputMode; /**< Output mode: enabled (value or value + 1), high-z, Vssa, or Vdda */
543 cy_en_ctdac_output_buffer_t outputBuffer; /**< Output path: Buffered through Opamp0 of CTB or connected directly to Pin 6 */
544 cy_en_ctdac_deep_sleep_t deepSleep; /**< Enable or disable the CTDAC during Deep Sleep */
545 uint32_t deglitchCycles; /**< Number of deglitch cycles from 0 to 63 */
546 int32_t value; /**< Current DAC value */
547 int32_t nextValue; /**< Next DAC value for double buffering */
548 bool enableInterrupt; /**< If true, enable interrupt when next value register is transferred to value register */
549
550 /* Configuring the clock */
551 bool configClock; /**< Configure or ignore clock information */
552 cy_en_divider_types_t dividerType; /**< Specifies which type of divider to use. Can be integer or fractional divider. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE */
553 uint32_t dividerNum; /**< Specifies which divider of the selected type to configure. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE */
554 uint32_t dividerIntValue; /**< The integer divider value. The divider value causes integer division of (divider value + 1). Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE or \ref CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */
555 uint32_t dividerFracValue; /**< The fractional divider value if using a fractional clock. Not used if updateMode is \ref CY_CTDAC_UPDATE_DIRECT_WRITE or \ref CY_CTDAC_UPDATE_STROBE_EDGE_IMMEDIATE */
556 }cy_stc_ctdac_config_t;
557
558 /** Configuration structure to quickly set up the CTDAC to be used with \ref Cy_CTDAC_FastInit
559 * This structure provides a selection for the CTDAC reference source and output path.
560 *
561 * The other configuration options are set to:
562 * - .formatMode = \ref CY_CTDAC_FORMAT_UNSIGNED
563 * - .updateMode = \ref CY_CTDAC_UPDATE_BUFFERED_WRITE
564 * - .deglitchMode = \ref CY_CTDAC_DEGLITCHMODE_NONE
565 * - .outputMode = \ref CY_CTDAC_OUTPUT_VALUE
566 * - .deepSleep = \ref CY_CTDAC_DEEPSLEEP_DISABLE
567 * - .deglitchCycles = \ref CY_CTDAC_DEINIT
568 * - .value = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE
569 * - .nextValue = \ref CY_CTDAC_UNSIGNED_MID_CODE_VALUE
570 * - .enableInterrupt = true
571 * - .configClock = true
572 * - .dividerType = \ref CY_CTDAC_FAST_CLKCFG_TYPE
573 * - .dividerNum = \ref CY_CTDAC_FAST_CLKCFG_NUM
574 * - .dividerInitValue = \ref CY_CTDAC_FAST_CLKCFG_DIV
575 * - .dividerFracValue = \ref CY_CTDAC_DEINIT
576 */
577 typedef struct
578 {
579 cy_en_ctdac_ref_source_t refSource; /**< Reference source: Vdda or externally through Opamp1 of CTB */
580 cy_en_ctdac_output_buffer_t outputBuffer; /**< Output path: Buffered through Opamp0 of CTB or connected directly to Pin 6 */
581 }cy_stc_ctdac_fast_config_t;
582
583 /** CTDAC context structure.
584 * All fields for the context structure are internal. Firmware never reads or
585 * writes these values. Firmware allocates the structure and provides the
586 * address of the structure when registering the \ref Cy_CTDAC_DeepSleepCallback.
587 * Firmware must ensure that the defined instance of this structure remains in scope
588 * while the drive is in use.
589 */
590 typedef struct
591 {
592 uint32_t deglitchModeBeforeSleep; /**< Tracks the state of the deglitch mode before sleep so that it can be re-enabled after wakeup */
593 }cy_stc_ctdac_context_t;
594
595 /** \} group_ctdac_data_structures */
596
597 /** \addtogroup group_ctdac_globals
598 * \{
599 */
600 /***************************************
601 * Global Variables
602 ***************************************/
603
604 /** Configure CTDAC to use Vdda reference and output unbuffered. See \ref Cy_CTDAC_FastInit. */
605 extern const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_VddaRef_UnbufferedOut;
606
607 /** Configure CTDAC to use Vdda reference and output buffered through Opamp0 of CTB. See \ref Cy_CTDAC_FastInit.
608 *
609 * To quickly configure Opamp0, call with \ref Cy_CTB_FastInit
610 * with \ref Cy_CTB_Fast_Opamp0_Vdac_Out or \ref Cy_CTB_Fast_Opamp0_Vdac_Out_SH.
611 */
612 extern const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_VddaRef_BufferedOut;
613
614 /** Configure CTDAC to use a buffered reference from Opamp1 of CTB
615 * and output unbuffered. See \ref Cy_CTDAC_FastInit.
616 *
617 * To use the reference from the Analog Reference (AREF),
618 * call \ref Cy_CTB_FastInit with \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref.
619 *
620 * To use an external reference from a GPIO,
621 * call \ref Cy_CTB_FastInit with \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5
622 * for Pin 5 on the CTB port.
623 */
624 extern const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_UnbufferedOut;
625
626 /** Configure CTDAC to use a buffered reference from Opamp1 of CTB
627 * and output buffered through Opamp0 of CTB. See \ref Cy_CTDAC_FastInit.
628 *
629 * To quickly configure Opamp0, call with \ref Cy_CTB_FastInit
630 * with \ref Cy_CTB_Fast_Opamp0_Vdac_Out or \ref Cy_CTB_Fast_Opamp0_Vdac_Out_SH.
631 *
632 * To use the reference from the Analog Reference (AREF),
633 * call \ref Cy_CTB_FastInit with \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Aref.
634 *
635 * To use an external reference from a GPIO,
636 * call \ref Cy_CTB_FastInit with \ref Cy_CTB_Fast_Opamp1_Vdac_Ref_Pin5
637 * for Pins 5 on the CTB port.
638 */
639 extern const cy_stc_ctdac_fast_config_t Cy_CTDAC_Fast_OA1Ref_BufferedOut;
640
641 /** \} group_ctdac_globals */
642
643 /***************************************
644 * Function Prototypes
645 ***************************************/
646
647 /**
648 * \addtogroup group_ctdac_functions
649 * \{
650 */
651
652 /**
653 * \addtogroup group_ctdac_functions_init
654 * This set of functions are for initializing, enabling, and disabling the CTDAC.
655 * \{
656 */
657 cy_en_ctdac_status_t Cy_CTDAC_Init(CTDAC_Type *base, const cy_stc_ctdac_config_t *config);
658 cy_en_ctdac_status_t Cy_CTDAC_DeInit(CTDAC_Type *base, bool deInitRouting);
659 cy_en_ctdac_status_t Cy_CTDAC_FastInit(CTDAC_Type *base, const cy_stc_ctdac_fast_config_t *config);
660 __STATIC_INLINE void Cy_CTDAC_Enable(CTDAC_Type *base);
661 __STATIC_INLINE void Cy_CTDAC_Disable(CTDAC_Type *base);
662 /** \} */
663
664 /**
665 * \addtogroup group_ctdac_functions_basic
666 * This set of functions are for configuring basic usage of the CTDAC.
667 * \{
668 */
669 __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value);
670 __STATIC_INLINE void Cy_CTDAC_SetValueBuffered(CTDAC_Type *base, int32_t value);
671 void Cy_CTDAC_SetSignMode(CTDAC_Type *base, cy_en_ctdac_format_t formatMode);
672 void Cy_CTDAC_SetDeepSleepMode(CTDAC_Type *base, cy_en_ctdac_deep_sleep_t deepSleep);
673 void Cy_CTDAC_SetOutputMode(CTDAC_Type *base, cy_en_ctdac_output_mode_t outputMode);
674 void Cy_CTDAC_SetDeglitchMode(CTDAC_Type *base, cy_en_ctdac_deglitch_t deglitchMode);
675 void Cy_CTDAC_SetDeglitchCycles(CTDAC_Type *base, uint32_t deglitchCycles);
676 void Cy_CTDAC_SetRef(CTDAC_Type *base, cy_en_ctdac_ref_source_t refSource);
677 /** \} */
678
679 /** \addtogroup group_ctdac_functions_switches
680 *
681 * This set of functions is for controlling the two CTDAC analog switches, CVD, and CO6.
682 * These are advanced functions. The switches will be managed by the reference
683 * source and output mode selections when initializing the hardware.
684 * \{
685 */
686 void Cy_CTDAC_SetAnalogSwitch(CTDAC_Type *base, uint32_t switchMask, cy_en_ctdac_switch_state_t state);
687 __STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type *base);
688 __STATIC_INLINE void Cy_CTDAC_SetSwitchCO6(CTDAC_Type *base, cy_en_ctdac_switch_state_t state);
689 __STATIC_INLINE void Cy_CTDAC_OpenAllSwitches(CTDAC_Type *base);
690 /** \} */
691
692 /** \addtogroup group_ctdac_functions_interrupts
693 * This set of functions is related to the CTDAC interrupt
694 * \{
695 */
696 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base);
697 __STATIC_INLINE void Cy_CTDAC_ClearInterrupt(CTDAC_Type *base);
698 __STATIC_INLINE void Cy_CTDAC_SetInterrupt(CTDAC_Type *base);
699 __STATIC_INLINE void Cy_CTDAC_SetInterruptMask(CTDAC_Type *base, uint32_t mask);
700 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask(const CTDAC_Type *base);
701 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type *base);
702 /** \} */
703
704 /** \addtogroup group_ctdac_functions_syspm_callback
705 * This driver supports one SysPm callback for Deep Sleep transition.
706 * \{
707 */
708 cy_en_syspm_status_t Cy_CTDAC_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode);
709 /** \} */
710
711 /**
712 * \addtogroup group_ctdac_functions_init
713 * \{
714 */
715 /*******************************************************************************
716 * Function Name: Cy_CTDAC_Enable
717 ****************************************************************************//**
718 *
719 * Power up the CTDAC hardware block.
720 *
721 * \param base
722 * Pointer to structure describing registers
723 *
724 * \return None
725 *
726 *******************************************************************************/
Cy_CTDAC_Enable(CTDAC_Type * base)727 __STATIC_INLINE void Cy_CTDAC_Enable(CTDAC_Type *base)
728 {
729 CTDAC_CTDAC_CTRL(base) |= CTDAC_CTDAC_CTRL_ENABLED_Msk;
730 }
731
732 /*******************************************************************************
733 * Function Name: Cy_CTDAC_Disable
734 ****************************************************************************//**
735 *
736 * Turn off the hardware block.
737 *
738 * \param base
739 * Pointer to structure describing registers
740 *
741 * \return None
742 *
743 *******************************************************************************/
Cy_CTDAC_Disable(CTDAC_Type * base)744 __STATIC_INLINE void Cy_CTDAC_Disable(CTDAC_Type *base)
745 {
746 CTDAC_CTDAC_CTRL(base) &= ~CTDAC_CTDAC_CTRL_ENABLED_Msk;
747 }
748 /** \} */
749
750 /**
751 * \addtogroup group_ctdac_functions_basic
752 * \{
753 */
754 /*******************************************************************************
755 * Function Name: Cy_CTDAC_SetValue
756 ****************************************************************************//**
757 *
758 * Set the CTDAC_VAL register (DAC hardware is
759 * updated on the next PeriClk cycle). Only the least significant 12 bits
760 * have an effect. Sign extension of negative values is unnecessary and is
761 * ignored by the hardware. The way in which the CTDAC interprets the 12-bit
762 * data is controlled by \ref Cy_CTDAC_SetSignMode.
763 *
764 * \note
765 * Call this function only when the update mode is set to \ref group_ctdac_updatemode_direct_write.
766 * Calling this function for any other update mode will not have the intended effect.
767 *
768 * \param base
769 * Pointer to structure describing registers
770 *
771 * \param value
772 * Value to write into the CTDAC_VAL register
773 *
774 * \return None
775 *
776 * \funcusage
777 *
778 * \snippet ctdac/snippet/main.c CTDAC_SNIPPET_SET_VALUE
779 *
780 *******************************************************************************/
Cy_CTDAC_SetValue(CTDAC_Type * base,int32_t value)781 __STATIC_INLINE void Cy_CTDAC_SetValue(CTDAC_Type *base, int32_t value)
782 {
783 CTDAC_CTDAC_VAL(base) = (((uint32_t)value) << CTDAC_CTDAC_VAL_VALUE_Pos) & CTDAC_CTDAC_VAL_VALUE_Msk;
784 }
785
786 /*******************************************************************************
787 * Function Name: Cy_CTDAC_SetValueBuffered
788 ****************************************************************************//**
789 *
790 * Set the CTDAC_VAL_NEXT register. The value is transferred
791 * to the CTDAC_VAL register on the next edge of the CTDAC clock.
792 * Only the least significant 12 bits
793 * have an effect. Sign extension of negative values is unnecessary and is
794 * ignored by the hardware. The way in which the CTDAC interprets the 12-bit
795 * data is controlled by \ref Cy_CTDAC_SetSignMode.
796 *
797 * \note
798 * Calling this function in \ref group_ctdac_updatemode_direct_write mode will not update the DAC output.
799 * Call this function for all modes that use buffered values (i.e. uses a clock).
800 *
801 * \param base
802 * Pointer to structure describing registers
803 *
804 * \param value
805 * Value to write into the CTDAC_VAL_NEXT register
806 *
807 * \return None
808 *
809 * \funcusage
810 *
811 * \snippet ctdac/snippet/main.c CTDAC_SNIPPET_SET_VALUE_BUFFERED
812 *
813 *******************************************************************************/
Cy_CTDAC_SetValueBuffered(CTDAC_Type * base,int32_t value)814 __STATIC_INLINE void Cy_CTDAC_SetValueBuffered(CTDAC_Type *base, int32_t value)
815 {
816 CTDAC_CTDAC_VAL_NXT(base) = (((uint32_t)value) << CTDAC_CTDAC_VAL_NXT_VALUE_Pos) & CTDAC_CTDAC_VAL_NXT_VALUE_Msk;
817 }
818 /** \} */
819
820 /**
821 * \addtogroup group_ctdac_functions_switches
822 * \{
823 */
824 /*******************************************************************************
825 * Function Name: Cy_CTDAC_GetAnalogSwitch
826 ****************************************************************************//**
827 *
828 * Return the state (open or close) of the CTDAC switches.
829 *
830 * \note
831 * The switches will be managed by the reference
832 * source and output mode selections when initializing the hardware.
833 *
834 * \param base
835 * Pointer to structure describing registers
836 *
837 * \return
838 * Switch state. Compare this value to the masks found in \ref cy_en_ctdac_switches_t.
839 *
840 *******************************************************************************/
Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type * base)841 __STATIC_INLINE uint32_t Cy_CTDAC_GetAnalogSwitch(const CTDAC_Type *base)
842 {
843 return CTDAC_CTDAC_SW(base);
844 }
845
846 /*******************************************************************************
847 * Function Name: Cy_CTDAC_SetSwitchCO6
848 ****************************************************************************//**
849 *
850 * Open or close switch CO6 that controls whether the output gets routed
851 * directly to a pin or through Opamp0 of the CTB. This function calls
852 * \ref Cy_CTDAC_SetAnalogSwitch with the switchMask set to \ref CY_CTDAC_SWITCH_CO6_MASK.
853 *
854 * \note
855 * The switches is configured by the output mode selections during initialization.
856 *
857 * \note
858 * This switch will temporarily
859 * be opened for deglitching if the deglitch mode is \ref CY_CTDAC_DEGLITCHMODE_UNBUFFERED or
860 * \ref CY_CTDAC_DEGLITCHMODE_BOTH.
861 *
862 * \param base
863 * Pointer to structure describing registers
864 *
865 * \param state
866 * State of the switch, open or close.
867 *
868 * \return None
869 *
870 * \funcusage
871 *
872 * \snippet ctdac/snippet/main.c CTDAC_SNIPPET_SET_SWITCH_CO6
873 *
874 *******************************************************************************/
Cy_CTDAC_SetSwitchCO6(CTDAC_Type * base,cy_en_ctdac_switch_state_t state)875 __STATIC_INLINE void Cy_CTDAC_SetSwitchCO6(CTDAC_Type *base, cy_en_ctdac_switch_state_t state)
876 {
877 Cy_CTDAC_SetAnalogSwitch(base, (uint32_t) CY_CTDAC_SWITCH_CO6_MASK, state);
878 }
879
880 /*******************************************************************************
881 * Function Name: Cy_CTDAC_OpenAllSwitches
882 ****************************************************************************//**
883 *
884 * Open all switches in the CTDAC (CO6 and CVD).
885 *
886 * \param base
887 * Pointer to structure describing registers
888 *
889 * \return None
890 *
891 * \funcusage
892 *
893 * \snippet ctdac/snippet/main.c CTDAC_SNIPPET_OPEN_ALL_SWITCHES
894 *
895 *******************************************************************************/
Cy_CTDAC_OpenAllSwitches(CTDAC_Type * base)896 __STATIC_INLINE void Cy_CTDAC_OpenAllSwitches(CTDAC_Type *base)
897 {
898 CTDAC_CTDAC_SW_CLEAR(base) = CY_CTDAC_DEINT_CTDAC_SW;
899 }
900
901 /** \} */
902
903 /**
904 * \addtogroup group_ctdac_functions_interrupts
905 * \{
906 */
907 /*******************************************************************************
908 * Function Name: Cy_CTDAC_GetInterruptStatus
909 ****************************************************************************//**
910 *
911 * Return the interrupt status which gets set by the hardware
912 * when the CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register.
913 * Once set, the CTDAC_VAL_NXT register is ready to accept a new value.
914 *
915 * \note
916 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
917 *
918 * \param base
919 * Pointer to structure describing registers
920 *
921 * \return
922 * - 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL
923 * - 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL
924 *
925 * \funcusage
926 *
927 * \snippet ctdac/snippet/main.c SNIPPET_CTDAC_GET_INTERRUPT_STATUS
928 *
929 *******************************************************************************/
Cy_CTDAC_GetInterruptStatus(const CTDAC_Type * base)930 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatus(const CTDAC_Type *base)
931 {
932 return (CTDAC_INTR(base) & CTDAC_INTR_VDAC_EMPTY_Msk) >> CTDAC_INTR_VDAC_EMPTY_Pos;
933 }
934
935 /*******************************************************************************
936 * Function Name: Cy_CTDAC_ClearInterrupt
937 ****************************************************************************//**
938 *
939 * Clear the interrupt that was set by the hardware when the
940 * CTDAC_VAL_NXT register value is transferred to the CTDAC_VAL register.
941 * The interrupt must be cleared with this function so that
942 * the hardware can set subsequent interrupts and those interrupts
943 * can be forwarded to the interrupt controller, if enabled.
944 *
945 * \note
946 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
947 *
948 * \param base
949 * Pointer to structure describing registers
950 *
951 * \return None
952 *
953 *******************************************************************************/
Cy_CTDAC_ClearInterrupt(CTDAC_Type * base)954 __STATIC_INLINE void Cy_CTDAC_ClearInterrupt(CTDAC_Type *base)
955 {
956 CTDAC_INTR(base) = CTDAC_INTR_VDAC_EMPTY_Msk;
957
958 /* This dummy reading is necessary here. It provides a guarantee that interrupt is cleared at returning from this function. */
959 (void) CTDAC_INTR(base);
960 }
961
962 /*******************************************************************************
963 * Function Name: Cy_CTDAC_SetInterrupt
964 ****************************************************************************//**
965 *
966 * Force the CTDAC interrupt to trigger using software.
967 *
968 * \note
969 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
970 *
971 * \param base
972 * Pointer to structure describing registers
973 *
974 * \return None
975 *
976 *******************************************************************************/
Cy_CTDAC_SetInterrupt(CTDAC_Type * base)977 __STATIC_INLINE void Cy_CTDAC_SetInterrupt(CTDAC_Type *base)
978 {
979 CTDAC_INTR_SET(base) = CTDAC_INTR_SET_VDAC_EMPTY_SET_Msk;
980 }
981
982 /*******************************************************************************
983 * Function Name: Cy_CTDAC_SetInterruptMask
984 ****************************************************************************//**
985 *
986 * Configure the CTDAC interrupt to be forwarded to the CPU interrupt
987 * controller.
988 *
989 * \note
990 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
991 *
992 * \param base
993 * Pointer to structure describing registers
994 *
995 * \param mask
996 * The CTDAC only has one interrupt so the mask is one bit.
997 * - 0: Disable CTDAC interrupt request (will not be forwarded to CPU interrupt controller)
998 * - 1: Enable CTDAC interrupt request (will be forwarded to CPU interrupt controller)
999 *
1000 * \return None
1001 *
1002 * \funcusage
1003 *
1004 * \snippet ctdac/snippet/main.c SNIPPET_CTDAC_SET_INTERRUPT_MASK
1005 *
1006 *******************************************************************************/
Cy_CTDAC_SetInterruptMask(CTDAC_Type * base,uint32_t mask)1007 __STATIC_INLINE void Cy_CTDAC_SetInterruptMask(CTDAC_Type *base, uint32_t mask)
1008 {
1009 CY_ASSERT_L2(CY_CTDAC_INTRMASK(mask));
1010
1011 CTDAC_INTR_MASK(base) = mask & CTDAC_INTR_MASK_VDAC_EMPTY_MASK_Msk;
1012 }
1013
1014 /*******************************************************************************
1015 * Function Name: Cy_CTDAC_GetInterruptMask
1016 ****************************************************************************//**
1017 *
1018 * Return whether the CTDAC interrupt is
1019 * forwarded to the CPU interrupt controller
1020 * as configured by \ref Cy_CTDAC_SetInterruptMask.
1021 *
1022 * \note
1023 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
1024 *
1025 * \param base
1026 * Pointer to structure describing registers
1027 *
1028 * \return
1029 * The CTDAC only has one interrupt so the return value is either 0 or 1.
1030 * - 0: Interrupt output not forwarded to CPU interrupt controller
1031 * - 1: Interrupt output forwarded to CPU interrupt controller
1032 *
1033 *******************************************************************************/
Cy_CTDAC_GetInterruptMask(const CTDAC_Type * base)1034 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptMask(const CTDAC_Type *base)
1035 {
1036 return (CTDAC_INTR_MASK(base) & CTDAC_INTR_MASK_VDAC_EMPTY_MASK_Msk) >> CTDAC_INTR_MASK_VDAC_EMPTY_MASK_Pos;
1037 }
1038
1039 /*******************************************************************************
1040 * Function Name: Cy_CTDAC_GetInterruptStatusMasked
1041 ****************************************************************************//**
1042 *
1043 * Return the bitwise AND of \ref Cy_CTDAC_GetInterruptStatus and
1044 * \ref Cy_CTDAC_SetInterruptMask. When high, the DAC interrupt is
1045 * asserted and the interrupt is forwarded to the CPU interrupt
1046 * controller.
1047 *
1048 * \note
1049 * Interrupts are available in all update modes except \ref group_ctdac_updatemode_direct_write.
1050 *
1051 * \param base
1052 * Pointer to structure describing registers
1053 *
1054 * \return
1055 * - 0: Value not moved from CTDAC_VAL_NXT to CTDAC_VAL or not masked
1056 * - 1: Value moved from CTDAC_VAL_NXT to CTDAC_VAL and masked
1057 *
1058 *******************************************************************************/
Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type * base)1059 __STATIC_INLINE uint32_t Cy_CTDAC_GetInterruptStatusMasked(const CTDAC_Type *base){
1060 return (CTDAC_INTR_MASKED(base) & CTDAC_INTR_MASKED_VDAC_EMPTY_MASKED_Msk) >> CTDAC_INTR_MASKED_VDAC_EMPTY_MASKED_Pos;
1061 }
1062
1063 /** \} */
1064
1065 /** \} group_ctdac_functions */
1066 CY_MISRA_BLOCK_END('MISRA C-2012 Rule 11.3')
1067
1068 #if defined(__cplusplus)
1069 }
1070 #endif
1071
1072 #endif /* CY_IP_MXS40PASS_CTDAC */
1073
1074 #endif /** !defined(CY_CTDAC_H) */
1075
1076 /** \} group_ctdac */
1077
1078 /* [] END OF FILE */
1079