简体   繁体   English

SystemC - 我可以从 sc_in_clk 端口检索时钟周期吗?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM