aaa SA
aaa SA

Reputation: 323

Verilog fgets from stdin but non-blocking

In verilog, I use $fgets(xxx,'h8000_0000), so that xxx gets the string from stdin. But it use blocking way, that if I don't press enter, it's will not running others at the same time. How to use an easy way to get string from stdin and it's non-blocking?

Upvotes: 0

Views: 1692

Answers (1)

Morgan
Morgan

Reputation: 20534

I would have thought that if the following code relies on the input string then you would want it to be blocking.

From the description of the problem I do not think it is a blocking, non-blocking assignment issue rather that of parallel code execution.

If the code is split into separate always or initial blocks then they would execute in parallel.

// main test program
initial begin
  // ...
end

// load from command line with out halting main program
initial begin
  $fgets(xxx,'h8000_0000);
end 

Another solution would be to put a timeout around the fgets, but the time mentioned is for verilog simulation time not actual time, might have to use quite a large value to make it a noticeable delay to the user.

initial begin
  //test program

  // load from command line
  fork : wait_or_timeout
    begin
      #10ms ;
      disable wait_or_timeout;
    end
    begin
      $fgets(xxx,'h8000_0000);
      disable wait_or_timeout;
    end
  join

Upvotes: 1

Related Questions