drv_axidma.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef __AXIDMA_H__
  13. #define __AXIDMA_H__
  14. #include "osi_api.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * @brief AXIDMA interrupt event
  20. */
  21. typedef enum
  22. {
  23. AD_EVT_FINISH = (1 << 0), ///< event transfer done
  24. AD_EVT_PART_FINISH = (1 << 1), ///< event transfer once done (part size)
  25. AD_EVT_STOP = (1 << 2), ///< event the channel stop
  26. } drvAxidmaIrqEvent_t;
  27. /**
  28. * @brief AXIDMA data type
  29. */
  30. typedef enum
  31. {
  32. AD_DATA_8BIT = 0,
  33. AD_DATA_16BIT = 1,
  34. AD_DATA_32BIT = 2,
  35. AD_DATA_64BIT = 3,
  36. } drvAxidmaDataType_t;
  37. /**
  38. * @brief function type to process AXIDMA channel interrupt
  39. */
  40. typedef void (*drvAxidmaIsr_t)(drvAxidmaIrqEvent_t evt, void *p);
  41. /**
  42. * @brief the AXIDMA channel, call do not need to know its implement
  43. */
  44. typedef struct drv_axidma_channel drvAxidmaCh_t;
  45. /**
  46. * @brief AXIDMA channel config
  47. */
  48. typedef struct drv_axidma_config
  49. {
  50. uint32_t src_addr; ///< source address
  51. uint32_t dst_addr; ///< destination address
  52. uint32_t data_size; ///< data size in byte
  53. uint32_t part_trans_size; ///< transfer size once in byte
  54. drvAxidmaDataType_t data_type; ///< dma data type
  55. drvAxidmaIrqEvent_t mask; ///< react interrupt mask
  56. uint8_t src_addr_fix : 1; ///< source address fixed (like hw fifo)
  57. uint8_t dst_addr_fix : 1; ///< destination address fixed
  58. uint8_t sync_irq : 1; ///< request trigger mode
  59. uint8_t force_trans : 1; ///< force trans start
  60. uint8_t req_sel_level : 1; ///< high level trigger
  61. } drvAxidmaCfg_t;
  62. /**
  63. * @brief AXIDMA module initialization
  64. *
  65. * CP will rely on the initialization, so it should be called before
  66. * release CP reset.
  67. */
  68. void drvAxidmaInit(void);
  69. /**
  70. * @brief AXIDMA resume after wakeup
  71. *
  72. * Due to CP will rely on AXIDMA, it will be called explicitly rather
  73. * than using the suspend/resume callback. This will make it earlier to
  74. * release CP reset.
  75. */
  76. void drvAxidmaResume(osiSuspendMode_t mode, uint32_t source);
  77. /**
  78. * @brief allocate an AXIDMA channel
  79. *
  80. * @return
  81. * - NULL no free axidma channel
  82. * - OTHERS axidma channel
  83. */
  84. drvAxidmaCh_t *drvAxidmaChAllocate();
  85. /**
  86. * @brief release an AXIDMA channel
  87. *
  88. * @param ch the AXIDMA channel
  89. */
  90. void drvAxidmaChRelease(drvAxidmaCh_t *ch);
  91. /**
  92. * @brief start the AXIDMA channel
  93. *
  94. * @param ch the AXIDMA channel
  95. * @param cfg start config
  96. * @return
  97. * - true success
  98. * - flase fail
  99. */
  100. bool drvAxidmaChStart(drvAxidmaCh_t *ch, const drvAxidmaCfg_t *cfg);
  101. /**
  102. * @brief stop the AXIDMA channel
  103. *
  104. * Stop the AXIDMA channel, all transfer will stop, may triger a STOP event.
  105. *
  106. * During stop, channel pending data count may be modified. So, the return
  107. * value of \p drvAxidmaChCount after this is unreliable. Rather, the return
  108. * value of this function shall be used.
  109. *
  110. * @param ch the AXIDMA channel
  111. * @return
  112. * - channel pending data count
  113. * - 0 on invalid parameter
  114. */
  115. unsigned drvAxidmaChStop(drvAxidmaCh_t *ch);
  116. /**
  117. * @brief check if the AXIDMA channel is busy
  118. *
  119. * @param ch the AXIDMA channel
  120. * @return
  121. * - true busy
  122. * - false not busy
  123. */
  124. bool drvAxidmaChBusy(drvAxidmaCh_t *ch);
  125. /**
  126. * @brief set AXIDMA map for a specific channel
  127. *
  128. * @param ch the AXIDMA channel
  129. * @param req_source request source
  130. * @param ack_map ack map
  131. */
  132. void drvAxidmaChSetDmamap(drvAxidmaCh_t *ch, uint8_t req_source, uint8_t ack_map);
  133. /**
  134. * @brief get AXIDMA channel pending count
  135. *
  136. * Get pending data for an AXIDMA channel in bytes.
  137. * Caller can calculate the AXIDMA actually transfered data size
  138. * by total size minus this count.
  139. *
  140. * @param ch the AXIDMA channel
  141. * @return
  142. * - (Non-negative integer) pending data count in byte
  143. */
  144. uint32_t drvAxidmaChCount(drvAxidmaCh_t *ch);
  145. /**
  146. * @brief register a interrupt handler for a specific AXIDMA channel
  147. *
  148. * @param ch the AXIDMA channel
  149. * @param isr interrupt routine
  150. * @param param call private data (like context)
  151. */
  152. void drvAxidmaChRegisterIsr(drvAxidmaCh_t *ch, drvAxidmaIsr_t isr, void *param);
  153. /**
  154. * @brief stop all AXIDMA channel
  155. *
  156. * It is only intented to be called at enter panic.
  157. */
  158. void drvAxidmaStopAll(void);
  159. #endif /* __AXIDMA_H__ */