Exemplo n.º 1
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)
Exemplo n.º 2
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 = []
Exemplo n.º 3
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)))