示例#1
0
文件: __init__.py 项目: powlib/sim
 def __init__(self, bpd=4):
     '''
     Constructor. bpd is the number of bytes in a data word.
     '''
     self.__bpd = bpd
     self.__busInport = InPort(block=self)
     self.__busOutport = OutPort(block=self)
     self.__ramInport = InPort(block=self)
     self.__ramOutport = OutPort(block=self)
示例#2
0
    def __init__(self, inputs, outputs, outport_params):
        '''
        Constructs the crossbar model.
        inputs         = Number of inports that represent the writing interfaces.
        outputs        = Number of outports that represent the reading interfaces.
        outport_params = List of Namespaces that correspond to the outputs. 
                         Each Namespace should contain a base address and
                        size, where size is minus 1 the actual size.
        '''

        # Create the inports.
        self.__inports = []
        for each_inport in range(inputs):
            self.__inports.append(InPort(block=self))

        # Create the outports.
        self.__outports = []
        self.__outport_params = outport_params
        for each_outport in range(outputs):
            self.__outports.append(OutPort(block=self))
            outport_param = outport_params[each_outport]
            if not hasattr(outport_param, "base"):
                raise ValueError(
                    "{} outport should have member base.".format(each_outport))
            if not hasattr(outport_param, "size"):
                raise ValueError(
                    "{} outport should have member size.".format(each_outport))
示例#3
0
    def read(self, addr):
        '''
        Reads data from the bus interface. addr specifies where to read. If
        addr is an int, then only a single read will occur. If addr is a list,
        a burst of reads will occur.
        '''

        # Create the receiving port. Clear the event.
        rdInport = InPort(block=self)
        self._monitors.rd.outport.connect(rdInport)

        # Prepare the list of read transactions.
        isinstance_long = False
        try:
            isinstance_long = isinstance(addr, long)
        except NameError:
            pass
        if isinstance(addr, int) or isinstance_long:
            addrList = [addr]
        elif isinstance(addr, list):
            addrList = addr
        else:
            raise TypeError("addr must be either int/long or list.")

        # Write out the burst read.
        for each_addr in addrList:
            self.write(addr=each_addr, data=self.__baseAddr, op=OP_READ)

        # Read each word.
        transList = []
        for each_read in range(len(addrList)):
            self.__rdEvent.clear()
            yield self.__rdEvent.wait()
            assert (rdInport.ready())
            trans = rdInport.read()
            transList.append(trans)

        # Disconnect the port.
        self._monitors.rd.outport.disconnect(rdInport)

        # If only a single read occurs, then return on the single transaction.
        # If a burst, then return the list.
        if len(transList) == 1:
            raise ReturnValue(transList[0])
        else:
            raise ReturnValue(transList)
示例#4
0
文件: component.py 项目: powlib/sim
 def __init__(self, interface):
     '''
     Constructs the driver with a given
     interface.
     '''
     Component.__init__(self, interface)
     self.__inport = InPort(block=self)
     self.__queue = deque()
     self.__event = Event()
     self.__flushevt = Event()
     fork(self._drive())
示例#5
0
class GatherBlock(Block):
    '''
    This gather block was created such that sets of
    data can be compared with the scoreboard.
    '''
    def __init__(self):
        self.__inport = InPort(block=self)
        self.__outport = OutPort(block=self)
        self.__lst = []

    inport = property(lambda self: self.__inport)
    outport = property(lambda self: self.__outport)

    def _behavior(self):
        if self.__inport.ready():
            self.__lst.append(self.__inport.read())

    def perform(self):
        self.__outport.write(data=set(self.__lst))
        self.__lst = []
示例#6
0
文件: __init__.py 项目: powlib/sim
 def __init__(self, trans_func, cond_func=AllCondFunc, inputs=1):
     '''
     Constructor. The trans_func is a function that should define the
     behavior of the swiss block. Its input parameters are the values read from each
     of the inports. If it returns a value, that value will be written to 
     the SwissBlock's outport. cond_func is a function that should determine
     when the trans_func is called. Its input parameters are the ready booleans
     of the inports. It should return another boolean, where True causes the
     trans_func to be called.
     '''
     self.__inports = [InPort(block=self) for _ in range(inputs)]
     self.__outport = OutPort(block=self)
     self.__trans_func = trans_func
     self.__cond_func = cond_func
示例#7
0
class DownFifoModel(Block):
    '''
    Models the behavior of the powlib_downfifo.
    '''
    def __init__(self, width, mult):
        self.__width = width
        self.__mult = mult
        self.__inport = InPort(block=self)
        self.__outport = OutPort(block=self)

    inport = property(lambda self: self.__inport)
    outport = property(lambda self: self.__outport)

    def _behavior(self):
        if self.__inport.ready():
            trans = self.__inport.read()
            wrdata = int(trans.data)
            for each in range(self.__mult):
                mask = (1 << self.__width) - 1
                shift = each * self.__width
                rdata = (wrdata & (mask << shift)) >> shift
                self.__outport.write(
                    Transaction(data=BinaryValue(
                        value=rdata, bits=self.__width, bigEndian=False)))
示例#8
0
 def __init__(self, width, mult):
     self.__width = width
     self.__mult = mult
     self.__inport = InPort(block=self)
     self.__outport = OutPort(block=self)
示例#9
0
 def __init__(self):
     self.__inport = InPort(block=self)
     self.__outport = OutPort(block=self)
     self.__lst = []