Skip to content

Commit eb8bc2c

Browse files
committed
Add implementation for the tlm ethernet
1 parent 0bbd49b commit eb8bc2c

File tree

11 files changed

+352
-25
lines changed

11 files changed

+352
-25
lines changed

modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ GRAY_DIR=../rgb2gray
2828
FILTER_DIR=../filter
2929
UNIFICATION_DIR=../unification
3030
COMPRESSION_DIR=../compression
31+
ETHERNET_DIR=../ethernetAMS
3132

32-
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src $(UNIFICATION_DIR)/src $(COMPRESSION_DIR)/src
33-
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include -I$(UNIFICATION_DIR)/include -I$(COMPRESSION_DIR)/include
33+
SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src $(UNIFICATION_DIR)/src $(COMPRESSION_DIR)/src $(ETHERNET_DIR)/src
34+
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include -I$(UNIFICATION_DIR)/include -I$(COMPRESSION_DIR)/include -I$(ETHERNET_DIR)/include
3435
endif # USING_TLM_TB_EN
3536

3637
ifdef INCLUDE_OPENCV
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
#ifndef ADDRESS_MAP_HPP
22
#define ADDRESS_MAP_HPP
33

4-
#define IMG_FILTER_KERNEL 0x00000003u
5-
#define SOBEL_INPUT_0 0x00000027u
6-
#define SOBEL_INPUT_1 0x0000002Fu
7-
#define SOBEL_OUTPUT 0x00000030u
8-
#define IMG_INPUT 0x00000034u
9-
#define IMG_INPROCESS_A 0x000E1034u
10-
#define IMG_INPROCESS_B 0x0012C034u
11-
#define IMG_INPROCESS_C 0x001C2034u
12-
#define IMG_COMPRESSED 0x00258034u
4+
#define IMG_FILTER_KERNEL 0x00000003u
5+
#define SOBEL_INPUT_0 0x00000027u
6+
#define SOBEL_INPUT_1 0x0000002Fu
7+
#define SOBEL_OUTPUT 0x00000030u
8+
#define IMG_INPUT 0x00000034u
9+
#define IMG_INPROCESS_A 0x000E1034u
10+
#define IMG_INPROCESS_B 0x0012C034u
11+
#define IMG_INPROCESS_C 0x001C2034u
12+
#define IMG_COMPRESSED 0x00258034u
13+
#define ETHERNET_DATA_WR 0x002A3034u
14+
#define ETHERNET_DATA_DONE 0x002A303Cu
15+
#define ETHERNET_CHECK_DONE 0x002A303Du
1316

14-
#define IMG_INPUT_SZ 0x000E1000u
15-
#define IMG_INPROCESS_A_SZ 0x0004B000u
16-
#define IMG_INPROCESS_B_SZ 0x00096000u
17-
#define IMG_INPROCESS_C_SZ 0x00096000u
18-
#define IMG_COMPRESSED_SZ 0x0004B000u
17+
#define IMG_INPUT_SZ 0x000E1000u
18+
#define IMG_INPROCESS_A_SZ 0x0004B000u
19+
#define IMG_INPROCESS_B_SZ 0x00096000u
20+
#define IMG_INPROCESS_C_SZ 0x00096000u
21+
#define IMG_COMPRESSED_SZ 0x0004B000u
1922

20-
#define MEM_START IMG_INPUT
21-
#define MEM_FINISH IMG_COMPRESSED + IMG_COMPRESSED_SZ
23+
#define MEM_START IMG_INPUT
24+
#define MEM_FINISH IMG_COMPRESSED + IMG_COMPRESSED_SZ - 1
2225

2326
#endif // ADDRESS_MAP_HPP

modules/ethernetAMS/src/ethernetEncoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ void ethernetEncoder::processing()
3636

3737
if (bitCount == 0) // Process new input only when bitCount is 4 (rightmost bit)
3838
{
39+
#ifndef USING_TLM_TB_EN
3940
std::cout << "Processing sample: " << sampleCount << ", received input: " << input << std::endl;
41+
#endif // USING_TLM_TB_EN
4042

4143
// 4B/5B Encoding
4244
if (encoding_map.find(input) != encoding_map.end())
@@ -68,9 +70,11 @@ void ethernetEncoder::processing()
6870
next_mlt3_out = currentLevel; // Store the computed value for the next cycle
6971
bitCount = (bitCount == 4) ? 0 : bitCount + 1; // Decrement bitCount from 4 to 0
7072

73+
#ifndef USING_TLM_TB_EN
7174
// Debugging output
7275
std::cout << "Sample: " << sampleCount << ", data_in: " << input
7376
<< ", code_out: " << lastCodeOut << ", mlt3_out: " << next_mlt3_out << std::endl;
77+
#endif // USING_TLM_TB_EN
7478

7579
sampleCount++;
7680
}

modules/ethernetAMS/src/packetGenerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ void packetGenerator::processing()
106106
n2_data_out = tmp_data_to_send.range(i * 4 + 3, i * 4);
107107
n2_data_out_valid = true;
108108
n2_data_valid = tmp_data_valid_to_send;
109+
#ifndef USING_TLM_TB_EN
109110
std::cout << "@" << sc_time_stamp() << " Inside generate_packet(): data to sent " << n2_data_out << std::endl;
111+
#endif // USING_TLM_TB_EN
110112
break;
111113
}
112114
else if ((bitCount == 0) && (tmp_data_out_valid == true))
@@ -123,7 +125,9 @@ void packetGenerator::processing()
123125
n1_data_out_valid = n2_data_out_valid;
124126
n1_data_valid = n2_data_valid;
125127
manual_update = true;
128+
#ifndef USING_TLM_TB_EN
126129
std::cout << "@" << sc_time_stamp() << " Inside generate_packet(): data to sent " << n2_data_out << std::endl;
130+
#endif // USING_TLM_TB_EN
127131
break;
128132
}
129133
}

modules/ethernetAMS/src/tb_ethernet_encoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef USING_TLM_TB_EN
2+
13
#ifndef TB_ETHERNET_ENCODER_CPP
24
#define TB_ETHERNET_ENCODER_CPP
35

@@ -136,3 +138,5 @@ int sc_main(int argc, char* argv[])
136138
}
137139

138140
#endif // TB_ETHERNET_ENCODER_CPP
141+
142+
#endif // USING_TLM_TB_EN

modules/router/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Include common Makefile
22
include ../Makefile
33

4+
LIBS+=-lsystemc-ams
5+
46
# Defining preprocessor directive for debug
57
ifdef IPS_DEBUG_EN
68
CFLAGS += -DIPS_DEBUG_EN
@@ -92,6 +94,11 @@ ifdef DISABLE_SOBEL_DEBUG
9294
LFLAGS += -DDISABLE_SOBEL_DEBUG
9395
endif # DISABLE_SOBEL_DEBUG
9496

97+
ifdef DISABLE_PACKET_GENERATOR_DEBUG
98+
CFLAGS += -DDISABLE_PACKET_GENERATOR_DEBUG
99+
LFLAGS += -DDISABLE_PACKET_GENERATOR_DEBUG
100+
endif # DISABLE_PACKET_GENERATOR_DEBUG
101+
95102
ifdef DISABLE_TB_DEBUG
96103
CFLAGS += -DDISABLE_TB_DEBUG
97104
LFLAGS += -DDISABLE_TB_DEBUG
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef PACKET_GENERATOR_TLM_HPP
2+
#define PACKET_GENERATOR_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 <systemc-ams.h>
14+
15+
#include "packetGenerator.h"
16+
#include "../src/img_target.cpp"
17+
18+
//Extended Unification TLM
19+
struct packetGenerator_tlm : public packetGenerator, public img_target
20+
{
21+
22+
packetGenerator_tlm(sc_module_name name, sca_core::sca_time sample_time) : packetGenerator((std::string(name) + "_AMS_HW_block").c_str(), sample_time), img_target((std::string(name) + "_target").c_str()), tmp_data_length(0) {
23+
#ifdef DISABLE_PACKET_GENERATOR_DEBUG
24+
this->use_prints = false;
25+
#endif // DISABLE_PACKET_GENERATOR_DEBUG
26+
checkprintenableimgtar(use_prints);
27+
}
28+
29+
//Override do_when_transaction functions
30+
virtual void do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
31+
virtual void do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address);
32+
33+
unsigned int tmp_data_length;
34+
unsigned char* tmp_data;
35+
};
36+
#endif // PACKET_GENERATOR_TLM_HPP

modules/router/run_all.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ case $1 in
55
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 all > output.log
66
;;
77
"save_log_no_dbg")
8-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_TB_DEBUG=1 all > output.log
8+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all > output.log
99
;;
1010
"print_all")
1111
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 print-all
1212
;;
1313
"compile")
14-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_TB_DEBUG=1 compile
14+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 compile
1515
;;
1616
"router_tb")
1717
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
@@ -20,6 +20,6 @@ case $1 in
2020
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 EDGE_DETECTOR_AT_EN=1 USING_TLM_ROUTER_TB_EN=1 USING_TLM_TB_EN=1 all > output.log
2121
;;
2222
*)
23-
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_TB_DEBUG=1 all
23+
make INCLUDE_OPENCV_PKG=1 RGB2GRAY_PV_EN=1 IPS_FILTER_LT_EN=1 EDGE_DETECTOR_AT_EN=1 IMG_UNIFICATE_PV_EN=1 IPS_JPG_PV_EN=1 USING_TLM_TB_EN=1 DISABLE_ROUTER_DEBUG=1 DISABLE_FILTER_DEBUG=1 DISABLE_MEM_DEBUG=1 DISABLE_RGB_DEBUG=1 DISABLE_SOBEL_DEBUG=1 DISABLE_PACKET_GENERATOR_DEBUG=1 DISABLE_TB_DEBUG=1 all
2424
;;
2525
esac

modules/router/src/img_router.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ struct img_router: sc_module
106106
#define IMG_FILTER_INITIATOR_ID 0
107107
#define IMG_SOBEL_INITIATOR_ID 1
108108
#define IMG_MEMORY_INITIATOR_ID 2
109-
#define INVALID_INITIATOR_ID 3
109+
#define IMG_ETHERNET_INITIATOR_ID 3
110+
#define INVALID_INITIATOR_ID 4
110111

111112
unsigned int decode_address (sc_dt::uint64 address)
112113
{
@@ -125,6 +126,15 @@ struct img_router: sc_module
125126
return IMG_SOBEL_INITIATOR_ID;
126127
}
127128

129+
case ETHERNET_DATA_WR:
130+
case ETHERNET_DATA_DONE:
131+
case ETHERNET_CHECK_DONE:
132+
{
133+
dbgmodprint(use_prints, "Decoded address %016llX corresponds to Ethernet module.", address);
134+
135+
return IMG_ETHERNET_INITIATOR_ID;
136+
}
137+
128138
// To/From Memory Valid addresses
129139
case MEM_START ... MEM_FINISH : {
130140
dbgmodprint(use_prints, "Decoded address %016llX corresponds to Memory.", address);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef PACKET_GENERATOR_TLM_CPP
2+
#define PACKET_GENERATOR_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 "packetGenerator_tlm.hpp"
14+
15+
#include "common_func.hpp"
16+
17+
#include "address_map.hpp"
18+
19+
void packetGenerator_tlm::do_when_read_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address){
20+
dbgimgtarmodprint(use_prints, "Calling do_when_read_transaction");
21+
22+
if ((address = ETHERNET_CHECK_DONE) && (data_length == 1))
23+
{
24+
if (packetGenerator::tmp_data_out_valid == true)
25+
{
26+
*data = 1;
27+
}
28+
else
29+
{
30+
*data = 0;
31+
}
32+
}
33+
}
34+
35+
void packetGenerator_tlm::do_when_write_transaction(unsigned char*& data, unsigned int data_length, sc_dt::uint64 address)
36+
{
37+
dbgimgtarmodprint(use_prints, "Calling do_when_write_transaction");
38+
39+
if ((address >= ETHERNET_DATA_WR) && (address + data_length - 1 < ETHERNET_DATA_DONE))
40+
{
41+
42+
if (tmp_data_length == 0)
43+
{
44+
tmp_data = new unsigned char[data_length];
45+
memcpy(tmp_data, data, sizeof(char) * data_length);
46+
}
47+
else
48+
{
49+
unsigned char* tmp_data_;
50+
tmp_data_ = tmp_data;
51+
tmp_data = new unsigned char[tmp_data_length + data_length];
52+
memcpy(tmp_data, tmp_data_, sizeof(char) * tmp_data_length);
53+
memcpy(tmp_data + tmp_data_length, data, data_length);
54+
55+
delete[] tmp_data_;
56+
}
57+
58+
dbgimgtarmodprint(use_prints, "Previous data_length %0d new data_length %0d", tmp_data_length, tmp_data_length + data_length);
59+
tmp_data_length = tmp_data_length + data_length;
60+
}
61+
else if ((address == ETHERNET_DATA_DONE) && (data_length == 1) && (*data == 1))
62+
{
63+
if (tmp_data_length == 0)
64+
{
65+
tmp_data = new unsigned char[1];
66+
*tmp_data = 0;
67+
tmp_data_length = 1;
68+
}
69+
70+
dbgimgtarmodprint(use_prints, "Preparing to send %0d bytes", tmp_data_length);
71+
72+
fill_data(tmp_data, (int)tmp_data_length);
73+
74+
delete[] tmp_data;
75+
tmp_data_length = 0;
76+
}
77+
}
78+
79+
#endif // PACKET_GENERATOR_TLM_CPP

0 commit comments

Comments
 (0)