SystemC Simulation Tutorial:
Design of a 1-bit Adder and a 4-bit Adder
Setting up SystemC
a Project Workspace:
- Start Microsoft Visual C++ 6.0
In the "Location" box, click on the down arrow, then on "Drives", and choose "h:\\some_server_name\cs1Xxx" , then click "OK" (some_server_name will have some name there (it changes periodically)) (csXxx is your login). You should not actually be typing anything here, just click.
For the "Project Name", We will use "lab1a" as the example.
Choose "An empty project" and click "Finish". Then click "OK".
You can now see a folder named "lab1a classes" in the workspace window. (Left part of screen)Port SystemC libraries to Microsoft Visual C++ 6.0:
Click on "File", then "New", select "Projects", then click on "Win32 Console Application".
on “Project”, then “Settings”, then select the C/C++ tab, and then finally select the “C++ Language” category. Make sure that the “Enable Run Time Type Information (RTTI)” checkbox is checked.
Also make sure that the SystemC header files are included by switching to the “Preprocessor” on the C/C++ tab and then typing “C:\SystemC\systemc-2.0.1\src” in the text entry field labeled “Additional include directories”.
Next click on the “Link” tab, and make sure the SystemC library is included to your project by typing “C:\SystemC\systemc-2.0.1\msvc60\systemc\Debug” in the text entry field labeled “Additional library path”.
Add the SystemC object files by first clicking on “Project”, then “Add to Project”, then “Files”. In the File Browser navigate to the “C:\SystemC\systemc-2.0.1\msvc60\systemc\Debug” directory. In the text entry field labeled “File Name” type “*.obj” and press enter. Click on the file “sc_attribute.obj” and then simultaneously press the “Ctrl” & “A” keys (CTRL+A). Click the OK button to add the files.
In your workspace window under the “File View” Tab, you should see a number of object files with the “sc_” prefix such as sc_attribute.obj, sc_bit.obj, etc. Find the file “sc_isdb_trace.obj”, click that file name, and press “delete” on your keyboard.
Creating the 1-bit adder
- After creating a new project by following the steps above, Click on "File", then "New", then click on "C++ Source File" under the "Files" tab.
- Make Sure the "Add to Project" box is checked. In the "Filename" box, type in the file's name.
To keep things simple, name your file "add1", the .cpp extension is automatically added.
- Enter the following is the SystemC code for the 1-bit adder. Enter the code as seen below into the empty file. NOTE: All lines that start with "//" are not needed. These are comments to help you better understand what the actual code is doing.
// Simulation Tutorial
// 1-bit Adder
// This is to include the SystemC constructs and objects.
// We declare the 1-bit ADDER as a "SC_MODULE" with the input and
// output ports declared immediately after the module declarations
// This will add two bits together(a,b), with a carry in(cin) and
// output the sum(sum) and a carry out(cout).
//In the constructor block of the module, declare a method called "process"
//with a sensitivity list that includes a, b, & cin.
sensitive << a << b << cin;
//Define the functionality for the "process" method in the 1-BIT adder
//Declare variables of type "logic" to be used in calculations
//Perform intermediate calculations for the 1-BIT adder
//Note to read input from a port, one must use the format: "port_name.read()"
aANDb = a.read() & b.read();
aXORb = a.read() ^ b.read();
cinANDaXORb = cin.read() & aXORb;
//Calculate sum and carry out of the 1-BIT adder
sum = aXORb ^ cin.read();
cout = aANDb | cinANDaXORb;
}; //Don't forget the semicolon!
Simulating the design
- Download the testbench file and the simulation file. (in Internet Explorer you can right click on the word 'here' and do a 'save target as').
- Save the file to your project directory.
- Select the Project Menu, choose "Add to Project", and click "Files". Add the testbench and simulation file to your project
- Select the Build menu and choose Build "lab1a.exe".
- If no errors, Select the Build menu again and this time choose Execute "lab1a.exe".
Creating and testing the 4-bit adder
What to turn in:
- Create a New Project by following steps 2-4 in the previous "Setting up SystemC" section.
- The design should be called adder4.
- Download the following files: vector.cpp, add4_tst.cpp,and add4_main.cpp
- Add all of these files to the design and the the model file from your 1-bit adder: add1.cpp.
- Note that there are only two test-cases in the testbench file. You have to add FOUR more unique test cases (each of which you need to include the correct 'assert' statement) and update the print() function in your testbench.
- Compile all files, then build and execute your project to simulate the design.
- View the simulation to verity that the 4-bit adder functionality is correct.
- Show the results of your test-bench to your TA.
- If you have demo'ed the design to your TA, write up a lab report and e-mail it.
- Attach your testbench for the 4-bit adder to your e-mail (the other code is not necessary).