Hi all,
this is our testbench for
handshake 4 Different Clock Domain. if you don't know it, you can
review our previous posted "
handshake 4 Different Clock Domain pt1".
t_ififo.h
#include <systemc.h>
#include <iostream>
using namespace std;
enum T_IFIFO_ST {
T_IDLE = 0,
T_GNT = 1,
T_Write= 2,
};
SC_MODULE(t_ififo) {
sc_out<bool> T_Rst;
sc_out<bool> T_Read_En;
sc_out<int> T_Read_Dt;
sc_in<bool> T_Read_Clk;
sc_out<bool> T_Read_Req;
sc_in<bool> T_Read_Gnt;
sc_in<bool> T_Write_En;
sc_in<int> T_Write_Dt;
sc_in<bool> T_Write_Clk;
sc_in<bool> T_Write_Req;
sc_out<bool> T_Write_Gnt;
sc_signal<int> T_Cur_ST;
sc_signal<int> T_Nxt_ST;
SC_CTOR(t_ififo){
SC_THREAD(TST_PRO_RD);
dont_initialize();
sensitive << T_Read_Clk.pos();
SC_METHOD(TST_PRO_WT);
dont_initialize();
sensitive << T_Rst;
sensitive << T_Write_Clk.pos();
SC_METHOD(TST_PRO_WT_DO);
dont_initialize();
sensitive << T_Cur_ST;
sensitive << T_Write_Req;
sensitive << T_Write_En;
SC_METHOD(TST_PRO_WT_OT);
dont_initialize();
sensitive << T_Write_Clk.pos();
SC_METHOD(TST_PRO_WT_DP);
dont_initialize();
sensitive << T_Write_Clk.pos();
TST_VCD_Dump();
};
void TST_PRO_RD();
void TST_2_OT( bool t, bool e, int d, bool r);
void TST_PRO_WT();
void TST_PRO_WT_DO();
void TST_PRO_WT_OT();
void TST_PRO_WT_DP();
void TST_VCD_Dump();
};
t_fifio.cpp
#include "t_ififo.h"
void t_ififo::TST_PRO_RD() {
TST_2_OT(false, false, 21, true);
wait();
TST_2_OT(false, true, 21, true);
wait();
//Reset
cout << "Send Reset ...\n" <<endl;
TST_2_OT(true, false, 21, false);
wait();
wait();
wait();
wait();
// release Reset
TST_2_OT(false, false, 21, false);
wait();
for(int i=1; i < 21; i++){
//Request
cout << "Send Request ...\n" <<endl;
while( T_Read_Gnt.read() != true ){
TST_2_OT(false, false, 21, true);
wait();
}
//release Reguest
TST_2_OT(false, false, 21, false);
wait();
// Data
cout << "Send Data ...\t"<< i <<endl;
TST_2_OT(false, true, i, false);
wait();
// release Data
TST_2_OT(false, false, i, false);
wait();
}
}
void t_ififo::TST_2_OT( bool t, bool e, int d, bool r) {
T_Rst.write(t);
T_Read_En.write(e);
T_Read_Dt.write(d);
T_Read_Req.write(r);
}
void t_ififo::TST_PRO_WT(){
sc_int<32> Tmp_Cur_ST = T_Cur_ST.read();
sc_int<32> Tmp_Nxt_ST = T_Nxt_ST.read();
Tmp_Cur_ST = ( T_Rst.read()== true )? T_IDLE : Tmp_Nxt_ST;
T_Cur_ST.write(Tmp_Cur_ST);
}
void t_ififo::TST_PRO_WT_DO(){
sc_int<32> Tmp_Cur_ST = T_Cur_ST.read();
sc_int<32> Tmp_Nxt_ST = T_Nxt_ST.read();
switch(Tmp_Cur_ST){
case T_IDLE : Tmp_Nxt_ST = ( T_Write_Req.read()==true )? T_GNT : T_IDLE; break;
case T_GNT : Tmp_Nxt_ST = T_Write; break;
case T_Write: Tmp_Nxt_ST = ( T_Write_En.read() ==true )? T_IDLE: T_Write; break;
default : Tmp_Nxt_ST = T_IDLE; break;
}
T_Nxt_ST.write(Tmp_Nxt_ST);
}
void t_ififo::TST_PRO_WT_OT(){
sc_int<32> Tmp_Cur_ST = T_Cur_ST.read();
sc_int<32> Tmp_Nxt_ST = T_Nxt_ST.read();
switch(Tmp_Cur_ST){
case T_IDLE : T_Write_Gnt.write(false); break;
case T_GNT : T_Write_Gnt.write(true); break;
case T_Write: T_Write_Gnt.write(false); break;
}
}
void t_ififo::TST_PRO_WT_DP(){
if(T_Write_En.read()==true){
cout<<"FeedBack::\t"<< T_Write_Dt.read() << endl;
}
}
void t_ififo::TST_VCD_Dump() {
sc_trace_file *fp = sc_create_vcd_trace_file("t_ififo_file");
((vcd_trace_file*)fp)->sc_set_vcd_time_unit(-9);
sc_trace(fp, T_Rst,"T_Rst");
sc_trace(fp, T_Write_En,"T_Write_En");
sc_trace(fp, T_Write_Dt,"T_Write_Dt");
sc_trace(fp, T_Write_Clk,"T_Write_Clk");
sc_trace(fp, T_Write_Req,"T_Write_Req");
sc_trace(fp, T_Write_Gnt,"T_Write_Gnt");
sc_trace(fp, T_Cur_ST,"T_Cur_ST");
sc_trace(fp, T_Nxt_ST,"T_Nxt_ST");
}
main.cpp
#include <systemc.h>
#include "ififo.h"
#include "t_ififo.h"
int sc_main (int argc , char *argv[]) {
sc_signal<bool> S_Rst;
sc_signal<bool> S_Read_En;
sc_signal<int> S_Read_Dt;
sc_signal<bool> S_Read_Req;
sc_signal<bool> S_Read_Gnt;
sc_signal<bool> S_Write_En;
sc_signal<int> S_Write_Dt;
sc_signal<bool> S_Write_Req;
sc_signal<bool> S_Write_Gnt;
// sc_clock S_Read_Clk;
sc_clock S_Read_Clk("S_Read_Clk", 10, SC_NS, 0.5, 0.0, SC_NS);
sc_clock S_Write_Clk("S_Write_Clk", 42, SC_NS, 0.5, 0.0, SC_NS);
ififo ififo_ptr("ififo");
ififo_ptr.Rst(S_Rst);
ififo_ptr.Read_Clk(S_Read_Clk);
ififo_ptr.Read_En(S_Read_En);
ififo_ptr.Read_Dt(S_Read_Dt);
ififo_ptr.Read_Req(S_Read_Req);
ififo_ptr.Read_Gnt(S_Read_Gnt);
ififo_ptr.Write_Clk(S_Write_Clk);
ififo_ptr.Write_Req(S_Write_Req);
ififo_ptr.Write_Gnt(S_Write_Gnt);
ififo_ptr.Write_En(S_Write_En);
ififo_ptr.Write_Dt(S_Write_Dt);
t_ififo t_ififo_ptr("t_ififo");
t_ififo_ptr.T_Rst(S_Rst);
t_ififo_ptr.T_Read_Clk(S_Read_Clk);
t_ififo_ptr.T_Read_En(S_Read_En);
t_ififo_ptr.T_Read_Dt(S_Read_Dt);
t_ififo_ptr.T_Read_Req(S_Read_Req);
t_ififo_ptr.T_Read_Gnt(S_Read_Gnt);
t_ififo_ptr.T_Write_Clk(S_Write_Clk);
t_ififo_ptr.T_Write_Req(S_Write_Req);
t_ififo_ptr.T_Write_Gnt(S_Write_Gnt);
t_ififo_ptr.T_Write_En(S_Write_En);
t_ififo_ptr.T_Write_Dt(S_Write_Dt);
sc_trace_file *fp = sc_create_vcd_trace_file("wave_file");
sc_trace(fp, S_Rst,"S_Rst");
sc_start(1000, SC_NS);
sc_close_vcd_trace_file(fp);
return 0;
}
compiler
g++ -Wall -g -c -I$(YourSystemC)/include/ ififo.cpp t_ififo.cpp main.cpp
g++ -Wall -DSC_INCLUDE_FX -O3 -o fifo ififo.o t_ififo.o main.o -L$(YourSystemC)/lib-linux -lsystemc -lm
./fifo
or you can download all files in
here
沒有留言:
張貼留言