Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ SystemC中测试台模块内的信号管理_C++_Segmentation Fault_Systemc_Test Bench - Fatal编程技术网

C++ SystemC中测试台模块内的信号管理

C++ SystemC中测试台模块内的信号管理,c++,segmentation-fault,systemc,test-bench,C++,Segmentation Fault,Systemc,Test Bench,我试图在SystemC中模拟一个模块,该模块使用一个CABA(周期精确/位精确)模型,该模型添加了两个数字。它具有以下信号: 模块添加\u CABA a:输入添加的编号 b:输入添加的编号 clk:时钟输入 valid:当输入a和b可用时变为1的输入信号 result:包含a+b结果的输出信号 就绪:当结果就绪时变为1的输出信号 为了测试此模块的结果是否正确,我创建了一个测试台模块,该模块具有以下信号: 模块测试台 result\u tb:从addition\u CABA模块接收结果信号的

我试图在SystemC中模拟一个模块,该模块使用一个CABA(周期精确/位精确)模型,该模型添加了两个数字。它具有以下信号:

模块
添加\u CABA

  • a
    :输入添加的编号
  • b
    :输入添加的编号
  • clk
    :时钟输入
  • valid
    :当输入
    a
    b
    可用时变为1的输入信号
  • result
    :包含
    a
    +
    b
    结果的输出信号
  • 就绪
    :当
    结果
    就绪时变为1的输出信号
为了测试此模块的结果是否正确,我创建了一个
测试台
模块,该模块具有以下信号:

模块
测试台

  • result\u tb
    :从
    addition\u CABA
    模块接收结果信号的输入信号
  • ready\u tb
    :从
    添加\u CABA
    模块接收就绪信号的输入信号
  • clk_tb
    :时钟输入信号。这两个模块都是一样的
  • rst\u tb
    :重置输入信号。这两个模块都是一样的
  • a\u tb
    :将数字a发送到
    加法\u CABA
    模块的输出信号
  • b_tb
    :将数字b发送到
    addition_CABA
    模块的输出信号
  • valid\u tb
    :将有效信号发送到
    加法\u CABA
    模块的输出信号
我正在做的测试如下:

  • 在模块
    testbench
    中,生成一对随机数,为
    a
    b
    赋值
  • 模块在一些时钟周期后计算结果
  • 测试台直接执行添加操作,并将其与模块生成的操作进行比较
  • 这些动作在一个循环中重复五次
我遇到的问题是,当我运行模拟
testbench
时,会给出正确的结果,
addition\u CABA
会显示结果,但会延迟一些时钟周期,因此比较是在两个不同的数字之间进行的。此外,当程序结束时,我有一条
分段错误(堆芯转储)
消息。我试图弄明白的是,如何指示
testbench
等待结果准备就绪(使用信号
ready_tb
),以便它可以使用正确的数字进行比较。我在(!ready_tb.read())wait()时尝试了
条件,但执行此操作时,程序结束,模拟从未开始

main.cpp
文件中,我只是在进行模块之间的连接,生成时钟并将
rst
信号设置为
0
。下面是我的代码:

添加\u CABA.h

#include <systemc.h>
//Module which adds two numbers
SC_MODULE(addition_CABA){
    sc_in< sc_uint<8> > a;
    sc_in< sc_uint<8> > b;
    sc_in<bool> clk;
    sc_in<bool> valid;
    sc_in<bool> rst;
    sc_out<bool> ready;
    sc_out< sc_uint<8> > result;

    int addcaba(int a, int b){
        int c;
        c = a+b;
        wait(3);
        return c;
    }

    void loop();

    SC_CTOR(addition_CABA){
        SC_CTHREAD(loop, clk.pos());
        async_reset_signal_is(rst, true);
    }

};
#include <systemc.h>

SC_MODULE(testbench){

    sc_in< sc_uint<8> > result_tb;
    sc_in<bool> ready_tb;
    sc_in<bool> clk_tb;
    sc_in<bool> rst_tb;

    sc_out< sc_uint<8> > a_tb;
    sc_out< sc_uint<8> > b_tb;
    sc_out<bool> valid_tb;

    void test();

    SC_CTOR(testbench){
        SC_CTHREAD(test, clk_tb.pos());
        async_reset_signal_is(rst_tb, true);
    }   

};
testbench.h

#include <systemc.h>
//Module which adds two numbers
SC_MODULE(addition_CABA){
    sc_in< sc_uint<8> > a;
    sc_in< sc_uint<8> > b;
    sc_in<bool> clk;
    sc_in<bool> valid;
    sc_in<bool> rst;
    sc_out<bool> ready;
    sc_out< sc_uint<8> > result;

    int addcaba(int a, int b){
        int c;
        c = a+b;
        wait(3);
        return c;
    }

    void loop();

    SC_CTOR(addition_CABA){
        SC_CTHREAD(loop, clk.pos());
        async_reset_signal_is(rst, true);
    }

};
#include <systemc.h>

SC_MODULE(testbench){

    sc_in< sc_uint<8> > result_tb;
    sc_in<bool> ready_tb;
    sc_in<bool> clk_tb;
    sc_in<bool> rst_tb;

    sc_out< sc_uint<8> > a_tb;
    sc_out< sc_uint<8> > b_tb;
    sc_out<bool> valid_tb;

    void test();

    SC_CTOR(testbench){
        SC_CTHREAD(test, clk_tb.pos());
        async_reset_signal_is(rst_tb, true);
    }   

};
#包括
SC_模块(测试台){
结果tb中的SCU;
sc_in ready_tb;
以时钟为单位的sc_tb;
sc_在rst_tb中;
sc_outa_tb;
sc_outb_tb;
sc_输出有效的_tb;
无效试验();
高级工程师(试验台){
SC_CTHREAD(test,clk_tb.pos());
异步复位信号为(rst_tb,真);
}   
};
testbench.cpp

void addition_CABA::loop(){

    ready.write(0);
    result.write(0);

    if(rst){
        ready.write(0);
        result.write(0);
    }   

    else{

        while(1){
            while (!valid.read()) wait();

            result.write(addcaba(a.read(),b.read()));
            ready.write(1);

            wait();
            ready.write(0);
        }

    }
}
void testbench::test(){

    uint8_t c = 0;
    int k = 0;

    if (rst_tb){
        c = 0;
        k = 0;
        cout << "\nReset on!\n" << endl;
    }

    else{
        //while(!ready_tb.read()) wait(); //when using this condition the simulation never starts
            while(k < 5){
                a_tb.write( (1 + rand() % (128-1)) );
                b_tb.write( (1 + rand() % (128-1)) );

                valid_tb.write(1);
                sc_start(10, SC_NS);

                valid_tb.write(0);
                sc_start(10, SC_NS);

                cout << "\nTest number " << k+1 << endl;
                cout << "\ta = " << a_tb.read() << " and b = " << b_tb.read() << endl;
                cout << "\tAddition of " << a_tb.read() << " and " << b_tb.read();
                cout << " = " << result_tb.read() << endl;

                c = a_tb.read() + b_tb.read();

                if ( result_tb.read() != c ){
                    cout << "Real result = " << a_tb.read() + b_tb.read();
                    cout << " and result with module = " << result_tb.read() << endl;  
                    cout << "Wrong result\n" << endl;
                    //  exit(1);
                }

                else cout << "Result OK\n" << endl;
                k++;
        }   
    }
}
void testbench::test(){
uint8_t c=0;
int k=0;
如果(rst_tb){
c=0;
k=0;

cout问题的根本原因如下:

  • main.cpp
    函数中的模拟时间太短(10 ns,我修改为500 ns)
  • 由于testbench模块中的test函数是一个
    SC_CTHREAD
    ,它必须在一个无限循环中。以前的实现是完全错误的,我认为这也是
    分段错误(内核转储)
    消息的根本原因
  • 此外,不需要重复测试五次的循环,因为迭代次数与模拟时间有关(在
    main.cpp
    函数中设置)。下面是
    testbench.cpp
    的代码:

    void testbench::test(){
    
        uint8_t c = 0;
        int k = 0;
    
        if (rst_tb){
            c = 0;
            k = 0;
            cout << "\nReset on!\n" << endl;
        }
    
        else{
            while(1){   
                    a_tb.write( (1 + rand() % (128-1)) );
                    b_tb.write( (1 + rand() % (128-1)) );
    
                    valid_tb.write(1);
                    wait();
                    valid_tb.write(0);
                    wait();
    
                    while(!ready_tb.read()) wait();//This condition waits until ready_tb = true to continue the simulation
    
                    cout << "\nTest number " << k+1 << endl;
                    cout << "\ta = " << a_tb.read() << " and b = " << b_tb.read() << endl;
                    cout << "\tAddition of " << a_tb.read() << " and " << b_tb.read();
                    cout << " = " << result_tb.read() << endl;
    
                    c = a_tb.read() + b_tb.read();
    
                    if ( result_tb.read() != c ){
                        cout << "Real result = " << a_tb.read() + b_tb.read();
                        cout << " and result with module = " << result_tb.read() << endl;  
                        cout << "Wrong result\n" << endl;
                        exit(1);
                    }
    
                    else cout << "Result OK\n" << endl;
    
                    k++;
            }   
        }
    }
    
    void testbench::test(){
    uint8_t c=0;
    int k=0;
    如果(rst_tb){
    c=0;
    k=0;
    库特