drv_dmac.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. /******************************************************************************
  17. * @file drv_dmac.h
  18. * @brief header file for dmac driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_DMA_H_
  23. #define _CSI_DMA_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_common.h>
  29. /// definition for dmac handle.
  30. typedef void *dmac_handle_t;
  31. /**
  32. \brief DMA Driver Capabilities.
  33. */
  34. typedef struct {
  35. uint32_t unalign_addr : 1; ///< support for unalign address transfer when memory is source
  36. } dma_capabilities_t;
  37. typedef enum {
  38. DMA_STATE_FREE = 0, ///< DMA not yet initialized or disabled
  39. DMA_STATE_READY, ///< DMA process success and ready for use, but not start yet
  40. DMA_STATE_BUSY, ///< DMA process is ongoing
  41. DMA_STATE_ERROR, ///< DMA transfer error
  42. DMA_STATE_DONE, ///< DMA transfer done
  43. } dma_status_e;
  44. /****** DMA specific error codes *****/
  45. typedef enum {
  46. EDRV_DMA_MODE = (EDRV_SPECIFIC + 1), ///< Specified Mode not supported
  47. } dma_error_e;
  48. /****** DMA Event *****/
  49. typedef enum {
  50. DMA_EVENT_TRANSFER_DONE = 0, ///< transfer complete
  51. DMA_EVENT_TRANSFER_ERROR = 1, ///< transfer error
  52. } dma_event_e;
  53. typedef enum {
  54. DMA_ADDR_INC = 0,
  55. DMA_ADDR_DEC,
  56. DMA_ADDR_CONSTANT
  57. } dma_addr_inc_e;
  58. typedef enum {
  59. DMA_MEM2MEM = 0,
  60. DMA_MEM2PERH,
  61. DMA_PERH2MEM,
  62. DMA_PERH2PERH,
  63. } dma_trans_type_e;
  64. typedef struct {
  65. dma_addr_inc_e src_inc; ///< source address increment
  66. dma_addr_inc_e dst_inc; ///< destination address increment
  67. uint8_t src_tw; ///< source transfer width in byte
  68. uint8_t dst_tw; ///< destination transfer width in byte
  69. uint8_t hs_if; ///< a hardware handshaking interface
  70. dma_trans_type_e type; ///< transfer type
  71. } dma_config_t;
  72. typedef void (*dma_event_cb_t)(dma_event_e event, int32_t ch); ///< Pointer to \ref dma_event_cb_t : CRC Event call back.
  73. /**
  74. \brief get dma instance count.
  75. \return dma instance count
  76. */
  77. int32_t csi_dma_get_instance_count(void);
  78. /**
  79. \brief Initialize DMA Interface. 1. Initializes the resources needed for the DMA interface 2.registers event callback function
  80. \param[in] idx must not exceed return value of csi_dma_get_instance_count()
  81. \return pointer to dma instances
  82. */
  83. dmac_handle_t csi_dma_initialize(int32_t idx);
  84. /**
  85. \brief De-initialize DMA Interface. stops operation and releases the software resources used by the interface
  86. \param[in] handle damc handle to operate.
  87. \return error code
  88. */
  89. int32_t csi_dma_uninitialize(dmac_handle_t handle);
  90. /**
  91. \brief Get driver capabilities.
  92. \param[in] handle damc handle to operate.
  93. \return \ref dma_capabilities_t
  94. */
  95. dma_capabilities_t csi_dma_get_capabilities(dmac_handle_t handle);
  96. /**
  97. \brief get one free dma channel
  98. \param[in] handle damc handle to operate.
  99. \param[in] ch channel num. if -1 then allocate a free channal in this dma
  100. \return -1 - no channel can be used, other - channel index
  101. */
  102. int32_t csi_dma_alloc_channel(dmac_handle_t handle, int32_t ch);
  103. /**
  104. \brief release dma channel and related resources
  105. \param[in] handle damc handle to operate.
  106. \param[in] ch channel num.
  107. \return error code
  108. */
  109. int32_t csi_dma_release_channel(dmac_handle_t handle, int32_t ch);
  110. /**
  111. \brief
  112. \param[in] handle damc handle to operate.
  113. \param[in] ch channel num. if -1 then allocate a free channal in this dma
  114. \param[in] psrcaddr dma transfer source address
  115. \param[in] pstdaddr dma transfer source address
  116. \param[in] length dma transfer length
  117. \param[in] config dma transfer configure
  118. \param[in] cb_event Pointer to \ref dma_event_cb_t
  119. \return error code
  120. */
  121. int32_t csi_dma_config(dmac_handle_t handle, int32_t ch,
  122. void *psrcaddr, void *pstdaddr,
  123. uint32_t length, dma_config_t *config, dma_event_cb_t cb_event);
  124. /**
  125. \brief start generate dma signal.
  126. \param[in] handle damc handle to operate.
  127. \param[in] ch channel num.
  128. \return error code
  129. */
  130. int32_t csi_dma_start(dmac_handle_t handle, int32_t ch);
  131. /**
  132. \brief Stop generate dma signal.
  133. \param[in] handle damc handle to operate.
  134. \param[in] ch channel num.
  135. \return error code
  136. */
  137. int32_t csi_dma_stop(dmac_handle_t handle, int32_t ch);
  138. /**
  139. \brief Get DMA status.
  140. \param[in] handle damc handle to operate.
  141. \param[in] ch channel num.
  142. \return DMA status \ref dma_status_e
  143. */
  144. dma_status_e csi_dma_get_status(dmac_handle_t handle, int32_t ch);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif /* _CSI_DMA_H_ */