2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /******************************************************************************
18 * @brief header file for dmac driver
21 ******************************************************************************/
30 #include <drv_common.h>
32 /// definition for dmac handle.
33 typedef void *dmac_handle_t;
36 \brief DMA Driver Capabilities.
39 uint32_t unalign_addr : 1; ///< support for unalign address transfer when memory is source
43 DMA_STATE_FREE = 0, ///< DMA not yet initialized or disabled
44 DMA_STATE_READY, ///< DMA process success and ready for use, but not start yet
45 DMA_STATE_BUSY, ///< DMA process is ongoing
46 DMA_STATE_ERROR, ///< DMA transfer error
47 DMA_STATE_DONE, ///< DMA transfer done
50 /****** DMA specific error codes *****/
52 EDRV_DMA_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not supported
55 /****** DMA Event *****/
57 DMA_EVENT_TRANSFER_DONE = 0, ///< transfer complete
58 DMA_EVENT_TRANSFER_ERROR = 1, ///< transfer error
75 dma_addr_inc_e src_inc; ///< source address increment
76 dma_addr_inc_e dst_inc; ///< destination address increment
77 uint8_t src_tw; ///< source transfer width in byte
78 uint8_t dst_tw; ///< destination transfer width in byte
79 uint8_t hs_if; ///< a hardware handshaking interface
80 dma_trans_type_e type; ///< transfer type
83 typedef void (*dma_event_cb_t)(dma_event_e event, int32_t ch); ///< Pointer to \ref dma_event_cb_t : CRC Event call back.
86 \brief get dma instance count.
87 \return dma instance count
89 int32_t csi_dma_get_instance_count(void);
92 \brief Initialize DMA Interface. 1. Initializes the resources needed for the DMA interface 2.registers event callback function
93 \param[in] idx must not exceed return value of csi_dma_get_instance_count()
94 \return pointer to dma instances
96 dmac_handle_t csi_dma_initialize(int32_t idx);
99 \brief De-initialize DMA Interface. stops operation and releases the software resources used by the interface
100 \param[in] handle damc handle to operate.
103 int32_t csi_dma_uninitialize(dmac_handle_t handle);
105 \brief Get driver capabilities.
106 \param[in] handle damc handle to operate.
107 \return \ref dma_capabilities_t
109 dma_capabilities_t csi_dma_get_capabilities(dmac_handle_t handle);
112 \brief get one free dma channel
113 \param[in] handle damc handle to operate.
114 \param[in] ch channel num. if -1 then allocate a free channal in this dma
115 \return -1 - no channel can be used, other - channel index
117 int32_t csi_dma_alloc_channel(dmac_handle_t handle, int32_t ch);
120 \brief release dma channel and related resources
121 \param[in] handle damc handle to operate.
122 \param[in] ch channel num.
125 int32_t csi_dma_release_channel(dmac_handle_t handle, int32_t ch);
129 \param[in] handle damc handle to operate.
130 \param[in] ch channel num. if -1 then allocate a free channal in this dma
131 \param[in] psrcaddr dma transfer source address
132 \param[in] pstdaddr dma transfer source address
133 \param[in] length dma transfer length
134 \param[in] config dma transfer configure
135 \param[in] cb_event Pointer to \ref dma_event_cb_t
138 int32_t csi_dma_config(dmac_handle_t handle, int32_t ch,
139 void *psrcaddr, void *pstdaddr,
140 uint32_t length, dma_config_t *config, dma_event_cb_t cb_event);
143 \brief start generate dma signal.
144 \param[in] handle damc handle to operate.
145 \param[in] ch channel num.
148 int32_t csi_dma_start(dmac_handle_t handle, int32_t ch);
151 \brief Stop generate dma signal.
152 \param[in] handle damc handle to operate.
153 \param[in] ch channel num.
156 int32_t csi_dma_stop(dmac_handle_t handle, int32_t ch);
159 \brief Get DMA status.
160 \param[in] handle damc handle to operate.
161 \param[in] ch channel num.
162 \return DMA status \ref dma_status_e
164 dma_status_e csi_dma_get_status(dmac_handle_t handle, int32_t ch);
170 #endif /* _CSI_DMA_H_ */