Skip to content

Commit 5ba58c2

Browse files
authored
Merge pull request #13 from ErickOF/jvillalobos/sobel-module
Adding AT model for Sobel module
2 parents d81c21e + 890f6e4 commit 5ba58c2

File tree

6 files changed

+406
-36
lines changed

6 files changed

+406
-36
lines changed

modules/Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ LD=g++
1414
LFLAGS=-Wall -I. -lm -g
1515
LIBS=-lsystemc -lm
1616

17+
# Source directories
18+
SRCDIR=src
19+
OBJDIR=obj
20+
BINDIR=./
21+
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
22+
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
23+
1724
ifdef INCLUDE_OPENCV
1825
# Target
1926
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
@@ -28,13 +35,6 @@ LFLAGS += $(shell pkg-config --libs opencv4)
2835
endif # INCLUDE_OPENCV_PKG
2936
endif # INCLUDE_OPENCV
3037

31-
# Source directories
32-
SRCDIR=src
33-
OBJDIR=obj
34-
BINDIR=./
35-
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
36-
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
37-
3838
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
3939
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
4040
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define SOBEL_INPUT_0 0x00000027u
2+
#define SOBEL_INPUT_1 0x0000002Fu
3+
#define SOBEL_OUTPUT 0x00000030u
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#ifdef EDGE_DETECTOR_AT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_HPP
3+
#define SOBEL_EDGE_DETECTOR_HPP
4+
5+
#include <systemc.h>
6+
#include "AddressMap.h"
7+
8+
SC_MODULE(Edge_Detector)
9+
{
10+
11+
sc_inout<sc_uint<64>> data;
12+
sc_in<sc_uint<24>> address;
13+
14+
const double delay_full_adder_1_bit = 0.361;
15+
const double delay_full_adder = delay_full_adder_1_bit * 16;
16+
17+
const double delay_multiplier = 9.82;
18+
19+
const sc_int<16> sobelGradientX[3][3] = {{-1, 0, 1},
20+
{-2, 0, 2},
21+
{-1, 0, 1}};
22+
const sc_int<16> sobelGradientY[3][3] = {{-1, -2, -1},
23+
{ 0, 0, 0},
24+
{ 1, 2, 1}};
25+
26+
sc_int<16> localWindow[3][3];
27+
28+
sc_int<16> resultSobelGradientX;
29+
sc_int<16> resultSobelGradientY;
30+
31+
sc_int<16> localMultX[3][3];
32+
sc_int<16> localMultY[3][3];
33+
34+
sc_event gotLocalWindow;
35+
36+
sc_event rd_t, wr_t;
37+
38+
sc_event mult_x, mult_y, sum_x, sum_y;
39+
40+
SC_CTOR(Edge_Detector)
41+
{
42+
SC_THREAD(wr);
43+
SC_THREAD(rd);
44+
SC_THREAD(compute_sobel_gradient_x);
45+
SC_THREAD(compute_sobel_gradient_y);
46+
SC_THREAD(perform_mult_gradient_x);
47+
SC_THREAD(perform_mult_gradient_y);
48+
SC_THREAD(perform_sum_gradient_x);
49+
SC_THREAD(perform_sum_gradient_y);
50+
}
51+
52+
void write();
53+
54+
void read();
55+
56+
void wr();
57+
58+
void rd();
59+
60+
void compute_sobel_gradient_x();
61+
62+
void compute_sobel_gradient_y();
63+
64+
void perform_mult_gradient_x();
65+
66+
void perform_mult_gradient_y();
67+
68+
void perform_sum_gradient_x();
69+
70+
void perform_sum_gradient_y();
71+
72+
};
73+
74+
#endif // SOBEL_EDGE_DETECTOR_HPP
75+
#endif // EDGE_DETECTOR_AT_EN
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#ifdef EDGE_DETECTOR_AT_EN
2+
#ifndef SOBEL_EDGE_DETECTOR_CPP
3+
#define SOBEL_EDGE_DETECTOR_CPP
4+
5+
#include "sobel_edge_detector_at_model.hpp"
6+
7+
void Edge_Detector::write()
8+
{
9+
wr_t.notify(5, SC_NS);
10+
}
11+
12+
void Edge_Detector::wr()
13+
{
14+
while (true)
15+
{
16+
wait(wr_t);
17+
if ((address.read() - SOBEL_INPUT_0) == 0)
18+
{
19+
int j = 0;
20+
for (int i = 0; i < 8; i++)
21+
{
22+
localWindow[0][0][i] = data.read()[i + (j * 8)];
23+
}
24+
j++;
25+
for (int i = 0; i < 8; i++)
26+
{
27+
localWindow[0][1][i] = data.read()[i + (j * 8)];
28+
}
29+
j++;
30+
for (int i = 0; i < 8; i++)
31+
{
32+
localWindow[0][2][i] = data.read()[i + (j * 8)];
33+
}
34+
j++;
35+
for (int i = 0; i < 8; i++)
36+
{
37+
localWindow[1][0][i] = data.read()[i + (j * 8)];
38+
}
39+
j++;
40+
for (int i = 0; i < 8; i++)
41+
{
42+
localWindow[1][1][i] = data.read()[i + (j * 8)];
43+
}
44+
j++;
45+
for (int i = 0; i < 8; i++)
46+
{
47+
localWindow[1][2][i] = data.read()[i + (j * 8)];
48+
}
49+
j++;
50+
for (int i = 0; i < 8; i++)
51+
{
52+
localWindow[2][0][i] = data.read()[i + (j * 8)];
53+
}
54+
j++;
55+
for (int i = 0; i < 8; i++)
56+
{
57+
localWindow[2][1][i] = data.read()[i + (j * 8)];
58+
}
59+
gotLocalWindow.notify(0, SC_NS);
60+
}
61+
else if ((address.read() - SOBEL_INPUT_1) == 0)
62+
{
63+
for (int i = 0; i < 8; i++)
64+
{
65+
localWindow[2][2][i] = data.read()[i];
66+
}
67+
gotLocalWindow.notify(0, SC_NS);
68+
}
69+
}
70+
}
71+
72+
void Edge_Detector::read()
73+
{
74+
rd_t.notify(5, SC_NS);
75+
}
76+
77+
void Edge_Detector::rd()
78+
{
79+
while (true)
80+
{
81+
wait(rd_t);
82+
if ((address.read() - SOBEL_OUTPUT) == 0)
83+
{
84+
data = (sc_uint<32>(0), resultSobelGradientY, resultSobelGradientX);
85+
}
86+
}
87+
}
88+
89+
void Edge_Detector::compute_sobel_gradient_x()
90+
{
91+
while (true)
92+
{
93+
wait(gotLocalWindow);
94+
95+
mult_x.notify(delay_multiplier, SC_NS);
96+
}
97+
}
98+
99+
void Edge_Detector::compute_sobel_gradient_y()
100+
{
101+
while (true)
102+
{
103+
wait(gotLocalWindow);
104+
105+
mult_y.notify(delay_multiplier, SC_NS);
106+
}
107+
}
108+
109+
void Edge_Detector::perform_mult_gradient_x()
110+
{
111+
while (true)
112+
{
113+
wait(mult_x);
114+
115+
for (int i = 0; i < 3; i++)
116+
{
117+
for (int j = 0; j < 3; j++)
118+
{
119+
localMultX[i][j] = localWindow[i][j] * sobelGradientX[i][j];
120+
}
121+
}
122+
123+
sum_x.notify(delay_full_adder, SC_NS);
124+
}
125+
}
126+
127+
void Edge_Detector::perform_mult_gradient_y()
128+
{
129+
while (true)
130+
{
131+
wait(mult_y);
132+
133+
for (int i = 0; i < 3; i++)
134+
{
135+
for (int j = 0; j < 3; j++)
136+
{
137+
localMultY[i][j] = localWindow[i][j] * sobelGradientY[i][j];
138+
}
139+
}
140+
141+
sum_y.notify(delay_full_adder, SC_NS);
142+
}
143+
}
144+
145+
void Edge_Detector::perform_sum_gradient_x()
146+
{
147+
while (true)
148+
{
149+
wait(sum_x);
150+
resultSobelGradientX = 0;
151+
152+
for (int i = 0; i < 3; i++)
153+
{
154+
for (int j = 0; j < 3; j++)
155+
{
156+
resultSobelGradientX += localMultX[i][j];
157+
}
158+
}
159+
}
160+
}
161+
162+
void Edge_Detector::perform_sum_gradient_y()
163+
{
164+
while (true)
165+
{
166+
wait(sum_y);
167+
resultSobelGradientY = 0;
168+
169+
for (int i = 0; i < 3; i++)
170+
{
171+
for (int j = 0; j < 3; j++)
172+
{
173+
resultSobelGradientY += localMultY[i][j];
174+
}
175+
}
176+
}
177+
}
178+
179+
#endif // SOBEL_EDGE_DETECTOR_CPP
180+
#endif // EDGE_DETECTOR_AT_EN

0 commit comments

Comments
 (0)