OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [trunk/] [scripts/] [rgen.py] - Blame information for rev 106

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 64 ghutchis
#!/usr/bin/python
2
# Copyright (c) 2004 Guy Hutchison (ghutchis@opencores.org)
3
#
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the "Software"),
6
# to deal in the Software without restriction, including without limitation
7
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
# and/or sell copies of the Software, and to permit persons to whom the
9
# Software is furnished to do so, subject to the following conditions:
10
#
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
13
#
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
 
22
# This script generates I/O mapped control and status registers based
23
# on an XML configuration file.
24
 
25
import reglib
26
import xml.dom.minidom
27
import sys, os, re
28
 
29
def node_info (node):
30
    print "Methods:",dir(node)
31
    print "Child Nodes:",node.childNodes
32
 
33
def create_reg_group (node):
34
    rg = reglib.register_group()
35
 
36
    rg.name = node.getAttribute ("name")
37 67 ghutchis
    rg.addr_size = reglib.number(node.getAttribute ("addr_sz"))
38
    rg.base_addr = reglib.number(node.getAttribute ("base_addr"))
39 64 ghutchis
 
40
    return rg
41
 
42
def create_register (rg, node):
43
    params = {}
44
    params['name'] = node.getAttribute ("name")
45
    type = node.getAttribute ("type")
46
    params['width'] = int(node.getAttribute ("width"))
47
    params['default'] = node.getAttribute ("default")
48 67 ghutchis
    params['int_value'] = node.getAttribute ("int_value")
49 64 ghutchis
 
50 67 ghutchis
    # May switch to this code later for a more general implementation
51
    #for anode in node.childNodes:
52
    #    if anode.nodeType = anode.ATTRIBUTE_NODE:
53
    #        params[anode.nodeName] = anode.nodeValue
54
 
55 64 ghutchis
    if type == '': type = 'config'
56
    if params['default'] == '': params['default'] = 0
57 67 ghutchis
    else: params['default'] = reglib.number (params['default'])
58 64 ghutchis
 
59
    rg.add_register (type, params)
60
 
61
def create_verilog (top_node):
62
    rg = create_reg_group (top_node)
63
 
64
    # get list of register nodes
65
    reg_nodes = top_node.getElementsByTagName ("register")
66
 
67
    for r in reg_nodes:
68
        create_register (rg, r)
69
 
70
    fname = rg.name + ".v"
71
    fh = open (fname, 'w')
72
    fh.write (rg.verilog())
73
    fh.close()
74
 
75
def parse_file (filename):
76
    rdoc = xml.dom.minidom.parse (filename)
77
    blk_list = rdoc.getElementsByTagName ("tv_registers")
78
 
79
    for blk in blk_list:
80
        create_verilog (blk)
81
 
82
    rdoc.unlink()
83
 
84
if (len (sys.argv) > 1):
85
    parse_file (sys.argv[1])
86
else:
87
    print "Usage: %s <filename>" % os.path.basename (sys.argv[0])
88
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.