0

我是 systemC 编程的新手,我正在编写一个 D 触发器,但我找不到编写主程序和输入信号的方法(在我的情况下是 din、clock 和 dout):

这是我的代码:

#include "systemc.h" 

 SC_MODULE(d_ff) { // on déclare le module à l'aide de la macro SC_MODULE.

  sc_in<bool> din;   // signal d'entrée
  sc_in<bool> clock;// définition de l'horlogue
  sc_out<bool> dout;// signal de sortie

   void doit() {  // La fonction qui assure le traitement de la bascule D
     dout = din; // Affectation de la valeur du port d'entrée dans le port de sortie

     cout << dout;
     }; 

    SC_CTOR(d_ff) { //le constructeur du module d_ff
    SC_METHOD(doit); //On enregistre la fonction doit comme un processus
    sensitive_pos << clock;  } 


   int sc_main (int argc , char *argv[]) {
     d_ff obj();
       din<=true;
     clock<=false;
     obj.doit();
     return 0;
         }};
4

2 回答 2

2

这个页面有帮助吗?

http://www.asic-world.com/systemc/first1.html

它的标题是“我在 System C 中的第一个程序”,所以看起来是关于你在哪里。

其他一些对新手有用的链接:

http://panoramis.free.fr/search.systemc.org/?doc=systemc/helloworld

http://www.ht-lab.com/howto/vh2sc_tut/vh2sc_tut1.html

于 2012-04-25T13:03:59.433 回答
2

您必须安装 VCD 查看器才能以波形的形式查看模拟结果。我想这就是你想要的我使用这个http://www.iss-us.com/wavevcd/index.htm,但还有其他的。

接下来,您必须对代码进行一些更改。更改将生成 vcd 文件:

我做了这个:

// File dff.h
#include <iostream>
#include <systemc.h>

SC_MODULE (dff) {
    sc_in <bool> clk;
    sc_in <bool> din;
    sc_out <bool> dout;

    void dff_method();

    SC_CTOR (dff) {
        SC_METHOD (dff_method);
            sensitive_pos << clk;
    }
};

// File dff.cpp
#include "dff.h"

void dff:: dff_method (){
    dout=din;
}


// File: main.cpp
#include <systemc.h>
#include "dff.h"

int sc_main(int argc, char* argv[])
{
    sc_signal<bool> din, dout;
    sc_clock clk("clk",10,SC_NS,0.5);

    dff dff1("dff");

    dff1.din(din);
    dff1.dout(dout);
    dff1.clk(clk);

    // WAVE
    sc_trace_file *fp;                    // VCD file
    fp=sc_create_vcd_trace_file("wave");
    fp->set_time_unit(100, SC_PS);        // resolution (trace) ps
    sc_trace(fp,clk,"clk");               // signals
    sc_trace(fp,din,"din");
    sc_trace(fp,dout,"dout");

    //Inicialization
    din=0;

    //START
    sc_start(31, SC_NS);               
    din=1;
    cout << "Din=1" << endl;
    cout << "Tempo: " << sc_time_stamp() << endl;

    sc_start(31, SC_NS);
    din=0;
    cout << "Din=0" << endl;
    cout << "Tempo: " << sc_time_stamp() << endl;

    sc_start(31, SC_NS);

    sc_close_vcd_trace_file(fp);        // fecho(fp)

    char myLine[100];
    cin.getline(myLine, 100);

    return 0;
}

我希望它会有所帮助

于 2012-05-04T15:14:20.190 回答