1 /***************************************************************************//**
2 * \file cyhal_dma_dmac.h
3 *
4 * \brief
5 * Defines a high level interface for interacting with the Infineon DMAC.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
10 * an affiliate of Cypress Semiconductor Corporation
11 *
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License");
15 * you may not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 *     http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 *******************************************************************************/
26 
27 #include "cyhal_dma.h"
28 
29 /**
30  * \addtogroup group_hal_impl_dma_dmac DMAC (Direct Memory Access Controller)
31  * \ingroup group_hal_impl_dma
32  * \{
33  * Implementation specific interface for using the DMAC DMA peripheral
34  */
35 
36 #pragma once
37 
38 #if (_CYHAL_DRIVER_AVAILABLE_DMA_DMAC)
39 
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif /* __cplusplus */
43 
44 /** Initialize the DMAC peripheral
45  *
46  * @param[out] obj          The DMA object to initialize
47  * @param[in]  src          An optional, input signal to connect to.
48  * @param[in]  dest         An optional, output target to drive.
49  * @param[in]  priority     The priority of this DMA operation relative to others. Values must be between 0-3 with 0 being the highest priority.
50  * @return The status of the init request
51  */
52 cy_rslt_t _cyhal_dma_dmac_init(cyhal_dma_t *obj, cyhal_source_t *src, cyhal_dest_t *dest, uint8_t priority);
53 
54 /** Initialize the DMAC peripheral using data provided by the configurator.
55  *
56  * @param[out] obj  Pointer to a DMA object. The caller must allocate the memory for this
57  * object but the init function will initialize its contents.
58  * @param[in]  cfg  Configuration structure generated by a configurator.
59  * @return The status of the init request
60  */
61 cy_rslt_t _cyhal_dma_dmac_init_cfg(cyhal_dma_t *obj, const cyhal_dma_configurator_t *cfg);
62 
63 /** Frees the DMAC specific object. This expects that common resources will be freed by caller.
64  *
65  * @param[in,out] obj The DMA object
66  */
67 void _cyhal_dma_dmac_free(cyhal_dma_t *obj);
68 
69 /** Setup a DMAC descriptor for the dma resource
70  *
71  * @param[in] obj    The DMA object
72  * @param[in] cfg    Configuration parameters for the transfer
73  * @return The status of the configure request
74  */
75 cy_rslt_t _cyhal_dma_dmac_configure(cyhal_dma_t *obj, const cyhal_dma_cfg_t *cfg);
76 
77 /** Enable the DMAC transfer so that it can start transfering data when triggered.
78  *
79  * @param[in] obj    The DMA object
80  * @return The status of the enable request
81  */
82 cy_rslt_t _cyhal_dma_dmac_enable(cyhal_dma_t *obj);
83 
84 /** Disable the DMAC transfer so that it does not continue to trigger.
85  *
86  * @param[in] obj    The DMA object
87  * @return The status of the enable request
88  */
89 cy_rslt_t _cyhal_dma_dmac_disable(cyhal_dma_t *obj);
90 
91 /** Start a DMAC transfer
92  *
93  * Initiates DMA channel transfer for specified DMA object
94  * @param[in] obj    The DMA object
95  * @return The status of the start_transfer request
96  */
97 cy_rslt_t _cyhal_dma_dmac_start_transfer(cyhal_dma_t *obj);
98 
99 /** Configure DMAC event enablement.
100  *
101  * @param[in] obj            The DMA object
102  * @param[in] event          The DMA event type
103  * @param[in] intr_priority  The priority for NVIC interrupt events. The priority from the most recent call will take precedence, i.e all events will have the same priority.
104  * @param[in] enable         True to turn on interrupts, False to turn off
105  */
106 void _cyhal_dma_dmac_enable_event(cyhal_dma_t *obj, cyhal_dma_event_t event, uint8_t intr_priority, bool enable);
107 
108 /** Checks whether a transfer is pending or running on the DMA channel
109  *
110  * @param[in] obj    The DMA object
111  * @return True if DMA channel is busy
112  */
113 bool _cyhal_dma_dmac_is_busy(cyhal_dma_t *obj);
114 
115 /** Connects a source signal and enables the specified input to the DMA
116  * channel
117  *
118  * @param[in] obj         The DMA object
119  * @param[in] source      Source signal obtained from another driver's cyhal_<PERIPH>_enable_output
120  * @param[in] input       Which input to enable
121  * @return The status of the connection
122  * */
123 cy_rslt_t _cyhal_dma_dmac_connect_digital(cyhal_dma_t *obj, cyhal_source_t source, cyhal_dma_input_t input);
124 
125 /** Enables the specified output signal from a DMA channel that is triggered when a transfer is completed
126  *
127  * @param[in]  obj         The DMA object
128  * @param[in]  output      Which event triggers the output
129  * @param[out] source      Pointer to user-allocated source signal object which
130  * will be initialized by enable_output. \p source should be passed to
131  * (dis)connect_digital functions to (dis)connect the associated endpoints.
132  * @return The status of the output enable
133  * */
134 cy_rslt_t _cyhal_dma_dmac_enable_output(cyhal_dma_t *obj, cyhal_dma_output_t output, cyhal_source_t *source);
135 
136 /** Disconnects a source signal and disables the specified input to the DMA channel
137  *
138  * @param[in] obj         The DMA object
139  * @param[in] source      Source signal from cyhal_<PERIPH>_enable_output to disable
140  * @param[in] input       Which input to disable
141  * @return The status of the disconnect
142  * */
143 cy_rslt_t _cyhal_dma_dmac_disconnect_digital(cyhal_dma_t *obj, cyhal_source_t source, cyhal_dma_input_t input);
144 
145 /** Disables the specified output signal from a DMA channel
146  *
147  * @param[in]  obj         The DMA object
148  * @param[in]  output      Which output to disable
149  * @return The status of the disablement
150  * */
151 cy_rslt_t _cyhal_dma_dmac_disable_output(cyhal_dma_t *obj, cyhal_dma_output_t output);
152 
153 #if defined(__cplusplus)
154 }
155 #endif /* __cplusplus */
156 
157 #endif /* _CYHAL_DRIVER_AVAILABLE_DMA_DMAC */
158 
159 /** \} group_hal_impl_dma_dmac */
160