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