add spec generation
[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
23
24 from bsv.pinmux_generator import pinmuxgen as bsvgen
25
26
27 def printhelp():
28 print ('''pinmux_generator.py [-o outputdir] [-v|--validate] [-h|--help]
29 [-t outputtype]
30 -t | outputtype : outputtype, defaults to bsv
31 -o outputdir : defaults to bsv_src. also location for reading pinmux.txt
32 interfaces.txt and *.txt
33 -v | --validate : runs some validation on the pinmux
34 -h | --help : this help message
35 ''')
36
37
38 if __name__ == '__main__':
39 try:
40 options, remainder = getopt.getopt(
41 sys.argv[1:],
42 'o:vht:s:',
43 ['output=',
44 'validate',
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 for opt, arg in options:
60 if opt in ('-o', '--output'):
61 output_dir = arg
62 elif opt in ('-s', '--spec'):
63 pinspec = arg
64 elif opt in ('-t', '--outputtype'):
65 output_type = arg
66 elif opt in ('-v', '--validate'):
67 validate = True
68 elif opt in ('-h', '--help'):
69 printhelp()
70 sys.exit(0)
71
72 if pinspec:
73 if not modules.has_key(pinspec):
74 print "ERROR: spec type '%s' does not exist" % pinspec
75 printhelp()
76 sys.exit(1)
77 module = modules[pinspec]
78 pinout, bankspec, fixedpins = module.pinspec()
79 specgen(output_dir, pinout, bankspec, fixedpins)
80 else:
81 gentypes = {'bsv': bsvgen}
82 if not gentypes.has_key(output_type):
83 print "ERROR: output type '%s' does not exist" % output_type
84 printhelp()
85 sys.exit(0)
86 gentypes[output_type](output_dir, validate)