SystemC:在模块之间传递事件

发布于 2024-10-17 16:50:26 字数 554 浏览 2 评论 0原文

在 SystemC 中,使用事件作为模块输入/输出的语法是什么。

我有一个工作模块,我想向它发送一个事件以抢占调度程序模块当前正在执行的操作。

sc_port<preempt_event_if> preempt_event;

我正在上面所示的工作模块中声明一个接口。

该接口定义如下:

class preempt_event_if : virtual public sc_interface
{
    public:
        virtual const sc_event& preempt_event() const = 0;
};

使用该事件的通道将其定义如下:

const sc_event& preempt_event() const { return preempt_interrupt; }

其中 preempt_interrupt 是从通道函数内部获取通知的 SystemC 事件。

In SystemC, what is the syntax to use events as module input/outputs.

I have a worker module and I want to send it an event to preempt what it's currently doing from a scheduler module.

sc_port<preempt_event_if> preempt_event;

I'm declaring an interface within the worker module shown above.

The interface is defined as the following:

class preempt_event_if : virtual public sc_interface
{
    public:
        virtual const sc_event& preempt_event() const = 0;
};

The channel which uses the event defines it as the following:

const sc_event& preempt_event() const { return preempt_interrupt; }

Which where preempt_interrupt is a SystemC event that gets notified from within the channel's functions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情独悲 2024-10-24 16:50:26

你做得对,我只是使用void preempt()来调用notify,而不是通过接口返回事件。

You are doing it right, I'd just use void preempt() which calls notify, instead of returning the event through the interface.

叫思念不要吵 2024-10-24 16:50:26

在woker模块中,您可以使用静态敏感列表在重写的end_of_elaboration()内核回调函数中创建动态进程:

SC_METHOD(do_something);
sensitive << preempt_event->preempt_event();

因为只有在elaboration阶段结束时,您才能确定端口已经绑定到现有的preempt_event 通道。

在woker模块中反应事件的另一种方法是,您可以在正常的SC_THREADnext_trigger( preempt_event->preempt_event()) 在正常的 SC_METHOD 中。这两种方式都允许您的进程动态地对事件敏感。然后,在调度程序模块中,您可以再次创建 sc_port 并访问 preempt_event().notify() 以将事件发送到工作模块。

In the woker module, you can use static sensitivity list to create a dynamic process in the overridden end_of_elaboration() kernel callback function:

SC_METHOD(do_something);
sensitive << preempt_event->preempt_event();

Because only in the end of elaboration phase, you are sure that the port is already bound to an existing preempt_event channel.

Another way to react the event in the woker module is that you can just use wait(preempt_event->preempt_event()) in your normal SC_THREAD or next_trigger(preempt_event->preempt_event()) in your normal SC_METHOD. Both ways allow your process to be sensitive to the event dynamically. Then in your scheduler module, you can again create a sc_port<preempt_event_if> and access the preempt_event().notify() to send an event to the worker module.

友欢 2024-10-24 16:50:26

SystemC 事件主要用于调度进程执行,并且不保存任何可查询的状态,因此您无法知道事件是否发生。

为此,您需要使用 sc_buffer。只需在工作程序中声明一个 bool 类型的输入端口:

sc_in<bool> i_preempt;

在调度程序中声明一个 bool 类型的输出端口:

sc_out<bool> o_preempt;

并将两者绑定到一个缓冲区实例:

sc_buffer<bool> preempt;
scheduler.i_preempt.bind(preempt);
worker.o_preempt.bind(preempt);

在调度程序模块中,您可以可以将 true 值写入该缓冲区:

o_preempt->write(true);

在工作线程中,您可以检查 posedge 条件或等待 posedge_event

wait(event1 | i_preempt->posedge_event());
if (i_preempt->posedge()) { /* do preemption */ }

SystemC events are used mainly to schedule a process for execution and do not hold any state that can be queried, so there is nothing for you to know if the event has occurred or not.

You need to use a sc_buffer for that purpose. Just declare an input port of bool type in the worker:

sc_in<bool> i_preempt;

and an output port of bool type in the scheduler:

sc_out<bool> o_preempt;

and bind both to a buffer instance:

sc_buffer<bool> preempt;
scheduler.i_preempt.bind(preempt);
worker.o_preempt.bind(preempt);

In the scheduler module you can write a value of true to that buffer:

o_preempt->write(true);

and in the worker you can check for posedge condition or wait for posedge_event:

wait(event1 | i_preempt->posedge_event());
if (i_preempt->posedge()) { /* do preemption */ }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文