[英]realtime communicate with Verilog simulation
I hope to realtime communicate with verilog simulation, just like I type a number at some where and verilog simulation can read it and show it.我希望与verilog模拟实时通信,就像我在某个地方输入一个数字,verilog模拟可以读取并显示它。 So I find a way that use read/write a file to communicate.
所以我找到了一种使用读/写文件进行通信的方法。 First I write ac program to scanf what I type in the terminal and realtime change a number in a specific file.
首先,我编写 ac 程序来扫描我在终端中输入的内容,并实时更改特定文件中的数字。 Then I thought if the verilog keep fscanf the file, it can communicate.
然后我想如果verilog保留fscanf文件,它可以通信。 I wrote the verilog code below, it works but not very good.
我写了下面的 verilog 代码,它可以工作但不是很好。 If I type 1 ~ 9 each for one second, it will lose about six numbers.
如果我分别输入 1 ~ 9 一秒钟,它会丢失大约六个数字。 I hope all the number I type can be read by verilog.
我希望我输入的所有数字都可以被 verilog 读取。 I use ncverilog to compile.
我使用 ncverilog 进行编译。 Can anyone tell me how to fix my verilog or there are another way to communicate with verilog.
谁能告诉我如何修复我的 verilog 或者有另一种与 verilog 通信的方式。 Thanks a lot.
非常感谢。
module testbench;
reg [100:0] t1;
reg [100:0] t2;
integer in;
initial begin
t1=0;t2=0;
end
always begin
in = $fopen("in.txt","r");
$fscanf(in,"%d",t1);
if(t1!=t2) begin
$display("%d",t1);
t2=t1;
end
$fclose(in);
end
endmodule
This is certainly possible, but I think attempting to use a file for communication is the wrong approach.这当然是可能的,但我认为尝试使用文件进行通信是错误的方法。 You are bound to run into race conditions and other issues with file/IO buffers.
您肯定会遇到竞争条件和文件/IO 缓冲区的其他问题。
Alternatively, you could use the Verilog PLI to have your C program send data to the simulation on a certain event, say when the Enter
key is pressed.或者,您可以使用 Verilog PLI 让您的 C 程序在某个事件(例如按下
Enter
键时)向仿真发送数据。
Old question, related answer.老问题,相关答案。 You can see bidirectiona file io here in my uart sim.
您可以在我的 uart sim 中看到双向文件 io。
https://github.com/Johnlon/spam-1/blob/master/verilog/uart/um245r.v https://github.com/Johnlon/spam-1/blob/master/verilog/uart/um245r.v
On unix you can use a unix domain socket and treat like a terminal with a little work.在 unix 上,您可以使用 unix 域套接字并像终端一样处理一些工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.