hosal_dma.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (c) 2016-2022 Bouffalolab.
  3. *
  4. * This file is part of
  5. * *** Bouffalolab Software Dev Kit ***
  6. * (see www.bouffalolab.com).
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * 3. Neither the name of Bouffalo Lab nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  25. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  26. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __HOSAL_DMA_H__
  31. #define __HOSAL_DMA_H__
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /** @addtogroup hosal_dma DMA
  36. * HOSAL DMA API
  37. *
  38. * @{
  39. */
  40. #include <stdint.h>
  41. #include <stdio.h>
  42. /**
  43. * @brief DMA irq callback function flag
  44. */
  45. #define HOSAL_DMA_INT_TRANS_COMPLETE 0
  46. #define HOSAL_DMA_INT_TRANS_ERROR 1
  47. /**
  48. * @brief DMA irq callback function
  49. */
  50. typedef void (*hosal_dma_irq_t)(void *p_arg, uint32_t flag);
  51. /**
  52. * @brief DMA channel describe
  53. */
  54. struct hosal_dma_chan {
  55. uint8_t used;
  56. hosal_dma_irq_t callback;
  57. void *p_arg;
  58. };
  59. /**
  60. * @brief DMA device type
  61. */
  62. typedef struct hosal_dma_dev {
  63. int max_chans;
  64. struct hosal_dma_chan *used_chan;
  65. void *priv;
  66. } hosal_dma_dev_t;
  67. /**
  68. * @brief DMA channel
  69. */
  70. typedef int hosal_dma_chan_t;
  71. /**
  72. * @brief Initialises a DMA interface
  73. *
  74. * @return 0 : on success, EIO : if an error occurred with any step
  75. */
  76. int hosal_dma_init(void);
  77. /**
  78. * @brief Request a DMA channel
  79. *
  80. * @param[in] flag : DMA CHAN REQUEST FLAG
  81. *
  82. * @return < 0 : an error occurred with any step, otherwise is DMA channel number
  83. */
  84. hosal_dma_chan_t hosal_dma_chan_request(int flag);
  85. /**
  86. * @brief Release a DMA channel
  87. *
  88. * @param[in] chan DMA channel number
  89. *
  90. * @return 0 : on success, EIO : if an error occurred with any step
  91. */
  92. int hosal_dma_chan_release(hosal_dma_chan_t chan);
  93. /**
  94. * @brief DMA channel trans start
  95. *
  96. * @param[in] chan DMA channel number
  97. *
  98. * @return 0 : on success, EIO : if an error occurred with any step
  99. */
  100. int hosal_dma_chan_start(hosal_dma_chan_t chan);
  101. /**
  102. * @brief DMA channel trans stop
  103. *
  104. * @param[in] chan DMA channel number
  105. *
  106. * @return 0 : on success, EIO : if an error occurred with any step
  107. */
  108. int hosal_dma_chan_stop(hosal_dma_chan_t chan);
  109. /**
  110. * @brief DMA irq callback set
  111. *
  112. * @param[in] chan : DMA channel number
  113. * @param[in] pfn : callback function
  114. * @param[in] arg : callback function parameter
  115. *
  116. * @return 0 : on success, EIO : if an error occurred with any step
  117. */
  118. int hosal_dma_irq_callback_set(hosal_dma_chan_t chan, hosal_dma_irq_t pfn, void *p_arg);
  119. /**
  120. * @brief Deinitialises a DMA interface
  121. *
  122. * @param[in] DMA the interface which should be deinitialised
  123. *
  124. * @return 0 : on success, EIO : if an error occurred with any step
  125. */
  126. int hosal_dma_finalize(void);
  127. /** @} */
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /* __HOSAL_DMA_H__ */
  132. /* end of file */