Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dma.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //---
  2. // gint:dma - Direct Memory Access for efficient data transfer
  3. //---
  4. #ifndef GINT_DMA
  5. #define GINT_DMA
  6. #ifdef FXCG50
  7. #include <gint/defs/types.h>
  8. /* dma_size_t - Transfer block size */
  9. typedef enum
  10. {
  11. /* Normal transfers of 1, 2, 4, 8, 16 or 32 bytes at a time */
  12. DMA_1B = 0,
  13. DMA_2B = 1,
  14. DMA_4B = 2,
  15. DMA_8B = 7,
  16. DMA_16B = 3,
  17. DMA_32B = 4,
  18. /* Transfers of 16 or 32 bytes divided in two operations */
  19. DMA_16B_DIV = 11,
  20. DMA_32B_DIV = 12,
  21. } dma_size_t;
  22. /* dma_address_t - Addressing mode for source and destination regions */
  23. typedef enum
  24. {
  25. /* Fixed address mode: the same address is read/written at each step */
  26. DMA_FIXED = 0,
  27. /* Increment: address is incremented by transfer size at each step */
  28. DMA_INC = 1,
  29. /* Decrement: only allowed for 1/2/4-byte transfers */
  30. DMA_DEC = 2,
  31. /* Fixed division mode: address is fixed even in 16/32-divide mode */
  32. DMA_FIXEDDIV = 3,
  33. } dma_address_t;
  34. /* dma_transfer() - Start a data transfer on channel 0
  35. This function returns just when the transfer starts. The transfer will end
  36. later on and the DMA will be stopped by an interrupt. Call
  37. dma_transfer_wait() if you need to wait for the transfer to finish. Don't
  38. start a new transfer until the current one is finished!
  39. @channel DMA channel (0..5)
  40. @size Transfer size
  41. @blocks Number of blocks (transferred memory = size * blocks)
  42. @src Source pointer, must be aligned with transfer size
  43. @src_mode Source address mode
  44. @dst Destination address, must be aligned with transfer size
  45. @dst_mode Destination address mode */
  46. void dma_transfer(int channel, dma_size_t size, uint length,
  47. void const *src, dma_address_t src_mode,
  48. void *dst, dma_address_t dst_mode);
  49. /* dma_transfer_wait() - Wait for a transfer to finish
  50. You should call this function when you need to transfer to be complete
  51. before continuing execution. If you are sure that the transfer is finished,
  52. this is not necessary (the only way to know is to look at the DMA registers
  53. or record interrupts).
  54. @channel DMA channel (0..5) */
  55. void dma_transfer_wait(int channel);
  56. /* dma_transfer_noint() - Perform a data transfer without interrupts
  57. This function performs a transfer much like dma_transfer(), but doesn't use
  58. interrupts and *actively waits* for the transfer to finish, returning when
  59. it's finished. Don't call dma_transfer_wait() after using this function.
  60. Not using interrupts is a bad design idea for a majority of programs, and is
  61. only ever needed to display panic messages inside exception handlers. */
  62. void dma_transfer_noint(int channel, dma_size_t size, uint blocks,
  63. void const *src, dma_address_t src_mode,
  64. void *dst, dma_address_t dst_mode);
  65. //---
  66. // DMA-based memory manipulation functions
  67. //---
  68. /* dma_memset(): Fast 32-aligned memset
  69. This function is your typical memset(), except that the destination and size
  70. must be 32-aligned, and that the pattern is 4 bytes instead of one. It is
  71. replicated to 32 bytes then used to fill the destination area. This 4-byte
  72. fixed size may be lifted in future versions.
  73. This function cannot be used with virtualized (P0) addresses.
  74. @dst Destination address (32-aligned)
  75. @pattern 4-byte pattern to fill @dst
  76. @size Sie of destination area (32-aligned) */
  77. void *dma_memset(void *dst, uint32_t pattern, size_t size);
  78. /* dma_memcpy(): Fast 32-aligned memcpy
  79. This function works exactly like memcpy(), but it expects 32-aligned source,
  80. destination, and size, and uses the DMA to efficiently copy.
  81. This function cannot be used with virtualized (P0) addresses.
  82. @dst Destination address (32-aligned)
  83. @dst Source addresss (32-aligned)
  84. @size Size of region (32-aligned) */
  85. void *dma_memcpy(void * restrict dst, const void * restrict src, size_t size);
  86. #endif /* FXCG50 */
  87. #endif /* GINT_DMA */