Quantcast
Channel: SystemC Language Forum RSS Feed
Viewing all articles
Browse latest Browse all 595

systemc model of d-flip-flop

$
0
0

1) I will be thankful if i could get some support to resolve error in the attachment as i have tried to implement a pre-defined example.

 

2) for what time  wait() statement is used in method tb_input

 

3) please guide me a bit about hierarchy ( module instantiation ) syntax part

 

4) how to view output in waveform

#include "systemc.h"

SC_MODULE (d_ff) 
{
	sc_in<bool> d;
	sc_in<bool> q;
	bool clk;

SC_CTOR (d_ff) 
{
	SC_METHOD(flop);
	sensitive<<clk.pos();
}

void flop()
{
	q.write(d.read());
}

};

// hierarchy
SC_MODULE (d_ff_4) 
{
	sc_in<bool> d;
	sc_out<bool> q3;
	sc_signal<bool> q0,q1,q2;
	bool clk;

	d_ff d1,d2,d3,d4;

SC_CTOR(d_ff_4) : d1("d1"), d2("d2"),d3("d3"),d4("d4")
{
	d1.d(d);
	d1.clk(clk);
	d1.q(q0);

	d2.d(q0);
	d2.clk(clk);
	d2.q(q1);

	d3.d(q1);
	d3.clk(clk);
	d3.q(q2);

	d4.d(q2);
	d4.clk(clk);
	d4.q(q3);
}

};

//test bench

SC_MODULE(tb) 
{
	sc_out<bool> d;
	bool clk;

void tb_input() 
{
	d.write(false);
	wait();
	d.write(true);
	wait();
	sc_stop();
}

SC_CTOR(tb)
{
	SC_THREAD(tb_input);
	sensitive<<clk.pos();
}
};

//top

int sc_main(int argc, char* argv[]) 
{
	sc_clock testclk("testclock", 10, SC_NS,0.5);

	d_ff d_111("d_111");
	d_mast.flop();

	d_ff_4 d_112("d_112");

	tb t1("t1");
	t1.tb_input();

	sc_start();

return (0);
}

Viewing all articles
Browse latest Browse all 595

Trending Articles