Example #1
0
    def __init__(self, entity, name="", default_values=None, *args, **kwargs):
        '''
        See the BusDriver definition for more information on the inputs.
        '''

        BusDriver.__init__(self, entity=entity, name=name, *args, **kwargs)

        # Create separate write and read buses.
        self.__wrbus = Bus(
            entity=entity,
            name="",  # Intentionally done this way.
            signals=self._wrsignals,
            optional_signals=self._optional_signals,
            bus_separator="")
        self.__rdbus = Bus(
            entity=entity,
            name="",  # Intentionally done this way.
            signals=self._rdsignals,
            bus_separator="")

        # The Bus assigned in the BusDriver shall be the write Bus.
        self.bus = self.__wrbus

        # Set default values.
        if default_values is None:
            self.__default_values = self._default_values
        else:
            self.__default_values = default_values
        self.set_defaults()
Example #2
0
    def __init__(self,
                 entity,
                 name,
                 clock,
                 reset=None,
                 size=1024,
                 mem=None,
                 *args,
                 **kwargs):
        self.log = logging.getLogger(f"cocotb.{entity._name}.{name}")
        self.entity = entity
        self.clock = clock
        self.reset = reset
        self.cmd_bus = Bus(self.entity, name, self._cmd_signals, **kwargs)
        self.resp_bus = Bus(self.entity, name, self._resp_signals, **kwargs)

        self.log.info("Parallel Simple Dual Port RAM model (read)")
        self.log.info("Copyright (c) 2020 Alex Forencich")

        super().__init__(size, mem, *args, **kwargs)

        self.pause = False
        self._pause_generator = None
        self._pause_cr = None

        self.width = len(self.resp_bus.rd_resp_data)
        self.byte_width = self.width // 8

        self.seg_count = len(self.cmd_bus.rd_cmd_valid)
        self.seg_data_width = self.width // self.seg_count
        self.seg_byte_width = self.seg_data_width // 8
        self.seg_addr_width = len(self.cmd_bus.rd_cmd_addr) // self.seg_count

        self.seg_data_mask = 2**self.seg_data_width - 1
        self.seg_addr_mask = 2**self.seg_addr_width - 1

        self.log.info("Parallel Simple Dual Port RAM model configuration:")
        self.log.info("  Memory size: %d bytes", len(self.mem))
        self.log.info("  Segment count: %d", self.seg_count)
        self.log.info("  Segment addr width: %d bits", self.seg_addr_width)
        self.log.info("  Segment data width: %d bits (%d bytes)",
                      self.seg_data_width, self.seg_byte_width)
        self.log.info("  Total data width: %d bits (%d bytes)", self.width,
                      self.width // 8)

        self.cmd_bus.rd_cmd_ready.setimmediatevalue(0)
        self.resp_bus.rd_resp_valid.setimmediatevalue(0)

        cocotb.fork(self._run())
Example #3
0
    def __init__(self,
                 entity,
                 name,
                 clock,
                 reset=None,
                 reset_n=None,
                 callback=None,
                 event=None,
                 bus_separator="_",
                 config={},
                 array_idx=None):
        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        self.entity = entity
        self.name = name
        self.clock = clock
        self.config = self._default_config.copy()

        for configoption, value in config.items():
            self.config[configoption] = value
            self.log.debug("Setting config option %s to %s" %
                           (configoption, str(value)))

        self.bus = Bus(self.entity,
                       self.name,
                       self._signals,
                       optional_signals=self._optional_signals,
                       bus_separator=bus_separator,
                       array_idx=array_idx)
        self._reset = reset
        self._reset_n = reset_n
        Monitor.__init__(self, callback=callback, event=event)
Example #4
0
 def __init__(self, entity, name, clock, reset=None, reset_n=None,
              callback=None, event=None):
     self.log = SimLog("cocotb.%s.%s" % (entity.name, name))
     self.entity = entity
     self.name = name
     self.clock = clock
     self.bus = Bus(self.entity, self.name, self._signals,
                    optional_signals=self._optional_signals)
     self._reset = reset
     self._reset_n = reset_n
     Monitor.__init__(self, callback=callback, event=event)
Example #5
0
    def __init__(self, entity, name, clock, **kwargs):
        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        Driver.__init__(self)
        self.entity = entity
        self.clock = clock
        index = kwargs.get("array_idx")
        self.bus = Bus(self.entity, name, self._signals,
                       self._optional_signals, array_idx=index)

        # Give this instance a unique name
        self.name = name if index is None else "%s_%d" % (name, index)
Example #6
0
    def __init__(self, entity, name, clock, reset=None, *args, **kwargs):
        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        self.entity = entity
        self.clock = clock
        self.reset = reset
        self.bus = Bus(self.entity,
                       name,
                       self._signals,
                       optional_signals=self._optional_signals,
                       **kwargs)

        self.log.info("AXI stream source")
        self.log.info("cocotbext-axi version %s", __version__)
        self.log.info("Copyright (c) 2020 Alex Forencich")
        self.log.info("https://github.com/alexforencich/cocotbext-axi")

        super().__init__(*args, **kwargs)

        self.active = False
        self.queue = deque()

        self.pause = False
        self._pause_generator = None
        self._pause_cr = None

        self.queue_occupancy_bytes = 0
        self.queue_occupancy_frames = 0

        self.width = len(self.bus.tdata)
        self.byte_width = 1

        self.reset = reset

        self.bus.tdata.setimmediatevalue(0)
        if hasattr(self.bus, "tvalid"):
            self.bus.tvalid.setimmediatevalue(0)
        if hasattr(self.bus, "tlast"):
            self.bus.tlast.setimmediatevalue(0)
        if hasattr(self.bus, "tkeep"):
            self.byte_width = len(self.bus.tkeep)
            self.bus.tkeep.setimmediatevalue(0)
        if hasattr(self.bus, "tid"):
            self.bus.tid.setimmediatevalue(0)
        if hasattr(self.bus, "tdest"):
            self.bus.tdest.setimmediatevalue(0)
        if hasattr(self.bus, "tuser"):
            self.bus.tuser.setimmediatevalue(0)

        self.byte_size = self.width // self.byte_width
        self.byte_mask = 2**self.byte_size - 1

        cocotb.fork(self._run())
Example #7
0
    def __init__(self, entity: SimHandleBase, name: Optional[str], clock: SimHandleBase, **kwargs: Any):
        index = kwargs.get("array_idx", None)

        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        Driver.__init__(self)
        self.entity = entity
        self.clock = clock
        self.bus = Bus(
            self.entity, name, self._signals, optional_signals=self._optional_signals,
            **kwargs
        )

        # Give this instance a unique name
        self.name = name if index is None else "%s_%d" % (name, index)
Example #8
0
    def __init__(self, entity, name, clock, **kwargs):
        # emulate keyword-only arguments in python 2
        index = kwargs.pop("array_idx", None)
        reject_remaining_kwargs('__init__', kwargs)

        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        Driver.__init__(self)
        self.entity = entity
        self.clock = clock
        self.bus = Bus(self.entity, name, self._signals,
                       self._optional_signals, array_idx=index)

        # Give this instance a unique name
        self.name = name if index is None else "%s_%d" % (name, index)
Example #9
0
    def __init__(self, entity, name, clock):
        """
        Args:
            entity (SimHandle) : a handle to the simulator entity

            name (str) : name of this bus. None for nameless bus, e.g.
                         bus-signals in an interface or a modport
                         (untested on struct/record, but could work here as well)
            clock (SimHandle) : A handle to the clock associated with this bus
        """
        self.log = SimLog("cocotb.%s.%s" % (entity.name, name))
        Driver.__init__(self)
        self.entity = entity
        self.name = name
        self.clock = clock
        self.bus = Bus(self.entity, self.name, self._signals,
                       self._optional_signals)
Example #10
0
    def __init__(self, entity, name, clock, reset=None, *args, **kwargs):
        self.log = logging.getLogger(f"cocotb.{entity._name}.{name}")
        self.entity = entity
        self.clock = clock
        self.reset = reset
        self.bus = Bus(self.entity,
                       name,
                       self._signals,
                       optional_signals=self._optional_signals,
                       **kwargs)

        super().__init__(*args, **kwargs)

        self.queue = deque()
        self.queue_sync = Event()

        self.ready = None
        self.valid = None

        if self._ready_signal is not None and hasattr(self.bus,
                                                      self._ready_signal):
            self.ready = getattr(self.bus, self._ready_signal)
            if self._ready_init is not None:
                self.ready.setimmediatevalue(self._ready_init)

        if self._valid_signal is not None and hasattr(self.bus,
                                                      self._valid_signal):
            self.valid = getattr(self.bus, self._valid_signal)
            if self._valid_init is not None:
                self.valid.setimmediatevalue(self._valid_init)

        for sig in self._signals + self._optional_signals:
            if hasattr(self.bus, sig):
                if sig in self._signal_widths:
                    assert len(getattr(self.bus,
                                       sig)) == self._signal_widths[sig]
                if self._init_x and sig not in (self._valid_signal,
                                                self._ready_signal):
                    v = getattr(self.bus, sig).value
                    v.binstr = 'x' * len(v)
                    getattr(self.bus, sig).setimmediatevalue(v)
Example #11
0
    def __init__(self, entity, name, clock, **kwargs):
        """Args:
            entity (SimHandle): A handle to the simulator entity.

            name (str): Name of this bus. ``None`` for nameless bus, e.g.
                bus-signals in an interface or a modport
                (untested on struct/record, but could work here as well).
            clock (SimHandle): A handle to the clock associated with this bus.
        """
        self.log = SimLog("cocotb.%s.%s" % (entity._name, name))
        Driver.__init__(self)
        self.entity = entity
        self.clock = clock
        index = kwargs.get("array_idx")
        self.bus = Bus(self.entity,
                       name,
                       self._signals,
                       self._optional_signals,
                       array_idx=index)

        # Give this instance a unique name
        self.name = name if index is None else "%s_%d" % (name, index)
Example #12
0
 def __init__(self, entity, data_name):
     self.data_bus = Bus(entity, '', data_name)
     self.data_name = data_name
     self.X = self.create_data()
     self.assign_bus(self.X)