fddma.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fddma.h
  15. * Date: 2022-02-10 14:53:42
  16. * LastEditTime: 2022-02-18 08:24:52
  17. * Description:  This files is for ddma interface definition
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. * 1.0 Zhugengyu 2022/5/13 init commit
  23. */
  24. #ifndef DRIVER_FDDMA_H
  25. #define DRIVER_FDDMA_H
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. /***************************** Include Files *********************************/
  31. #include "ftypes.h"
  32. #include "ferror_code.h"
  33. /************************** Constant Definitions *****************************/
  34. typedef enum
  35. {
  36. FDDMA_CHAN_0 = 0,
  37. FDDMA_CHAN_1,
  38. FDDMA_CHAN_2,
  39. FDDMA_CHAN_3,
  40. FDDMA_CHAN_4,
  41. FDDMA_CHAN_5,
  42. FDDMA_CHAN_6,
  43. FDDMA_CHAN_7,
  44. FDDMA_NUM_OF_CHAN
  45. } FDdmaChanIndex; /* DDMA channel index */
  46. typedef enum
  47. {
  48. FDDMA_CHAN_REQ_RX = 0,
  49. FDDMA_CHAN_REQ_TX,
  50. } FDdmaChanRequst; /* DDMA channel direction */
  51. typedef enum
  52. {
  53. FDDMA_CHAN_EVT_REQ_DONE = 0,
  54. FDDMA_CHAN_EVT_FIFO_EMPTY,
  55. FDDMA_CHAN_EVT_FIFO_FULL,
  56. FDDMA_NUM_OF_CHAN_EVT
  57. } FDdmaChanEvt; /* DDMA channel interrupt event */
  58. #define FDDMA_SUCCESS FT_SUCCESS
  59. #define FDDMA_ERR_NOT_INIT FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 0)
  60. #define FDDMA_ERR_CHAN_BINDED FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 1)
  61. #define FDDMA_ERR_CHAN_RUNNING FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 2)
  62. #define FDDMA_ERR_INVALID_TRANS_SIZE FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 3)
  63. #define FDDMA_ERR_WAIT_TIMEOUT FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 4)
  64. #define FDDMA_ERR_INVALID_DDR_ADDR FT_MAKE_ERRCODE(ErrModBsp, ErrDdma, 5)
  65. /**************************** Type Definitions *******************************/
  66. typedef struct FDdma_ FDdma;
  67. typedef struct FDdmaChan_ FDdmaChan;
  68. typedef void (*FDdmaChanEvtHandler)(FDdmaChan *const dma_chan, void *arg); /* DMA interrupt event handler */
  69. typedef struct
  70. {
  71. u32 id; /* DDMA ctrl id */
  72. uintptr base_addr; /* DDMA ctrl base address */
  73. u32 irq_num; /* DDMA ctrl interrupt id */
  74. u32 irq_prority; /* DDMA ctrl interrupt priority */
  75. } FDdmaConfig; /* DDMA instance configuration */
  76. typedef struct
  77. {
  78. FDdmaChanIndex id; /* DMA channel index */
  79. u32 slave_id; /* Perpherial slave id for DDMA */
  80. FDdmaChanRequst req_mode; /* DMA transfer direction */
  81. uintptr ddr_addr; /* DMA channel DDR address, could be source or destination */
  82. u32 dev_addr; /* DMA channel Perpherial, could be source or destination */
  83. u32 trans_len; /* DMA channel transfer length */
  84. #define FDDMA_MAX_TRANSFER_LEN 64 /* max bytes in transfer */
  85. #define FDDMA_MIN_TRANSFER_LEN 4 /* min bytes in transfer */
  86. u32 timeout; /* timeout = 0 means no use DMA timeout */
  87. } FDdmaChanConfig; /* DDMA channel instance */
  88. typedef struct FDdmaChan_
  89. {
  90. FDdmaChanConfig config; /* DDMA channel configuration */
  91. boolean is_used; /* TRUE means channel is in use */
  92. FDdma *dma; /* DMA instance of this channel */
  93. FDdmaChanEvtHandler evt_handler[FDDMA_NUM_OF_CHAN_EVT]; /* interrupt evt */
  94. void *evt_handler_args[FDDMA_NUM_OF_CHAN_EVT]; /* interrupt evt args */
  95. } FDdmaChan; /* DDMA channel instance */
  96. typedef struct FDdma_
  97. {
  98. FDdmaConfig config; /* DDMA instance configuration */
  99. FDdmaChan *chan[FDDMA_NUM_OF_CHAN]; /* DDMA channel instance, NULL means channel not yet allocate */
  100. u32 is_ready; /* TRUE means DDMA init ok */
  101. u32 bind_status; /* channel bind status, BIT(n) = 1 means channel n is allocated */
  102. } FDdma; /* DDMA instance */
  103. /************************** Variable Definitions *****************************/
  104. /***************** Macros (Inline Functions) Definitions *********************/
  105. #define FDDMA_DDR_ADDR_ALIGMENT 128 /* DMA DDR Buffer need align wiht 128 bytes */
  106. /************************** Function Prototypes ******************************/
  107. /* 获取DDMA实例默认配置 */
  108. const FDdmaConfig *FDdmaLookupConfig(u32 instance_id);
  109. /* 初始化DDMA控制器 */
  110. FError FDdmaCfgInitialization(FDdma *const instance, const FDdmaConfig *input_config);
  111. /* 去初始化DDMA控制器 */
  112. void FDdmaDeInitialization(FDdma *const instance);
  113. /* 按照配置分配DDMA通道 */
  114. FError FDdmaAllocateChan(FDdma *const instance, FDdmaChan *const dma_chan, const FDdmaChanConfig *dma_chan_config);
  115. /* 释放之前分配的DDMA通道 */
  116. FError FDdmaDellocateChan(FDdmaChan *const dma_chan);
  117. /* 使能指定的DDMA通道,调用FDdmaAllocateChan后无需调用此函数 */
  118. FError FDdmaActiveChan(FDdmaChan *const dma_chan);
  119. /* 去使能DDMA通道 */
  120. FError FDdmaDeactiveChan(FDdmaChan *const dma_chan);
  121. /* 启动DDMA控制器并开始传输 */
  122. FError FDdmaStart(FDdma *const instance);
  123. /* 停止DDMA控制器 */
  124. FError FDdmaStop(FDdma *const instance);
  125. /* DDMA中断处理函数 */
  126. void FDdmaIrqHandler(s32 vector, void *args);
  127. /* 注册DDMA通道中断响应事件函数 */
  128. void FDdmaRegisterChanEvtHandler(FDdmaChan *const dma_chan,
  129. FDdmaChanEvt evt,
  130. FDdmaChanEvtHandler handler,
  131. void *handler_arg);
  132. /* DDMA控制器寄存器自检测试 */
  133. void FDdmaDumpRegisters(uintptr base_addr);
  134. void FDdmaDumpChanRegisters(uintptr base_addr, FDdmaChanIndex chan);
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif