在 verilog 或 systemverilog 中每个时钟从文件中读取行

Read line from file every clock in verilog or systemverilog

我想测试一个模块,它在每个时钟周期都从文件中接受数字,但所需的数据太长了。我无法将完整的文件存储在内存中,因此我需要在每个时钟周期将文件中的数据提供给 I_data。

有什么方法可以使用 verilog 或 systemverilog 来实现吗?

简而言之:在每个时钟的位置读取一行,一直到文件末尾。

你的问题的答案是肯定的:是的。

使用$fopen打开文件,然后$fscanf读取每一行并将值存储到变量中。

例子很多out there

正如 Dave 所建议的那样,您可以为此目的使用 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