-4

when i put the code below in my solution and then debug it, a massage containing this "Unhandled exception at 0x0016ec86 in Q2.exe: 0xC0000005: Access violation reading location 0x00000000." come up on my screen. i think it's due to "cout" but i don't know how to solve it ""code is written in "systemC" a library of 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;
}
Ali Banagozar
  • 11
  • 1
  • 3
  • 1
    If you don't care to comment the systemC specifics for us, at least provide a link to documentation. Without knowing what e.g. `sc_lv<8>` is supposed to be, you're limiting the group of people capable of ansering you to those who know systemC already, or can be bothered to search for it themselves. ;-) `0x00000000` is *always* an invalid address in C and C++. – DevSolar Jan 15 '15 at 08:45
  • sc_lv<8> is a type like int – Ali Banagozar Jan 15 '15 at 09:12
  • My comment stands. See the answer by Paul Richter -- you say it's a "type like int", and claim it's initialized by its parent class. But is it, or is this just your assumption? What is `in1`? What does `get()` actually do? Without knowing, or being able to comfortably look it up, your chances at getting a helpful answer are low. You *made* an error in there, or it would be working. So why not help us helping you? – DevSolar Jan 15 '15 at 09:22
  • for example: "sc_module(source)" makes a class named source. sc_port declare a type of put_if(put_if is one of parent classes) – Ali Banagozar Jan 15 '15 at 10:07
  • 1
    **Please** check what a [Simple, Self-Contained, Compilable Example](http://www.sscce.org) looks like, with a focus on "simple". That's certainly not the minimum amount of code required to reproduce your problem. And a [link to SystemC](http://www.accellera.org/community/systemc/) would have been nice as well. – DevSolar Jan 15 '15 at 10:07
  • 1
    You have not debugged. – Lightness Races in Orbit Jan 15 '15 at 11:09

1 Answers1

1

what_got is not being initialized.

Paul Richter
  • 6,154
  • 2
  • 20
  • 22
  • what_got is initialized in the parent class – Ali Banagozar Jan 15 '15 at 09:11
  • You are declaring what_got in drain::getting(), so it does not exist until the program enters the function. Variables declared within a function are created on the stack when the function is called. what_got could not have been initialized before then. – Paul Richter Jan 16 '15 at 01:09