SystemC 仿真错过了第一次迭代
我在启动模拟方面遇到困难。 每当我为循环启动时,我总是会错过循环的第一次迭代。 这是我的代码:
#include <systemc.h>
#include <iostream>
using namespace std;
SC_MODULE(cpu){
sc_in_clk clk { "cpu_clk" };
sc_in<bool> rw { "cpu_rw" };
sc_inout<sc_lv<16>> dbus { "cpu_dbus" };
sc_out<sc_lv<20>> abus { "cpu_abus" };
void cpu_loop();
SC_CTOR(cpu){
SC_CTHREAD(cpu_loop, clk.pos());
}
};
void cpu::cpu_loop(){
while(1){
wait();
cout << "cpu" << endl;
}
}
SC_MODULE(sram){
sc_in_clk clk { "sram_clk" };
sc_in<bool> rw { "sram_rw" };
sc_inout<sc_lv<16>> dbus { "sram_dbus" };
sc_in<sc_lv<20>> abus { "sram_abus" };
void sram_loop();
SC_CTOR(sram){
SC_CTHREAD(sram_loop, clk.pos());
}
};
void sram::sram_loop(){
while(1){
wait();
cout << "sram" << endl;
}
}
int sc_main(int argc, char* argv[]) {
int i;
sc_signal<sc_lv<16>, SC_MANY_WRITERS> dbus { "main_dbus" };
sc_signal<sc_lv<20>, SC_MANY_WRITERS> abus { "main_abus" };
sc_signal<bool> clk { "main_clk" };
sc_signal<bool> rw { "main_rw" };
cpu custom_cpu("custom_cpu");
sram custom_sram ("custom_sram");
custom_cpu.abus(abus);
custom_cpu.dbus(dbus);
custom_cpu.clk(clk);
custom_cpu.rw(rw);
custom_sram.abus(abus);
custom_sram.dbus(dbus);
custom_sram.clk(clk);
custom_sram.rw(rw);
sc_start(1, SC_MS);
clk = 0;
for(i = 0; i < 10; i++){
cout << "============== " << i << "==============" << endl;
clk = 1;
sc_start(1, SC_MS);
clk = 0;
sc_start(1, SC_MS);
}
return 0;
}
这是输出:
============== 0==============
============== 1==============
cpu
sram
============== 2==============
cpu
sram
============== 3==============
cpu
sram
============== 4==============
cpu
sram
============== 5==============
cpu
sram
============== 6==============
cpu
sram
============== 7==============
cpu
sram
============== 8==============
cpu
sram
============== 9==============
cpu
sram
我已经搜索了一个答案,但是似乎没有其他人有这个问题,所以我假设我在做错了什么。
I'm having difficulties with initiating the simulation.
Whenever I start a for
loop, I always miss the first iteration of the loop.
Here is my code:
#include <systemc.h>
#include <iostream>
using namespace std;
SC_MODULE(cpu){
sc_in_clk clk { "cpu_clk" };
sc_in<bool> rw { "cpu_rw" };
sc_inout<sc_lv<16>> dbus { "cpu_dbus" };
sc_out<sc_lv<20>> abus { "cpu_abus" };
void cpu_loop();
SC_CTOR(cpu){
SC_CTHREAD(cpu_loop, clk.pos());
}
};
void cpu::cpu_loop(){
while(1){
wait();
cout << "cpu" << endl;
}
}
SC_MODULE(sram){
sc_in_clk clk { "sram_clk" };
sc_in<bool> rw { "sram_rw" };
sc_inout<sc_lv<16>> dbus { "sram_dbus" };
sc_in<sc_lv<20>> abus { "sram_abus" };
void sram_loop();
SC_CTOR(sram){
SC_CTHREAD(sram_loop, clk.pos());
}
};
void sram::sram_loop(){
while(1){
wait();
cout << "sram" << endl;
}
}
int sc_main(int argc, char* argv[]) {
int i;
sc_signal<sc_lv<16>, SC_MANY_WRITERS> dbus { "main_dbus" };
sc_signal<sc_lv<20>, SC_MANY_WRITERS> abus { "main_abus" };
sc_signal<bool> clk { "main_clk" };
sc_signal<bool> rw { "main_rw" };
cpu custom_cpu("custom_cpu");
sram custom_sram ("custom_sram");
custom_cpu.abus(abus);
custom_cpu.dbus(dbus);
custom_cpu.clk(clk);
custom_cpu.rw(rw);
custom_sram.abus(abus);
custom_sram.dbus(dbus);
custom_sram.clk(clk);
custom_sram.rw(rw);
sc_start(1, SC_MS);
clk = 0;
for(i = 0; i < 10; i++){
cout << "============== " << i << "==============" << endl;
clk = 1;
sc_start(1, SC_MS);
clk = 0;
sc_start(1, SC_MS);
}
return 0;
}
And here is the output:
============== 0==============
============== 1==============
cpu
sram
============== 2==============
cpu
sram
============== 3==============
cpu
sram
============== 4==============
cpu
sram
============== 5==============
cpu
sram
============== 6==============
cpu
sram
============== 7==============
cpu
sram
============== 8==============
cpu
sram
============== 9==============
cpu
sram
I've searched for an answer, but it seems that no one else has this problem, so I'm assuming I'm doing something wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在之前进行打印,则在中呼叫 循环中的,您将获得预期的输出。这与循环的
一致。
例如:
这将在 eda playgrpound 上运行。
If you do the print out before you call
wait
in yourwhile
loops, you get the expected output. This is consistent with thefor
loop.For example:
This runs on EDA playgrpound.