Writing the main program of a D flip-flop
-
03-06-2021 - |
Question
I'm new to systemC programming i'm writing a D flip-flop but i couldn't find a way to write the main program and to enter signals (din , clock and dout in my case) :
this is my code :
#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;
}};
Solution
You have to install VCD Viewers to see simulation results in the form of waveforms. I suppose that's what you want I use this one http://www.iss-us.com/wavevcd/index.htm, but there are others.
Next you have to make some changes in you code. The changes will produce the vcd files:
I made this one:
// 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;
}
I hope it will help
OTHER TIPS
Does this page help any?
http://www.asic-world.com/systemc/first1.html
It's entitled "My first program in System C", so looks to be about where you are.
Some other useful links for new starters:
http://panoramis.free.fr/search.systemc.org/?doc=systemc/helloworld