@@ -27,10 +27,10 @@ struct img_initiator: sc_module
2727 // Memory Manager for transaction memory allocation
2828 mm memory_manager;
2929
30- // Internal fields
31- unsigned char * data_ptr;
32- unsigned int data_length;
30+ // Address for this Initiator
3331 unsigned int address;
32+ unsigned char * data;
33+ unsigned int data_length;
3434
3535 // Pointer to transaction in progress
3636 tlm::tlm_generic_payload* pending_transaction;
@@ -58,25 +58,25 @@ struct img_initiator: sc_module
5858
5959 // Create transaction and allocate it
6060 tlm::tlm_generic_payload* transaction = memory_manager.allocate ();
61- transaction->acquire ();
6261
6362 // Set transaction fields
6463 transaction->set_command (tlm::TLM_READ_COMMAND);
6564 transaction->set_address (address);
6665 transaction->set_data_ptr (reinterpret_cast <unsigned char *>(data));
6766 transaction->set_data_length (data_length); // In Bytes
6867 transaction->set_streaming_width (data_length);
68+ transaction->set_byte_enable_ptr (0 );
6969 transaction->set_dmi_allowed (false ); // Mandatory Initial Value
7070 transaction->set_response_status (tlm::TLM_INCOMPLETE_RESPONSE); // Mandatory Initial Value
7171
7272 // Send transaction
7373 this ->send_transaction (transaction);
7474
75- data = reinterpret_cast <int *>(pending_transaction-> get_data_ptr () );
75+ data = reinterpret_cast <int *>(this -> data );
7676 // -----------DEBUG-----------
7777 printf (" [DEBUG] Reading at Initiator: " );
78- for (int i = 0 ; i < this ->data_length ; ++i){
79- printf (" %02x" , *(reinterpret_cast <int *>(data)+i));
78+ for (int i = 0 ; i < this ->pending_transaction -> get_data_length ()/ sizeof ( int ) ; ++i){
79+ printf (" %02x" , *(reinterpret_cast <int *>(this -> data )+i));
8080 }
8181 printf (" \n " );
8282 // -----------DEBUG-----------
@@ -86,21 +86,21 @@ struct img_initiator: sc_module
8686
8787 // Create transaction and allocate it
8888 tlm::tlm_generic_payload* transaction = memory_manager.allocate ();
89- transaction->acquire ();
9089
9190 // Set transaction fields
9291 transaction->set_command (tlm::TLM_WRITE_COMMAND);
9392 transaction->set_address (address);
9493 transaction->set_data_ptr (reinterpret_cast <unsigned char *>(data));
9594 transaction->set_data_length (data_length); // In Bytes
9695 transaction->set_streaming_width (data_length);
96+ transaction->set_byte_enable_ptr (0 );
9797 transaction->set_dmi_allowed (false ); // Mandatory Initial Value
9898 transaction->set_response_status (tlm::TLM_INCOMPLETE_RESPONSE); // Mandatory Initial Value
9999
100100 // -----------DEBUG-----------
101101 printf (" [DEBUG] Writing: " );
102- for (int i = 0 ; i < data_length; ++i){
103- printf (" %02x" , *(reinterpret_cast < int *>( data) +i));
102+ for (int i = 0 ; i < data_length/ sizeof ( int ) ; ++i){
103+ printf (" %02x" , *(data+i));
104104 }
105105 printf (" \n " );
106106 // -----------DEBUG-----------
@@ -117,6 +117,7 @@ struct img_initiator: sc_module
117117
118118 // Begin Request
119119 phase = tlm::BEGIN_REQ;
120+ transaction->acquire ();
120121 cout << name () << " BEGIN_REQ SENT" << " TRANS ID " << 0 << " at time " << sc_time_stamp () << endl;
121122 pending_transaction = transaction;
122123 status = socket->nb_transport_fw (*transaction, phase, this ->write_delay ); // Non-blocking transport call
@@ -125,23 +126,32 @@ struct img_initiator: sc_module
125126 switch (status) {
126127 // Case 1: Transaction was accepted
127128 case tlm::TLM_ACCEPTED: {
128- // printf("%s:\t %s received -> Transaction ID %d at time %s", name(), "TLM_ACCEPTED", this->id_extension->transaction_id , sc_time_stamp());
129+ printf (" %s:\t %s received -> Transaction ID %d at time %s\n " , name (), " TLM_ACCEPTED" , 0 , sc_time_stamp ());
129130 // cout << name() << " TLM_ACCEPTED RECEIVED " << " TRANS ID " << transaction->transaction_id << " at time " << sc_time_stamp() << endl;
130131 check_transaction (*transaction);
132+ transaction->release ();
131133 pending_transaction = 0 ;
132134 // Initiator only cares about sending the transaction, doesnt need to wait for response (non-blocking)
133135 break ;
134136 }
135137
136138 // Not implementing Updated and Completed Status
137139 default : {
138- // printf("%s:\t [ERROR] %s status is not supported by initiator", name(), status );
140+ printf (" %s:\t [ERROR] Invalid status received at initiator" , name ());
139141 break ;
140142 }
141143 }
142144
143145 // Wait for response transaction
144146 wait (transaction_received_e);
147+ // -----------DEBUG-----------
148+ printf (" [DEBUG1] Reading at Initiator: " );
149+ for (int i = 0 ; i < this ->data_length /sizeof (int ); ++i){
150+ printf (" %02x" , *(reinterpret_cast <int *>(this ->data )+i));
151+ }
152+ printf (" \n " );
153+ // -----------DEBUG-----------
154+
145155 // Increment transaction ID
146156 }
147157
@@ -152,6 +162,7 @@ struct img_initiator: sc_module
152162 {
153163 // Call event queue
154164 m_peq.notify (trans, phase, delay);
165+ cout<<" HERE" <<endl;
155166 return tlm::TLM_ACCEPTED;
156167 }
157168
@@ -164,21 +175,37 @@ struct img_initiator: sc_module
164175 switch (phase) {
165176 case tlm::BEGIN_RESP: {
166177
167- printf (" WAITING" );
168- pending_transaction = &trans; // Set response transaction to return
178+ cout<<" HERE3" <<endl;
179+
180+ trans.acquire ();
181+ this ->data_length = trans.get_data_length ();
182+ this ->data = new unsigned char [this ->data_length ];
183+ memcpy (this ->data , trans.get_data_ptr (), this ->data_length );
184+
185+ this ->pending_transaction = &trans; // Set response transaction to return
169186 check_transaction (trans);
170187
171188 // Initiator dont care about confirming resp transaction. So nothing else to do.
172189
173190 // -----------DEBUG-----------
174191 printf (" [DEBUG] Reading at Initiator: " );
175- for (int i = 0 ; i < trans.get_data_length ()/4 ; ++i){
192+ for (int i = 0 ; i < trans.get_data_length ()/sizeof ( int ) ; ++i){
176193 printf (" %02x" , *(reinterpret_cast <int *>(trans.get_data_ptr ())+i));
177194 }
178195 printf (" \n " );
179196 // -----------DEBUG-----------
180197
198+ cout<<" HERE3" <<endl;
199+
181200 transaction_received_e.notify ();
201+ // -----------DEBUG-----------
202+ printf (" [DEBUG] Reading at Initiator: " );
203+ for (int i = 0 ; i < this ->data_length /sizeof (int ); ++i){
204+ printf (" %02x" , *(reinterpret_cast <int *>(this ->data )+i));
205+ }
206+ printf (" \n " );
207+ // -----------DEBUG-----------
208+ cout<<" HERE10" <<endl;
182209 break ;
183210 }
184211 default : {
0 commit comments