1 /**
2  * \file
3  *
4  * \brief DMA related functionality declaration.
5  *
6  * Copyright (C) 2015 Atmel Corporation. All rights reserved.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  *
22  * 3. The name of Atmel may not be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * 4. This software may only be redistributed and used in connection with an
26  *    Atmel microcontroller product.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  * \asf_license_stop
41  *
42  */
43 
44 #ifndef _HPL_DMA_H_INCLUDED
45 #define _HPL_DMA_H_INCLUDED
46 
47 /**
48  * \addtogroup HPL DMA
49  *
50  * \section hpl_dma_rev Revision History
51  * - v1.0.0 Initial Release
52  *
53  *@{
54  */
55 
56 #include <compiler.h>
57 #include <hpl_irq.h>
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
63 struct _dma_resource;
64 
65 /**
66  * \brief DMA callback types
67  */
68 enum _dma_callback_type { DMA_TRANSFER_COMPLETE_CB, DMA_TRANSFER_ERROR_CB };
69 
70 /**
71  * \brief DMA interrupt callbacks
72  */
73 struct _dma_callbacks {
74 	void (*transfer_done)(struct _dma_resource *resource);
75 	void (*error)(struct _dma_resource *resource);
76 };
77 
78 /**
79  * \brief DMA resource structure
80  */
81 struct _dma_resource {
82 	struct _dma_callbacks dma_cb;
83 	void *                back;
84 };
85 
86 /**
87  * \brief Initialize DMA
88  *
89  * This function does low level DMA configuration.
90  *
91  * \return initialize status
92  */
93 int32_t _dma_init(void);
94 
95 /**
96  * \brief Set destination address
97  *
98  * \param[in] channel DMA channel to set destination address for
99  * \param[in] dst Destination address
100  *
101  * \return setting status
102  */
103 int32_t _dma_set_destination_address(const uint8_t channel, const void *const dst);
104 
105 /**
106  * \brief Set source address
107  *
108  * \param[in] channel DMA channel to set source address for
109  * \param[in] src Source address
110  *
111  * \return setting status
112  */
113 int32_t _dma_set_source_address(const uint8_t channel, const void *const src);
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 Set the amount of data to be transfered per transaction
127  *
128  * \param[in] channel DMA channel to set data amount for
129  * \param[in] amount Data amount
130  *
131  * \return status of operation
132  */
133 int32_t _dma_set_data_amount(const uint8_t channel, const uint32_t amount);
134 
135 /**
136  * \brief Trigger DMA transaction on the given channel
137  *
138  * \param[in] channel DMA channel to trigger transaction on
139  *
140  * \return status of operation
141  */
142 int32_t _dma_enable_transaction(const uint8_t channel, const bool software_trigger);
143 
144 /**
145  * \brief Retrieves DMA resource structure
146  *
147  * \param[out] resource The resource to be retrieved
148  * \param[in] channel DMA channel to retrieve structure for
149  *
150  * \return status of operation
151  */
152 int32_t _dma_get_channel_resource(struct _dma_resource **resource, const uint8_t channel);
153 
154 /**
155  * \brief Enable/disable DMA interrupt
156  *
157  * \param[in] channel DMA channel to enable/disable interrupt for
158  * \param[in] type The type of interrupt to disable/enable if applicable
159  * \param[in] state Enable or disable
160  */
161 void _dma_set_irq_state(const uint8_t channel, const enum _dma_callback_type type, const bool state);
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* HPL_DMA_H_INCLUDED */
168