Skip to content

Commit 0ae2449

Browse files
jgavillalobosErickOF
authored andcommitted
Add new dbgprint function to show file and line from which a print is comming from
1 parent 7100a18 commit 0ae2449

File tree

5 files changed

+60
-46
lines changed

5 files changed

+60
-46
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef COMMON_FUNC
2+
#define COMMON_FUNC
3+
4+
#define dbgprint(FORMAT, ARGS...) \
5+
printf("%s -> %0d : " FORMAT "\n", __FILE__, __LINE__, ##ARGS)
6+
7+
#endif // COMMON_FUNC

modules/router/src/img_initiator.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ using namespace std;
1616
#include "tlm_utils/simple_target_socket.h"
1717
#include "tlm_utils/peq_with_cb_and_phase.h"
1818

19+
#include "common_func.hpp"
20+
1921
//const char* tlm_enum_names[] = {"TLM_ACCEPTED", "TLM_UPDATED", "TLM_COMPLETED"};
2022

2123
// Initiator module generating generic payload transactions
@@ -74,9 +76,9 @@ struct img_initiator: sc_module
7476

7577
data = reinterpret_cast<int*>(this->data);
7678
//-----------DEBUG-----------
77-
printf("[DEBUG] Reading at Initiator: ");
79+
dbgprint("Reading at Initiator: ");
7880
for (int i = 0; i < this->pending_transaction->get_data_length()/sizeof(int); ++i){
79-
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
81+
dbgprint("%02x", *(reinterpret_cast<int*>(this->data)+i));
8082
}
8183
printf("\n");
8284
//-----------DEBUG-----------
@@ -98,9 +100,9 @@ struct img_initiator: sc_module
98100
transaction->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); //Mandatory Initial Value
99101

100102
//-----------DEBUG-----------
101-
printf("[DEBUG] Writing: ");
103+
dbgprint("Writing: ");
102104
for (int i = 0; i < data_length/sizeof(int); ++i){
103-
printf("%02x", *(data+i));
105+
dbgprint("%02x", *(data+i));
104106
}
105107
printf("\n");
106108
//-----------DEBUG-----------
@@ -118,16 +120,15 @@ struct img_initiator: sc_module
118120
//Begin Request
119121
phase = tlm::BEGIN_REQ;
120122
transaction->acquire();
121-
cout << name() << " BEGIN_REQ SENT" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
123+
dbgprint("%s BEGIN_REQ SENT TRANS ID %0d at time %s", name(), 0, sc_time_stamp().to_string().c_str());
122124
pending_transaction = transaction;
123125
status = socket->nb_transport_fw(*transaction, phase, this->write_delay); // Non-blocking transport call
124126

125127
// Check request status returned by target
126128
switch (status) {
127129
//Case 1: Transaction was accepted
128130
case tlm::TLM_ACCEPTED: {
129-
printf("%s:\t %s received -> Transaction ID %d at time %s\n", name(), "TLM_ACCEPTED", 0, sc_time_stamp());
130-
//cout << name() << " TLM_ACCEPTED RECEIVED " << " TRANS ID " << transaction->transaction_id << " at time " << sc_time_stamp() << endl;
131+
dbgprint("%s:\t %s received -> Transaction ID %d at time %s", name(), "TLM_ACCEPTED", 0, sc_time_stamp().to_string().c_str());
131132
check_transaction(*transaction);
132133
transaction->release();
133134
pending_transaction = 0;
@@ -137,17 +138,17 @@ struct img_initiator: sc_module
137138

138139
//Not implementing Updated and Completed Status
139140
default: {
140-
printf("%s:\t [ERROR] Invalid status received at initiator", name());
141+
dbgprint("%s:\t [ERROR] Invalid status received at initiator", name());
141142
break;
142143
}
143144
}
144145

145146
//Wait for response transaction
146147
wait(transaction_received_e);
147148
//-----------DEBUG-----------
148-
printf("[DEBUG1] Reading at Initiator: ");
149+
dbgprint("[DEBUG1] Reading at Initiator: ");
149150
for (int i = 0; i < this->data_length/sizeof(int); ++i){
150-
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
151+
dbgprint("%02x", *(reinterpret_cast<int*>(this->data)+i));
151152
}
152153
printf("\n");
153154
//-----------DEBUG-----------
@@ -162,20 +163,20 @@ struct img_initiator: sc_module
162163
{
163164
//Call event queue
164165
m_peq.notify(trans, phase, delay);
165-
cout<<"HERE"<<endl;
166+
dbgprint("HERE");
166167
return tlm::TLM_ACCEPTED;
167168
}
168169

169170
//Payload event and queue callback to handle transactions received from target
170171
void peq_cb(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase)
171172
{
172173

173-
//printf("%s:\t %s received -> Transaction ID %d from address %x at time %s\n", name(), phase, this->id_extension->transaction_id, trans.get_address(), sc_time_stamp());
174+
//dbgprint("%s:\t %s received -> Transaction ID %d from address %x at time %s\n", name(), phase, this->id_extension->transaction_id, trans.get_address(), sc_time_stamp());
174175
//cout << name() << " " <<hex << trans.get_address() << " BEGIN_RESP RECEIVED at " << sc_time_stamp() << endl;
175176
switch (phase) {
176177
case tlm::BEGIN_RESP: {
177178

178-
cout<<"HERE3"<<endl;
179+
dbgprint("HERE3");
179180

180181
trans.acquire();
181182
this->data_length = trans.get_data_length();
@@ -188,24 +189,24 @@ struct img_initiator: sc_module
188189
//Initiator dont care about confirming resp transaction. So nothing else to do.
189190

190191
//-----------DEBUG-----------
191-
printf("[DEBUG] Reading at Initiator: ");
192+
dbgprint("[DEBUG] Reading at Initiator: ");
192193
for (int i = 0; i < trans.get_data_length()/sizeof(int); ++i){
193-
printf("%02x", *(reinterpret_cast<int*>(trans.get_data_ptr())+i));
194+
dbgprint("%02x", *(reinterpret_cast<int*>(trans.get_data_ptr())+i));
194195
}
195196
printf("\n");
196197
//-----------DEBUG-----------
197198

198-
cout<<"HERE3"<<endl;
199+
dbgprint("HERE3");
199200

200201
transaction_received_e.notify();
201202
//-----------DEBUG-----------
202-
printf("[DEBUG] Reading at Initiator: ");
203+
dbgprint("[DEBUG] Reading at Initiator: ");
203204
for (int i = 0; i < this->data_length/sizeof(int); ++i){
204-
printf("%02x", *(reinterpret_cast<int*>(this->data)+i));
205+
dbgprint("%02x", *(reinterpret_cast<int*>(this->data)+i));
205206
}
206207
printf("\n");
207208
//-----------DEBUG-----------
208-
cout<<"HERE10"<<endl;
209+
dbgprint("HERE10");
209210
break;
210211
}
211212
default: {

modules/router/src/img_target.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ using namespace std;
1111
#include "tlm_utils/simple_target_socket.h"
1212
#include "tlm_utils/peq_with_cb_and_phase.h"
1313

14+
#include "common_func.hpp"
15+
1416
//For an internal response phase
1517
DECLARE_EXTENDED_PHASE(internal_processing_ph);
1618

@@ -71,7 +73,7 @@ struct img_target: sc_module
7173
switch (phase) {
7274
//Case 1: Target is receiving the first transaction of communication -> BEGIN_REQ
7375
case tlm::BEGIN_REQ: {
74-
cout << name() << " BEGIN_REQ RECEIVED" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
76+
dbgprint("%s BEGIN_REQ RECEIVED TRANS ID %0d at time %s", name(), 0, sc_time_stamp().to_string().c_str());
7577
//Check for errors here
7678

7779
// Increment the transaction reference count
@@ -90,7 +92,7 @@ struct img_target: sc_module
9092
}
9193
default: {
9294
if (phase == internal_processing_ph){
93-
cout << "INTERNAL PHASE: PROCESSING TRANSACTION" << endl;
95+
dbgprint("INTERNAL PHASE: PROCESSING TRANSACTION");
9496
process_transaction(trans);
9597
}
9698
break;
@@ -106,20 +108,20 @@ struct img_target: sc_module
106108

107109
response_phase = tlm::BEGIN_RESP;
108110
status = socket->nb_transport_bw(trans, response_phase, response_delay);
109-
cout << "HERE" << endl;
111+
dbgprint("HERE");
110112

111113
//Check Initiator response
112114
switch(status) {
113115
case tlm::TLM_ACCEPTED: {
114-
cout << name() << " TLM_ACCEPTED RECEIVED" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
116+
dbgprint("%s TLM_ACCEPTED RECEIVED TRANS ID %0d at time %s", name(), 0, sc_time_stamp().to_string().c_str());
115117
// Target only care about acknowledge of the succesful response
116118
trans.release();
117119
break;
118120
}
119121

120122
//Not implementing Updated and Completed Status
121123
default: {
122-
printf("%s:\t [ERROR] Invalid status received at target", name());
124+
dbgprint("%s:\t [ERROR] Invalid status received at target", name());
123125
break;
124126
}
125127
}
@@ -140,7 +142,7 @@ struct img_target: sc_module
140142
tlm::tlm_sync_enum status;
141143
tlm::tlm_phase phase;
142144

143-
cout << name() << " Processing transaction: " << 0 << endl;
145+
dbgprint("%s Processing transaction: %0d", name(), 0);
144146

145147
//get variables from transaction
146148
tlm::tlm_command cmd = trans.get_command();
@@ -154,12 +156,13 @@ struct img_target: sc_module
154156
switch(cmd) {
155157
case tlm::TLM_READ_COMMAND: {
156158
unsigned char* response_data_ptr;
159+
response_data_ptr = (unsigned char*)malloc(2 * sizeof(int));
157160
this->do_when_read_transaction(response_data_ptr);
158161
//Add read according to length
159162
//-----------DEBUG-----------
160-
printf("[DEBUG] Reading: ");
163+
dbgprint("[DEBUG] Reading: ");
161164
for (int i = 0; i < len/sizeof(int); ++i){
162-
printf("%02x", *(reinterpret_cast<int*>(response_data_ptr)+i));
165+
dbgprint("%02x", *(reinterpret_cast<int*>(response_data_ptr)+i));
163166
}
164167
printf("\n");
165168
//-----------DEBUG-----------
@@ -169,21 +172,21 @@ struct img_target: sc_module
169172
case tlm::TLM_WRITE_COMMAND: {
170173
this->do_when_write_transaction(data_ptr);
171174
//-----------DEBUG-----------
172-
printf("[DEBUG] Writing: ");
175+
dbgprint("[DEBUG] Writing: ");
173176
for (int i = 0; i < len/sizeof(int); ++i){
174-
printf("%02x", *(reinterpret_cast<int*>(data_ptr)+i));
177+
dbgprint("%02x", *(reinterpret_cast<int*>(data_ptr)+i));
175178
}
176179
printf("\n");
177180
//-----------DEBUG-----------
178181
break;
179182
}
180183
default: {
181-
cout << " ERROR " << "Command " << cmd << "is NOT valid" << endl;
184+
dbgprint("ERROR Command %0d is NOT valid", cmd);
182185
}
183186
}
184187

185188
//Send response
186-
cout << name() << " BEGIN_RESP SENT" << " TRANS ID " << 0 << " at time " << sc_time_stamp() << endl;
189+
dbgprint("%s BEGIN_RESP SENT TRANS ID %0d at time %s", name(), 0, sc_time_stamp().to_string().c_str());
187190
send_response(trans);
188191
}
189192
};

modules/router/src/sobel_edge_detector_tlm.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ using namespace std;
1111
#include "tlm_utils/peq_with_cb_and_phase.h"
1212

1313
#include "sobel_edge_detector_tlm.hpp"
14-
// #include "tlm_transaction.cpp"
14+
15+
#include "common_func.hpp"
1516

1617
void sobel_edge_detector_tlm::do_when_read_transaction(unsigned char*& data){
1718
int sobel_results[2];
1819

1920
sobel_results[0] = obtain_sobel_gradient_x();
2021
sobel_results[1] = obtain_sobel_gradient_y();
21-
cout << sobel_results[0] << endl;
22-
cout << sobel_results[1] << endl;
22+
dbgprint("%0d", sobel_results[0]);
23+
dbgprint("%0d", sobel_results[1]);
2324
memcpy(data, &sobel_results[0], 2*sizeof(int));
2425
}
2526
void sobel_edge_detector_tlm::do_when_write_transaction(unsigned char*&data){
2627
int window[3][3];
2728
for (int* i = reinterpret_cast<int*>(data), row = 0, col = 0; i - reinterpret_cast<int*>(data) < 9; i++) {
2829
window[row][col] = *i;
29-
printf("VAL: %0d -> %0d", i-reinterpret_cast<int*>(data), *i);
30+
dbgprint("VAL: %0d -> %0d", i-reinterpret_cast<int*>(data), *i);
3031
row++;
3132
if (row == 3) {
3233
row = 0;

modules/router/src/tb_edge_detector_tlm.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ using namespace std;
2727
#include "sobel_edge_detector_tlm.hpp"
2828
#include "img_initiator.cpp"
2929

30+
#include "common_func.hpp"
31+
3032
SC_MODULE(Tb_top)
3133
{
3234
img_initiator *initiator;
@@ -182,21 +184,21 @@ SC_MODULE(Tb_top)
182184
}
183185
}
184186
initiator->write(local_window_ptr, 0, 9*4);
185-
printf("OUTSIDE");
187+
dbgprint("OUTSIDE");
186188
wait(sc_time(100, SC_NS));
187-
printf("OUTSIDE");
189+
dbgprint("OUTSIDE");
188190
int* data_returned = new int;
189191
initiator->read(data_returned, 0, 2*4);
190-
// printf("OUTSIDE");
191-
printf("Data_returned: %0d\n", *data_returned);
192-
printf("Data_returned: %0d\n", *(data_returned+1));
192+
// dbgprint("OUTSIDE");
193+
dbgprint("Data_returned: %0d\n", *data_returned);
194+
dbgprint("Data_returned: %0d\n", *(data_returned+1));
193195

194196
//edge_detector_DUT->set_local_window(localWindow);
195197
localGradientX = edge_detector_DUT->obtain_sobel_gradient_x();
196198
localGradientY = edge_detector_DUT->obtain_sobel_gradient_y();
197199

198-
printf("Data_returned2: %0d\n", localGradientX);
199-
printf("Data_returned2: %0d\n", localGradientY);
200+
dbgprint("Data_returned2: %0d\n", localGradientX);
201+
dbgprint("Data_returned2: %0d\n", localGradientY);
200202

201203

202204
//initiator->write(&localWindow[0][0]+8, 1);
@@ -226,10 +228,10 @@ SC_MODULE(Tb_top)
226228

227229
localResult = (int)sqrt((float)(pow((int)localGradientX, 2)) + (float)(pow((int)localGradientY, 2)));
228230
#endif // EDGE_DETECTOR_AT_EN
229-
cout << "HERE01" << endl;
231+
dbgprint("HERE01");
230232
localGradientX = *data_returned;
231233
localGradientY = *(data_returned+1);
232-
cout << "HERE01" << endl;
234+
dbgprint("HERE01");
233235

234236
localResult = (int)sqrt((float)(pow(localGradientX, 2)) + (float)(pow(localGradientY, 2)));
235237
#ifdef TEST_NORMALIZE_MAGNITUDE
@@ -268,7 +270,7 @@ SC_MODULE(Tb_top)
268270
#if defined(EDGE_DETECTOR_LT_EN) || defined(EDGE_DETECTOR_AT_EN)
269271
current_number_of_pixels++;
270272
if (((((float)(current_number_of_pixels)) / ((float)(total_number_of_pixels))) * 100.0) >= next_target_of_completion) {
271-
std::cout << "@" << sc_time_stamp() << " Image processing completed at " << next_target_of_completion << std::endl;
273+
dbgprint("At time %s Image processing completed at %0d", sc_time_stamp().to_string().c_str(), next_target_of_completion);
272274
next_target_of_completion += 10.0;
273275
}
274276
#endif // EDGE_DETECTOR_LT_EN || EDGE_DETECTOR_AT_EN
@@ -355,7 +357,7 @@ int sc_main(int, char*[])
355357

356358
sc_start();
357359

358-
std::cout << "@" << sc_time_stamp() << " Terminating simulation" << std::endl;
360+
dbgprint("At time %s Terminating simulation", sc_time_stamp().to_string().c_str());
359361
sc_close_vcd_trace_file(wf);
360362

361363
return 0;

0 commit comments

Comments
 (0)