new axi addr map class
[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 from spec import modules, specgen, dummytest
23
24
25 def printhelp():
26 print ('''pinmux_generator.py [-o outputdir] [-v|--validate] [-h|--help]
27 [-t outputtype] [-s|--spec spec]
28 -s | spec : generate from spec (python module)
29 -t | outputtype : outputtype, defaults to bsv
30 -o outputdir : defaults to bsv_src. also location for reading pinmux.txt
31 interfaces.txt and *.txt
32 -v | --validate : runs some validation on the pinmux
33 -h | --help : this help message
34 ''')
35
36
37 if __name__ == '__main__':
38 try:
39 options, remainder = getopt.getopt(
40 sys.argv[1:],
41 'o:vht:s:',
42 ['output=',
43 'validate',
44 'test',
45 'outputtype=',
46 'spec=',
47 'help',
48 'version=',
49 ])
50 except getopt.GetoptError as err:
51 print ("ERROR: %s" % str(err))
52 printhelp()
53 sys.exit(1)
54
55 output_type = 'bsv'
56 output_dir = None
57 validate = False
58 spec = None
59 pinspec = None
60 testing = False
61 for opt, arg in options:
62 if opt in ('-o', '--output'):
63 output_dir = arg
64 elif opt in ('-s', '--spec'):
65 pinspec = arg
66 elif opt in ('-t', '--outputtype'):
67 output_type = arg
68 elif opt in ('-v', '--validate'):
69 validate = True
70 elif opt in ('--test',):
71 testing = True
72 elif opt in ('-h', '--help'):
73 printhelp()
74 sys.exit(0)
75
76 if pinspec:
77 if pinspec not in modules:
78 print ("ERROR: spec type '%s' does not exist" % pinspec)
79 printhelp()
80 sys.exit(1)
81 module = modules[pinspec]
82
83 fname = os.path.join(output_dir or '', "%s.mdwn" % pinspec)
84 d = os.path.split(fname)[0]
85 if not os.path.exists(d):
86 os.makedirs(d)
87 with open(fname, "w") as of:
88 ps = module.pinspec()
89 pinout, bankspec, pinspec, fixedpins = ps.write(of)
90 if testing:
91 dummytest(ps, output_dir, output_type)
92 else:
93 specgen(of, output_dir, pinout,
94 bankspec, ps.muxwidths, pinspec, fixedpins, ps.fastbus)
95 else:
96 if output_type == 'bsv':
97 from bsv.pinmux_generator import pinmuxgen as gentypes
98 elif output_type == 'myhdl':
99 from myhdlgen.pinmux_generator import pinmuxgen as gentypes
100 else:
101 print ("ERROR: output type '%s' does not exist" % output_type)
102 printhelp()
103 sys.exit(0)
104
105 gentypes(output_dir, validate)