forked from olofk/ipyxact
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipxactwriter.py
140 lines (111 loc) · 4.03 KB
/
ipxactwriter.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import sys
import ipyxact.ipyxact as ipyxact
class Signal(object):
def __init__(self, name, width=0, low=0, asc=False):
self.name = name
self.width=width
self.low = low
self.asc = asc
class Vector(ipyxact.Vector):
def __init__(self, width=0, low=0, asc=False):
if asc:
self.left = low
self.right = low+width-1
else:
self.left = low+width-1
self.right = low
class Port(ipyxact.Port):
def __init__(self, name, direction, width=0, low=0, asc=False):
self.name = name
self.wire = ipyxact.Wire()
self.wire.direction = direction
if width > 0:
self.wire.vector = Vector(width, low, asc)
class WBBusInterface(ipyxact.BusInterface):
def __init__(self, name, mode):
super(WBBusInterface, self).__init__()
self.name = name
if mode == 'master':
self.master = ''
self.mdir = 'o'
self.sdir = 'i'
else:
self.slave = ''
self.mdir = 'i'
self.sdir = 'o'
abstractionType = ipyxact.AbstractionType()
abstractionType.vendor = "org.opencores"
abstractionType.library = "wishbone"
abstractionType.name = "wishbone.absDef"
abstractionType.version = "b3"
self.abstractionType = abstractionType
busType = ipyxact.BusType()
busType.vendor = "org.opencores"
busType.library = "wishbone"
busType.name = "wishbone"
busType.version = "b3"
self.busType = busType
self.portMaps = ipyxact.PortMaps()
def connect(self, prefix):
for p in WB_MASTER_PORTS:
portMap = ipyxact.PortMap()
physicalPort = ipyxact.PhysicalPort()
physicalPort.name = "{}_{}_i".format(prefix, p.name)
if p.width > 0:
physicalPort.vector = Vector(p.width)
portMap.physicalPort = physicalPort
logicalPort = ipyxact.LogicalPort()
logicalPort.name = "{}_o".format(p.name)
if p.width > 0:
logicalPort.vector = Vector(p.width)
portMap.logicalPort = logicalPort
busif.portMaps.portMap.append(portMap)
for p in WB_SLAVE_PORTS:
portMap = ipyxact.PortMap()
physicalPort = ipyxact.PhysicalPort()
physicalPort.name = "{}_{}_o".format(prefix, p.name)
if p.width > 0:
physicalPort.vector = Vector(p.width)
portMap.physicalPort = physicalPort
logicalPort = ipyxact.LogicalPort()
logicalPort.name = "{}_i".format(p.name)
if p.width > 0:
logicalPort.vector = Vector(p.width)
portMap.logicalPort = logicalPort
busif.portMaps.portMap.append(portMap)
WB_MASTER_PORTS = [Signal('adr', 32),
Signal('dat', 32),
Signal('sel', 4),
Signal('we'),
Signal('cyc'),
Signal('stb'),
Signal('cti', 3),
Signal('bte', 2)]
WB_SLAVE_PORTS = [Signal('dat', 32),
Signal('ack'),
Signal('err'),
Signal('rty')]
component = ipyxact.Component()
component.version = '1.5'
component.vendor = 'opencores'
component.library = 'ip'
component.name = 'autointercon'
component.version = '0'
component.model = ipyxact.Model()
ports = ipyxact.Ports()
clk = Port('wb_clk_i', 'in')
rst = Port('wb_rst_i', 'in')
ports.port.append(clk)
ports.port.append(rst)
for p in WB_MASTER_PORTS:
mp = Port('wbs_ram_{}_i'.format(p.name), 'in', p.width)
ports.port.append(mp)
for p in WB_SLAVE_PORTS:
mp = Port('wbs_ram_{}_o'.format(p.name), 'out', p.width)
ports.port.append(mp)
component.model.ports = ports
component.busInterfaces = ipyxact.BusInterfaces()
busif = WBBusInterface("wb", "mirroredMaster")
busif.connect("wbs_ram")
component.busInterfaces.busInterface.append(busif)
component.write(sys.argv[1])