Added ls2 svg, added rgmii to N bank
[pinmux.git] / src / pinmux_generator.py
1 # ================================== Steps to add peripherals ============
2 # Step-1: create interface declaration for the peripheral to be added.
3 # Remember these are interfaces defined for the pinmux and hence
4 # will be opposite to those defined at the peripheral.
5 # For eg. the output TX from the UART will be input (method Action)
6 # for the pinmux.
7 # These changes will have to be done in interface_decl.py
8 # Step-2 define the wires that will be required to transfer data from the
9 # peripheral interface to the IO cell and vice-versa. Create a
10 # mkDWire for each input/output between the peripheral and the
11 # pinmux. Also create an implicit wire of GenericIOType for each cell
12 # that can be connected to a each bit from the peripheral.
13 # These changes will have to be done in wire_def.py
14 # Step-3: create the definitions for each of the methods defined above.
15 # These changes will have to be done in interface_decl.py
16 # ========================================================================
17
18 # default module imports
19 import getopt
20 import os.path
21 import sys
22 import json
23 from spec import modules, specgen, dummytest
24 from spec.ifaceprint import create_sv, temp_create_sv
25 import jsoncreate
26
27 def printhelp():
28 print ('''pinmux_generator.py [-o outputdir] [-v|--validate] [-h|--help]
29 [-t outputtype] [-s|--spec spec]
30 -s | spec : generate from spec (python module)
31 -t | outputtype : outputtype, defaults to bsv
32 -o outputdir : defaults to bsv_src. also location for reading pinmux.txt
33 interfaces.txt and *.txt
34 -v | --validate : runs some validation on the pinmux
35 -h | --help : this help message
36 ''')
37
38
39 if __name__ == '__main__':
40 try:
41 options, remainder = getopt.getopt(
42 sys.argv[1:],
43 'o:vht:s:',
44 ['output=',
45 'validate',
46 'test',
47 'outputtype=',
48 'spec=',
49 'help',
50 'version=',
51 ])
52 except getopt.GetoptError as err:
53 print ("ERROR: %s" % str(err))
54 printhelp()
55 sys.exit(1)
56
57 output_type = 'bsv'
58 output_dir = None
59 validate = False
60 spec = None
61 pinspec = None
62 testing = False
63 for opt, arg in options:
64 if opt in ('-o', '--output'):
65 output_dir = arg
66 elif opt in ('-s', '--spec'):
67 pinspec = arg
68 elif opt in ('-t', '--outputtype'):
69 output_type = arg
70 elif opt in ('-v', '--validate'):
71 validate = True
72 elif opt in ('--test',):
73 testing = True
74 elif opt in ('-h', '--help'):
75 printhelp()
76 sys.exit(0)
77
78 if pinspec:
79 if pinspec not in modules:
80 print ("ERROR: spec type '%s' does not exist" % pinspec)
81 printhelp()
82 sys.exit(1)
83 module = modules[pinspec]
84
85 fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec)
86 pyname = os.path.join(output_dir or '', "%s_pins.py" % pinspec)
87 d = os.path.split(fname)[0]
88 if not os.path.exists(d):
89 os.makedirs(d)
90 with open(fname, "w") as of:
91 with open(pyname, "w") as pyf:
92 ps = module.pinspec()
93 pinout, bankspec, pin_spec, fixedpins = ps.write(of)
94 #chip['litex.map'] = litexmap
95 if testing:
96 dummytest(ps, output_dir, output_type)
97 else:
98 specgen(of, output_dir, pinout,
99 bankspec, ps.muxwidths, pin_spec, fixedpins,
100 ps.fastbus)
101 pm, chip = jsoncreate.pinparse(ps, pinspec)
102 litexmap = ps.pywrite(pyf, pm)
103 jchip = json.dumps(chip)
104 with open("%s/litex_pinpads.json" % pinspec, "w") as f:
105 f.write(jchip)
106 # octavius: please keep line-lengths to below 80 chars
107 # TODO: fix create_sv to allow different packages
108 # (and die images)
109 # Test with different package size, once working
110 # 'create_sv' will be improved
111 if pinspec == "ngi_router":
112 temp_create_sv("%s/%s.svg" % (pinspec, pinspec), chip)
113 if pinspec == "ls180":
114 create_sv("%s/%s.svg" % (pinspec, pinspec), chip)
115 if pinspec == "ls2":
116 create_sv("%s/%s.svg" % (pinspec, pinspec), chip)
117 else:
118 if output_type == 'bsv':
119 from bsv.pinmux_generator import pinmuxgen as gentypes
120 elif output_type == 'myhdl':
121 from myhdlgen.pinmux_generator import pinmuxgen as gentypes
122 else:
123 print ("ERROR: output type '%s' does not exist" % output_type)
124 printhelp()
125 sys.exit(0)
126
127 gentypes(output_dir, validate)