SystemC:在模块之间传递事件
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你做得对,我只是使用
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.在woker模块中,您可以使用静态敏感列表在重写的end_of_elaboration()内核回调函数中创建动态进程:
因为只有在elaboration阶段结束时,您才能确定端口已经绑定到现有的
preempt_event
通道。在woker模块中反应事件的另一种方法是,您可以在正常的
SC_THREAD
或next_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:
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 normalSC_THREAD
ornext_trigger(preempt_event->preempt_event())
in your normalSC_METHOD
. Both ways allow your process to be sensitive to the event dynamically. Then in your scheduler module, you can again create asc_port<preempt_event_if>
and access thepreempt_event().notify()
to send an event to the worker module.SystemC 事件主要用于调度进程执行,并且不保存任何可查询的状态,因此您无法知道事件是否发生。
为此,您需要使用
sc_buffer
。只需在工作程序中声明一个bool
类型的输入端口:在调度程序中声明一个
bool
类型的输出端口:并将两者绑定到一个缓冲区实例:
在调度程序模块中,您可以可以将
true
值写入该缓冲区:在工作线程中,您可以检查
posedge
条件或等待posedge_event
: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 ofbool
type in the worker:and an output port of
bool
type in the scheduler:and bind both to a buffer instance:
In the scheduler module you can write a value of
true
to that buffer:and in the worker you can check for
posedge
condition or wait forposedge_event
: