当我将下面的代码放入我的解决方案然后进行调试时,按下包含这个“Q2.exe中0x0016ec86处的未处理异常:0xC0000005:访问冲突读取位置0x00000000”。来到我的屏幕上。 我认为这是由于“cout”,但我不知道如何解决它 “”代码写在“systemC”中,是一个c ++“”
的库#ifndef IF_classes
#define IF_classes
#include "systemc.h"
#include <iostream>
class put_if : virtual public sc_interface
{
public:
virtual void put(sc_lv<8>[16], int) = 0;
};
class get_if : virtual public sc_interface
{
public:
int d;
virtual void get(sc_lv<8>[16], int) = 0;
};
#endif
#include "IF_classes.h"
class router : public put_if, public get_if
{
bool full[4];
sc_lv<8> reg[4];
int rf;
sc_signal<bool> getD_ev[4], putD_ev[4], timeout_ev;
public:
router() {};
~router() {};
void put(sc_lv<8> data[16], int RF);
void get(sc_lv<8> data[16], int d);
};
#include "router.h"
void router::put(sc_lv<8> data[16], int RF)
{
rf = RF;
if (rf < 0) //////////////////////////Routing Field < 0
{
rf = abs(rf+1)%4;
for(int i = 0; i<= 15; i++)
{
if (full[rf] == true)
wait (getD_ev[rf].posedge());
reg[rf] = data[i];
full[rf] = true;
getD_ev[rf] = 0;
putD_ev[rf] = 1;
}
}
else if (rf == 0) ////////////////////Routing Field == 0
{
int i = 0;
while ( i < 16)
{
if (full[0] = false)
for(i = 0; i <= 15; i++)
{
if (full[0] == true)
wait (getD_ev[0].posedge());
reg[0] = data[i];
full[0] = true;
getD_ev[0] = 0;
putD_ev[0] = 1;
}
else if (full[1] = false)
for(i = 0; i <= 15; i++)
{
if (full[1] == true)
wait (getD_ev[1].posedge());
reg[1] = data[i];
full[1] = true;
getD_ev[1] = 0;
putD_ev[1] = 1;
}
else if (full[2] = false)
for(i = 0; i <= 15; i++)
{
if (full[2] == true)
wait (getD_ev[2].posedge());
reg[2] = data[i];
full[2] = true;
getD_ev[2] = 0;
putD_ev[2] = 1;
}
else if (full[3] = false)
for(i = 0; i <= 15; i++)
{
if (full[3] == true)
wait (getD_ev[3].posedge());
reg[3] = data[i];
full[3] = true;
getD_ev[3] = 0;
putD_ev[3] = 1;
}
}
}
else /////////////////////////////////Routing Field > 0
{
for(int j = 0; j < rf; j++)
{
if (full[0] = false)
for(int i = 0; i <= 15; i++)
{
if (full[0] == true)
wait (getD_ev[0].posedge());
reg[0] = data[i];
full[0] = true;
getD_ev[0] = 0;
putD_ev[0] = 1;
}
else if (full[1] = false)
for(int i = 0; i <= 15; i++)
{
if (full[1] == true)
wait (getD_ev[1].posedge());
reg[1] = data[i];
full[1] = true;
getD_ev[1] = 0;
putD_ev[1] = 1;
}
else if (full[2] = false)
for(int i = 0; i <= 15; i++)
{
if (full[2] == true)
wait (getD_ev[2].posedge());
reg[2] = data[i];
full[2] = true;
getD_ev[2] = 0;
putD_ev[2] = 1;
}
else if (full[3] = false)
for(int i = 0; i <= 15; i++)
{
if (full[3] == true)
wait (getD_ev[3].posedge());
reg[3] = data[i];
full[3] = true;
getD_ev[3] = 0;
putD_ev[3] = 1;
}
if (j = rf)
timeout_ev = 1;
}
}
}
void router :: get( sc_lv<8> data[16],int d)
{
for(int i = 0; i <= 15; i++)
{
if (full[d] == false)
wait (putD_ev[d].posedge());
data[i] = reg[d];
full[d] = false;
putD_ev[d] = 0;
getD_ev[d] = 1;
}
}
#ifndef transfer
#define transfer
#include "router.h"
SC_MODULE (source)
{
sc_port<put_if> out;
void putting();
SC_CTOR(source)
{
SC_THREAD(putting);
}
};
SC_MODULE (drain)
{
sc_port<get_if> in1, in2, in3, in4;
void getting();
SC_CTOR(drain)
{
SC_THREAD(getting);
}
};
#endif
#include "transfer.h"
void source :: putting()
{
sc_lv<8> to_put[16];
int routing_field;
for (int i = 0; i < 128 ; i++)
{
wait(2, SC_NS);
to_put[i%16] = (sc_lv<8>) i;
if (i%16 == 0 && i != 0)
{
routing_field = ((-1)^(i))*(rand()%4);
out->put(to_put, routing_field);
cout << "At: " << sc_time_stamp() << "\n" << to_put[0]
<< "\n" << to_put[1]
<< "\n" << to_put[2]
<< "\n" << to_put[3]
<< "\n" << to_put[4]
<< "\n" << to_put[5]
<< "\n" << to_put[6]
<< "\n" << to_put[7]
<< "\n" << to_put[8]
<< "\n" << to_put[9]
<< "\n" << to_put[10]
<< "\n" << to_put[11]
<< "\n" << to_put[12]
<< "\n" << to_put[13]
<< "\n" << to_put[14]
<< "\n" << to_put[15]
<< "\n" << " was transmitted to: rf" << routing_field+1 << ".\n";
}
}
}
void drain :: getting()
{
sc_lv<8> what_got[16];
for (int i = 0; i < 128; i++)
{
wait(2,SC_NS);
in1->get(what_got, 0);
in2->get(what_got, 1);
in3->get(what_got, 2);
in4->get(what_got, 3);
if (i%16 == 0 && i != 0)
{
cout << "At: " << sc_time_stamp() << "\n" << what_got[0]
<< "\n" << what_got[1]
<< "\n" << what_got[2]
<< "\n" << what_got[3]
<< "\n" << what_got[4]
<< "\n" << what_got[5]
<< "\n" << what_got[6]
<< "\n" << what_got[7]
<< "\n" << what_got[8]
<< "\n" << what_got[9]
<< "\n" << what_got[10]
<< "\n" << what_got[11]
<< "\n" << what_got[12]
<< "\n" << what_got[13]
<< "\n" << what_got[14]
<< "\n" << what_got[15]
<< "was recieved at: " << "\n";
}
}
}
#include "transfer.h"
SC_MODULE (transfer_tb)
{
router *rout;
source *S;
drain *D1, *D2, *D3, *D4;
SC_CTOR (transfer_tb)
{
//rout = new router();
S = new source("source");
S->out(*rout);
D1 = new drain("drain1");
D1->in1(*rout);
D2 = new drain("drain2");
D2->in2(*rout);
D3 = new drain("drain3");
D3->in3(*rout);
D4 = new drain("drain4");
D4->in4(*rout);
}
};
#include "transfer_tb.h"
int sc_main (int argc, char* argv[])
{
transfer_tb T_tb1("transfer_tb");
sc_start(1000, SC_NS);
return 0;
}
答案 0 :(得分:1)
what_got
未初始化。