天天看點

VS2012下systemC配置

一、編譯System庫

        1.下載下傳SystemC library source code

              到http://www.systemc.org注冊會員賬号後,即可下載下傳SystemC library soure code

        2. 以SystemC 23.0為例,下載下傳後的檔案名喂systemc-2.3.0.tgz,解壓到C槽目錄下:F:systemc-2.2.0

        3. 打開C:systemc-2.3.0msvc80SystemC目錄下的SystemC.sln

        4.VS一般都是Debug模式,是以直接"生成(Build英文)"-->“生成解決方案(Build Solution)”,如果編譯成功的話(忽略那些Warning)。在C:systemc-2.3.0msvc80SystemCdebug目錄下就生成了SystemC.lib

        我在編譯時遇到這樣的問題:fatal error C1189: #error :  The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro. 在這截下來跟大家分享下,解決方案是:

        右鍵Properties -> configuration Properties ->C/C++ -> Preprocessor -> Preprocessor Definitions 添加_XKEYCHECK_H 。

二、建立一個控制台應用程式。添加測試代碼,這裡給出一個測試代碼:

//mon.h

#ifndef _MON_H
#define _MON_H
#include <systemc>
SC_MODULE(mon){
	sc_in<bool> A,B,F;
	sc_in_clk Clk;
	void monitor(){	//watch the inport and outport signal until simulatus stop	
		while(1){
			wait();
			cout<<sc_time_stamp()<<"	"<<A.read()
		    	<<"	"<<B.read()<<"	"<<F.read()<<endl;
		}
	}
	SC_CTOR(mon){
		SC_THREAD(monitor);
		sensitive<<Clk.pos();
		cout<<"Time	A	B	F"<<endl;
	}
};
#endif      

//nand2.h

#ifndef _NAND2_H
#define _NAND2_H

#include <systemc>

SC_MODULE (nand2){			//declare nand2 module
       sc_in<bool> A,B;          		//input signal ports
       sc_out<bool> F;			//output port
       void do_nand(){			//simulate logic function of the nand
              F.write(!( A.read() && B.read()));
       };
       SC_CTOR(nand2){			//constructor for nand2
              SC_METHOD (do_nand);		//register do_nand with kernel
              sensitive<<A<<B;		//sensitivity list
       }
};
#endif      

//stim.h

#ifndef _STIM_H
#define _STIM_H

#include <systemc>

SC_MODULE(stim){
	sc_out<bool> A,B;				//declare outport signal
	sc_in<bool> Clk;				//declare clock
 
	void gen_stim(){				//function to generate the test bench
		A.write(0);
		B.write(0);
		wait();
		A.write(0);
		B.write(1);
		wait();
		A.write(1);
		B.write(0);
		wait();
		A.write(1);
		B.write(1);
		wait();
		sc_stop();
	}
	SC_CTOR(stim){
		SC_THREAD(gen_stim);
		sensitive<<Clk.pos();
	}
};
#endif
      

//main.cpp

#include"nand2.h"
#include"stim.h"
#include"mon.h"
 
int sc_main(int argc, char* argv[]){
	sc_signal<bool> Asig, Bsig, Fsig;
	sc_clock testClk("TestClock",10,SC_NS,0.5);
 
	nand2 nand("nand2");
	nand.A(Asig);
	nand.B(Bsig);
	nand.F(Fsig);
 
	stim stim1("Stimulus");
	stim1.A(Asig);
	stim1.B(Bsig);
	stim1.Clk(testClk);
 
	mon monitor1("Monitor");
	monitor1.A(Asig);
	monitor1.B(Bsig);
	monitor1.F(Fsig);
	monitor1.Clk(testClk);
 
	sc_start();							//stimulus start
	return 0;
}      

      右擊工程名�選擇Properties

VS2012下systemC配置

        C/C++→General →Additional Include Directories (F:systemc-2.3.0src)

        C/C++ →Language →Enable Run-Time Type Info→Yes

        C/C++→Code Generation→Runtime Library→Multi-thread Debug(/MTd)

        C/C++→ Command Line→Additional Options加上/vmg /D_CRT_SECURE_NO_DEPRECATE

        Linker →General→Additional Library Directories (D:systemc- 2.3.0msvc80SystemCDebug)

        Linker →Input→Additional Dependencies (SystemC.lib)

        之後編譯運作即可。