a5e381adbd7143c9987d1c564090be5da355b720
[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
23 from bsv.pinmux_generator import pinmuxgen as bsvgen
24
25
26 def printhelp():
27 print ('''pinmux_generator.py [-o outputdir] [-v|--validate] [-h|--help]
28 [-t outputtype]
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:',
42 ['output=',
43 'validate',
44 'outputtype=',
45 'help',
46 'version=',
47 ])
48 except getopt.GetoptError as err:
49 print "ERROR: %s" % str(err)
50 printhelp()
51 sys.exit(1)
52
53 output_type = 'bsv'
54 output_dir = None
55 validate = False
56 for opt, arg in options:
57 if opt in ('-o', '--output'):
58 output_dir = arg
59 elif opt in ('-t', '--outputtype'):
60 output_type = arg
61 elif opt in ('-v', '--validate'):
62 validate = True
63 elif opt in ('-h', '--help'):
64 printhelp()
65 sys.exit(0)
66
67 gentypes = {'bsv': bsvgen}
68 if not gentypes.has_key(output_type):
69 print "ERROR: output type '%s' does not exist" % output_type
70 printhelp()
71 sys.exit(0)
72 gentypes[output_type](output_dir, validate)