Skip to content

Commit a7013da

Browse files
jgavillalobosErickOF
authored andcommitted
Use AT model of edge_detector instead of LT
1 parent 00982c7 commit a7013da

File tree

11 files changed

+190
-121
lines changed

11 files changed

+190
-121
lines changed

modules/edge-detector/include/sobel_edge_detector_at_model.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
SC_MODULE(Edge_Detector)
99
{
1010

11+
#ifndef USING_TLM_TB_EN
1112
sc_inout<sc_uint<64>> data;
1213
sc_in<sc_uint<24>> address;
14+
#else
15+
sc_uint<64> data;
16+
sc_uint<24> address;
17+
#endif // USING_TLM_TB_EN
1318

1419
const double delay_full_adder_1_bit = 0.361;
1520
const double delay_full_adder = delay_full_adder_1_bit * 16;
@@ -49,9 +54,9 @@ SC_MODULE(Edge_Detector)
4954
SC_THREAD(perform_sum_gradient_y);
5055
}
5156

52-
void write();
57+
virtual void write();
5358

54-
void read();
59+
virtual void read();
5560

5661
void wr();
5762

modules/edge-detector/src/sobel_edge_detector_at_model.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,30 @@ void Edge_Detector::wr()
1414
while (true)
1515
{
1616
wait(wr_t);
17+
#ifdef USING_TLM_TB_EN
18+
if ((address - SOBEL_INPUT_0) == 0)
19+
#else
1720
if ((address.read() - SOBEL_INPUT_0) == 0)
21+
#endif // USING_TLM_TB_EN
1822
{
1923
int j = 0;
24+
#ifdef USING_TLM_TB_EN
25+
localWindow[0][0] = data.range((j + 1) * 8 - 1, j * 8);
26+
j++;
27+
localWindow[0][1] = data.range((j + 1) * 8 - 1, j * 8);
28+
j++;
29+
localWindow[0][2] = data.range((j + 1) * 8 - 1, j * 8);
30+
j++;
31+
localWindow[1][0] = data.range((j + 1) * 8 - 1, j * 8);
32+
j++;
33+
localWindow[1][1] = data.range((j + 1) * 8 - 1, j * 8);
34+
j++;
35+
localWindow[1][2] = data.range((j + 1) * 8 - 1, j * 8);
36+
j++;
37+
localWindow[2][0] = data.range((j + 1) * 8 - 1, j * 8);
38+
j++;
39+
localWindow[2][1] = data.range((j + 1) * 8 - 1, j * 8);
40+
#else
2041
for (int i = 0; i < 8; i++)
2142
{
2243
localWindow[0][0][i] = data.read()[i + (j * 8)];
@@ -56,14 +77,23 @@ void Edge_Detector::wr()
5677
{
5778
localWindow[2][1][i] = data.read()[i + (j * 8)];
5879
}
80+
#endif // USING_TLM_TB_EN
5981
gotLocalWindow.notify(0, SC_NS);
6082
}
83+
#ifdef USING_TLM_TB_EN
84+
else if ((address - SOBEL_INPUT_1) == 0)
85+
#else
6186
else if ((address.read() - SOBEL_INPUT_1) == 0)
87+
#endif // USING_TLM_TB_EN
6288
{
89+
#ifdef USING_TLM_TB_EN
90+
localWindow[2][2] = data.range(15, 0);
91+
#else
6392
for (int i = 0; i < 8; i++)
6493
{
6594
localWindow[2][2][i] = data.read()[i];
6695
}
96+
#endif // USING_TLM_TB_EN
6797
gotLocalWindow.notify(0, SC_NS);
6898
}
6999
}
@@ -79,7 +109,11 @@ void Edge_Detector::rd()
79109
while (true)
80110
{
81111
wait(rd_t);
112+
#ifdef USING_TLM_TB_EN
113+
if ((address - SOBEL_OUTPUT) == 0)
114+
#else
82115
if ((address.read() - SOBEL_OUTPUT) == 0)
116+
#endif // USING_TLM_TB_EN
83117
{
84118
data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX);
85119
}

modules/router/include/common_func.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#define COMMON_FUNC
33

44
#define dbgprint(FORMAT, ARGS...) \
5-
printf("%s(%0d) : " FORMAT "\n", __FILE__, __LINE__, ##ARGS)
5+
printf("%s(%0d) @%s: " FORMAT "\n", __FILE__, __LINE__, sc_time_stamp().to_string().c_str(), ##ARGS)
66

77
#define dbgmodprint(FORMAT, ARGS...) \
8-
printf("%s(%0d) [%s] : " FORMAT "\n", __FILE__, __LINE__, this->name(), ##ARGS)
8+
printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, this->name(), sc_time_stamp().to_string().c_str(), ##ARGS)
99

1010
#define dbgimgtarmodprint(FORMAT, ARGS...) \
11-
printf("%s(%0d) [%s] : " FORMAT "\n", __FILE__, __LINE__, img_target::name(), ##ARGS)
11+
printf("%s(%0d) [%s] @%s : " FORMAT "\n", __FILE__, __LINE__, img_target::name(), sc_time_stamp().to_string().c_str(), ##ARGS)
1212

1313
#endif // COMMON_FUNC

modules/router/include/rgb2gray_tlm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct rgb2gray_tlm : public Rgb2Gray, public img_target
2121
}
2222

2323
//Override do_when_transaction functions
24-
virtual void do_when_read_transaction(unsigned char*& data);
25-
virtual void do_when_write_transaction(unsigned char*& data);
24+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
25+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
2626

2727
};
2828
#endif // RGB2GRAY_TLM_HPP

modules/router/include/sobel_edge_detector_tlm.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using namespace std;
1010
#include "tlm_utils/simple_target_socket.h"
1111
#include "tlm_utils/peq_with_cb_and_phase.h"
1212

13-
#include "sobel_edge_detector_lt_model.hpp"
13+
#include "sobel_edge_detector_at_model.hpp"
1414
#include "../src/img_target.cpp"
1515

1616
//Extended Unification TLM
@@ -21,8 +21,10 @@ struct sobel_edge_detector_tlm : public Edge_Detector, public img_target
2121
}
2222

2323
//Override do_when_transaction functions
24-
virtual void do_when_read_transaction(unsigned char*& data);
25-
virtual void do_when_write_transaction(unsigned char*& data);
24+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
25+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
2626

27+
void read() override;
28+
void write() override;
2729
};
28-
#endif
30+
#endif

modules/router/run_all.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
case $1 in
44
"save_log")
5-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_LT_EN=1 USING_TLM_TB_EN=1 all > output.log
5+
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all > output.log
66
;;
77
"print_all")
8-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_LT_EN=1 USING_TLM_TB_EN=1 print-all
8+
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 print-all
9+
;;
10+
"compile")
11+
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 compile
912
;;
1013
*)
11-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_LT_EN=1 USING_TLM_TB_EN=1 all
14+
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all
1215
;;
1316
esac

modules/router/src/img_initiator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ struct img_initiator: sc_module
130130
phase = tlm::BEGIN_REQ;
131131
transaction->acquire();
132132
transaction->get_extension(img_ext);
133-
dbgmodprint("BEGIN_REQ SENT TRANS ID %0d at time %s", img_ext->transaction_number, sc_time_stamp().to_string().c_str());
133+
dbgmodprint("BEGIN_REQ SENT TRANS ID %0d", img_ext->transaction_number);
134134
pending_transaction = transaction;
135135
status = socket->nb_transport_fw(*transaction, phase, this->write_delay); // Non-blocking transport call
136136

137137
// Check request status returned by target
138138
switch (status) {
139139
//Case 1: Transaction was accepted
140140
case tlm::TLM_ACCEPTED: {
141-
dbgmodprint("%s received -> Transaction ID %d at time %s", "TLM_ACCEPTED", img_ext->transaction_number, sc_time_stamp().to_string().c_str());
141+
dbgmodprint("%s received -> Transaction ID %d", "TLM_ACCEPTED", img_ext->transaction_number);
142142
check_transaction(*transaction);
143143
transaction->release();
144144
pending_transaction = 0;
@@ -181,7 +181,7 @@ struct img_initiator: sc_module
181181
void peq_cb(tlm::tlm_generic_payload& trans, const tlm::tlm_phase& phase)
182182
{
183183

184-
//dbgmodprint("%s received -> Transaction ID %d from address %x at time %s\n", phase, this->id_extension->transaction_id, trans.get_address(), sc_time_stamp());
184+
//dbgmodprint("%s received -> Transaction ID %d from address %x", phase, this->id_extension->transaction_id);
185185
//cout << name() << " " <<hex << trans.get_address() << " BEGIN_RESP RECEIVED at " << sc_time_stamp() << endl;
186186
switch (phase) {
187187
case tlm::BEGIN_RESP: {

modules/router/src/img_target.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct img_target: sc_module
8181
trans.acquire();
8282
trans.get_extension(img_ext);
8383

84-
dbgmodprint("BEGIN_REQ RECEIVED TRANS ID %0d at time %s", img_ext->transaction_number, sc_time_stamp().to_string().c_str());
84+
dbgmodprint("BEGIN_REQ RECEIVED TRANS ID %0d", img_ext->transaction_number);
8585

8686
//Queue a response
8787
tlm::tlm_phase int_phase = internal_processing_ph;
@@ -121,7 +121,7 @@ struct img_target: sc_module
121121
// Target only care about acknowledge of the succesful response
122122
trans.release();
123123
trans.get_extension(img_ext);
124-
dbgmodprint("TLM_ACCEPTED RECEIVED TRANS ID %0d at time %s", img_ext->transaction_number, sc_time_stamp().to_string().c_str());
124+
dbgmodprint("TLM_ACCEPTED RECEIVED TRANS ID %0d", img_ext->transaction_number);
125125
break;
126126
}
127127

@@ -134,10 +134,10 @@ struct img_target: sc_module
134134

135135
}
136136

137-
virtual void do_when_read_transaction(unsigned char*& data){
137+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address){
138138

139139
}
140-
virtual void do_when_write_transaction(unsigned char*&data){
140+
virtual void do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address){
141141

142142
}
143143

@@ -165,7 +165,7 @@ struct img_target: sc_module
165165
case tlm::TLM_READ_COMMAND: {
166166
unsigned char* response_data_ptr;
167167
response_data_ptr = (unsigned char*)malloc(len);
168-
this->do_when_read_transaction(response_data_ptr);
168+
this->do_when_read_transaction(response_data_ptr, len, addr);
169169
//Add read according to length
170170
//-----------DEBUG-----------
171171
dbgmodprint("[DEBUG] Reading: ");
@@ -178,7 +178,7 @@ struct img_target: sc_module
178178
break;
179179
}
180180
case tlm::TLM_WRITE_COMMAND: {
181-
this->do_when_write_transaction(data_ptr);
181+
this->do_when_write_transaction(data_ptr, len, addr);
182182
//-----------DEBUG-----------
183183
dbgmodprint("[DEBUG] Writing: ");
184184
for (int i = 0; i < len/sizeof(int); ++i){
@@ -194,7 +194,7 @@ struct img_target: sc_module
194194
}
195195

196196
//Send response
197-
dbgmodprint("BEGIN_RESP SENT TRANS ID %0d at time %s", img_ext->transaction_number, sc_time_stamp().to_string().c_str());
197+
dbgmodprint("BEGIN_RESP SENT TRANS ID %0d", img_ext->transaction_number);
198198
send_response(trans);
199199
}
200200

modules/router/src/rgb2gray_tlm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ using namespace std;
1414

1515
#include "common_func.hpp"
1616

17-
void rgb2gray_tlm::do_when_read_transaction(unsigned char*& data){
17+
void rgb2gray_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address){
1818
unsigned char pixel_value;
1919

2020
pixel_value = this->obtain_gray_value();
2121
dbgimgtarmodprint("%0u", pixel_value);
2222
memcpy(data, &pixel_value, sizeof(char));
2323
}
2424

25-
void rgb2gray_tlm::do_when_write_transaction(unsigned char*&data){
25+
void rgb2gray_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address){
2626
unsigned char rgb_values[3];
2727

2828
unsigned char *i = data;

modules/router/src/sobel_edge_detector_tlm.cpp

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,51 @@ using namespace std;
1414

1515
#include "common_func.hpp"
1616

17-
void sobel_edge_detector_tlm::do_when_read_transaction(unsigned char*& data){
18-
int sobel_results[2];
19-
20-
sobel_results[0] = obtain_sobel_gradient_x();
21-
sobel_results[1] = obtain_sobel_gradient_y();
22-
dbgimgtarmodprint("%0d", sobel_results[0]);
23-
dbgimgtarmodprint("%0d", sobel_results[1]);
24-
memcpy(data, &sobel_results[0], 2*sizeof(int));
25-
}
26-
void sobel_edge_detector_tlm::do_when_write_transaction(unsigned char*&data){
27-
int window[3][3];
28-
for (int* i = reinterpret_cast<int*>(data), row = 0, col = 0; i - reinterpret_cast<int*>(data) < 9; i++) {
29-
window[row][col] = *i;
30-
dbgimgtarmodprint("VAL: %0d -> %0d", i-reinterpret_cast<int*>(data), *i);
31-
row++;
32-
if (row == 3) {
33-
row = 0;
34-
col++;
35-
}
36-
}
37-
this->set_local_window(window);
17+
void sobel_edge_detector_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address){
18+
short int sobel_results[4];
19+
sc_int<16> local_result;
20+
21+
dbgimgtarmodprint("Calling do_when_read_transaction");
22+
23+
Edge_Detector::address = address;
24+
read();
25+
26+
for (int i = 0; i < 4; i++)
27+
{
28+
local_result = Edge_Detector::data.range((i + 1) * 16 - 1, i * 16).to_int();
29+
sobel_results[i] = (short int)local_result;
30+
dbgimgtarmodprint("%0d", sobel_results[i]);
31+
}
32+
33+
memcpy(data, sobel_results, 4 * sizeof(short int));
34+
}
35+
36+
void sobel_edge_detector_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
37+
{
38+
sc_uint<8> values[8];
39+
40+
dbgimgtarmodprint("Calling do_when_write_transaction");
41+
42+
for (int i = 0; i < 8; i++)
43+
{
44+
values[i] = *(data + i);
45+
}
46+
Edge_Detector::data = (values[7], values[6], values[5], values[4], values[3], values[2], values[1], values[0]);
47+
Edge_Detector::address = address;
48+
write();
49+
}
50+
51+
void sobel_edge_detector_tlm::read()
52+
{
53+
if ((Edge_Detector::address - SOBEL_OUTPUT) == 0)
54+
{
55+
Edge_Detector::data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX);
56+
}
57+
}
58+
59+
void sobel_edge_detector_tlm::write()
60+
{
61+
wr_t.notify(0, SC_NS);
3862
}
3963

4064
#endif

0 commit comments

Comments
 (0)