凿子打印失败(使用凿子3然后Verilator构建C++)



这是 https://github.com/freechipsproject/chisel3/wiki/Frequently-Asked-Questions 中 HelloWorld.scala 示例的略微修改版本

// say hello                                                                     
package HelloWorld
import chisel3._
class HelloWorld extends Module {
val io = IO(new Bundle{
val halt = Output(Bool())
val may_halt = Input(Bool())
})
printf("hello, world!n");
when (io.may_halt) {
io.halt := true.B
} .otherwise {
io.halt := false.B
}
}

// code for building HelloWorld                                                  
object HelloWorld extends App {
chisel3.Driver.execute(args, () => new HelloWorld)
}

我使用 chisel3 然后使用验证器生成C++构建它。 以下是C++线束的有趣部分:

VHelloWorld *top;               // Instantiation of module                       
int main(int argc, char** argv) {
Verilated::commandArgs(argc, argv); // Remember args                           
top = new VHelloWorld;              // Create instance                         
printf("eval loop startn");
long long cycle = 0;
for (; !Verilated::gotFinish(); ++cycle) {
printf("tcycle: %lldn", cycle);
if (2 <= cycle) {
printf("ttput io_may_halt = 1n");
top->io_may_halt = 1;
}
top->eval();                      // Evaluate model                          
if (top->io_halt) {
printf("ttgot an io_halt, so haltingn");
break;                   // halt when we get the signal to do so           
}
}
printf("eval loop stopn");
top->final();                       // Done simulating                         
delete top;                         // (Though this example doesn't get here)  
return 0;
}

我运行它几个周期,然后发出停止信号。 然而,"你好,世界!"的信息从未出现过。

HelloWorld.cppdir/HelloWorld.exe
eval loop start
cycle: 0
cycle: 1
cycle: 2
put io_may_halt = 1
got an io_halt, so halting
eval loop stop

我想通了:printf(( 只发生在上升的时钟上,所以缠绕在验证器代码上的C++线束必须明确地 (1( 将时钟驱动得很低,(2( eval((,(2( 将时钟驱动高电平,(3( eval((,然后 printf(( 将打印出来。(实际上我不确定 (2( 是必需的,但不这样做会很奇怪。

我在上面的评论中说过,验证器示例没有显示C++线束执行此操作,但是在更复杂的示例中,以更复杂的方式,它们确实如此。

最新更新