Jump to content

apfitch

Members
  • Posts

    613
  • Joined

  • Last visited

  • Days Won

    118

Posts posted by apfitch

  1. That's because c is connected to an sc_signal. An sc_signal only updates after the process suspends.

    Probably the neatest solution is to use a variable in your do_and. I'd also move the wait() to the top of the process, otherwise the process will run at time 0 before a and have been assigned.

     

    regards

    Alan

    void do_and()
    {
         bool c_temp;
         while(true)
         {
            wait();
            c_temp = a.read()&b.read());
            c.write(c_temp);
            data = 0xFF000000 | (c_temp | 0x00000030);
    
            tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
            sc_time delay = sc_time(10, SC_NS);
    
            tlm::tlm_command cmd = tlm::TLM_WRITE_COMMAND;
    
            trans->set_command( cmd );
            trans->set_address(0);
            trans->set_data_ptr( reinterpret_cast<unsigned char*>(&data) );
            trans->set_data_length( 4 );
            trans->set_streaming_width( 4 ); // = data_length to indicate no streaming
            trans->set_byte_enable_ptr( 0 ); // 0 indicates unused
            trans->set_dmi_allowed( false ); // Mandatory initial value
            trans->set_response_status( tlm::TLM_INCOMPLETE_RESPONSE ); // Mandatory initial value
    
            socket->b_transport( *trans, delay ); // Blocking transport call
    
             //Initiator obliged to check response status and delay
            if ( trans->is_response_error() )
                SC_REPORT_ERROR("TLM-2", "Response error from b_transport");
            
            cout << " a = " << hex << a << " , b = " << hex << b << " , c = " << hex << c_temp << " , data = " << hex << data << " , " << sc_time_stamp() << endl;
    
    //        wait();
         }
    }

    By the way, the code you've written is a very strange mixture of TLM and RTL style code :-)

  2. When you say "both ports"  you imply two ports. The error message says the *third* port in the object labelled "Waveform" is not bound.

    Please look for the third port and check it is bound,

     

    regards

    Alan

     

    P.S. The ports are automatically named starting from 0, so port_2 must be the third port.

  3. Did you download the example from this page:

    http://www.doulos.com/knowhow/systemc/tlm2/tutorial__1/tlm2_1_downloads.php

     

    ?

     

    It works for me...

            SystemC 2.3.1-Accellera --- Nov 18 2015 09:31:09
            Copyright (c) 1996-2014 by all Contributors,
            ALL RIGHTS RESERVED
    trans = { R, 20 } , data = aa000029 at time 0 s delay = 10 ns
    trans = { R, 24 } , data = aa0000cd at time 10 ns delay = 10 ns
    trans = { R, 28 } , data = aa0000ba at time 20 ns delay = 10 ns
    trans = { R, 2c } , data = aa0000ab at time 30 ns delay = 10 ns
    trans = { R, 30 } , data = aa0000f2 at time 40 ns delay = 10 ns
    trans = { W, 34 } , data = ff000034 at time 50 ns delay = 10 ns
    trans = { R, 38 } , data = aa0000e3 at time 60 ns delay = 10 ns
    trans = { R, 3c } , data = aa000046 at time 70 ns delay = 10 ns
    trans = { R, 40 } , data = aa00007c at time 80 ns delay = 10 ns
    trans = { R, 44 } , data = aa0000c2 at time 90 ns delay = 10 ns
    trans = { R, 48 } , data = aa000054 at time 100 ns delay = 10 ns
    trans = { W, 4c } , data = ff00004c at time 110 ns delay = 10 ns
    trans = { R, 50 } , data = aa00001b at time 120 ns delay = 10 ns
    trans = { R, 54 } , data = aa0000e8 at time 130 ns delay = 10 ns
    trans = { R, 58 } , data = aa0000e7 at time 140 ns delay = 10 ns
    trans = { R, 5c } , data = aa00008d at time 150 ns delay = 10 ns
    
    

    regards

    Alan

  4. The TLM function calls use an array of character.

    What I suggest you do is actually use a character, then it will be easier to understand.

     

    So in the initiator

     unsigned char c_char[4]; 
     while(true)
    	  {
    		c_char[0] = a.read()&b.read();
                    c.write(c_char[0]);
    
     ...
     		trans->set_data_ptr( c_char);
    
    

    I.e. put the boolean value into byte 0 of an array of 4 bytes. Then you don't need the reinterpret_cast etc,

     

    regards

    Alan

  5. Hi Huy,

      I realised I did not read your code properly.

    You have an instance Top *and* you have instances of Initiator and Memory in your sc_main.

     

    I think the way you have written your code, you do not need Top.

     

    So if you take out Top and also take out the socket declarations in sc_main that is better.

     

    regards

    Alan

  6. Probably the most readable thing would be to read into a temporary variable, manipulate it, then write back. E.g.

     

    sc_lv<8> temp = dummy;

    temp[2] = SC_LOGIC_1;

    dummy.write(temp);

     

    The main thing you need to think about is that in VHDL each element of a signal of type std_logic_vector is itself a signal (of type std_logic). In SystemC that's not true.  sc_signal <sc_lv<8> > s is a single signal s containing data of type sc_lv<8>. You can't do s[2], but you can do s.read()[2]. The [], concat(), and range() methods belong to the data type, not to the signal class,

     

    regards

    Alan

     

    P.S. You can also run into issues with concat() and range() because they don't return  the data type you think they do (i.e. sc_lv<> in the example I gave), they return proxy classes, which you sometimes need to cast.

  7. The only thing that looks weird to me is that you're calling b_transport with an argument sc_time(SC_ZERO_TIME). What happens if you call it with just SC_ZERO_TIME?

     

    The error message seems to be saying it's looking for a function prototype that takes an argument passed by value rather than by reference, so perhaps calling the copy constructor explicity is confusing something?

     

    Alan

  8. I'm not sure what you mean. You could change the printing code to use an SC_THREAD, and then you could add a small wait to allow the outputs to settle. And make the printing process only sensitive to sum, e.g.

    #include "half_adder.h"
    SC_MODULE (full_adder) {
      sc_in<bool>a,b ,cin;
      sc_out<bool>sum,carry;  
      sc_signal<bool> c1,c2,s1;
     
      void disp()
      {
        while (true) {
          wait(1, SC_NS);
          cout<<"a="<<a<<endl;
          cout<<"b="<<b<<endl;
          cout<<"cin="<<cin<<endl;
          cout<<"sum="<<sum<<endl;
          cout<<"carry="<<carry<<endl;
          cout<<endl;
        }
      }
     ...
     
     
      SC_CTOR(full_adder){
       ...
        SC_THREAD(disp);
        sensitive <<sum;
      }
    ...
    };
    

    regards

    Alan

×
×
  • Create New...