Visual Studio 2008配置SystemC开发环境
一、编译System库
1.下载SystemC library source code
到http://www.systemc.org注册会员账号后,即可下载SystemC library soure code
2. 以SystemC 2.2.0为例,下载后的文件名喂systemc-2.2.0.tgz,解压到C盘目录下:C:\systemc-2.2.0
3. 打开C:\systemc-2.2.0\msvc71\SystemC目录下的SystemC.sln
4.VS一般都是Debug模式,所以直接"生成(Build英文)"-->“生成解决方案(Build Solution)”,如果编译成功的话(忽略那些Warning)。在C:\systemc-2.2.0\msvc71\SystemC\debug目录下就生成了SystemC.lib
二:更新SystemC include file 和 library
1. Select Tools(工具) -> Options(选项) . . . and the Projects(项目和解决方案) -> VC++ Directories tab(Vc++目录)
2. Select show directories for: Library files(库文件)
3. Select the 'New' icon and browse to: C:\systemc-2.2.0\msvc71\SystemC\Debug
4. Select show directories for: Include files(包含文件)
5. Select the 'New' icon and browse to: C:\systemc-2.2.0\src
步骤三:创建SystemC应用程序
1. Start Visual Studio. From the Start Page select New Project and Win32 Console Project (Windows 控制台应用程序). Type the project name and select a suitable location then click OK.
2. Select the Application Settings page of the Win32 Application Wizard and make sure the 'Empty project' box is ticked(把空项目勾起来). Click 'Finish' to complete the wizard.
3. Add new/existing C++ files to the project and edit code.【一定要添加某个C++文件否则下一步就找不到C/c++的选项了】
4. Display the project Property Pages by selecting 'Properties...' from the Project menu.
5. C/C++ -> General properties Warning level= Level 1(/W1)
6. C/C++ -> Code Generation Runtime Library =Multi-thread Debug (/MTd)
7. C/C++ -> Command Line properties Additional Options = /vmg /D_CRT_SECURE_NO_DEPRECATE
8. Linker -> Input properties Additional Dependiences = systemc.lib
9. Click
结束
附上一个测试文件: 一个加法器:
adder.h
- #ifndef _ADDER_H
- #define _ADDER_H
- SC_MODULE(Adder){
- public:
- sc_in<int> data_in_1;
- sc_in<int> data_in_2;
- sc_out<int> data_out;
- SC_CTOR(Adder){
- SC_METHOD(adder_action);
- sensitive << data_in_1 <<data_in_2;
- }
- void adder_action(){
- data_out = data_in_1 + data_in_2;
- }
- };
- #endif
#ifndef _ADDER_H
#define _ADDER_H
SC_MODULE(Adder){
public:
sc_in<int> data_in_1;
sc_in<int> data_in_2;
sc_out<int> data_out;
SC_CTOR(Adder){
SC_METHOD(adder_action);
sensitive << data_in_1 <<data_in_2;
}
void adder_action(){
data_out = data_in_1 + data_in_2;
}
};
#endif
adder.cpp
- #include <systemc.h>
- #include "adder.h"
- SC_MODULE(Stimulator) {
- public:
- sc_out<int> data_out_1, data_out_2;
- SC_CTOR(Stimulator){
- SC_THREAD(send_data);
- dont_initialize();
- };
- private:
- void send_data() {
- int i = 3;
- while(true){
- wait(i, SC_NS);
- cout << "Time: " << sc_time_stamp() << "::";
- cout << "Send data: " << 4*i << ", " << 5*i-2 << endl;
- data_out_1 = 4*i;
- data_out_2 = 5*i-2;
- i++;
- if(i >= 14) {
- wait(1,SC_NS);
- sc_stop();
- }
- }
- };
- };
- SC_MODULE(Monitor) {
- public:
- sc_in<int> data_in;
- SC_CTOR(Monitor){
- SC_METHOD(display);
- dont_initialize();
- sensitive << data_in;
- };
- private:
- void display(){
- cout << "Time: " << sc_time_stamp() << "::";
- cout << "Receive data: " << data_in.read() << endl;
- };
- };
- int sc_main(int argc, char* argv[]) {
- Stimulator *stim;
- Monitor *mon;
- Adder *adder;
- stim = new Stimulator("Stimulator");
- mon = new Monitor("Monitor");
- adder = new Adder("Adder");
- sc_signal<int> data_in_1, data_in_2, data_out;
- stim->data_out_1(data_in_1);
- stim->data_out_2(data_in_2);
- mon->data_in(data_out);
- adder->data_in_1(data_in_1);
- adder->data_in_2(data_in_2);
- adder->data_out(data_out);
- sc_start();
- return 0;
- }