Jump to content

TRANG

Members
  • Content Count

    57
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by TRANG


  1. 24 minutes ago, AmeyaVS said:

    Hello @TRANG,

    You probably need to change from this:

    
    sc_vector< simple_initiator_socket_tagged<Router >* > initiator_socket;

    to this:

    
    sc_core::sc_vector< tlm_utils::simple_initiator_socket_tagged<Router > > initiator_socket;

    And to understand the better use of sc_vector you can probably search and find many references on  using sc_vector in the forum or on stackoverflow such as these ones:

    Hope these helps.

    Regards,

    Ameya Vikram Singh

    Thanks @AmeyaVS

    how to set base name for each initiator_socket?

    Suppose, I have initiator_socket[4]. I only initialize initiator_socket as bellow code.

    sc_core::sc_vector< tlm_utils::simple_initiator_socket_tagged<Router > > initiator_socket;
    ...
    ///
    Router::Router():initiator_socket("initiator_socket",4)
    {}

    I can't set base name for each initiator_socket as my expected.

    ex:   initiator_socket[0]   : " initiator_0_socket"

             initiator_socket [ 1]    : " initiator_1_socket"

             initiator_socket [ 2]    : " initiator_2_socket"

             initiator_socket [ 3]    : " initiator_3_socket"


  2. 4 hours ago, Eyck said:

    Just looked further: there is a typo in case 1. It should read

    
    //bind
      for(int i=0;i<3;i++){
        objA->initiator_socket[i]->bind(*(objB->target_socket[i]));
      }

    as you use an array of pointers. Again, sc_vector eases your life:

    
    //Model A
    sc_core::sc_vector<tlm_utils::simple_initiator_socket_tagged<ModelA>> initiator_socket;
      ...
    // Model B
    sc_core::sc_vector<tlm_utils::simple_target_socket_tagged<ModelB>> target_socket;
      ...
    //bind
      for(int i=0;i<3;i++){
        objA->initiator_socket[i].bind(objB->target_socket[i]);
      }
                         
        

    The same applies to case 2:

    
    //bind
    objA->initiator_socket1->bind(*(objB->target_socket2));
    objA->initiator_socket2->bind(*(objB->target_socket3));
    objA->initiator_socket3->bind(*(objB->target_socket1));

    Best regards

    Thank @Eyck @David Black

     

    ///Constructor 
    for (unsigned int channel = 0 ; channel < NUM_CHANNEL ; channel++) {
        char socketName[100];
        sprintf(socketName,"initiator%d",channel);
        initiator_socket[channel] = new tlm_utils::simple_initiator_socket_tagged<ModelA>(socketName);
    }
    ....

    I want to use pointer to set name for each inittiator_socket[channel] (as above code I used "socketName" variable)

    @Eyck Can you show me how to use sc_vector and set name for each inittiator_socket? 

    Thanks all.


  3. Hi all,

    I want to understand more about simple_initiator_sọket and simple_target_socket. How is it working??

    Suppose, "Model A 3 initiator" -->  <-- "3 target Model B"

    Case 1:

    //Model A
    tlm_utils::simple_initiator_socket_tagged<ModelA>* initiator_socket[3];
      ...
    // Model B
    tlm_utils::simple_target_socket_tagged<ModelB>* target_socket[3];
      ...
    //bind
      for(int i=0;i<3;i++){
        objA->initiator_socket[i]->bind(objB->target_socket[i]);
      }

    Case 2:

    //Model A
    tlm_utils::simple_initiator_socket_tagged<ModelA>* initiator_socket1;
    tlm_utils::simple_initiator_socket_tagged<ModelA>* initiator_socket2;
    tlm_utils::simple_initiator_socket_tagged<ModelA>* initiator_socket3;
      ...
    // Model B
    tlm_utils::simple_target_socket_tagged<ModelB>* target_socket1;
    tlm_utils::simple_target_socket_tagged<ModelB>* target_socket2;
    tlm_utils::simple_target_socket_tagged<ModelB>* target_socket3;
      ...
    //bind
    objA->initiator_socket1->bind(objB->target_socket2)
    objA->initiator_socket2->bind(objB->target_socket3)
    objA->initiator_socket3->bind(objB->target_socket1)
    

     

    Question 1: Is both above code is correct?                   

    Question 2: In case 2,  I set "bind" between Model A and Model B (unordered declare, initiator_socket1 with target_socket2 ,..... ). Is it right?         

    Thanks all.


  4. 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


  5. 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

    /
    //A.h
    class A: public sc_module
    {
    
    public:
        sc_in<bool>     clkAPM;
        sc_out<bool>    resetPort;
        sc_signal<bool> sig;
    ...
    ///A.cpp
    A::A(sc_module_name name)
            :sc_module(name)
    	    // Initializing
            ,clkAPM("clkAPM")
            ,resetPort("resetPort")
            ,sig("sig")
    {//{{{ 
        /// Initializing
    
        resetPort.initialize(true);
        sig.write(true);
    
        SC_METHOD(AMethod);
        dont_initialize();
        sensitive << sig ;
    ...

     


  6. 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:

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

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

    Thanks.


  7. 7 hours ago, Roman Popov said:

    This is a very old style.

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

    
    //exxe.h
    class EXXE : public sc_module
    {
    public:
        sc_vector<sc_in<sc_dt::uint64>>  SC_NAMED(clock,3);
        sc_vector<sc_in<bool>>           SC_NAMED(input,5);
        EXXE(sc_module_name);
        ~EXXE();
    }

    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


  8. @David Black Thank you so much !!

    I see some projects . They use code as bellow:

    //exxe.h
    class EXXE
    {
    public:
        sc_in<sc_dt::uint64>  *clock[3];
        sc_in<bool>           *input[5];
        EXXE();
        ~EXXE();
    }
    //exxe.cpp
    ///Constructor
    EXXE::EXXE()
    {
        std::ostringstream name;
        for (unsigned int index = 0; index < 5; index++) {
            name.str("");
            name << "input" << index;
            input[index] = new sc_in<bool>(name.str().c_str());
        }
        for (unsigned int index = 0; index < 3; index++) {
            name.str("");
            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


  9. 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:

    
    #define SC_INCLUDE_DYNAMIC_PROCESSES
    #include <systemc.h>
    
    SC_MODULE(spawn_demo) {
    
        SC_CTOR(spawn_demo) {
            SC_THREAD(static_thread);
        }
    
        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"};
        sc_start();
        return 0;
    }

     

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


  10. 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,
      Philipp

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

×
×
  • Create New...