我正在为 cocotb 测试平台编写代码以验证 hdl 模块,但我遇到了一些问题。我想提供从 .txt 文件中读取并存储在数组中的数据,但是当我尝试提供数据时,它显示索引错误,因为 Array 没有存储任何数据。
class expample():
def __init__(self):
self.lin = [[],[]]
self.lout = []
def gen_in():
lin_files = ['prach_din1.txt', 'prach_din2.txt', 'prach_din3.txt', 'prach_din4.txt', 'prach_din5.txt', 'prach_din6.txt', 'prach_din7.txt','prach_din8.txt','prach_din9.txt', 'prach_din10.txt', 'prach_din11.txt', 'prach_din12.txt']
for antenna_num in lin_files:
in_file = open( antenna_num,'r').readlines()
self.lin = [ int(i) for i in in_file ]
print(self.lin)
class tb_expample(object):
expample_obj = expample()
@cocotb.coroutine
def drive_antenna(self, num):
for ant_num in range(4):
for samp_num in (self.expample_obj.lin[ant_num]):
self.dut.osample_data[ant_num] = samp_num
self.dut.osample_enable[ant_num] = 1
self.dut.oframe_strobe[ant_num] = 1
@cocotb.test()
def test_expample_processor(dut):
test = tb_expample(dut)
yield test.drive_antenna()
如何将数据存储在 lin[0],lin[1],.....,lin[11] 中。将数据提供给 sample_data?