-
Notifications
You must be signed in to change notification settings - Fork 9
/
netv2_pcie.py
executable file
·79 lines (60 loc) · 2.42 KB
/
netv2_pcie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
from netv2_base import *
from litepcie.phy.s7pciephy import S7PCIEPHY
from litepcie.core import LitePCIeEndpoint, LitePCIeMSI
from litepcie.frontend.dma import LitePCIeDMA
from litepcie.frontend.wishbone import LitePCIeWishboneBridge
from litex.build.tools import write_to_file
import cpu_interface
class PCIeDMASoC(BaseSoC):
csr_map = {
"pcie_phy": 20,
"dma": 21,
"msi": 22,
}
csr_map.update(BaseSoC.csr_map)
interrupt_map = {
"dma_writer": 0,
"dma_reader": 1,
}
interrupt_map.update(BaseSoC.interrupt_map)
BaseSoC.mem_map["csr"] = 0x00000000
BaseSoC.mem_map["rom"] = 0x20000000
def __init__(self, platform, **kwargs):
BaseSoC.__init__(self, platform, **kwargs)
# pcie phy
self.submodules.pcie_phy = S7PCIEPHY(platform, link_width=1, cd="sys")
# pcie endpoint
self.submodules.pcie_endpoint = LitePCIeEndpoint(self.pcie_phy, with_reordering=True)
# pcie wishbone bridge
self.submodules.pcie_wishbone = LitePCIeWishboneBridge(self.pcie_endpoint, lambda a: 1)
self.add_wb_master(self.pcie_wishbone.wishbone)
# pcie dma
self.submodules.dma = LitePCIeDMA(self.pcie_phy, self.pcie_endpoint, with_loopback=True)
self.dma.source.connect(self.dma.sink)
# pcie msi
self.submodules.msi = LitePCIeMSI()
self.comb += self.msi.source.connect(self.pcie_phy.interrupt)
self.interrupts = {
"dma_writer": self.dma.writer.irq,
"dma_reader": self.dma.reader.irq
}
for k, v in sorted(self.interrupts.items()):
self.comb += self.msi.irqs[self.interrupt_map[k]].eq(v)
# flash the led on pcie clock
counter = Signal(32)
self.sync.clk125 += counter.eq(counter + 1)
self.comb += platform.request("user_led", 0).eq(counter[26])
def main():
parser = argparse.ArgumentParser(description="NeTV2 LiteX PCIe SoC")
builder_args(parser)
soc_sdram_args(parser)
args = parser.parse_args()
platform = netv2.Platform()
soc = PCIeDMASoC(platform, **soc_sdram_argdict(args))
builder = Builder(soc, output_dir="build")
vns = builder.build()
csr_header = cpu_interface.get_csr_header(soc.get_csr_regions(), soc.get_constants())
write_to_file(os.path.join("software", "pcie", "kernel", "csr.h"), csr_header)
if __name__ == "__main__":
main()