DMA Controller Code in VHDL
DMA Controller Code in VHDL
library ieee;
library work;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use work.components.all;
entity dma is
Port (
clk : in std_logic; -- clock
rstn : in std_logic; -- reset
start : in std_logic; -- trigger state machine
dati : in std_logic_vector(31 downto 0); -- data input
adr : in std_logic_vector(7 downto 0);  -- address of the dma
register
reg_wen : in std_logic; -- dma register write enable
fifo_wen : in std_logic; -- dma fifo write enable
wr_rdn : in std_logic; -- write/read signal to dma registers
cs : in std_logic; -- chip select (dma_register)
bcr_cnten : in std_logic; -- byte counter count enable
acr_cnten : in std_logic; -- address counter count enable
lar_cnten : in std_logic; -- local address counter count
enable
p2s_fifo_empty : in std_logic; -- high and low p2s both empty
s2p_fifo_usedw : in std_logic_vector(6 downto 0);
mstr_busy : in std_logic;
stop : in std_logic; -- PCI core signals stop current dma
abort : in std_logic; -- PCI core signals abort current dma
last_xfr : in std_logic; -- PCI core signals last transfer
local_busy : in std_logic; -- sdram is busy
err_pend : in std_logic; -- target abort, parity error, master
abort
lm_tsr : in std_logic_vector(9 downto 0);  -- master status
std_logics
isr_rd : in std_logic; -- isr read signal
end dma;
-- assert local irq when there is error pending or DMA has completed
 local_irq <= dma_isr(1) or (dma_isr(3) and not dma_csr(5));
 isr_in(1) <= err_pend;
 dma_on <= (dma_isr(4) and dma_csr(4) and not err_pend) or (isr_in(5) and
dma_csr(4) and  not err_pend);
port map (
clk =>  clk,
rstn =>  rstn,
normal_termination =>  normal_termination,
stop =>  stop,
lm_tsr =>  lm_tsr,
err_pend =>  err_pend,
start =>  start ,
start_chain =>  start_chain,
chain_end =>  chain_end,
p2s_fifo_empty =>  p2s_fifo_empty,
s2p_fifo_usedw =>  s2p_fifo_usedw,
direction =>  direction,
dma_bcr =>  dma_bcr,
local_busy =>  local_busy,
req =>  req_int,
dma_done =>  dma_done,
dma_error =>  dma_error,
chain_acr_ld =>  chain_acr_ld,
chain_bcr_ld =>  chain_bcr_ld,
dma_fifo_rd =>  dma_fifo_rd,
local_start =>  local_start,
chain_dma_loading =>  reg_dat_sel
);
 port map (
clk =>  clk ,
rstn =>  rstn ,
adr =>  adr ,
dati =>  dma_reg_dati , -- mux output select between
dati and dma_fifo_dato
wen =>  reg_wen ,
acr_ld =>  chain_acr_ld ,
bcr_ld =>  chain_bcr_ld ,
acr_cnten =>  acr_cnten,
lar_cnten =>  lar_cnten,
bcr_cnten =>  bcr_cnten,
isr_in =>  isr_in ,
dma_on =>  dma_on ,
cs =>  cs,
acr =>  dma_acr ,
bcr =>  dma_bcr ,
csr =>  dma_csr ,
isr =>  dma_isr ,
lar =>  dma_lar ,
dato =>  dato,
dma_reg_hit =>  dma_reg_hit
);
-- assign outputs
end rtl;