2015-01-15 192 views
-5

當我把下面的代碼放在我的解決方案中,然後調試它,包含此「在Q2.exe 0x0016ec86未處理的異常:0xC0000005:訪問衝突讀取位置0x00000000」。出現在我的屏幕上。 我認爲這是由於「COUT」但我不知道如何解決它 「」代碼寫在「systemC的」 C庫++「」訪問衝突讀取位置0x00000000

#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; 
} 
+1

如果您不介意爲我們評論systemC的具體信息,請至少提供一個文檔鏈接。不知道如何'sc_lv <8>'應該是,你正在限制那些能夠幫助你瞭解那些已經知道systemC的人,或者可能會被打擾到自己去搜索它。 ;-)'0x00000000'在C和C++中總是*無效地址。 – DevSolar

+0

sc_lv <8>是類似int –

+0

我的評論的立場。看到Paul Richter的回答 - 你說它是一個「類似int的類型」,並聲稱它是由其父類初始化的。但是,或者這只是你的假設?什麼是'in1'? get()實際上做了什麼?如果不知道,或者能夠輕鬆查找,那麼獲得有用答案的機會就會很低。你*在那裏犯了一個錯誤,或者它會起作用。那麼,爲什麼不幫助我們幫助你?例如: – DevSolar

回答

1

what_got沒有被初始化。

+0

what_got在父類中被初始化 –

+0

不是在任何代碼中,我們可以看到它不是 –

+0

您正在drain :: getting()中聲明what_got,所以它在程序進入函數之前不存在。函數中聲明的變量在調用函數時在堆棧上創建。 what_got在此之前不能被初始化。 –