hpl_dma.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #ifndef _HPL_DMA_H_INCLUDED
  34. #define _HPL_DMA_H_INCLUDED
  35. /**
  36. * \addtogroup HPL DMA
  37. *
  38. * \section hpl_dma_rev Revision History
  39. * - v1.0.0 Initial Release
  40. *
  41. *@{
  42. */
  43. #include <compiler.h>
  44. #include <hpl_irq.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. struct _dma_resource;
  49. /**
  50. * \brief DMA callback types
  51. */
  52. enum _dma_callback_type { DMA_TRANSFER_COMPLETE_CB, DMA_TRANSFER_ERROR_CB };
  53. /**
  54. * \brief DMA interrupt callbacks
  55. */
  56. struct _dma_callbacks {
  57. void (*transfer_done)(struct _dma_resource *resource);
  58. void (*error)(struct _dma_resource *resource);
  59. };
  60. /**
  61. * \brief DMA resource structure
  62. */
  63. struct _dma_resource {
  64. struct _dma_callbacks dma_cb;
  65. void * back;
  66. };
  67. /**
  68. * \brief Initialize DMA
  69. *
  70. * This function does low level DMA configuration.
  71. *
  72. * \return initialize status
  73. */
  74. int32_t _dma_init(void);
  75. /**
  76. * \brief Set destination address
  77. *
  78. * \param[in] channel DMA channel to set destination address for
  79. * \param[in] dst Destination address
  80. *
  81. * \return setting status
  82. */
  83. int32_t _dma_set_destination_address(const uint8_t channel, const void *const dst);
  84. /**
  85. * \brief Set source address
  86. *
  87. * \param[in] channel DMA channel to set source address for
  88. * \param[in] src Source address
  89. *
  90. * \return setting status
  91. */
  92. int32_t _dma_set_source_address(const uint8_t channel, const void *const src);
  93. /**
  94. * \brief Set next descriptor address
  95. *
  96. * \param[in] current_channel Current DMA channel to set next descriptor address
  97. * \param[in] next_channel Next DMA channel used as next descriptor
  98. *
  99. * \return setting status
  100. */
  101. int32_t _dma_set_next_descriptor(const uint8_t current_channel, const uint8_t next_channel);
  102. /**
  103. * \brief Enable/disable source address incrementation during DMA transaction
  104. *
  105. * \param[in] channel DMA channel to set source address for
  106. * \param[in] enable True to enable, false to disable
  107. *
  108. * \return status of operation
  109. */
  110. int32_t _dma_srcinc_enable(const uint8_t channel, const bool enable);
  111. /**
  112. * \brief Enable/disable Destination address incrementation during DMA transaction
  113. *
  114. * \param[in] channel DMA channel to set destination address for
  115. * \param[in] enable True to enable, false to disable
  116. *
  117. * \return status of operation
  118. */
  119. int32_t _dma_dstinc_enable(const uint8_t channel, const bool enable);
  120. /**
  121. * \brief Set the amount of data to be transfered per transaction
  122. *
  123. * \param[in] channel DMA channel to set data amount for
  124. * \param[in] amount Data amount
  125. *
  126. * \return status of operation
  127. */
  128. int32_t _dma_set_data_amount(const uint8_t channel, const uint32_t amount);
  129. /**
  130. * \brief Trigger DMA transaction on the given channel
  131. *
  132. * \param[in] channel DMA channel to trigger transaction on
  133. *
  134. * \return status of operation
  135. */
  136. int32_t _dma_enable_transaction(const uint8_t channel, const bool software_trigger);
  137. /**
  138. * \brief Retrieves DMA resource structure
  139. *
  140. * \param[out] resource The resource to be retrieved
  141. * \param[in] channel DMA channel to retrieve structure for
  142. *
  143. * \return status of operation
  144. */
  145. int32_t _dma_get_channel_resource(struct _dma_resource **resource, const uint8_t channel);
  146. /**
  147. * \brief Enable/disable DMA interrupt
  148. *
  149. * \param[in] channel DMA channel to enable/disable interrupt for
  150. * \param[in] type The type of interrupt to disable/enable if applicable
  151. * \param[in] state Enable or disable
  152. */
  153. void _dma_set_irq_state(const uint8_t channel, const enum _dma_callback_type type, const bool state);
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* HPL_DMA_H_INCLUDED */