systemc - 需要帮助来实现处理 ISR 的中断控制器模拟器
问题描述
我正在实现一个中断控制器模拟器,它将在模拟中从其他硬件模块获取信号并运行 ISR。
下面是为清楚概念而粗略制作的 SystemC 代码。在这种情况下,我们需要以某种方式处理 ISR,即使 FW_main 卡在 while(1) 循环中。
通过以下实现,上下文仅在 FW_main 循环内。在 FW_main 中添加等待不是我们想要的。我们需要正确的中断控制器功能。有什么想法可以摆脱这个问题吗?
SC_MODULE (processor)
{
sc_in < bool > interrupt;
void ISR(void)
{
cout << "i am in ISR\n";
}
void FW_main(void)
{
while(1)
{
cout << "i am in FW_main\n";
}
}
SC_CTOR (processor)
{
SC_METHOD(ISR);
sensitive << interrupt;
SC_THREAD(FW_main);
}
};
解决方案
不幸的是,SystemC 进程是协作的,而不是抢占式的。甚至 SystemC 内核也无法介入并挂起FW_main方法。
没有处理器系统/固件以这种方式真正卡在 while 循环中。任何指令集模拟器都必须在某种选通脉冲或事件(理想情况下是时钟边缘)上逐步运行时间。
您尝试建模的系统的功能表示如下所示。
SC_MODULE (processor)
{
sc_in < bool > clk;
sc_in < bool > interrupt;
void ISR(void)
{
cout << "i am in ISR\n";
}
void FW_main(void)
{
cout << "i am in FW_main\n";
}
SC_CTOR (processor)
{
SC_METHOD(ISR);
sensitive << interrupt;
SC_METHOD(FW_main);
sensitive << clk;
}
};
我建议的上述代码有两个问题。首先,您可能不想要需要外部切换的实际时钟信号或任何时间感。其次,在单核处理器系统中,ISR 和 FW_Main 本质上并不是真正的并行。您尝试建模的更现实的实现如下。
SC_MODULE(processor)
{
sc_in < bool > interrupt;
void ISR(void)
{
cout << "i am in ISR\n";
}
void FW_main(void)
{
if(interrupt.read())
{
ISR();
}
cout << "i am in FW_main\n";
next_trigger(SC_ZERO_TIME, interrupt);
}
SC_CTOR (processor)
{
SC_METHOD(FW_main);
}
};
该next_trigger(SC_ZERO_TIME, interrupt)
语句使 FW_main 模拟 while(1) 同时也对中断输入敏感。
推荐阅读
- python - Python 中的 Fibonacci o/p 不正确,因为未在同一行代码上分配值。为什么?
- node.js - 在 Log4js 中如何启用跟踪?
- angular - 我想用 Angular2 检查是否存在文件
- angular - 打开模态窗口组件
- c# - 在 MVC C# 中通过属性路由使用分页时,我们如何跳过可选的空参数?
- c# - AWS Cogntio:注册/登录后如何在 .Net 中发出身份验证请求
- c++ - Qt QByteArray 无符号数据类型
- ios - 带有图像和文本的自定义按钮
- php - Codeigniter 3 迭代多维数组并插入数据库(控制器和模型)
- hibernate - Hibernate Cascade:在没有子实体的情况下保存父实体时删除子实体