简体   繁体   English

SystemC:在模块之间传递事件

[英]SystemC: passing events between modules

In SystemC, what is the syntax to use events as module input/outputs. 在SystemC中,将事件用作模块输入/输出的语法是什么。

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. 其中preempt_interrupt是从通道函数内获得通知的SystemC事件。

In the woker module, you can use static sensitivity list to create a dynamic process in the overridden end_of_elaboration() kernel callback function: 在woker模块中,您可以使用静态敏感性列表在重写的end_of_elaboration()内核回调函数中创建动态过程:

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. 因为仅在preempt_event阶段结束时,您确定该端口已绑定到现有的preempt_event通道。

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 . 反应在woker模块中的事件的另一种方法是,你可以只用wait(preempt_event->preempt_event())在你的正常SC_THREADnext_trigger(preempt_event->preempt_event())在您的正常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. 然后在调度程序模块中,您可以再次创建sc_port<preempt_event_if>并访问preempt_event().notify()以将事件发送到工作模块。

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. SystemC事件主要用于安排执行过程,并且不保留任何可以查询的状态,因此您无需知道事件是否已发生。

You need to use a sc_buffer for that purpose. 您需要使用sc_buffer来实现此目的。 Just declare an input port of bool type in the worker: 只需在worker中声明一个bool类型的输入端口:

sc_in<bool> i_preempt;

and an output port of bool type in the scheduler: 和调度程序中的bool类型的输出端口:

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: 在调度程序模块中,您可以将值true写入该缓冲区:

o_preempt->write(true);

and in the worker you can check for posedge condition or wait for posedge_event : 在工人中你可以检查posedge条件或等待posedge_event

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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