//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!