[英]SystemC - Can I retrieve clock period from sc_in_clk port?
Can I retrieve the clock period through sc_port
?我可以通过
sc_port
检索时钟周期吗?
The following code doesn't work.以下代码不起作用。 I'd like to call method
period()
defined in sc_clock
.我想调用
sc_clock
定义的方法period()
。
sc_in_clk clk;
*clk.get_interface()->period();
You could use dynamic_cast<>
to cast the sc_interface
returned by get_interface()
as an sc_clock
:你可以使用
dynamic_cast<>
铸就sc_interface
由归国get_interface()
作为sc_clock
:
#include <iostream>
#include <systemc>
using namespace std;
using namespace sc_core;
SC_MODULE(A) {
sc_in_clk clk;
SC_CTOR(A) {}
void start_of_simulation() {
sc_clock *channel = dynamic_cast<sc_clock *>(clk.get_interface());
cout << name() << ": period is "
<< (channel ? channel->period() : SC_ZERO_TIME) << endl;
}
};
int sc_main(int argc, char *argv[]) {
A a1("a1");
A a2("a2");
sc_clock clk("clk", 3.0, SC_NS);
sc_signal<bool> fake_clk("fake_clk");
a1.clk(clk);
a2.clk(fake_clk);
sc_start(10, SC_NS);
return EXIT_SUCCESS;
}
This works because sc_clock
is a subclass of sc_interface
.这工作,因为
sc_clock
是的子类sc_interface
。
If dynamic_cast<>
succeeds, then a valid sc_clock
pointer is returned.如果
dynamic_cast<>
成功,则返回有效的sc_clock
指针。 If it fails, NULL
is returned.如果失败,则返回
NULL
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.