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

Subversion Repositories nocmodel

[/] [nocmodel/] [trunk/] [nocmodel/] [noc_helpers.py] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dargor
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
#
5
# Helper functions for NoC Objects
6
#   Functions that easily construct predefined NoC structures and objects
7
#
8
# Author:  Oscar Diaz
9
# Version: 0.2
10
# Date:    14-03-2011
11
#
12
# This code is free software; you can redistribute it and/or
13
# modify it under the terms of the GNU Lesser General Public
14
# License as published by the Free Software Foundation; either
15
# version 2.1 of the License, or (at your option) any later version.
16
#
17
# This code is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
# Lesser General Public License for more details.
21
#
22
# You should have received a copy of the GNU Lesser General Public
23
# License along with this library; if not, write to the
24
# Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
25
# Boston, MA  02111-1307  USA
26
#
27
 
28
#
29
# Changelog:
30
#
31
# 14-03-2011 : (OD) initial release
32
#
33
 
34
import networkx as nx
35
from noc_base import *
36
 
37
def generate_squarenoc(orderx=3, ordery=None, with_ipcore=False):
38
    """
39
    NoC generator helper: generates a 2D grid NoC object
40
 
41
    Arguments
42
    * orderx: optional X-axis length of the grid. By default build a 3x3 square
43
      grid.
44
    * ordery: optional Y-axis length of the grid. By default build a square grid
45
      of order "orderx". This argument is used to build rectangular grids.
46
    * with_ipcore: If True, add ipcores to routers automatically.
47
    """
48
    if ordery == None:
49
        ordery = orderx
50
 
51
    # 1. generate a 2d grid
52
    basegrid = nx.grid_2d_graph(orderx, ordery)
53
 
54
    # 2. convert to a graph with ints as nodes
55
    convgrid = nx.Graph()
56
    for n in basegrid.nodes_iter():
57
        n2 = n[0] + n[1]*orderx
58
        convgrid.add_node(n2, coord_x=n[0], coord_y=n[1])
59
    for e in basegrid.edges_iter():
60
        e1 = e[0][0] + e[0][1]*orderx
61
        e2 = e[1][0] + e[1][1]*orderx
62
        convgrid.add_edge(e1, e2)
63
 
64
    nocbase = noc(name="NoC grid %dx%d" % (orderx, ordery), data=convgrid)
65
 
66
    # 2. for each node add router object
67
    for n in nocbase.nodes_iter():
68
        cx = nocbase.node[n]["coord_x"]
69
        cy = nocbase.node[n]["coord_y"]
70
        r = nocbase._add_router_from_node(n, coord_x=cx, coord_y=cy)
71
        if with_ipcore:
72
            nocbase.add_ipcore(r)
73
 
74
    # 3. for each edge add channel object
75
    for e in nocbase.edges_iter():
76
        nocbase._add_channel_from_edge(e)
77
 
78
    return nocbase

powered by: WebSVN 2.1.0

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