为什么我在systemC中遇到分段错误(核心转储)



我不明白为什么在systemC中出现分段错误。我不知道为什么我会犯这些错误。也许这与我如何调用函数有关?服务器有三个过程:接收、更新和传输。服务器接收信号,然后更新其数据结构,然后将更新后的状态响应发送回机器人。我现在只测试一个模块。我还没有连接机器人模块。

这是我的服务器.cpp代码:

#include "systemc.h"
SC_MODULE(server){
//Inputs
sc_in<sc_uint<2> > statusIn1;
sc_in<bool> incomingSig1;
sc_in<sc_uint<2> > statusIn2;
sc_in<bool> incomingSig2;
//Outputs
sc_out<bool> statusOut1;
sc_out<sc_uint<2> > outgoingSig1;
sc_out<bool> statusOut2;
sc_out<sc_uint<2> > outgoingSig2;
//Variables
sc_uint<6> robot1Path[11] = {10,9,8,7,6,5,4,3,2,1,11}; //Robot 1 Path
sc_uint<6> robot2Path[10] = {51,49,39,36,26,23,13,11,1,2}; //Robot 2 Path
int currentPath1;
int nextPath1;
int currentPath2;
int nextPath2;
sc_uint<2> status[2]; //Stauses for each robot, 0 - OK, 1 - STOP, 2 - RESUME, 3 = CROSSED
//Update
void prc_update(){
//Update Robot 1
if(incomingSig1.read()){
cout << "Incoming Robot 1 Signal " << endl;
//Respond to Signal 0 - CROSSING
if(statusIn1.read() == 0){
cout << "Robot 1 crossing " << endl;
if(robot1Path[nextPath1] == robot2Path[currentPath2]){
cout << "Robot 1 should stop, robot 2 in the way " << endl;
status[0] = 1; // STOP
}else{
cout << "Robot 1 can cross " << endl;
status[0] = 0; //OK
}
}else if(statusIn1.read() == 1 || statusIn1.read() == 2){
//Respond to Signal 1 (STOP) and Signal 2 (RESUME)
cout << "Robot 1 STOP OR RESUME " << endl;
status[0] = statusIn1;
}else{
//Respond to Signal 3 - CROSSED by updating the grid indexes
if(currentPath1 < sizeof(robot1Path)/sizeof(int) - 1){
currentPath1++;
status[0] = 3;
cout << "Robot 1 CROSSED " << endl;
}
if(nextPath1 < sizeof(robot1Path)/sizeof(int) - 1){
nextPath1++;
}
}
}
//Update Robot 2
if(incomingSig2.read()){
cout << "Incoming Robot 2 Signal " << endl;
//Respond to Signal 0 - CROSSING
if(statusIn1.read() == 0){
cout << "Robot 2 crossing " << endl;
if(robot1Path[nextPath2] == robot2Path[currentPath1]){
cout << "Robot 2 should stop, robot 1 in the way " << endl;
status[1] = 1; // STOP
}else{
cout << "Robot 2 can cross " << endl;
status[1] = 0; //OK
}
}else if(statusIn2.read() == 1 || statusIn2.read() == 2){
//Respond to Signal 1 (STOP) and Signal 2 (RESUME)
cout << "Robot 2 STOP OR RESUME " << endl;
status[1] = statusIn2;
}else{
//Respond to Signal 3 - CROSSED by updating the grid indexes
if(currentPath2 < sizeof(robot2Path)/sizeof(int) - 1){
currentPath2++;
status[1] = 3;
cout << "Robot 2 CROSSED " << endl;
}
if(nextPath2 < sizeof(robot2Path)/sizeof(int) - 1){
nextPath2++;
}
}
}
prc_transmit();
}
//Receive
void prc_receive(){
prc_update();
}
//Transmit
void prc_transmit(){
if(incomingSig1.read()){
statusOut1 = 1;
outgoingSig1 = status[0];
cout << "Robot 1: " << outgoingSig1 << " position: " << robot1Path[currentPath1] << endl;
}
if(incomingSig2.read()){
statusOut2 = 1;
outgoingSig2 = status[1];
cout << "Robot 2: " << outgoingSig2 << " position: " << robot2Path[currentPath2] << endl;
}
}

SC_CTOR(server){
cout << "Executing server.cpp" << endl;
SC_METHOD(prc_receive);
sensitive << incomingSig1.pos();
sensitive << incomingSig2.pos();
}
};

这是我的测试台:

#include "systemc.h"
#include "server.cpp"
int sc_main(int argc, char* argv[]){
//Inputs
sc_signal<bool> incomingSig1;
sc_signal<sc_uint<2> > statusIn1;
sc_signal<bool> incomingSig2;
sc_signal<sc_uint<2> > statusIn2;
sc_signal<bool> statusOut1;
sc_signal<sc_uint<2> > outgoingSig1;
sc_signal<bool> statusOut2;
sc_signal<sc_uint<2> > outgoingSig2;
server srvr("server");
srvr.statusIn1(statusIn1);
srvr.incomingSig1(incomingSig1);
srvr.statusIn2(statusIn2);
srvr.incomingSig2(incomingSig2);
srvr.statusOut1(statusOut1);
srvr.outgoingSig1(outgoingSig1);
srvr.statusOut2(statusOut2);
srvr.outgoingSig2(outgoingSig2);
sc_start(1, SC_NS);
incomingSig1 = 0;
incomingSig2 = 0;
sc_start(1, SC_NS);
incomingSig1 = 1;
incomingSig2 = 1;
statusIn1 = 0;
statusIn2 = 0;
sc_start(1, SC_NS);
incomingSig1 = 0;
incomingSig2 = 0;
sc_start(1, SC_NS);
incomingSig1 = 1;
incomingSig2 = 1;
statusIn1 = 1;
statusIn2 = 1;
for(int i = 0; i < 8; i++){
sc_start(1, SC_NS);
incomingSig1 = 0;
incomingSig2 = 0;
sc_start(1, SC_NS);
incomingSig1 = 1;
incomingSig2 = 1;
statusIn1 = 3;
statusIn2 = 3;
}
//8th loop
sc_start(1, SC_NS);
incomingSig1 = 0;
incomingSig2 = 0;
sc_start(1, SC_NS);
incomingSig1 = 1;
incomingSig2 = 1;
statusIn1 = 0;
statusIn2 = 0;
}

我通过删除.exe文件并重新制作exe文件克服了这一问题。这个解决方案解决了这个问题。

最新更新