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

Subversion Repositories nocmodel

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dargor
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
4
#
5
# NoCmodel basic example
6
#
7
# Author:  Oscar Diaz
8
# Version: 0.1
9
# Date:    03-03-2011
10
 
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
# 03-03-2011 : (OD) initial release
32
#
33
 
34
import myhdl
35
import logging
36
 
37
from nocmodel import *
38
from nocmodel.basicmodels import *
39
 
40 4 dargor
# Basic example model with TBM simulation
41 2 dargor
 
42
# 1. Create the model
43
 
44
basicnoc = noc(name="Basic 2x2 NoC example")
45
 
46
# 1.1 create a rectangular 2x2 NoC, make its connections and add default protocol
47
 
48
R11 = basicnoc.add_router("R11", with_ipcore=True, coord_x = 1, coord_y = 1)
49
R12 = basicnoc.add_router("R12", with_ipcore=True, coord_x = 1, coord_y = 2)
50
R21 = basicnoc.add_router("R21", with_ipcore=True, coord_x = 2, coord_y = 1)
51
R22 = basicnoc.add_router("R22", with_ipcore=True, coord_x = 2, coord_y = 2)
52
 
53
basicnoc.add_channel(R11,R12)
54
basicnoc.add_channel(R11,R21)
55
basicnoc.add_channel(R12,R22)
56
basicnoc.add_channel(R21,R22)
57
 
58
basicnoc.protocol_ref = basic_protocol()
59
 
60
for r in basicnoc.router_list():
61
    r.update_ports_info()
62
    r.update_routes_info()
63
 
64 4 dargor
# 2. add tbm support, and configure logging
65
add_tbm_basic_support(basicnoc, log_file="simulation.log", log_level=logging.DEBUG)
66 2 dargor
 
67 4 dargor
# 3. Declare generators to put in the TBM simulation
68 2 dargor
 
69
# set ip_cores functionality as myhdl generators
70 4 dargor
def sourcegen(din, dout, tbm_ref, mydest, data=None, startdelay=100, period=100):
71 2 dargor
    # this generator only drives dout
72
    @myhdl.instance
73
    def putnewdata():
74
        datacount = 0
75 4 dargor
        protocol_ref = tbm_ref.ipcore_ref.get_protocol_ref()
76
        mysrc = tbm_ref.ipcore_ref.router_ref.address
77
        tbm_ref.debug("sourcegen: init dout is %s" % repr(dout.val))
78 2 dargor
        yield myhdl.delay(startdelay)
79
        while True:
80
            if len(data) == datacount:
81 4 dargor
                tbm_ref.debug("sourcegen: end of data. waiting for %d steps" % (period*10))
82 2 dargor
                yield myhdl.delay(period*10)
83
                raise myhdl.StopSimulation("data ended at time %d" % myhdl.now())
84
            dout.next = protocol_ref.newpacket(False, mysrc, mydest, data[datacount])
85 4 dargor
            tbm_ref.debug("sourcegen: data next element %d dout is %s datacount is %d" % (data[datacount], repr(dout.val), datacount))
86 2 dargor
            yield myhdl.delay(period)
87
            datacount += 1
88
    return putnewdata
89
 
90 4 dargor
def checkgen(din, dout, tbm_ref, mysrc, data=None):
91 2 dargor
    # this generator only respond to din
92
    @myhdl.instance
93
    def checkdata():
94
        datacount = 0
95 4 dargor
        protocol_ref = tbm_ref.ipcore_ref.get_protocol_ref()
96
        mydest = tbm_ref.ipcore_ref.router_ref.address
97 2 dargor
        while True:
98
            yield din
99
            if len(data) > datacount:
100
                checkdata = din.val["data"]
101 4 dargor
                tbm_ref.debug("checkgen: assert checkdata != data[datacount] => %d != %d [%d]" % (checkdata, data[datacount], datacount))
102 2 dargor
                if checkdata != data[datacount]:
103 4 dargor
                    tbm_ref.error("checkgen: value != %d (%d)" % (data[datacount], checkdata))
104
                tbm_ref.debug("checkgen: assert source address != mysrc => %d != %d " % (din.val["src"], mysrc))
105 2 dargor
                if din.val["src"] != mysrc:
106 4 dargor
                    tbm_ref.error("checkgen: source address != %d (%d)" % (mysrc, din.val["src"]))
107
                tbm_ref.debug("checkgen: assert destination address != mydest => %d != %d " % (din.val["dst"], mydest))
108 2 dargor
                if din.val["dst"] != mydest:
109 4 dargor
                    tbm_ref.error("checkgen: destination address != %d (%d)" % (mydest, din.val["dst"]))
110 2 dargor
                datacount += 1
111
    return checkdata
112
 
113
# 4. Set test vectors
114
R11_testdata = [5, 12, 50, -11, 6, 9, 0, 3, 25]
115
R12_testdata = [x*5 for x in R11_testdata]
116
 
117 4 dargor
# 5. assign generators to ip cores (in TBM model !)
118 2 dargor
# R11 will send to R22, R12 will send to R21
119 4 dargor
R11.ipcore_ref.tbm.register_generator(sourcegen, mydest=R22.address, data=R11_testdata, startdelay=10, period=20)
120
R12.ipcore_ref.tbm.register_generator(sourcegen, mydest=R21.address, data=R12_testdata, startdelay=15, period=25)
121
R21.ipcore_ref.tbm.register_generator(checkgen, mysrc=R12.address, data=R12_testdata)
122
R22.ipcore_ref.tbm.register_generator(checkgen, mysrc=R11.address, data=R11_testdata)
123 2 dargor
 
124
# 6. configure simulation and run!
125 4 dargor
basicnoc.tbmsim.configure_simulation(max_time=1000)
126 2 dargor
print "Starting simulation..."
127 4 dargor
basicnoc.tbmsim.run()
128 2 dargor
print "Simulation finished. Pick the results in log files."
129
 
130
# 7. View graphical representation
131
 
132
draw_noc(basicnoc)

powered by: WebSVN 2.1.0

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