#if !defined(__RPI_DMA_H__)
#define __RPI_DMA_H__

#include <stdint.h>

#include "../common.h"

#define DMA_CHAN_A 10
#define DMA_CHAN_B 11

// DMA control block (must be 32-byte aligned)
typedef struct {
  uint32_t ti, // Transfer info
      srce_ad, // Source address
      dest_ad, // Destination address
      tfr_len, // Transfer length
      stride,  // Transfer stride
      next_cb, // Next control block
      debug,   // Debug register, zero in control block
      unused;
} DMA_CB __attribute__((aligned(32)));

void dma_setup(MEM_MAP *mp, int chan, int nsamp, uint8_t **txdata, int offset, uint32_t dest_ad);
void dma_close();

void enable_dma(int chan);
void start_dma(MEM_MAP *mp, int chan, DMA_CB *cbp, uint32_t csval);
uint32_t dma_transfer_len(int chan);
uint32_t dma_active(int chan);
void stop_dma(int chan);
void disp_dma(int chan);

#endif // __RPI_DMA_H__