Skip to content

Commit 411343e

Browse files
RMorales25jgavillalobos
authored andcommitted
Add sobel module
1 parent aa36976 commit 411343e

File tree

5 files changed

+65
-39
lines changed

5 files changed

+65
-39
lines changed

VirtualPrototype/inc/ips_filter_tlm.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ using namespace sc_core;
55
using namespace sc_dt;
66
using namespace std;
77

8-
#include <tlm.h>
9-
#include <tlm_utils/simple_initiator_socket.h>
10-
#include <tlm_utils/simple_target_socket.h>
11-
#include <tlm_utils/peq_with_cb_and_phase.h>
128

139
#include "ips_filter_lt_model.hpp"
1410
#include "../src/img_target.cpp"
@@ -21,7 +17,7 @@ struct ips_filter_tlm : public Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTE
2117

2218
SC_CTOR(ips_filter_tlm): Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>(Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>::name()), img_target(img_target::name()) {
2319

24-
set_mem_attributes(IMG_FILTER_KERNEL_ADDRESS_LO, IMG_FILTER_KERNEL_ADDRESS_LO);
20+
set_mem_attributes(IMG_FILTER_KERNEL_ADDRESS_LO, IMG_FILTER_KERNEL_SIZE);
2521
}
2622

2723
//Override do_when_transaction functions

VirtualPrototype/inc/sobel_edge_detector_at_model.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifdef EDGE_DETECTOR_AT_EN
21
#ifndef SOBEL_EDGE_DETECTOR_HPP
32
#define SOBEL_EDGE_DETECTOR_HPP
3+
#define USING_TLM_TB_EN
44

55
#include <systemc.h>
6-
#include "address_map.hpp"
76

87
SC_MODULE(Edge_Detector)
98
{
@@ -77,4 +76,3 @@ SC_MODULE(Edge_Detector)
7776
};
7877

7978
#endif // SOBEL_EDGE_DETECTOR_HPP
80-
#endif // EDGE_DETECTOR_AT_EN
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef SOBEL_EDGE_DETECTOR_TLM_HPP
2+
#define SOBEL_EDGE_DETECTOR_TLM_HPP
3+
using namespace sc_core;
4+
using namespace sc_dt;
5+
using namespace std;
6+
7+
#include "sobel_edge_detector_at_model.hpp"
8+
#include "../src/img_target.cpp"
9+
#include "address_map.hpp"
10+
11+
//Extended Unification TLM
12+
struct sobel_edge_detector_tlm : public Edge_Detector, public img_target
13+
{
14+
15+
SC_CTOR(sobel_edge_detector_tlm): Edge_Detector(Edge_Detector::name()), img_target(img_target::name()) {
16+
sobel_input = new sc_uint<8>[9];
17+
set_mem_attributes(SOBEL_INPUT_0_ADDRESS_LO, SOBEL_INPUT_0_SIZE+SOBEL_INPUT_1_SIZE);
18+
}
19+
20+
//Override do_when_transaction functions
21+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
22+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
23+
24+
void read() override;
25+
void write() override;
26+
27+
sc_uint<8> *sobel_input;
28+
};
29+
#endif // SOBEL_EDGE_DETECTOR_TLM_HPP

VirtualPrototype/src/sobel_edge_detector_at_model.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#ifdef EDGE_DETECTOR_AT_EN
21
#ifndef SOBEL_EDGE_DETECTOR_CPP
32
#define SOBEL_EDGE_DETECTOR_CPP
3+
#define USING_TLM_TB_EN
44

55
#include "sobel_edge_detector_at_model.hpp"
6+
#include "address_map.hpp"
67

78
void Edge_Detector::write()
89
{
@@ -15,9 +16,9 @@ void Edge_Detector::wr()
1516
{
1617
wait(wr_t);
1718
#ifdef USING_TLM_TB_EN
18-
if ((address - SOBEL_INPUT_0) == 0)
19+
if ((address - SOBEL_INPUT_0_ADDRESS_LO) == 0)
1920
#else
20-
if ((address.read() - SOBEL_INPUT_0) == 0)
21+
if ((address.read() - SOBEL_INPUT_0_ADDRESS_LO) == 0)
2122
#endif // USING_TLM_TB_EN
2223
{
2324
int j = 0;
@@ -81,9 +82,9 @@ void Edge_Detector::wr()
8182
gotLocalWindow.notify(0, SC_NS);
8283
}
8384
#ifdef USING_TLM_TB_EN
84-
else if ((address - SOBEL_INPUT_1) == 0)
85+
else if ((address - SOBEL_INPUT_1_ADDRESS_LO) == 0)
8586
#else
86-
else if ((address.read() - SOBEL_INPUT_1) == 0)
87+
else if ((address.read() - SOBEL_INPUT_1_ADDRESS_LO) == 0)
8788
#endif // USING_TLM_TB_EN
8889
{
8990
#ifdef USING_TLM_TB_EN
@@ -110,9 +111,9 @@ void Edge_Detector::rd()
110111
{
111112
wait(rd_t);
112113
#ifdef USING_TLM_TB_EN
113-
if ((address - SOBEL_OUTPUT) == 0)
114+
if ((address - SOBEL_INPUT_0_ADDRESS_LO) == 0)
114115
#else
115-
if ((address.read() - SOBEL_OUTPUT) == 0)
116+
if ((address.read() - SOBEL_OUTPUT_ADDRESS_LO) == 0)
116117
#endif // USING_TLM_TB_EN
117118
{
118119
data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX);
@@ -211,4 +212,4 @@ void Edge_Detector::perform_sum_gradient_y()
211212
}
212213

213214
#endif // SOBEL_EDGE_DETECTOR_CPP
214-
#endif // EDGE_DETECTOR_AT_EN
215+

VirtualPrototype/src/sobel_edge_detector_tlm.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,53 @@ using namespace sc_dt;
66
using namespace std;
77

88
#include <tlm.h>
9-
#include <tlm_utils/simple_initiator_socket.h>
10-
#include <tlm_utils/simple_target_socket.h>
11-
#include <tlm_utils/peq_with_cb_and_phase.h>
12-
139
#include "sobel_edge_detector_tlm.hpp"
10+
#include "address_map.hpp"
1411

1512
#include "common_func.hpp"
1613

1714
void sobel_edge_detector_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address){
1815
short int sobel_results[4];
1916
sc_int<16> local_result;
20-
21-
dbgimgtarmodprint("Calling do_when_read_transaction");
2217

23-
Edge_Detector::address = address;
18+
Edge_Detector::address = (sc_uint<24>) address+SOBEL_OUTPUT_ADDRESS_LO;
2419
read();
2520

26-
for (int i = 0; i < 4; i++)
21+
for (int i = 0; i < data_length; i++)
2722
{
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]);
23+
local_result = Edge_Detector::data.range((address + i + 1) * 16 - 1, (address+i) * 16).to_int();
24+
sobel_results[address+i] = (short int)local_result;
25+
*(data+i) = sobel_results[address+i];
26+
//dbgimgtarmodprint("%0d", sobel_results[address+i]);
3127
}
3228

33-
memcpy(data, sobel_results, 4 * sizeof(short int));
3429
}
3530

3631
void sobel_edge_detector_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
3732
{
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);
33+
if (address < SOBEL_INPUT_0_SIZE) {
34+
for (int i = 0; i < data_length; data++) {
35+
this->sobel_input[address+i] = *(data+i);
36+
}
4537
}
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();
38+
else if (SOBEL_INPUT_0_SIZE <= address && address < SOBEL_INPUT_0_SIZE + SOBEL_INPUT_1_SIZE) {
39+
for (int i = 0; i < data_length; data++) {
40+
this->sobel_input[address+i-SOBEL_INPUT_0_SIZE] = *(data+i-SOBEL_INPUT_0_SIZE);
41+
}
42+
}
43+
44+
Edge_Detector::data = (this->sobel_input[7], this->sobel_input[6], this->sobel_input[5], this->sobel_input[4], this->sobel_input[3], this->sobel_input[2], this->sobel_input[1], this->sobel_input[0]);
45+
Edge_Detector::address = address+SOBEL_INPUT_0_ADDRESS_LO;
46+
47+
if ((address == SOBEL_INPUT_0_SIZE-1) || (address == SOBEL_INPUT_0_SIZE+SOBEL_INPUT_1_SIZE-1)) {
48+
write();
49+
}
50+
4951
}
5052

5153
void sobel_edge_detector_tlm::read()
5254
{
53-
if ((Edge_Detector::address - SOBEL_OUTPUT) == 0)
55+
if ((Edge_Detector::address - SOBEL_OUTPUT_ADDRESS_LO) == 0)
5456
{
5557
Edge_Detector::data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX);
5658
}

0 commit comments

Comments
 (0)