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

Subversion Repositories nocmodel

[/] [nocmodel/] [trunk/] [nocmodel/] [basicmodels/] [basic_channel.py] - Diff between revs 2 and 4

Show entire file | Details | Blame | View Log

Rev 2 Rev 4
Line 1... Line 1...
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
 
 
#
#
# Basic Channel model
# Basic Channel model
#  * TLM model
#  * TBM model
#
#
# Author:  Oscar Diaz
# Author:  Oscar Diaz
# Version: 0.1
# Version: 0.1
# Date:    03-03-2011
# Date:    03-03-2011
 
 
Line 31... Line 31...
#
#
# 03-03-2011 : (OD) initial release
# 03-03-2011 : (OD) initial release
#
#
 
 
"""
"""
Basic channel TLM model
Basic channel TBM model
"""
"""
 
 
from nocmodel.noc_tlm_base import *
from nocmodel.noc_tbm_base import *
 
 
# ---------------------------
# ---------------------------
# Channel TLM model
# Channel TBM model
 
 
class basic_channel_tlm(noc_tlm_base):
class basic_channel_tbm(noc_tbm_base):
    """
    """
    TLM model of a NoC channel. It models a simple FIFO channel with
    TBM model of a NoC channel. It models a simple FIFO channel with
    adjustable delay. This channel will move any kind of data as a whole, but
    adjustable delay. This channel will move any kind of data as a whole, but
    ideally will move packet objects.
    ideally will move packet objects.
 
 
    Attributes:
    Attributes:
    * Channel delay: delay in clock ticks.
    * Channel delay: delay in clock ticks.
 
 
    Notes:
    Notes:
    *This model is completely behavioral
    *This model is completely behavioral
    """
    """
    def __init__(self, channel_ref, channel_delay=1):
    def __init__(self, channel_ref, channel_delay=2):
        noc_tlm_base.__init__(self)
        noc_tbm_base.__init__(self)
        if isinstance(channel_ref, channel):
        if isinstance(channel_ref, channel):
            self.channel_ref = channel_ref
            self.channel_ref = channel_ref
            self.graph_ref = channel_ref.graph_ref
            self.graph_ref = channel_ref.graph_ref
            self.logname = "Channel '%s'" % channel_ref.name
            self.logname = "Channel '%s'" % channel_ref.name
        else:
        else:
Line 75... Line 75...
 
 
        self.has_delay = False
        self.has_delay = False
        if self.channel_delay > 0:
        if self.channel_delay > 0:
            self.has_delay = True
            self.has_delay = True
            self.delay_fifo = []
            self.delay_fifo = []
            self.delay_fifo_max = 10 # error-catch parameter, avoid fifo excessive growing
            self.delay_fifo_max = 4 # error-catch parameter, avoid fifo excessive growing
            self.delay_event = myhdl.Signal(False)
            self.delay_event = myhdl.Signal(False)
            # implement delay generator
            # implement delay generator
            @myhdl.instance
            @myhdl.instance
            def delay_generator():
            def delay_generator():
                while True:
                while True:
                    while len(self.delay_fifo) > 0:
                    while len(self.delay_fifo) > 0:
                        # extract packet and recorded time
                        # extract packet and recorded time
                        timed_packet = self.delay_fifo.pop(0)
                        timed_packet = self.delay_fifo.pop(0)
                        # calculate the exact delay value
                        # calculate the exact delay value
                        next_delay = self.channel_delay - (myhdl.now() - timed_packet[0])
                        next_delay = self.channel_delay - (myhdl.now() - timed_packet[0])
                        if next_delay <= 0:
                        # time could be 0, when the packets arrive from both endpoints
 
                        # at the same time. In that case don't yield
 
                        if next_delay < 0:
                            self.debug("delay_generator CATCH next_delay is '%d'" % next_delay)
                            self.debug("delay_generator CATCH next_delay is '%d'" % next_delay)
                        else:
                        elif next_delay > 0:
                            yield myhdl.delay(next_delay)
                            yield myhdl.delay(next_delay)
                        self.debug("delay_generator sending delayed packet (by %d), timed_packet format %s" % (next_delay, repr(timed_packet)) )
                        self.debug("delay_generator sending delayed packet (by %d), timed_packet format %s" % (next_delay, repr(timed_packet)) )
                        # use send()
                        # use send()
                        retval = self.send(*timed_packet[1:])
                        retval = self.send(*timed_packet[1:])
                        # what to do in error case? report and continue
                        # what to do in error case? report and continue
                        if retval != noc_tlm_errcodes.no_error:
                        if retval != noc_tbm_errcodes.no_error:
                            self.error("delay_generator send returns code '%d'?" % retval )
                            self.error("delay_generator send returns code '%d'?" % retval )
                    self.delay_event.next = False
                    self.delay_event.next = False
                    yield self.delay_event
                    yield self.delay_event.posedge
            self.generators.append(delay_generator)
            self.generators.append(delay_generator)
 
 
        self.debugstate()
        self.debugstate()
 
 
    # channel only relays transactions
    # channel only relays transactions
Line 116... Line 118...
        if isinstance(dest, int):
        if isinstance(dest, int):
            # assume router direction
            # assume router direction
            thedest = self.graph_ref.get_router_by_address(dest)
            thedest = self.graph_ref.get_router_by_address(dest)
            if thedest == False:
            if thedest == False:
                self.error("-> send: dest %s not found" % repr(dest) )
                self.error("-> send: dest %s not found" % repr(dest) )
                return noc_tlm_errcodes.tlm_badcall_send
                return noc_tbm_errcodes.tbm_badcall_send
        elif isinstance(dest, (router, ipcore)):
        elif isinstance(dest, (router, ipcore)):
            thedest = dest
            thedest = dest
        else:
        else:
            self.error("-> send: what is dest '%s'?" % repr(dest) )
            self.error("-> send: what is dest '%s'?" % repr(dest) )
            return noc_tlm_errcodes.tlm_badcall_send
            return noc_tbm_errcodes.tbm_badcall_send
 
 
        # check dest as one of the channel endpoints
        # check dest as one of the channel endpoints
        if thedest not in self.endpoints:
        if thedest not in self.endpoints:
            self.error("-> send: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thedest), repr(self.endpoints[0]), repr(self.endpoints[1])) )
            self.error("-> send: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thedest), repr(self.endpoints[0]), repr(self.endpoints[1])) )
            return noc_tlm_errcodes.tlm_badcall_send
            return noc_tbm_errcodes.tbm_badcall_send
 
 
 
        # call trace functions
 
        traceargs = {"self": self, "src": src, "dest": dest, "packet": packet, "addattrs": addattrs}
 
        for f in self.tracesend:
 
            if callable(f):
 
                f(traceargs)
 
 
        # call recv on the dest object
        # call recv on the dest object
        retval = thedest.tlm.recv(self.channel_ref, dest, packet, addattrs)
        retval = thedest.tbm.recv(self.channel_ref, dest, packet, addattrs)
 
 
        # Something to do with the retval? Only report it.
        # Something to do with the retval? Only report it.
        self.debug("-> send returns code '%s'" % repr(retval))
        self.debug("-> send returns code '%s'" % repr(retval))
        return retval
        return retval
 
 
Line 148... Line 156...
        if isinstance(src, int):
        if isinstance(src, int):
            # assume router direction
            # assume router direction
            thesrc = self.graph_ref.get_router_by_address(src)
            thesrc = self.graph_ref.get_router_by_address(src)
            if thesrc == False:
            if thesrc == False:
                self.error("-> recv: src %s not found" % repr(src) )
                self.error("-> recv: src %s not found" % repr(src) )
                return noc_tlm_errcodes.tlm_badcall_recv
                return noc_tbm_errcodes.tbm_badcall_recv
        elif isinstance(src, (router, ipcore)):
        elif isinstance(src, (router, ipcore)):
            thesrc = src
            thesrc = src
        else:
        else:
            self.error("-> recv: what is src '%s'?" % repr(src) )
            self.error("-> recv: what is src '%s'?" % repr(src) )
            return noc_tlm_errcodes.tlm_badcall_recv
            return noc_tbm_errcodes.tbm_badcall_recv
 
 
        # check src as one of the channel endpoints
        # check src as one of the channel endpoints
        if thesrc not in self.endpoints:
        if thesrc not in self.endpoints:
            self.error("-> recv: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thesrc), repr(self.endpoints[0]), repr(self.endpoints[1])) )
            self.error("-> recv: object %s is NOT one of the channel endpoints [%s,%s]" % (repr(thesrc), repr(self.endpoints[0]), repr(self.endpoints[1])) )
            return noc_tlm_errcodes.tlm_badcall_recv
            return noc_tbm_errcodes.tbm_badcall_recv
 
 
 
        # call trace functions        
 
        for f in self.tracerecv:
 
            if callable(f):
 
                traceargs = {"self": self, "src": src, "dest": dest, "packet": packet, "addattrs": addattrs}
 
                f(traceargs)
 
 
        # calculate the other endpoint
        # calculate the other endpoint
        end_index = self.endpoints.index(thesrc) - 1
        end_index = self.endpoints.index(thesrc) - 1
 
 
        if self.has_delay:
        if self.has_delay:
Line 172... Line 186...
            # catch growing fifo
            # catch growing fifo
            if len(self.delay_fifo) > self.delay_fifo_max:
            if len(self.delay_fifo) > self.delay_fifo_max:
                self.warning("-> recv: delay_fifo is getting bigger! current size is %d" % len(self.delay_fifo) )
                self.warning("-> recv: delay_fifo is getting bigger! current size is %d" % len(self.delay_fifo) )
            # trigger event
            # trigger event
            self.delay_event.next = True
            self.delay_event.next = True
            retval = noc_tlm_errcodes.no_error
            retval = noc_tbm_errcodes.no_error
        else:
        else:
            # use send() call directly
            # use send() call directly
            router_dest = self.endpoints[end_index]
            router_dest = self.endpoints[end_index]
            retval = self.send(self.channel_ref, router_dest, packet, addattrs)
            retval = self.send(self.channel_ref, router_dest, packet, addattrs)
 
 

powered by: WebSVN 2.1.0

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