Skip to content

Commit 8ca3cf7

Browse files
jgavillalobosErickOF
authored andcommitted
Add Filter block to TLM TB
1 parent ddf95ad commit 8ca3cf7

File tree

11 files changed

+436
-223
lines changed

11 files changed

+436
-223
lines changed

modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
2424
ifdef USING_TLM_TB_EN
2525
EDGE_DIR=../edge-detector
2626
GRAY_DIR=../rgb2gray
27+
FILTER_DIR=../filter
2728

28-
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src
29-
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include
29+
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src
30+
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include
3031
endif # USING_TLM_TB_EN
3132

3233
ifdef INCLUDE_OPENCV
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef IPS_FILTER_DEFINES
2+
#define IPS_FILTER_DEFINES
3+
4+
#ifndef IPS_FILTER_KERNEL_SIZE
5+
#define IPS_FILTER_KERNEL_SIZE 3
6+
#endif // IPS_FILTER_KERNEL_SIZE
7+
8+
#ifndef IPS_FILTER_PV_EN
9+
// N * N * copy_pixel_to_mem_time + mult + redux + copy_pixel_to_mem_time
10+
// Image is copied pixel by pixel
11+
#define DELAY_TIME (IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE * 1) + 4 + 2 + 1
12+
#endif // IPS_FILTER_PV_EN
13+
14+
#endif // IPS_FILTER_DEFINES

modules/filter/include/ips_filter_lt_model.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#endif // IPS_DUMP_EN
99
#include <systemc.h>
1010

11+
#ifdef USING_TLM_TB_EN
12+
#include "ips_filter_defines.h"
13+
#endif
1114

1215
/**
1316
* @brief Filter module.

modules/filter/src/tb_filter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifndef USING_TLM_TB_EN
12
#define int64 systemc_int64
23
#define uint64 systemc_uint64
34
#include <systemc.h>
@@ -28,7 +29,7 @@
2829
#define IPS_OUT_TYPE_TB float
2930
#endif // IPS_OUT_TYPE_TB
3031
#ifndef IPS_IMG_PATH_TB
31-
#define IPS_IMG_PATH_TB "../../tools/datagen/src/imgs/car_noisy_image.png"
32+
#define IPS_IMG_PATH_TB "../../tools/datagen/src/imgs/car_grayscale_image.jpg"
3233
#endif // IPS_IMG_PATH_TB
3334

3435
#ifndef IPS_FILTER_PV_EN
@@ -335,3 +336,5 @@ int sc_main(int, char*[])
335336
#endif // IPS_DUMP_EN
336337
return 0;
337338
}
339+
340+
#endif // USING_TLM_TB_EN

modules/router/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ ifdef USING_TLM_TB_EN
4747
LFLAGS += -DUSING_TLM_TB_EN
4848
endif # USING_TLM_TB_EN
4949

50+
ifdef IPS_FILTER_LT_EN
51+
CFLAGS += -DIPS_FILTER_LT_EN
52+
LFLAGS += -DIPS_FILTER_LT_EN
53+
endif # IPS_FILTER_LT_EN
54+
5055
.PHONY: print-all
5156
print-all:
5257
@echo "Incdir is $(INCDIR)"

modules/router/include/ImportantDefines.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@
66
#define IMAG_ROWS 480
77
#define IMAG_COLS 640
88

9+
#ifndef IPS_FILTER_KERNEL_SIZE
10+
#define IPS_FILTER_KERNEL_SIZE 3
11+
#endif // IPS_FILTER_KERNEL_SIZE
12+
#ifndef IPS_IN_TYPE_TB
13+
#define IPS_IN_TYPE_TB float
14+
#endif // IPS_IN_TYPE_TB
15+
#ifndef IPS_OUT_TYPE_TB
16+
#define IPS_OUT_TYPE_TB float
17+
#endif // IPS_OUT_TYPE_TB
18+
919
#endif IMPORTANTDEFINES_H
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef IPS_FILTER_TLM_HPP
2+
#define IPS_FILTER_TLM_HPP
3+
#include "systemc.h"
4+
using namespace sc_core;
5+
using namespace sc_dt;
6+
using namespace std;
7+
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"
12+
13+
#include "ips_filter_lt_model.hpp"
14+
#include "../src/img_target.cpp"
15+
16+
#include "ImportantDefines.h"
17+
18+
//Extended Unification TLM
19+
struct ips_filter_tlm : public Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>, public img_target
20+
{
21+
22+
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()) {
23+
}
24+
25+
//Override do_when_transaction functions
26+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
27+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
28+
29+
IPS_IN_TYPE_TB img_window[IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE];
30+
IPS_OUT_TYPE_TB img_result;
31+
32+
};
33+
#endif // IPS_FILTER_TLM_HPP

modules/router/run_all.sh

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

33
case $1 in
44
"save_log")
5-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all > output.log
5+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_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_AT_EN=1 USING_TLM_TB_EN=1 print-all
8+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 print-all
99
;;
1010
"compile")
11-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 compile
11+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 compile
1212
;;
1313
*)
14-
make RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all
14+
make RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_TB_EN=1 all
1515
;;
1616
esac
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef IPS_FILTER_TLM_CPP
2+
#define IPS_FILTER_TLM_CPP
3+
#include "systemc.h"
4+
using namespace sc_core;
5+
using namespace sc_dt;
6+
using namespace std;
7+
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"
12+
13+
#include "ips_filter_tlm.hpp"
14+
15+
#include "common_func.hpp"
16+
#include "ImportantDefines.h"
17+
18+
void ips_filter_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address)
19+
{
20+
this->img_result = *(Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>::result_ptr);
21+
memcpy(data, Filter<IPS_IN_TYPE_TB, IPS_OUT_TYPE_TB, IPS_FILTER_KERNEL_SIZE>::result_ptr, sizeof(IPS_OUT_TYPE_TB));
22+
}
23+
24+
void ips_filter_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
25+
{
26+
IPS_OUT_TYPE_TB* result = new IPS_OUT_TYPE_TB;
27+
IPS_IN_TYPE_TB* img_window = new IPS_IN_TYPE_TB[3 * 3];
28+
29+
if ((IPS_FILTER_KERNEL_SIZE * IPS_FILTER_KERNEL_SIZE * sizeof(char)) != data_length)
30+
{
31+
SC_REPORT_FATAL("IPS_FILTER", "Illegal transaction size");
32+
}
33+
34+
for (int i = 0; i < IPS_FILTER_KERNEL_SIZE; i++)
35+
{
36+
for (int j = 0; j < IPS_FILTER_KERNEL_SIZE; j++)
37+
{
38+
*(img_window + ((i * IPS_FILTER_KERNEL_SIZE) + j)) = (IPS_IN_TYPE_TB)*(data + ((i * IPS_FILTER_KERNEL_SIZE) + j));
39+
this->img_window[(i * IPS_FILTER_KERNEL_SIZE) + j] = (IPS_IN_TYPE_TB)*(data + ((i * IPS_FILTER_KERNEL_SIZE) + j));
40+
}
41+
}
42+
43+
filter(img_window, result);
44+
}
45+
46+
#endif // IPS_FILTER_TLM_CPP

modules/router/src/memory_tlm.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ using namespace std;
1414

1515
#include "common_func.hpp"
1616

17+
#include "AddressMap.h"
18+
1719
void memory_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address)
1820
{
1921
sc_uint<8> local_data[8];
@@ -28,9 +30,9 @@ void memory_tlm::do_when_read_transaction(unsigned char*& data, unsigned int dat
2830
local_data[i] = 0;
2931
}
3032
mem_data = (local_data[7], local_data[6], local_data[5], local_data[4], local_data[3], local_data[2], local_data[1], local_data[0]);
31-
mem_address = address;
33+
mem_address = address - MEM_START;
3234
mem_we = 0;
33-
memcpy(data, (mem_array + address), data_length);
35+
memcpy(data, (mem_array + address - MEM_START), data_length);
3436
}
3537

3638
void memory_tlm::do_when_write_transaction(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
@@ -47,14 +49,14 @@ void memory_tlm::do_when_write_transaction(unsigned char*&data, unsigned int dat
4749
local_data[i] = 0;
4850
}
4951
mem_data = (local_data[7], local_data[6], local_data[5], local_data[4], local_data[3], local_data[2], local_data[1], local_data[0]);
50-
mem_address = address;
52+
mem_address = address - MEM_START;
5153
mem_we = 1;
52-
memcpy((mem_array + address), data, data_length);
54+
memcpy((mem_array + address - MEM_START), data, data_length);
5355
}
5456

5557
void memory_tlm::backdoor_write(unsigned char*&data, unsigned int data_length, sc_dt::uint64 address)
5658
{
57-
memcpy((mem_array + address), data, data_length);
59+
memcpy((mem_array + address - MEM_START), data, data_length);
5860
}
5961

6062
#endif // MEMORY_TLM_CPP

0 commit comments

Comments
 (0)