首页 > 解决方案 > 需要帮助来实现处理 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 进程是协作的,而不是抢占式的。甚至 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) 同时也对中断输入敏感。


推荐阅读