dma.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * DMA C definitions and help macros
  3. *
  4. */
  5. #ifndef dma_h
  6. #define dma_h
  7. /* registers */ /* Really needed, since both are listed in sw.list? */
  8. #include "dma_defs.h"
  9. /* descriptors */
  10. // ------------------------------------------------------------ dma_descr_group
  11. typedef struct dma_descr_group {
  12. struct dma_descr_group *next;
  13. unsigned eol : 1;
  14. unsigned tol : 1;
  15. unsigned bol : 1;
  16. unsigned : 1;
  17. unsigned intr : 1;
  18. unsigned : 2;
  19. unsigned en : 1;
  20. unsigned : 7;
  21. unsigned dis : 1;
  22. unsigned md : 16;
  23. struct dma_descr_group *up;
  24. union {
  25. struct dma_descr_context *context;
  26. struct dma_descr_group *group;
  27. } down;
  28. } dma_descr_group;
  29. // ---------------------------------------------------------- dma_descr_context
  30. typedef struct dma_descr_context {
  31. struct dma_descr_context *next;
  32. unsigned eol : 1;
  33. unsigned : 3;
  34. unsigned intr : 1;
  35. unsigned : 1;
  36. unsigned store_mode : 1;
  37. unsigned en : 1;
  38. unsigned : 7;
  39. unsigned dis : 1;
  40. unsigned md0 : 16;
  41. unsigned md1;
  42. unsigned md2;
  43. unsigned md3;
  44. unsigned md4;
  45. struct dma_descr_data *saved_data;
  46. char *saved_data_buf;
  47. } dma_descr_context;
  48. // ------------------------------------------------------------- dma_descr_data
  49. typedef struct dma_descr_data {
  50. struct dma_descr_data *next;
  51. char *buf;
  52. unsigned eol : 1;
  53. unsigned : 2;
  54. unsigned out_eop : 1;
  55. unsigned intr : 1;
  56. unsigned wait : 1;
  57. unsigned : 2;
  58. unsigned : 3;
  59. unsigned in_eop : 1;
  60. unsigned : 4;
  61. unsigned md : 16;
  62. char *after;
  63. } dma_descr_data;
  64. // --------------------------------------------------------------------- macros
  65. // enable DMA channel
  66. #define DMA_ENABLE( inst ) \
  67. do { reg_dma_rw_cfg e = REG_RD( dma, inst, rw_cfg );\
  68. e.en = regk_dma_yes; \
  69. REG_WR( dma, inst, rw_cfg, e); } while( 0 )
  70. // reset DMA channel
  71. #define DMA_RESET( inst ) \
  72. do { reg_dma_rw_cfg r = REG_RD( dma, inst, rw_cfg );\
  73. r.en = regk_dma_no; \
  74. REG_WR( dma, inst, rw_cfg, r); } while( 0 )
  75. // stop DMA channel
  76. #define DMA_STOP( inst ) \
  77. do { reg_dma_rw_cfg s = REG_RD( dma, inst, rw_cfg );\
  78. s.stop = regk_dma_yes; \
  79. REG_WR( dma, inst, rw_cfg, s); } while( 0 )
  80. // continue DMA channel operation
  81. #define DMA_CONTINUE( inst ) \
  82. do { reg_dma_rw_cfg c = REG_RD( dma, inst, rw_cfg );\
  83. c.stop = regk_dma_no; \
  84. REG_WR( dma, inst, rw_cfg, c); } while( 0 )
  85. // give stream command
  86. #define DMA_WR_CMD( inst, cmd_par ) \
  87. do { reg_dma_rw_stream_cmd __x = {0}; \
  88. do { __x = REG_RD(dma, inst, rw_stream_cmd); } while (__x.busy); \
  89. __x.cmd = (cmd_par); \
  90. REG_WR(dma, inst, rw_stream_cmd, __x); \
  91. } while (0)
  92. // load: g,c,d:burst
  93. #define DMA_START_GROUP( inst, group_descr ) \
  94. do { REG_WR_INT( dma, inst, rw_group, (int) group_descr ); \
  95. DMA_WR_CMD( inst, regk_dma_load_g ); \
  96. DMA_WR_CMD( inst, regk_dma_load_c ); \
  97. DMA_WR_CMD( inst, regk_dma_load_d | regk_dma_burst ); \
  98. } while( 0 )
  99. // load: c,d:burst
  100. #define DMA_START_CONTEXT( inst, ctx_descr ) \
  101. do { REG_WR_INT( dma, inst, rw_group_down, (int) ctx_descr ); \
  102. DMA_WR_CMD( inst, regk_dma_load_c ); \
  103. DMA_WR_CMD( inst, regk_dma_load_d | regk_dma_burst ); \
  104. } while( 0 )
  105. // if the DMA is at the end of the data list, the last data descr is reloaded
  106. #define DMA_CONTINUE_DATA( inst ) \
  107. do { reg_dma_rw_cmd c = {0}; \
  108. c.cont_data = regk_dma_yes;\
  109. REG_WR( dma, inst, rw_cmd, c ); } while( 0 )
  110. #endif