本文整理汇总了Python中cocotb.binary.BinaryValue类的典型用法代码示例。如果您正苦于以下问题:Python BinaryValue类的具体用法?Python BinaryValue怎么用?Python BinaryValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_data
def _write_data(self):
clock_re = RisingEdge(self.clock)
while True:
while True:
self.bus.WREADY <= 0
yield ReadOnly()
yield NextTimeStep()
if self.bus.AWVALID.value:
self.bus.WREADY <= 1
break
yield clock_re
yield ReadOnly()
_awaddr = int(self.bus.AWADDR)
_awlen = int(self.bus.AWLEN)
_awsize = int(self.bus.AWSIZE)
_awburst = int(self.bus.AWBURST)
_awprot = int(self.bus.AWPROT)
burst_length = _awlen + 1
bytes_in_beat = self._size_to_bytes_in_beat(_awsize)
word = BinaryValue(bits=bytes_in_beat*8, bigEndian=self.big_endain)
if __debug__:
self.log.debug(
"AWADDR 0x{:x}\n".format(_awaddr) +
"AWLEN %d\n" % _awlen +
"AWSIZE %d\n" % _awsize +
"AWBURST %d\n" % _awburst +
"BURST_LENGTH %d\n" % burst_length +
"Bytes in beat %d\n" % bytes_in_beat)
burst_count = burst_length
yield clock_re
while True:
if self.bus.WVALID.value:
word = self.bus.WDATA.value
word.big_endian = self.big_endain
_burst_diff = burst_length - burst_count
_st = _awaddr + (_burst_diff * bytes_in_beat) # start
_end = _awaddr + ((_burst_diff + 1) * bytes_in_beat) # end
self._memory[_st:_end] = array.array('B', word.get_buff())
burst_count -= 1
if burst_count == 0:
self.bus.BVALID.value = 1
while self.bus.BREADY == 0:
yield clock_re
self.bus.BVALID.value = 0
break
yield clock_re
示例2: Ram_Read
def Ram_Read(self,dut, A):
############# Reading value from RAM
Ad = BinaryValue()
Ad.assign(A)
#print Ad, Bd
dut.a_adbus.value = Ad
yield RisingEdge(self.dut.clk)
yield ReadOnly()
raise ReturnValue(dut.a_data_out.value)
示例3: _read_data
def _read_data(self):
clock_re = RisingEdge(self.clock)
while True:
while True:
yield ReadOnly()
if self.bus.ARVALID.value:
break
yield clock_re
yield ReadOnly()
self._araddr = int(self.bus.ARADDR)
_arlen = int(self.bus.ARLEN)
_arsize = int(self.bus.ARSIZE)
_arburst = int(self.bus.ARBURST)
_arprot = int(self.bus.ARPROT)
burst_length = _arlen + 1
bytes_in_beat = self._size_to_bytes_in_beat(_arsize)
word = BinaryValue(bits=bytes_in_beat*8, bigEndian=self.big_endain)
if __debug__:
self.log.debug(
"ARLEN %d\n" % _arlen +
"ARSIZE %d\n" % _arsize +
"ARBURST %d\n" % _arburst +
"BURST_LENGTH %d\n" % burst_length +
"Bytes in beat %d\n" % bytes_in_beat)
burst_count = burst_length
word.buff = self._read_memory(burst_length,
burst_count,
bytes_in_beat)
yield clock_re
self.bus.RDATA <= word
while True:
self.bus.RVALID <= 1
yield clock_re
if self.bus.RREADY.value:
word.buff = self._read_memory(burst_length,
burst_count,
bytes_in_beat)
self.bus.RDATA <= word
if burst_count == 1:
self.bus.RLAST <= 1
yield clock_re
self.bus.RLAST <= 0
self.bus.RVALID <= 0
break
burst_count -= 1
示例4: __init__
def __init__(self, entity, name, clock):
BusDriver.__init__(self, entity, name, clock)
word = BinaryValue(bits=32)
single = BinaryValue(bits=1)
word.binstr = ("x" * 32)
single.binstr = ("x")
self.bus.load_i <= single
self.bus.rst_i <= single
self.bus.dat_i <= word
示例5: _read_data
def _read_data(self):
clock_re = RisingEdge(self.clock)
while True:
while True:
yield ReadOnly()
if self.bus.ARVALID.value:
break
yield clock_re
yield ReadOnly()
_araddr = int(self.bus.ARADDR)
_arlen = int(self.bus.ARLEN)
_arsize = int(self.bus.ARSIZE)
_arburst = int(self.bus.ARBURST)
_arprot = int(self.bus.ARPROT)
burst_length = _arlen + 1
bytes_in_beat = self._size_to_bytes_in_beat(_arsize)
word = BinaryValue(n_bits=bytes_in_beat*8, bigEndian=self.big_endian)
if __debug__:
self.log.debug(
"ARADDR %d\n" % _araddr +
"ARLEN %d\n" % _arlen +
"ARSIZE %d\n" % _arsize +
"ARBURST %d\n" % _arburst +
"BURST_LENGTH %d\n" % burst_length +
"Bytes in beat %d\n" % bytes_in_beat)
burst_count = burst_length
yield clock_re
while True:
self.bus.RVALID <= 1
yield ReadOnly()
if self.bus.RREADY.value:
_burst_diff = burst_length - burst_count
_st = _araddr + (_burst_diff * bytes_in_beat)
_end = _araddr + ((_burst_diff + 1) * bytes_in_beat)
word.buff = self._memory[_st:_end].tostring()
self.bus.RDATA <= word
if burst_count == 1:
self.bus.RLAST <= 1
yield clock_re
burst_count -= 1
self.bus.RLAST <= 0
if burst_count == 0:
break
示例6: _driver_send
def _driver_send(self, value, sync=True):
"""Send a transmission over the bus.
Args:
value: data to drive onto the bus.
"""
self.log.debug("Sending Avalon transmission: %d" % value)
# Avoid spurious object creation by recycling
clkedge = RisingEdge(self.clock)
word = BinaryValue(n_bits=len(self.bus.data), bigEndian=False)
# Drive some defaults since we don't know what state we're in
self.bus.valid <= 0
if sync:
yield clkedge
# Insert a gap where valid is low
if not self.on:
self.bus.valid <= 0
for i in range(self.off):
yield clkedge
# Grab the next set of on/off values
self._next_valids()
# Consume a valid cycle
if self.on is not True and self.on:
self.on -= 1
self.bus.valid <= 1
word.assign(value)
self.bus.data <= word
# If this is a bus with a ready signal, wait for this word to
# be acknowledged
if hasattr(self.bus, "ready"):
yield self._wait_ready()
yield clkedge
self.bus.valid <= 0
word.binstr = ("x"*len(self.bus.data))
self.bus.data <= word
self.log.debug("Successfully sent Avalon transmission: %d" % value)
示例7: PUSH
def PUSH(self,dut, A,command):
Ad = BinaryValue()
Ad.assign(A)
dut.Data_in_Core1_Inp.value = Ad
dut.wr_en_Core1_Inp.value=1
dut.wr_en_Core1_Cmd.value =1
dut.Data_in_Core1_Cmd.value=command
yield RisingEdge(self.dut.clk)
dut.wr_en_Core1_Inp.value=0
dut.wr_en_Core1_Cmd.value =0
yield ReadOnly()
示例8: __init__
def __init__(self, *args, **kwargs):
config = kwargs.pop('config', {})
ValidatedBusDriver.__init__(self, *args, **kwargs)
self.config = AvalonSTPkts._default_config.copy()
# Set default config maxChannel to max value on channel bus
if hasattr(self.bus, 'channel'):
self.config['maxChannel'] = (2 ** len(self.bus.channel)) -1
for configoption, value in config.items():
self.config[configoption] = value
self.log.debug("Setting config option %s to %s" %
(configoption, str(value)))
num_data_symbols = (len(self.bus.data) /
self.config["dataBitsPerSymbol"])
if (num_data_symbols > 1 and not hasattr(self.bus, 'empty')):
raise AttributeError(
"%s has %i data symbols, but contains no object named empty" %
(self.name, num_data_symbols))
self.use_empty = (num_data_symbols > 1)
self.config["useEmpty"] = self.use_empty
word = BinaryValue(n_bits=len(self.bus.data),
bigEndian=self.config['firstSymbolInHighOrderBits'])
single = BinaryValue(n_bits=1, bigEndian=False)
word.binstr = ("x"*len(self.bus.data))
single.binstr = ("x")
self.bus.valid <= 0
self.bus.data <= word
self.bus.startofpacket <= single
self.bus.endofpacket <= single
if self.use_empty:
empty = BinaryValue(n_bits=len(self.bus.empty), bigEndian=False)
empty.binstr = ("x"*len(self.bus.empty))
self.bus.empty <= empty
if hasattr(self.bus, 'channel'):
if len(self.bus.channel) > 128:
raise AttributeError(
"Avalon-ST interface specification defines channel width as 1-128. %d channel width is %d" %
(self.name, len(self.bus.channel))
)
maxChannel = (2 ** len(self.bus.channel)) -1
if self.config['maxChannel'] > maxChannel:
raise AttributeError(
"%s has maxChannel=%d, but can only support a maximum channel of (2**channel_width)-1=%d, channel_width=%d" %
(self.name,self.config['maxChannel'],maxChannel,len(self.bus.channel)))
channel = BinaryValue(n_bits=len(self.bus.channel), bigEndian=False)
channel.binstr = ("x"*len(self.bus.channel))
self.bus.channel <= channel
示例9: ConstantObject
class ConstantObject(NonHierarchyObject):
"""
Constant objects have a value that can be read, but not set.
We can also cache the value since it is elaboration time fixed and won't
change within a simulation
"""
def __init__(self, handle, handle_type):
NonHierarchyObject.__init__(self, handle)
if handle_type in [simulator.INTEGER, simulator.ENUM]:
self._value = simulator.get_signal_val_long(self._handle)
elif handle_type == simulator.REAL:
self._value = simulator.get_signal_val_real(self._handle)
elif handle_type == simulator.STRING:
self._value = simulator.get_signal_val_str(self._handle)
else:
val = simulator.get_signal_val_binstr(self._handle)
self._value = BinaryValue(bits=len(val))
try:
self._value.binstr = val
except:
self._value = val
def __int__(self):
return int(self._value)
def __eq__(self, other):
return self._value.__eq__(other)
def __ne__(self, other):
if isinstance(self._value, str):
return self._value.__ne__(other)
else:
return self._value != other
def __repr__(self):
return str(self._value)
@property
def value(self):
return self._value
def _setcachedvalue(self, *args, **kwargs):
raise ValueError("Not permissible to set values on a constant object")
def __le__(self, *args, **kwargs):
raise ValueError("Not permissible to set values on a constant object")
示例10: _write_data
def _write_data(self):
clock_re = RisingEdge(self.clock)
while True:
while True:
self.bus.WREADY <= 0
yield ReadOnly()
if self.bus.AWVALID.value:
self.bus.WREADY <= 1
break
yield clock_re
yield ReadOnly()
_awaddr = int(self.bus.AWADDR)
_awlen = int(self.bus.AWLEN)
_awsize = int(self.bus.AWSIZE)
_awburst = int(self.bus.AWBURST)
_awprot = int(self.bus.AWPROT)
burst_length = _awlen + 1
bytes_in_beat = self._size_to_bytes_in_beat(_awsize)
word = BinaryValue(bits=bytes_in_beat*8, bigEndian=self.big_endain)
if __debug__:
self.log.debug(
"AWADDR %d\n" % _awaddr +
"AWLEN %d\n" % _awlen +
"AWSIZE %d\n" % _awsize +
"AWBURST %d\n" % _awburst +
"BURST_LENGTH %d\n" % burst_length +
"Bytes in beat %d\n" % bytes_in_beat)
burst_count = burst_length
yield clock_re
while True:
if self.bus.WVALID.value:
word = self.bus.WDATA.value
word.big_endian = self.big_endain
self._memory[_awaddr+((burst_length-burst_count)*bytes_in_beat):_awaddr+(((burst_length-burst_count)+1)*bytes_in_beat)] = array.array('B',word.get_buff())
burst_count -= 1
if burst_count == 0:
break
yield clock_re
示例11: __init__
def __init__(self, *args, **kwargs):
config = kwargs.pop('config', {})
ValidatedBusDriver.__init__(self, *args, **kwargs)
self.config = AvalonSTPkts._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)))
word = BinaryValue(bits=len(self.bus.data),
bigEndian=self.config['firstSymbolInHighOrderBits'])
word.binstr = ("x"*len(self.bus.data))
self.bus.valid <= 0
self.bus.data <= word
self.bus.empty <= word
self.bus.startofpacket <= word
self.bus.endofpacket <= word
示例12: _ad9361_tx_to_rx_loopback
def _ad9361_tx_to_rx_loopback(self):
cocotb.fork(self._tx_data_from_ad9361())
i_bin_val = BinaryValue(bits=12, bigEndian=False)
q_bin_val = BinaryValue(bits=12, bigEndian=False)
while True:
yield RisingEdge(self.dut.rx_clk_in_p)
if self.rx_frame_asserted:
self.dut.rx_data_in_p <= i_bin_val[5:0]
self.dut.rx_data_in_n <= ~i_bin_val[5:0]
self.rx_frame_asserted = False
self.dut.rx_frame_in_p <= 0
self.dut.rx_frame_in_n <= 1
else:
if len(self.lbqi) > 0:
i_bin_val = self.lbqi.popleft()
else:
i_bin_val.set_value(0)
if len(self.lbqq) > 0:
q_bin_val = self.lbqq.popleft()
else:
q_bin_val.set_value(0)
self.dut.rx_data_in_p <= i_bin_val[11:6]
self.dut.rx_data_in_n <= ~i_bin_val[11:6]
self.rx_frame_asserted = True
self.dut.rx_frame_in_p <= 1
self.dut.rx_frame_in_n <= 0
yield RisingEdge(self.dut.rx_clk_in_n)
if self.rx_frame_asserted:
self.dut.rx_data_in_p <= q_bin_val[11:6]
self.dut.rx_data_in_n <= ~q_bin_val[11:6]
else:
self.dut.rx_data_in_p <= q_bin_val[5:0]
self.dut.rx_data_in_n <= ~q_bin_val[5:0]
示例13: __init__
def __init__(self, handle, handle_type):
NonHierarchyObject.__init__(self, handle)
if handle_type in [simulator.INTEGER, simulator.ENUM]:
self._value = simulator.get_signal_val_long(self._handle)
elif handle_type == simulator.REAL:
self._value = simulator.get_signal_val_real(self._handle)
elif handle_type == simulator.STRING:
self._value = simulator.get_signal_val_str(self._handle)
else:
val = simulator.get_signal_val_binstr(self._handle)
self._value = BinaryValue(bits=len(val))
try:
self._value.binstr = val
except:
self._value = val
示例14: Ram_write
def Ram_write(self,dut, A, B):
###### Writing value from RAM
Ad = BinaryValue()
Ad.assign(A)
Bd = BinaryValue()
Bd.assign(B)
dut.a_adbus.value = Bd
dut.a_data_in.value = Ad
dut.a_w.value=1
yield RisingEdge(self.dut.clk)
dut.a_w.value=0
yield ReadOnly()
示例15: _getvalue
def _getvalue(self):
result = BinaryValue()
result.binstr = simulator.get_signal_val_binstr(self._handle)
return result