dma.h 4.5 KB

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