Jump to content

what the initialize phase do really?


red_dandelion

Recommended Posts

Codes  as follows:

#include <systemc>
using namespace sc_core;

SC_MODULE(DELTA) {
    sc_in<bool> clk;
    int y = 1; 
    SC_CTOR(DELTA) {

        SC_THREAD(add_y); 
        sensitive << clk.pos();

        SC_THREAD(multiply_y); 
        sensitive << clk.pos();

        //dont_initialize();

    }

    void add_y() { // y += 2 happens after a delta cycle
        while (true)
        {
            std::cout << "add_y0 stamp: " << sc_time_stamp() << std::endl;
            wait(SC_ZERO_TIME);
            std::cout << "add_y: " << y << " + 2" << " = ";
            y += 2;
            std::cout << y << std::endl;
            std::cout << "add_y stamp: " << sc_time_stamp() << std::endl;
            wait();
        }
    }
    void multiply_y() { 
        while (true)
        {
            std::cout << "multiply_y: " << y << " * 3" << " = ";
            y *= 3;
            std::cout << y << std::endl;
            std::cout << "multiply_y stamp: " << sc_time_stamp() << std::endl;
            wait();
        }
    }

};

int sc_main(int, char* []) {
    sc_clock clk("clock", 5, SC_SEC);
    DELTA delta("delta");
    delta.clk(clk);
    sc_start(30, SC_SEC);
    return 0;
}

output:

add_y0 stamp: 0 s
multiply_y: 1 * 3 = 3
multiply_y stamp: 0 s
multiply_y: 3 * 3 = 9
multiply_y stamp: 0 s
add_y: 9 + 2 = 11
add_y stamp: 0 s
multiply_y: 11 * 3 = 33
multiply_y stamp: 5 s
add_y0 stamp: 5 s
add_y: 33 + 2 = 35
add_y stamp: 5 s
multiply_y: 35 * 3 = 105
multiply_y stamp: 10 s
add_y0 stamp: 10 s
add_y: 105 + 2 = 107
add_y stamp: 10 s

I am confused for function multiply_y execute twice,  If I make the "dont_initialize();" valid, the function only execute once! 

Appreciate Any one who can explain why.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...