Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created June 15, 2013 19:22
Show Gist options
  • Save pamaury/5789261 to your computer and use it in GitHub Desktop.
Save pamaury/5789261 to your computer and use it in GitHub Desktop.
_4k = 4 * 1024
packet_addr = 0x40000000
src_addr = packet_addr + _4k
dst_addr = src_addr + _4k
buf_size = 4
dcp_virt_addr = 0x20000000
---[[
-- init page table
pagetable_addr = packet_addr + 32 * _4k
for i=0,4095 do
-- identity map, noncached, nonbuffered
DEV.write32(pagetable_addr + 4 * i, 0)
end
DEV.write32(pagetable_addr + dcp_virt_addr / 1024 / 1024 * 4, 0x40000000 + 0xc12)
DEV.write32(pagetable_addr + 0x40000000 / 1024 / 1024 * 4, 0x40000000 + 0xc12)
--]]
-- setup DFLT
-- DFLT cannot be used with the DCP pagetable: it's on AHB2 but DCP cannot only access AXI and AHB!
--[[
pagetable_addr = 0x800c0000
-- create one entry for the 1MB at 0x40000000 (identity sdram)
HW.DIGCTL.MPTEn_LOC[0].write(1024)
-- fill it with a section translation at 0x40000000, manager access
DEV.write32(pagetable_addr + 1024 * 4, 0x40000000 + 0xc12)
-- create one entry for the 1MB at the virtual DCP address (mapped to SDRAM)
HW.DIGCTL.MPTEn_LOC[1].write(dcp_virt_addr / 1024 / 1024)
-- fill it with a section translation at 0x40000000, manager access
DEV.write32(pagetable_addr + dcp_virt_addr / 1024 / 1024 * 4, 0x40000000 + 0xc12)
--]]
function dcp_virt(addr)
return addr - 0x40000000 + dcp_virt_addr
end
-- reset DCP
HW.DCP.CTRL.SFTRST.set()
HW.DCP.CTRL.SFTRST.clr()
HW.DCP.CTRL.CLKGATE.clr()
-- set pagetable
HW.DCP.PAGETABLE.write(pagetable_addr)
HW.DCP.PAGETABLE.ENABLE.write(1)
HW.DCP.PAGETABLE.FLUSH.write(1)
HW.DCP.PAGETABLE.FLUSH.write(0)
-- setup memcpy packet
DEV.write32(packet_addr, 0) -- next buffer
DEV.write32(packet_addr + 4, 0x12) -- ctrl0: enable_memcpy, decr_sema
DEV.write32(packet_addr + 8, 0) -- ctrl1
DEV.write32(packet_addr + 12, dcp_virt(src_addr)) -- source buffer
DEV.write32(packet_addr + 16, dcp_virt(dst_addr)) -- destination buffer
DEV.write32(packet_addr + 20, buf_size) -- buffer size
-- init source buffer randomly and clear destination
io.write("source buffer: ");
for i=0,buf_size-1 do
DEV.write8(src_addr + i, math.random(256))
io.write(tostring(DEV.read8(src_addr + i)) .. " ")
DEV.write8(dst_addr + i, 0)
end
io.write("\n")
-- kick channel
HW.DCP.CHnCMDPTR[0].write(packet_addr)
HW.DCP.CHnSEMA[0].write(1)
HW.DCP.CHANNELCTRL.ENABLE_CHANNEL.set(0x1)
-- wait for completion
i = 0
while HW.DCP.CHnSEMA[0].VALUE.read() ~= 0 and i < 10 do
io.write("waiting for completion...\n")
i = i + 1
end
if i >= 10 then
io.write("warning: sema = " .. HW.DCP.CHnSEMA[0].VALUE.read() .. "\n")
end
-- print destination buffer
io.write("destination buffer: ");
for i=0,buf_size-1 do
io.write(tostring(DEV.read8(dst_addr + i)) .. " ")
end
io.write("\n")
io.write("status: " .. string.format("%#x", HW.DCP.CHnSTAT[0].read()) .. "\n")
if HW.DCP.CHnSTAT[0].ERROR_PAGEFAULT.read() == 1 then
io.write("-> page fault\n")
end
if HW.DCP.CHnSTAT[0].ERROR_PACKET.read() == 1 then
io.write("-> packet error\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment