Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Posts posted by TRANG

  1. On 12/15/2018 at 7:24 PM, David Black said:

    The 'initialize(T)' method is a leftover from SystemC 1.0 circa 1999, when SystemC had not yet properly abstracted the port/channel concept. At that point in time, there was a stronger emphasis on making SystemC look like Verilog or VHDL. The 'initialize(T)' method is only present on the 'sc_out<T>' and 'sc_inout<T>' port classes, as part of their partial template specialization. The 'initialize(T)' method is not generally available to 'sc_port<>'.

    I usually don't mention it because then the reader gets the wrong impression that 'initialize(T)' should be present everywhere. In fact, it is only useful for RTL aspects. Certainly, this is not part of TLM.

    Since SystemC is more about abstraction and modeling, I avoid it. It is straightforward to override start_of_simulation.

    @TRANGIt is important for you to understand this distinction. I realize that the specification may say that "port is initialized to zero" or some such, but the concept of port in the specification is quite different than the concept of port in SystemC. If you don't understand this, you will hobble your understanding of SystemC. So there are three ways in SystemC of modeling what the specification says regarding an output pin on a hardware design.

    1. Depend on the underlying datatype's initial value to initialize the signal (not very flexible)
    2. If using the specialized ports (sc_out and sc_inout only), call the initialize(T) method.
    3. Write to the port during start_of_simulation, which is the most general and powerful approach.

    Challenge: How would you initialize an sc_fifo< float > connected to an sc_fifo< float > channel with four values?

    Key concepts:

    • SystemCis a modeling language mapped on top of C++.
    • SystemC ports are not signals or pins.
    • sc_in<T>, sc_out<T> and sc_inout<T> are partial template specializations of sc_port<T> on the respective sc_signal<T> interface classes.
    • For historic reasons (SystemC 1.0), there are extra methods added to these specializations including initialize(T), read(), and write(T) that can later confuse novice SystemC programmers.

    I usually don't use sc_fifo ( only use sc_signal, sc_in, sc_out ). But I don't see any function  initialize the value for sc_fifo . Both "write()" and "nb_write()" (sc_fifo) will call to sc_prim_channel::request_update() . So I think , sc_fifo can set value for buffer ( this isn't called initialize the value forbuffer )

    Thank you so much!!! @David Black

  2. Thank @David Black and @Roman Popov

    Thank you so much!!!

    But I think that, initialize the value depend on specification model require.

    Ex:  Model A can reset Model B  with reset port active with LOW level

    Then sc_out<bool> resetPort; in the Model A must be set initialize the value for resetPort is 1 on constructor

    So I think that , Should set initialize the value of port on constructor

     -->  Clearly

    -->  Easy maintain source code

    class A: public sc_module
        sc_in<bool>     clkAPM;
        sc_out<bool>    resetPort;
        sc_signal<bool> sig;
    A::A(sc_module_name name)
    	    // Initializing
        /// Initializing
        sensitive << sig ;


  3. 2 minutes ago, Philipp A Hartmann said:


    Why do you want to do this?

    I think if use pointer, my code faster and save memory .

    my project:

    class APM: public sc_module
        sc_in<bool>     clkAPM;
        sc_in<bool>              *IFA[4];
    APM::APM(sc_module_name name)
    	    // Initializing
        /// Initializing
        std::ostringstream port_name;
        for (unsigned int index = 0; index < 4; index++) {
            port_name << "IFA" << index;
            IFA[index] = new sc_in<bool>(port_name.str().c_str());
            sc_assert(IFA[index] != NULL);
        sensitive << (*IFA)[0];

    I know this it old style code. So, I want to use sc_vector.


  4. 7 hours ago, Roman Popov said:

    This is a very old style.

    With a modern SystemC you can have the same with sc_vector:

    class EXXE : public sc_module
        sc_vector<sc_in<sc_dt::uint64>>  SC_NAMED(clock,3);
        sc_vector<sc_in<bool>>           SC_NAMED(input,5);

    But as David mentioned, before starting learning SystemC you should learn C++ first.  Trying to understand SystemC without being proficient with C++ is a waste of time.

    I tried above code ,but it's not working , Can you share me docs about "SC_NAMED" ? 

    Thank @Roman Popov

  5. @David Black Thank you so much !!

    I see some projects . They use code as bellow:

    class EXXE
        sc_in<sc_dt::uint64>  *clock[3];
        sc_in<bool>           *input[5];
        std::ostringstream name;
        for (unsigned int index = 0; index < 5; index++) {
            name << "input" << index;
            input[index] = new sc_in<bool>(name.str().c_str());
        for (unsigned int index = 0; index < 3; index++) {
            name << "clock" << index;
            clock[index] = new sc_in<sc_dt::uint64>(name.str().c_str());

    But you said that: "None of your three attempted examples appear correct,...."

    Are they incorrect?

    Thank @David Black

  6. On 6/15/2018 at 12:56 AM, Roman Popov said:

    sc_spawn allows to create process during simulation runtime.  SC_* macro can be used only at elaboration time. Please read more details in IEEE SystemC standard.

    Here is small usage example:

    #include <systemc.h>
    SC_MODULE(spawn_demo) {
        SC_CTOR(spawn_demo) {
        void static_thread() {
            sc_spawn_options opts;
            sc_spawn([&]() {
                wait(1, SC_NS);
                cout<< "spawned @ " << sc_time_stamp() << "\n";
                }, "spawned_thread", &opts);
            wait(1, SC_NS);
            cout<< "static @ " << sc_time_stamp() << "\n";
    int sc_main(int argc, char **argv) {
        spawn_demo demo0{"demo0"};
        return 0;


    This is it means: sc_spawn can use for function have parameter and SC_* it not. Right or wrong?

  7. On 7/11/2013 at 5:20 AM, Philipp A Hartmann said:

    The sc_logic constructor taking a char is marked as explicit.  Therefore, you can't pass a char to functions expecting an sc_logic (e.g. initialize).


    You can either explicitly create (pun intended) an sc_logic from a char, or use the predefined sc_logic constants for assignments and parameter passing:

    sc_logic a;
    a = sc_logic('1');
    eoc.initialize( SC_LOGIC_0 ); // SC_LOGIC_1, SC_LOGIC_X, SC_LOGIC_Z

    Greetings from Oldenburg,

    Hi , can you explain the diffrence between " eoc.initialize(false) and  eoc .write ( false) "?