Jump to content

two dimension memory access using DMI ptr


Recommended Posts

well i am trying to access a simple two dimensional memory  ..

but am finding problem with that ...

the initiator file is :

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
traffic_injector<DATA_TYPE,BUS_WIDTH>::traffic_injector(sc_module_name name){
    dmi_valid = false;
    initiator_socket(*this);
    SC_THREAD(run);
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
tlm::tlm_sync_enum traffic_injector<DATA_TYPE,BUS_WIDTH>::nb_transport_bw(tlm::tlm_generic_payload &,tlm::tlm_phase &,sc_core::sc_time & ){
    return tlm::TLM_ACCEPTED;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::invalidate_direct_mem_ptr(sc_dt::uint64 start_range,sc_dt::uint64 end_range){
    dmi_valid = false;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
traffic_injector<DATA_TYPE,BUS_WIDTH>::~traffic_injector(){
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::run(){ 
    wait(10, SC_NS);
    printf("=== normal accesses....\n");
    int count = 2;
    while(count >= 0){
        DATA_TYPE * data;
	DATA_TYPE wdata;
	data = &wdata;
	dmi_valid=false;
	read(0x0,data,4,0,0,4);
	printf("\tdata @ 0x0 : %#x\n",*data);
        wait(SC_ZERO_TIME);
	wdata = 0x87383743;
	dmi_valid=false;
	write(0x0,data,4,0,0,4);
	dmi_valid=false;
	read(0x0,data,4,0,0,4);
	printf("\tdata @ 0x0 : %#x\n",*data);
        count--;
    }
    printf("=== DMI accesses....\n");
    print_memory();
    DATA_TYPE * data;
    DATA_TYPE wdata;
    data = &wdata;
    for(uint32_t add = 0; add < 32; add+=4){
	wdata = 0xFFFFF;
        write(add,data,4,0,0,4);
    }
    print_memory();
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool traffic_injector<DATA_TYPE,BUS_WIDTH>::read(const uint64_t & addr, DATA_TYPE * data,const uint32_t length,const DATA_TYPE * byte_enable,const uint32_t byte_enable_length,const uint32_t streaming_width){
    tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
    sc_time delay = sc_time(0, SC_NS);
    trans->set_command(tlm::TLM_READ_COMMAND);
    if((dmi_valid) && (addr >=dmi_data.get_start_address()) && (addr<=dmi_data.get_end_address())) {
	printf("READ : DMI access....\n");
	memcpy(data,dmi_data.get_dmi_ptr()+addr,4);
    } else {
	printf("READ : normal access....\n");
        trans->set_address(addr);
        trans->set_data_ptr(reinterpret_cast<unsigned char*>(data));
        trans->set_data_length(4);
        trans->set_streaming_width(4); 
        trans->set_byte_enable_ptr(0); 
        trans->set_dmi_allowed(false);
        trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
        initiator_socket->b_transport(*trans,delay);
        if (trans->is_response_error()){
            SC_REPORT_ERROR("TLM-2", "Response error from b_transport");
        }
        wait(delay);
        unsigned char* data_ptr = trans->get_data_ptr();
        memcpy(&data, data_ptr, 4);
        if (trans->is_dmi_allowed()){
            dmi_data.init();
            dmi_valid = initiator_socket->get_direct_mem_ptr(*trans, dmi_data);
        }
    }
    return 0;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool traffic_injector<DATA_TYPE,BUS_WIDTH>::write(const uint64_t & addr, DATA_TYPE * data,const uint32_t length,const DATA_TYPE * byte_enable,const uint32_t byte_enable_length,const uint32_t streaming_width){
    tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
    sc_time delay = sc_time(0, SC_NS);
    trans->set_command(tlm::TLM_WRITE_COMMAND);
    if((dmi_valid) && (addr >=dmi_data.get_start_address()) && (addr<=dmi_data.get_end_address())) {
	printf("WRITE : DMI access....\n");
	//printf("writing data :%#x @ %#x",*data,dmi_data.get_dmi_ptr()+addr);
	memcpy(dmi_data.get_dmi_ptr()+addr,data,4);
    } else {
	printf("WRITE : normal access....\n");
        trans->set_address(addr);
        trans->set_data_ptr( reinterpret_cast<unsigned char*>(data));
        trans->set_data_length(4);
        trans->set_streaming_width(4); 
        trans->set_byte_enable_ptr(0); 
        trans->set_dmi_allowed(false);
        trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
        initiator_socket->b_transport(*trans,delay);
        if (trans->is_response_error()){
            SC_REPORT_ERROR("TLM-2", "Response error from b_transport");
        }
        wait(delay);
        if (trans->is_dmi_allowed()){
            dmi_data.init();
            dmi_valid = initiator_socket->get_direct_mem_ptr(*trans, dmi_data);
        }
    }


    return 0;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::print_memory(){
     tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
     trans->set_address(0);
     trans->set_read();
     trans->set_data_length(32);
     unsigned char* data = new unsigned char[128];
     trans->set_data_ptr(data);
     uint32_t count = initiator_socket->transport_dbg( *trans );
     for(uint32_t j=0;j<MSIZE2;j++){
     for(uint32_t i=0;i<MSIZE1;i++){
	printf("MEM[%d][%d]=%d \n",j,i,*(reinterpret_cast<uint32_t*>(&(data[i][j]))));}}
     // printf("MEM[i][j]=%d\n",j,*(reinterpret_cast<uint32_t*>(&data[j])));
     //}
}

the target file is 

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
ufs_model<DATA_TYPE,BUS_WIDTH>::ufs_model(sc_module_name name):sc_module(name){
    target_socket(*this);
    ufs_AHID_register.reset();
    for(uint32_t i = 0; i < MSIZE1; i++){
    for(uint32_t j=0; j<MSIZE2; j++)
	memory[i][j] = i+j;
    }
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void ufs_model<DATA_TYPE,BUS_WIDTH>::reset_ufs_registers(){
    ufs_AHID_register.reset();
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool ufs_model<DATA_TYPE,BUS_WIDTH>::get_direct_mem_ptr(tlm::tlm_generic_payload& trans,tlm::tlm_dmi&  dmi_data){
    dmi_data.allow_read_write();
    dmi_data.set_dmi_ptr(reinterpret_cast<unsigned char*>(&memory[0][0]));
    dmi_data.set_start_address(0);
    dmi_data.set_end_address(4*(MSIZE2)-1);
    return true;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
unsigned int ufs_model<DATA_TYPE,BUS_WIDTH>::transport_dbg(tlm::tlm_generic_payload& trans){
    tlm::tlm_command cmd = trans.get_command();
    uint64    adr = trans.get_address()/4;
    unsigned char*   ptr = trans.get_data_ptr();
    //unsigned int     len = trans.get_data_length();
    if (cmd == tlm::TLM_READ_COMMAND){
      memcpy(ptr, &memory[0][0], (MSIZE2)*4);
    } else if (cmd == tlm::TLM_WRITE_COMMAND){
      memcpy(&memory[0][0], ptr, MSIZE2*4);
    }
    return MSIZE1*4;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void ufs_model<DATA_TYPE,BUS_WIDTH>::b_transport(tlm::tlm_generic_payload& trans, sc_core::sc_time &t){
    tlm::tlm_command cmd = trans.get_command();
    uint64_t addr = trans.get_address();
    unsigned char*   data_ptr = trans.get_data_ptr();
    unsigned int     len = trans.get_data_length();
    //unsigned char*   byt = trans.get_byte_enable_ptr();
    //unsigned int     wid = trans.get_streaming_width();
    if (cmd == tlm::TLM_READ_COMMAND){
	uint32_t data = read(addr);
	memcpy(data_ptr, &data, len);
    } else if (cmd == tlm::TLM_WRITE_COMMAND){
	uint32_t data;
	memcpy(&data,data_ptr,4);
	write(addr,data);
    }
    trans.set_response_status( tlm::TLM_OK_RESPONSE );
    trans.set_dmi_allowed(true);
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
tlm::tlm_sync_enum ufs_model<DATA_TYPE,BUS_WIDTH>::nb_transport_fw(tlm::tlm_generic_payload& trans, tlm::tlm_phase& phase, sc_core::sc_time& t){
    return tlm::TLM_ACCEPTED;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
tlm::tlm_sync_enum ufs_model<DATA_TYPE,BUS_WIDTH>::nb_transport_bw(tlm::tlm_generic_payload &,tlm::tlm_phase &,sc_core::sc_time & ){
    return tlm::TLM_ACCEPTED;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void ufs_model<DATA_TYPE,BUS_WIDTH>::invalidate_direct_mem_ptr(sc_dt::uint64 start_range,sc_dt::uint64 end_range){
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
DATA_TYPE ufs_model<DATA_TYPE,BUS_WIDTH>::read(const uint64_t addr){
    DATA_TYPE data=0;
    switch(addr){
        case UFS_AHID_REGISTER_OFFSET :
            ufs_AHID_register.behavior_before_read();
            data = ufs_AHID_register.read();
            ufs_AHID_register.behavior_after_read();
            break;
        default :
            cout<<"Invalid read address "<<std::hex<<addr<<"\n";
    }
    return data;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool ufs_model<DATA_TYPE,BUS_WIDTH>::write(const uint64_t addr, const DATA_TYPE data){
    bool status=0;
    switch(addr){
        case UFS_AHID_REGISTER_OFFSET :
            ufs_AHID_register.behavior_before_write();
            ufs_AHID_register.write(data);
            ufs_AHID_register.behavior_after_write();
            break;
        default :
            cout<<"Invalid write address "<<std::hex<<addr<<"\n";
            status = 1;
    }
    return status;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
ufs_model<DATA_TYPE,BUS_WIDTH>::~ufs_model(){
}

the error i am getiing is ::

 make
Makefile:36: Make.deps: No such file or directory
******** making Make.deps ********

/home/mohit/Desktop//include/traffic_injector.tpp: In member function ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::print_memory()’:
/home/mohit/Desktop//include/traffic_injector.tpp:132: error: invalid types ‘unsigned char[uint32_t]’ for array subscript
/home/mohit/Desktop//include/traffic_injector.tpp: In member function ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::print_memory() [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’:
/home/mohit/Desktop//include/traffic_injector.tpp:45:   instantiated from ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::run() [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop//include/traffic_injector.tpp:6:   instantiated from ‘traffic_injector<DATA_TYPE, BUS_WIDTH>::traffic_injector(sc_core::sc_module_name) [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop//src/top.cpp:7:   instantiated from here
/home/mohit/Desktop//include/traffic_injector.tpp:129: warning: unused variable ‘count’
In file included from /home/mohit/Desktop/include/ufs_model.hpp:45,
                 from /home/mohit/Desktop//src/top.cpp:1:
/home/mohit/Desktop/ufs_dmi/ufs/include/: In member function ‘unsigned int ufs_model<DATA_TYPE, BUS_WIDTH>::transport_dbg(tlm::tlm_generic_payload&) [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’:
/home/mohit/Desktop//src/top.cpp:12:   instantiated from here
/home/mohit/Desktop//include/ufs_model.tpp:29: warning: unused variable ‘adr’
make: *** [top.o] Error 1
Link to comment
Share on other sites

In the print_memory function, you allocate (and never delete, but this is a separate problem) a plain unsigned char array:

     unsigned char* data = new unsigned char[128];
     trans->set_data_ptr(data);

Later in that function, you try to use it as a two-dimensional array:

printf("MEM[%d][%d]=%d \n",j,i,*(reinterpret_cast<uint32_t*>(&(data[i][j]))));

Obviously, this can't work.  Apart from the invalid dimensions, the offsets and alignments will also be quite wrong for casting the values to uint32_t, I suppose.

 

Instead, you should use a properly typed array within print_memory (maybe even related to the DATA_TYPE template argument?) and cast it to unsigned char when passing it to the set_data_ptr of the transaction.

Some other observations in that function:

  • Why do you allocate the generic payload object with new? (memory leak)
  • Why do you allocate the array with new? (memory leak)
  • Using hard-coded constants (128, 32, ...) seems to be inconsistent with MSIZE1, MSIZE2…

I didn't look at the other parts of the code.

 

/Philipp

Link to comment
Share on other sites

In the print_memory function, you allocate (and never delete, but this is a separate problem) a plain unsigned char array:

     unsigned char* data = new unsigned char[128];
     trans->set_data_ptr(data);

Later in that function, you try to use it as a two-dimensional array:

printf("MEM[%d][%d]=%d \n",j,i,*(reinterpret_cast<uint32_t*>(&(data[i][j]))));

Obviously, this can't work.  Apart from the invalid dimensions, the offsets and alignments will also be quite wrong for casting the values to uint32_t, I suppose.

 

Instead, you should use a properly typed array within print_memory (maybe even related to the DATA_TYPE template argument?) and cast it to unsigned char when passing it to the set_data_ptr of the transaction.

Some other observations in that function:

  • Why do you allocate the generic payload object with new? (memory leak)
  • Why do you allocate the array with new? (memory leak)
  • Using hard-coded constants (128, 32, ...) seems to be inconsistent with MSIZE1, MSIZE2…

I didn't look at the other parts of the code.

 

/Philipp

 

thanks Philipp for your response  ...

well am using pointer to array of pointers for dynamic 2D memory allocation ...

the changes done are as follows


template <typename DATA_TYPE, unsigned int BUS_WIDTH>
traffic_injector<DATA_TYPE,BUS_WIDTH>::traffic_injector(sc_module_name name){
    dmi_valid = false;
    initiator_socket(*this);
    SC_THREAD(run);
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
tlm::tlm_sync_enum traffic_injector<DATA_TYPE,BUS_WIDTH>::nb_transport_bw(tlm::tlm_generic_payload &,tlm::tlm_phase &,sc_core::sc_time & ){
    return tlm::TLM_ACCEPTED;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::invalidate_direct_mem_ptr(sc_dt::uint64 start_range,sc_dt::uint64 end_range){
    dmi_valid = false;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
traffic_injector<DATA_TYPE,BUS_WIDTH>::~traffic_injector(){
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::run(){ 
    wait(10, SC_NS);
    printf("=== normal accesses....\n");
    int count = 2;
    while(count >= 0){
        DATA_TYPE * data;
	DATA_TYPE wdata;
	data = &wdata;
	dmi_valid=false;
	read(0x0,data,4,0,0,4);
	printf("\tdata @ 0x0 : %#x\n",*data);
        wait(SC_ZERO_TIME);
	wdata = 0x87383743;
	dmi_valid=false;
	write(0x0,data,4,0,0,4);
	dmi_valid=false;
	read(0x0,data,4,0,0,4);
	printf("\tdata @ 0x0 : %#x\n",*data);
        count--;
    }
    printf("=== DMI accesses....\n");
    print_memory();
    DATA_TYPE * data;
    DATA_TYPE wdata;
    data = &wdata;
    for(uint32_t add = 0; add < 32; add+=4){
	wdata = 0xFFFFF;
        write(add,data,4,0,0,4);
    }
    print_memory();
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool traffic_injector<DATA_TYPE,BUS_WIDTH>::read(const uint64_t & addr, DATA_TYPE * data,const uint32_t length,const DATA_TYPE * byte_enable,const uint32_t byte_enable_length,const uint32_t streaming_width){
    tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
    sc_time delay = sc_time(0, SC_NS);
    trans->set_command(tlm::TLM_READ_COMMAND);
    if((dmi_valid) && (addr >=dmi_data.get_start_address()) && (addr<=dmi_data.get_end_address())) {
	printf("READ : DMI access....\n");
	memcpy(data,dmi_data.get_dmi_ptr()+addr,4);
    } else {
	printf("READ : normal access....\n");
        trans->set_address(addr);
        trans->set_data_ptr(reinterpret_cast<unsigned char*>(data));
        trans->set_data_length(4);
        trans->set_streaming_width(4); 
        trans->set_byte_enable_ptr(0); 
        trans->set_dmi_allowed(false);
        trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
        initiator_socket->b_transport(*trans,delay);
        if (trans->is_response_error()){
            SC_REPORT_ERROR("TLM-2", "Response error from b_transport");
        }
        wait(delay);
        unsigned char* data_ptr = trans->get_data_ptr();
        memcpy(&data, data_ptr, 4);
        if (trans->is_dmi_allowed()){
            dmi_data.init();
            dmi_valid = initiator_socket->get_direct_mem_ptr(*trans, dmi_data);
        }
    }
    return 0;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
bool traffic_injector<DATA_TYPE,BUS_WIDTH>::write(const uint64_t & addr, DATA_TYPE * data,const uint32_t length,const DATA_TYPE * byte_enable,const uint32_t byte_enable_length,const uint32_t streaming_width){
    tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
    sc_time delay = sc_time(0, SC_NS);
    trans->set_command(tlm::TLM_WRITE_COMMAND);
    if((dmi_valid) && (addr >=dmi_data.get_start_address()) && (addr<=dmi_data.get_end_address())) {
	printf("WRITE : DMI access....\n");
	//printf("writing data :%#x @ %#x",*data,dmi_data.get_dmi_ptr()+addr);
	memcpy(dmi_data.get_dmi_ptr()+addr,data,4);
    } else {
	printf("WRITE : normal access....\n");
        trans->set_address(addr);
        trans->set_data_ptr( reinterpret_cast<unsigned char*>(data));
        trans->set_data_length(4);
        trans->set_streaming_width(4); 
        trans->set_byte_enable_ptr(0); 
        trans->set_dmi_allowed(false);
        trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
        initiator_socket->b_transport(*trans,delay);
        if (trans->is_response_error()){
            SC_REPORT_ERROR("TLM-2", "Response error from b_transport");
        }
        wait(delay);
        if (trans->is_dmi_allowed()){
            dmi_data.init();
            dmi_valid = initiator_socket->get_direct_mem_ptr(*trans, dmi_data);
        }
    }


    return 0;
}

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::print_memory(){
     tlm::tlm_generic_payload* trans = new tlm::tlm_generic_payload;
     trans->set_address(0);
     trans->set_read();
     trans->set_data_length(32);
     unsigned char* data = new unsigned char[128];
     for(int i=0;i<128;i++)
       data[i]=new unsigned char [32];
     trans->set_data_ptr(data);
     uint32_t count = initiator_socket->transport_dbg( *trans );
     for(uint32_t j=0;j<MSIZE2;j++){
     for(uint32_t i=0;i<MSIZE1;i++){
	printf("MEM[%d][%d]=%d \n",j,i,*(reinterpret_cast<uint32_t*>(&data)));}}
     // printf("MEM[i][j]=%d\n",j,*(reinterpret_cast<uint32_t*>(&data[j])));
     //}
}

still getting this error ..

 make
******** Generating top.o ********
g++ -Wall -DSC_INCLUDE_DYNAMIC_PROCESSES -g -I. -I.. -I/home/mohit/Desktop/ufs_dmi/ufs/include -I/usr/local/systemc-2.3.1/include   -c /home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp -o top.o
In file included from /home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.hpp:25,
                 from /home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp:2:
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp: In member function ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::print_memory() [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’:
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:45:   instantiated from ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::run() [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:6:   instantiated from ‘traffic_injector<DATA_TYPE, BUS_WIDTH>::traffic_injector(sc_core::sc_module_name) [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp:7:   instantiated from here
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:129: error: invalid conversion from ‘unsigned char*’ to ‘unsigned char’
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:45:   instantiated from ‘void traffic_injector<DATA_TYPE, BUS_WIDTH>::run() [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:6:   instantiated from ‘traffic_injector<DATA_TYPE, BUS_WIDTH>::traffic_injector(sc_core::sc_module_name) [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’
/home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp:7:   instantiated from here
/home/mohit/Desktop/ufs_dmi/ufs/include/traffic_injector.tpp:131: warning: unused variable ‘count’
In file included from /home/mohit/Desktop/ufs_dmi/ufs/include/ufs_model.hpp:45,
                 from /home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp:1:
/home/mohit/Desktop/ufs_dmi/ufs/include/ufs_model.tpp: In member function ‘unsigned int ufs_model<DATA_TYPE, BUS_WIDTH>::transport_dbg(tlm::tlm_generic_payload&) [with DATA_TYPE = unsigned int, unsigned int BUS_WIDTH = 32u]’:
/home/mohit/Desktop/ufs_dmi/ufs/src/top.cpp:12:   instantiated from here
/home/mohit/Desktop/ufs_dmi/ufs/include/ufs_model.tpp:29: warning: unused variable ‘adr’
make: *** [top.o] Error 1

Link to comment
Share on other sites

The code is still quite wrong: an array of pointers is not a two-dimensional array and won't work at all.  You need to pass a contiguous memory block as data pointer in the generic payload.

 

As said in my previous answer, you need to provide a buffer of the target type (i.e. the two dimensional array), not a raw pointer of unsigned char.  Otherwise alignment, offsets and arithmetic will go completely wrong.

 

I don't really understand, what you intend to do in print_memory, as there are still quite strange constants in use (128, 32, vs. MSIZE1, MSIZE2).  Nevertheless, I tried to address your "casting issue" in the following (fully untested) snippet:

template <typename DATA_TYPE, unsigned int BUS_WIDTH>
void traffic_injector<DATA_TYPE,BUS_WIDTH>::print_memory(){
     tlm::tlm_generic_payload trans; // no need to use a pointer, avoid memory leaks!
     trans.set_address(0);
     trans.set_read();
     trans.set_data_length(32); // you only read 32 bytes?!

     // don't use a char pointer.  use the "real" type instead
     // again, no need for dynamic allocation with leaking memory
     uint32_t data[MSIZE1][MSIZE2]; // sizes are just a guess
    
     // cast for generic payload data pointer
     trans.set_data_ptr(reinterpret_cast<unsigned char*>(data));
     // don't you want to read the whole memory?
     trans.set_data_length( sizeof(data) ); 

     uint32_t count = initiator_socket->transport_dbg( trans );

     for(uint32_t j=0;j<MSIZE2;j++){
         for(uint32_t i=0;i<MSIZE1;i++){
            // no cast here, correct pointer arithmetic
            printf("MEM[%d][%d]=%d \n",j,i,data[i][j])));
         }   
     }
}

Side note: Please educate yourself about the C++ memory model and management.  You leak memory in nearly every function.  Never use new without a matching delete, C++ is not Java or C#.

 

hth,
  Philipp

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