1 /**
2  * \file
3  *
4  * \brief DMA related functionality declaration.
5  *
6  * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Subject to your compliance with these terms, you may use Microchip
13  * software and any derivatives exclusively with Microchip products.
14  * It is your responsibility to comply with third party license terms applicable
15  * to your use of third party software (including open source software) that
16  * may accompany Microchip software.
17  *
18  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
19  * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
20  * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
21  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
22  * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
23  * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
24  * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
25  * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE FULLEST EXTENT
26  * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
27  * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
28  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
29  *
30  * \asf_license_stop
31  *
32  */
33 
34 #ifndef _HPL_DMA_H_INCLUDED
35 #define _HPL_DMA_H_INCLUDED
36 
37 /**
38  * \addtogroup HPL DMA
39  *
40  * \section hpl_dma_rev Revision History
41  * - v1.0.0 Initial Release
42  *
43  *@{
44  */
45 
46 #include <compiler.h>
47 #include <hpl_irq.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 struct _dma_resource;
54 
55 /**
56  * \brief DMA callback types
57  */
58 enum _dma_callback_type { DMA_TRANSFER_COMPLETE_CB, DMA_TRANSFER_ERROR_CB };
59 
60 /**
61  * \brief DMA interrupt callbacks
62  */
63 struct _dma_callbacks {
64 	void (*transfer_done)(struct _dma_resource *resource);
65 	void (*error)(struct _dma_resource *resource);
66 };
67 
68 /**
69  * \brief DMA resource structure
70  */
71 struct _dma_resource {
72 	struct _dma_callbacks dma_cb;
73 	void *                back;
74 };
75 
76 /**
77  * \brief Initialize DMA
78  *
79  * This function does low level DMA configuration.
80  *
81  * \return initialize status
82  */
83 int32_t _dma_init(void);
84 
85 /**
86  * \brief Set destination address
87  *
88  * \param[in] channel DMA channel to set destination address for
89  * \param[in] dst Destination address
90  *
91  * \return setting status
92  */
93 int32_t _dma_set_destination_address(const uint8_t channel, const void *const dst);
94 
95 /**
96  * \brief Set source address
97  *
98  * \param[in] channel DMA channel to set source address for
99  * \param[in] src Source address
100  *
101  * \return setting status
102  */
103 int32_t _dma_set_source_address(const uint8_t channel, const void *const src);
104 
105 /**
106  * \brief Set next descriptor address
107  *
108  * \param[in] current_channel Current DMA channel to set next descriptor address
109  * \param[in] next_channel Next DMA channel used as next descriptor
110  *
111  * \return setting status
112  */
113 int32_t _dma_set_next_descriptor(const uint8_t current_channel, const uint8_t next_channel);
114 
115 /**
116  * \brief Enable/disable source address incrementation during DMA transaction
117  *
118  * \param[in] channel DMA channel to set source address for
119  * \param[in] enable True to enable, false to disable
120  *
121  * \return status of operation
122  */
123 int32_t _dma_srcinc_enable(const uint8_t channel, const bool enable);
124 
125 /**
126  * \brief Enable/disable Destination address incrementation during DMA transaction
127  *
128  * \param[in] channel DMA channel to set destination address for
129  * \param[in] enable True to enable, false to disable
130  *
131  * \return status of operation
132  */
133 int32_t _dma_dstinc_enable(const uint8_t channel, const bool enable);
134 /**
135  * \brief Set the amount of data to be transfered per transaction
136  *
137  * \param[in] channel DMA channel to set data amount for
138  * \param[in] amount Data amount
139  *
140  * \return status of operation
141  */
142 int32_t _dma_set_data_amount(const uint8_t channel, const uint32_t amount);
143 
144 /**
145  * \brief Trigger DMA transaction on the given channel
146  *
147  * \param[in] channel DMA channel to trigger transaction on
148  *
149  * \return status of operation
150  */
151 int32_t _dma_enable_transaction(const uint8_t channel, const bool software_trigger);
152 
153 /**
154  * \brief Retrieves DMA resource structure
155  *
156  * \param[out] resource The resource to be retrieved
157  * \param[in] channel DMA channel to retrieve structure for
158  *
159  * \return status of operation
160  */
161 int32_t _dma_get_channel_resource(struct _dma_resource **resource, const uint8_t channel);
162 
163 /**
164  * \brief Enable/disable DMA interrupt
165  *
166  * \param[in] channel DMA channel to enable/disable interrupt for
167  * \param[in] type The type of interrupt to disable/enable if applicable
168  * \param[in] state Enable or disable
169  */
170 void _dma_set_irq_state(const uint8_t channel, const enum _dma_callback_type type, const bool state);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* HPL_DMA_H_INCLUDED */
177