#!/usr/bin/env python
|
#!/usr/bin/env python
|
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
|
|
#
|
#
|
# NoCmodel basic example
|
# NoCmodel basic example
|
#
|
#
|
# Author: Oscar Diaz
|
# Author: Oscar Diaz
|
# Version: 0.1
|
# Version: 0.1
|
# Date: 03-03-2011
|
# Date: 03-03-2011
|
|
|
#
|
#
|
# This code is free software; you can redistribute it and/or
|
# This code is free software; you can redistribute it and/or
|
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
#
|
#
|
# This code is distributed in the hope that it will be useful,
|
# This code is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
# License along with this library; if not, write to the
|
# License along with this library; if not, write to the
|
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
# Boston, MA 02111-1307 USA
|
# Boston, MA 02111-1307 USA
|
#
|
#
|
|
|
#
|
#
|
# Changelog:
|
# Changelog:
|
#
|
#
|
# 03-03-2011 : (OD) initial release
|
# 03-03-2011 : (OD) initial release
|
#
|
#
|
|
|
import matplotlib.pyplot as plt
|
|
import myhdl
|
import myhdl
|
import logging
|
import logging
|
|
|
from nocmodel import *
|
from nocmodel import *
|
from nocmodel.basicmodels import *
|
from nocmodel.basicmodels import *
|
|
|
# Basic example model with TLM simulation
|
# Basic example model with TLM simulation
|
|
|
# 1. Create the model
|
# 1. Create the model
|
|
|
basicnoc = noc(name="Basic 2x2 NoC example")
|
basicnoc = noc(name="Basic 2x2 NoC example")
|
|
|
# 1.1 create a rectangular 2x2 NoC, make its connections and add default protocol
|
# 1.1 create a rectangular 2x2 NoC, make its connections and add default protocol
|
|
|
R11 = basicnoc.add_router("R11", with_ipcore=True, coord_x = 1, coord_y = 1)
|
R11 = basicnoc.add_router("R11", with_ipcore=True, coord_x = 1, coord_y = 1)
|
R12 = basicnoc.add_router("R12", with_ipcore=True, coord_x = 1, coord_y = 2)
|
R12 = basicnoc.add_router("R12", with_ipcore=True, coord_x = 1, coord_y = 2)
|
R21 = basicnoc.add_router("R21", with_ipcore=True, coord_x = 2, coord_y = 1)
|
R21 = basicnoc.add_router("R21", with_ipcore=True, coord_x = 2, coord_y = 1)
|
R22 = basicnoc.add_router("R22", with_ipcore=True, coord_x = 2, coord_y = 2)
|
R22 = basicnoc.add_router("R22", with_ipcore=True, coord_x = 2, coord_y = 2)
|
|
|
basicnoc.add_channel(R11,R12)
|
basicnoc.add_channel(R11,R12)
|
basicnoc.add_channel(R11,R21)
|
basicnoc.add_channel(R11,R21)
|
basicnoc.add_channel(R12,R22)
|
basicnoc.add_channel(R12,R22)
|
basicnoc.add_channel(R21,R22)
|
basicnoc.add_channel(R21,R22)
|
|
|
basicnoc.protocol_ref = basic_protocol()
|
basicnoc.protocol_ref = basic_protocol()
|
|
|
for r in basicnoc.router_list():
|
for r in basicnoc.router_list():
|
r.update_ports_info()
|
r.update_ports_info()
|
r.update_routes_info()
|
r.update_routes_info()
|
|
|
# 2. add tlm support, and configure logging
|
# 2. add tlm support, and configure logging
|
add_tlm_basic_support(basicnoc, log_file="simulation.log", log_level=logging.DEBUG)
|
add_tlm_basic_support(basicnoc, log_file="simulation.log", log_level=logging.DEBUG)
|
|
|
# 3. Declare generators to put in the TLM simulation
|
# 3. Declare generators to put in the TLM simulation
|
|
|
# set ip_cores functionality as myhdl generators
|
# set ip_cores functionality as myhdl generators
|
def sourcegen(din, dout, tlm_ref, mydest, data=None, startdelay=100, period=100):
|
def sourcegen(din, dout, tlm_ref, mydest, data=None, startdelay=100, period=100):
|
# this generator only drives dout
|
# this generator only drives dout
|
@myhdl.instance
|
@myhdl.instance
|
def putnewdata():
|
def putnewdata():
|
datacount = 0
|
datacount = 0
|
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref()
|
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref()
|
mysrc = tlm_ref.ipcore_ref.router_ref.address
|
mysrc = tlm_ref.ipcore_ref.router_ref.address
|
tlm_ref.debug("sourcegen: init dout is %s" % repr(dout.val))
|
tlm_ref.debug("sourcegen: init dout is %s" % repr(dout.val))
|
yield myhdl.delay(startdelay)
|
yield myhdl.delay(startdelay)
|
while True:
|
while True:
|
if len(data) == datacount:
|
if len(data) == datacount:
|
tlm_ref.debug("sourcegen: end of data. waiting for %d steps" % (period*10))
|
tlm_ref.debug("sourcegen: end of data. waiting for %d steps" % (period*10))
|
yield myhdl.delay(period*10)
|
yield myhdl.delay(period*10)
|
raise myhdl.StopSimulation("data ended at time %d" % myhdl.now())
|
raise myhdl.StopSimulation("data ended at time %d" % myhdl.now())
|
dout.next = protocol_ref.newpacket(False, mysrc, mydest, data[datacount])
|
dout.next = protocol_ref.newpacket(False, mysrc, mydest, data[datacount])
|
tlm_ref.debug("sourcegen: data next element %d dout is %s datacount is %d" % (data[datacount], repr(dout.val), datacount))
|
tlm_ref.debug("sourcegen: data next element %d dout is %s datacount is %d" % (data[datacount], repr(dout.val), datacount))
|
yield myhdl.delay(period)
|
yield myhdl.delay(period)
|
datacount += 1
|
datacount += 1
|
return putnewdata
|
return putnewdata
|
|
|
def checkgen(din, dout, tlm_ref, mysrc, data=None):
|
def checkgen(din, dout, tlm_ref, mysrc, data=None):
|
# this generator only respond to din
|
# this generator only respond to din
|
@myhdl.instance
|
@myhdl.instance
|
def checkdata():
|
def checkdata():
|
datacount = 0
|
datacount = 0
|
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref()
|
protocol_ref = tlm_ref.ipcore_ref.get_protocol_ref()
|
mydest = tlm_ref.ipcore_ref.router_ref.address
|
mydest = tlm_ref.ipcore_ref.router_ref.address
|
while True:
|
while True:
|
yield din
|
yield din
|
if len(data) > datacount:
|
if len(data) > datacount:
|
checkdata = din.val["data"]
|
checkdata = din.val["data"]
|
tlm_ref.debug("checkgen: assert checkdata != data[datacount] => %d != %d [%d]" % (checkdata, data[datacount], datacount))
|
tlm_ref.debug("checkgen: assert checkdata != data[datacount] => %d != %d [%d]" % (checkdata, data[datacount], datacount))
|
if checkdata != data[datacount]:
|
if checkdata != data[datacount]:
|
tlm_ref.error("checkgen: value != %d (%d)" % (data[datacount], checkdata))
|
tlm_ref.error("checkgen: value != %d (%d)" % (data[datacount], checkdata))
|
tlm_ref.debug("checkgen: assert source address != mysrc => %d != %d " % (din.val["src"], mysrc))
|
tlm_ref.debug("checkgen: assert source address != mysrc => %d != %d " % (din.val["src"], mysrc))
|
if din.val["src"] != mysrc:
|
if din.val["src"] != mysrc:
|
tlm_ref.error("checkgen: source address != %d (%d)" % (mysrc, din.val["src"]))
|
tlm_ref.error("checkgen: source address != %d (%d)" % (mysrc, din.val["src"]))
|
tlm_ref.debug("checkgen: assert destination address != mydest => %d != %d " % (din.val["dst"], mydest))
|
tlm_ref.debug("checkgen: assert destination address != mydest => %d != %d " % (din.val["dst"], mydest))
|
if din.val["dst"] != mydest:
|
if din.val["dst"] != mydest:
|
tlm_ref.error("checkgen: destination address != %d (%d)" % (mydest, din.val["dst"]))
|
tlm_ref.error("checkgen: destination address != %d (%d)" % (mydest, din.val["dst"]))
|
datacount += 1
|
datacount += 1
|
return checkdata
|
return checkdata
|
|
|
# 4. Set test vectors
|
# 4. Set test vectors
|
R11_testdata = [5, 12, 50, -11, 6, 9, 0, 3, 25]
|
R11_testdata = [5, 12, 50, -11, 6, 9, 0, 3, 25]
|
R12_testdata = [x*5 for x in R11_testdata]
|
R12_testdata = [x*5 for x in R11_testdata]
|
|
|
# 5. assign generators to ip cores (in TLM model !)
|
# 5. assign generators to ip cores (in TLM model !)
|
# R11 will send to R22, R12 will send to R21
|
# R11 will send to R22, R12 will send to R21
|
R11.ipcore_ref.tlm.register_generator(sourcegen, mydest=R22.address, data=R11_testdata, startdelay=10, period=20)
|
R11.ipcore_ref.tlm.register_generator(sourcegen, mydest=R22.address, data=R11_testdata, startdelay=10, period=20)
|
R12.ipcore_ref.tlm.register_generator(sourcegen, mydest=R21.address, data=R12_testdata, startdelay=15, period=25)
|
R12.ipcore_ref.tlm.register_generator(sourcegen, mydest=R21.address, data=R12_testdata, startdelay=15, period=25)
|
R21.ipcore_ref.tlm.register_generator(checkgen, mysrc=R12.address, data=R12_testdata)
|
R21.ipcore_ref.tlm.register_generator(checkgen, mysrc=R12.address, data=R12_testdata)
|
R22.ipcore_ref.tlm.register_generator(checkgen, mysrc=R11.address, data=R11_testdata)
|
R22.ipcore_ref.tlm.register_generator(checkgen, mysrc=R11.address, data=R11_testdata)
|
|
|
# 6. configure simulation and run!
|
# 6. configure simulation and run!
|
basicnoc.tlmsim.configure_simulation(max_time=1000)
|
basicnoc.tlmsim.configure_simulation(max_time=1000)
|
print "Starting simulation..."
|
print "Starting simulation..."
|
basicnoc.tlmsim.run()
|
basicnoc.tlmsim.run()
|
print "Simulation finished. Pick the results in log files."
|
print "Simulation finished. Pick the results in log files."
|
|
|
# 7. View graphical representation
|
# 7. View graphical representation
|
|
|
draw_noc(basicnoc)
|
draw_noc(basicnoc)
|
|
|