drv_ifc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 _DRV_IFC_H_
  13. #define _DRV_IFC_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "drv_names.h"
  18. #include "quec_cust_patch.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @brief IFC direction
  24. */
  25. typedef enum
  26. {
  27. DRV_IFC_RX, ///< RX, from peripherals to memory
  28. DRV_IFC_TX ///< TX, from memory to peripherals
  29. } drvIfcDirection_t;
  30. /**
  31. * @brief IFC peripherial size
  32. */
  33. #if QUEC_PATCH_SPI_DMA_IRQ
  34. typedef enum
  35. {
  36. DRV_IFC_PERI_8BIT = 0,
  37. DRV_IFC_PERI_32BIT,
  38. } drvIfcPeriSize_t;
  39. #endif
  40. /**
  41. * @brief IFC channel data structure
  42. *
  43. * *Don't* access the members directly.
  44. */
  45. typedef struct
  46. {
  47. //! @cond Doxygen_Suppress
  48. const void *ifc_desc;
  49. #if QUEC_PATCH_SPI_DMA_IRQ
  50. uintptr_t hwp_channel;
  51. uint8_t channel_id;
  52. drvIfcPeriSize_t peri_size;
  53. #else
  54. volatile void *hwp_channel;
  55. #endif
  56. //! @endcond
  57. } drvIfcChannel_t;
  58. /**
  59. * @brief initialize IFC channel data structure
  60. *
  61. * @param ch IFC channel to be initialized
  62. * @param name device name
  63. * @param dir IFC direction
  64. * @return
  65. * - true on success
  66. * - false if the device name or direction is not supported by IFC
  67. */
  68. bool drvIfcChannelInit(drvIfcChannel_t *ch, uint32_t name, drvIfcDirection_t dir);
  69. /**
  70. * @brief request a hardware IFC channel
  71. *
  72. * @param ch IFC channel data structure, must be valid
  73. * @return
  74. * - true if a hardware channel is requested
  75. * - false if there are no available hardware channels
  76. */
  77. bool drvIfcRequestChannel(drvIfcChannel_t *ch);
  78. /**
  79. * @brief request and wait a hardware IFC channel
  80. *
  81. * It can't be called inside ISR.
  82. *
  83. * @param ch IFC channel data structure, must be valid
  84. */
  85. void drvIfcWaitChannel(drvIfcChannel_t *ch);
  86. /**
  87. * @brief release the hardware channel
  88. *
  89. * @param ch IFC channel data structure, must be valid
  90. */
  91. void drvIfcReleaseChannel(drvIfcChannel_t *ch);
  92. /**
  93. * @brief whether there is requested hardware channel
  94. *
  95. * @param ch IFC channel data structure, must be valid
  96. * @return
  97. * - true if a hardware channel is requested
  98. * - false if no hardware channels are requested
  99. */
  100. bool drvIfcReady(drvIfcChannel_t *ch);
  101. /**
  102. * @brief flush hardware IFC channel
  103. *
  104. * This should be only called for RX channel. At flush, IFC controller
  105. * will pause to fetch data from hardware module. For example, when
  106. * \a drvIfcFlush is called for UART RX channel, UART arriving data
  107. * won't be transfered to memory configured in IFC. Rather, they will
  108. * be put to UART FIFO.
  109. *
  110. * @param ch IFC channel data structure, must be valid
  111. */
  112. void drvIfcFlush(drvIfcChannel_t *ch);
  113. /**
  114. * @brief clear flush state of IFC channel
  115. *
  116. * It should be only called on *flushed* IFC channel. After it is called,
  117. * IFC will continue to fetch data from hardware module.
  118. *
  119. * @param ch IFC channel data structure, must be valid
  120. */
  121. void drvIfcClearFlush(drvIfcChannel_t *ch);
  122. /**
  123. * @brief get current transfer count
  124. *
  125. * \a TC will be decreased from the initial value. Current transfer count
  126. * is the remaining byte count for the configured DMA transfer.
  127. *
  128. * @param ch IFC channel data structure, must be valid
  129. * @return
  130. * - \a TC
  131. */
  132. uint32_t drvIfcGetTC(drvIfcChannel_t *ch);
  133. /**
  134. * @brief start a transfer
  135. *
  136. * Caller should take care cache coherence before.
  137. *
  138. * @param ch IFC channel data structure, must be valid
  139. * @param address DMA address
  140. * @param size DMA size
  141. */
  142. void drvIfcStart(drvIfcChannel_t *ch, const void *address, uint32_t size);
  143. /**
  144. * @brief start a transfer with almost done threshold
  145. *
  146. * Caller should take care cache coherence before.
  147. *
  148. * @param ch IFC channel data structure, must be valid
  149. * @param address DMA address
  150. * @param size DMA size
  151. * @param threshold almost done threshold
  152. */
  153. void drvIfcStartThreshold(drvIfcChannel_t *ch, const void *address, uint32_t size, uint32_t threshold);
  154. /**
  155. * @brief stop a transfer
  156. *
  157. * After stop, *TC* will be set to 0. If the *TC* before stop, it is needed
  158. * to call \p drvIfcGetTC before stop.
  159. *
  160. * @param ch IFC channel data structure, must be valid
  161. */
  162. void drvIfcStop(drvIfcChannel_t *ch);
  163. /**
  164. * @brief extend current transfer
  165. *
  166. * Caller should take care cache coherence before.
  167. *
  168. * When the next DMA address is adjacent to the previous started DMA end
  169. * address, \a drvIfcExtend can be called to transfer mode bytes. For RX
  170. * channel, it means receiving more bytes. For TX channel, it means sending
  171. * more bytes.
  172. *
  173. * It can be called even the DMA is on going.
  174. *
  175. * @param ch IFC channel data structure, must be valid
  176. * @param size extend DMA size
  177. */
  178. void drvIfcExtend(drvIfcChannel_t *ch, uint32_t size);
  179. /**
  180. * @brief whether the IFC fifo is empty
  181. *
  182. * @param ch IFC channel data structure, must be valid
  183. * @return
  184. * - true if the hardware IFC channel FIFO is empty
  185. * - false otherwise
  186. */
  187. bool drvIfcIsFifoEmpty(drvIfcChannel_t *ch);
  188. /**
  189. * @brief whether the hardware is running
  190. *
  191. * @param ch IFC channel data structure, must be valid
  192. * @return
  193. * - true if the hardware IFC channel is started, and not finished
  194. * - false otherwise
  195. */
  196. bool drvIfcIsRunning(drvIfcChannel_t *ch);
  197. /**
  198. * @brief wait IFC channel is done
  199. *
  200. * @param ch IFC channel data structure, must be valid
  201. */
  202. void drvIfcWaitDone(drvIfcChannel_t *ch);
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif