Is it possible to change the SV DPI execution order?

//C layer

#include "svdpi.h"
char fetchI()
{
char ch;
ch = getchar();
 return ch;
}

//SV layer
module Bus;
  import "DPI-C" function int fetchI();
  int char;

  initial begin
    for(int r = 0; r < 10 ; r++)
    begin
      $display("calling the scan func---press the key", $time);
      $display("iteration number is %d", r);
      // Calling C function
      char = fetchI(); // Arguments passed by copy
      $display("The character received is %c", char);
    end
  end
endmodule

The intention of the above code is to receive characters from the C layer whenever the function is “fetchI()” is called. The problem I am facing is during the simulation. When I run the simulation, the in the beginning I have to provide the input for all 10 iterations in this case egle… abcdefgh10 otherwise the simulation keeps hanging till all the characters are received. My requirement is to fetch one character every iteration and not to provide all input characters at once.

Please let me know if this is possible.

Thanks!

This is likely because your input file is buffered. Getting to read stdin un-buffered is going to be OS-specific, and may not even be possible. Your simulation tool may have control over how stdin is read.

As I tried to explain to you in another post, what you are try to do does not make much sense. It ids like drawing a picture of a vibrating bell and expecting to it hear ringing.

You are trying to connect the imaginary world of simulation described by SystemVerilog with a real-world piece of hardware, the keyboard. Normally in hardware, you have multiple processes running. The keyboard is one process that interrupts another process and sends a code for the key just pressed.

If you are doing this to integrate some type of debugger, than that is a tool synchronization issue. In any case, you will need to describe in a lot more detail what your goal is.