我想测试一个模块,它在每个时钟周期接受来自文件的数字,并且所需的数据太长。我无法将完整的文件存储在内存中,因此我需要从文件的每个时钟周期将数据提供给I_data。
有什么方法可以使用verilog或systemverilog来做到这一点?
Nutshell:在每个时钟的posedge处读取一行到文件末尾。
答案 0 :(得分:1)
答案 1 :(得分:0)
正如戴夫所说,你可以为此目的使用fopen和fscanf。示例代码如下所示:
integer outfile0; //file descriptor
initial begin
outfile0=$fopen("file_to_be_read.txt","r"); //"r" means reading and "w" means writing
//read line by line.
while (! $feof(outfile0)) begin //read until an "end of file" is reached.
$fscanf(outfile0,"%h\n",A); //scan each line and get the value as an hexadecimal, use %b for binary and %d for decimal.
#10; //wait some time as needed.
end
//once reading and writing is finished, close the file.
$fclose(outfile0);
end
有更多解释和详细代码here。