Skip to content

Commit 08eda6f

Browse files
authored
Merge pull request #29 from ErickOF/dev
Integrating Ethernet AMS feature
2 parents cd22d5d + 9ddd598 commit 08eda6f

11 files changed

+853
-5
lines changed

modules/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SYSTEMC?=$(SYSTEMC_HOME)
22
TARGET?=test
3+
SYSTEMC_AMS?=$(SYSTEMC_AMS_HOME)
34

45
# Compiler
56
CC=g++
@@ -18,8 +19,8 @@ LIBS=-lsystemc -lm
1819
SRCDIR=src
1920
OBJDIR=obj
2021
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
22+
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2 -I$(SYSTEMC_AMS)/include/
23+
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64 -L$(SYSTEMC_AMS)/lib-linux64/
2324

2425
ifdef USING_TLM_TB_EN
2526
EDGE_DIR=../edge-detector

modules/ams/a.gtkw

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[*]
2+
[*] GTKWave Analyzer v3.3.104 (w)1999-2020 BSI
3+
[*] Tue Jul 23 09:49:40 2024
4+
[*]
5+
[dumpfile] "/mnt/c/Users/Erick/Documents/Git/MP6160-ImageProcessingSystem/modules/ams/ips_ams.vcd"
6+
[dumpfile_mtime] "Tue Jul 23 09:49:40 2024"
7+
[dumpfile_size] 135676078
8+
[savefile] "/mnt/c/Users/Erick/Documents/Git/MP6160-ImageProcessingSystem/modules/ams/a.gtkw"
9+
[timestart] 1118089100
10+
[size] 1908 999
11+
[pos] -1 -1
12+
*-16.066919 1118333188 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
13+
[sst_width] 214
14+
[signals_width] 224
15+
[sst_expanded] 1
16+
[sst_vpaned_height] 563
17+
@28
18+
SystemC_AMS.clk
19+
@24
20+
SystemC_AMS.v_count
21+
SystemC_AMS.h_count
22+
@28
23+
SystemC_AMS.vsync
24+
SystemC_AMS.hsync
25+
@22
26+
SystemC_AMS.tx_blue
27+
SystemC_AMS.tx_green
28+
SystemC_AMS.tx_red
29+
@24
30+
SystemC_AMS.ana_blue
31+
SystemC_AMS.ana_green
32+
SystemC_AMS.ana_red
33+
@22
34+
SystemC_AMS.rx_blue
35+
SystemC_AMS.rx_green
36+
SystemC_AMS.rx_red
37+
SystemC_AMS.to_mem_blue
38+
SystemC_AMS.to_mem_green
39+
SystemC_AMS.to_mem_red
40+
SystemC_AMS.address
41+
@28
42+
SystemC_AMS.we
43+
@22
44+
SystemC_AMS.rdata
45+
[pattern_trace] 1
46+
[pattern_trace] 0

modules/ethernetAMS/Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
LIBS+=-lsystemc-ams
5+
6+
# Defining preprocessor directive for debug
7+
ifdef IPS_DEBUG_EN
8+
CFLAGS += -DIPS_DEBUG_EN
9+
LFLAGS += -DIPS_DEBUG_EN
10+
endif # IPS_DEBUG_EN
11+
12+
# Defining preprocessor directive for dumping enable
13+
ifdef IPS_DUMP_EN
14+
CFLAGS += -DIPS_DUMP_EN
15+
LFLAGS += -DIPS_DUMP_EN
16+
endif # IPS_DUMP_EN
17+
18+
# Defining preprocessor directive for normalizing the resulting magnitude
19+
ifdef TEST_NORMALIZE_MAGNITUDE
20+
CFLAGS += -DTEST_NORMALIZE_MAGNITUDE
21+
LFLAGS += -DTEST_NORMALIZE_MAGNITUDE
22+
endif # TEST_NORMALIZE_MAGNITUDE
23+
24+
# Defining preprocessor directive for using PV model
25+
ifdef RGB2GRAY_PV_EN
26+
CFLAGS += -DRGB2GRAY_PV_EN
27+
LFLAGS += -DRGB2GRAY_PV_EN
28+
endif # RGB2GRAY_PV_EN
29+
30+
# all: encoder_testbench decoder_testbench
31+
32+
# encoder_testbench: tb_ethernet_encoder.o ethernetEncoder.o InputSignalGenerator.o
33+
# $(CXX) -o encoder_testbench tb_ethernet_encoder.o ethernetEncoder.o InputSignalGenerator.o $(CXXFLAGS) $(LDFLAGS)
34+
35+
# decoder_testbench: tb_ethernet_decoder.o ethernetEncoder.o ethernetDecoder.o InputSignalGenerator.o
36+
# $(CXX) -o decoder_testbench tb_ethernet_decoder.o ethernetEncoder.o ethernetDecoder.o InputSignalGenerator.o $(CXXFLAGS) $(LDFLAGS)
37+
38+
# tb_ethernet_encoder.o: $(SRC_DIR)/tb_ethernet_encoder.cpp
39+
# $(CXX) -c $(SRC_DIR)/tb_ethernet_encoder.cpp $(CXXFLAGS) -o tb_ethernet_encoder.o
40+
41+
# tb_ethernet_decoder.o: $(SRC_DIR)/tb_ethernet_decoder.cpp
42+
# $(CXX) -c $(SRC_DIR)/tb_ethernet_decoder.cpp $(CXXFLAGS) -o tb_ethernet_decoder.o
43+
44+
# ethernetEncoder.o: $(SRC_DIR)/ethernetEncoder.cpp
45+
# $(CXX) -c $(SRC_DIR)/ethernetEncoder.cpp $(CXXFLAGS) -o ethernetEncoder.o
46+
47+
# ethernetDecoder.o: $(SRC_DIR)/ethernetDecoder.cpp
48+
# $(CXX) -c $(SRC_DIR)/ethernetDecoder.cpp $(CXXFLAGS) -o ethernetDecoder.o
49+
50+
# InputSignalGenerator.o: $(SRC_DIR)/InputSignalGenerator.cpp
51+
# $(CXX) -c $(SRC_DIR)/InputSignalGenerator.cpp $(CXXFLAGS) -o InputSignalGenerator.o
52+
53+
# clean:
54+
# rm -f *.o encoder_testbench decoder_testbench
55+
56+
# Run the compiled file
57+
run:
58+
@./test
59+
60+
# Show waveform
61+
waveform:
62+
@gtkwave rgb2gray.vcd
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef ETHERNET_DECODER_H
2+
#define ETHERNET_DECODER_H
3+
4+
#include <systemc-ams.h>
5+
#include <map>
6+
#include <systemc.h>
7+
#include <deque>
8+
9+
SCA_TDF_MODULE(ethernetDecoder)
10+
{
11+
public:
12+
sca_tdf::sca_in<double> mlt3_in; // MLT-3 input signal
13+
sca_tdf::sca_out<sc_dt::sc_bv<4>> data_out; // 4-bit output
14+
15+
std::map<std::string, std::string> decoding_map;
16+
17+
void set_attributes();
18+
void initialize();
19+
void processing();
20+
21+
SCA_CTOR(ethernetDecoder)
22+
: mlt3_in("mlt3_in"), data_out("data_out"), previous_level(0), bit_count(0), sample_count(0), found_sequence(false),
23+
received_first_eight_decodes(false), data_length(0), decode_count(0)
24+
{
25+
}
26+
27+
private:
28+
int previous_level;
29+
int current_level;
30+
int bit_count;
31+
int sample_count;
32+
std::deque<char> bit_sequence;
33+
bool found_sequence;
34+
const std::string target_sequence = "10110";
35+
const std::string end_sequence = "10111";
36+
37+
bool check_sequence(const std::deque<char>& sequence);
38+
39+
// New members
40+
bool received_first_eight_decodes;
41+
int data_length;
42+
sc_dt::sc_bv<4> first_eight_decodes[8];
43+
int decode_count;
44+
};
45+
46+
#endif // ETHERNET_DECODER_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef ETHERNET_ENCODER_H
2+
#define ETHERNET_ENCODER_H
3+
4+
#include <systemc-ams.h>
5+
#include <map>
6+
#include <systemc.h>
7+
8+
SCA_TDF_MODULE(ethernetEncoder)
9+
{
10+
public:
11+
sca_tdf::sca_in<sc_dt::sc_bv<4>> data_in; // 4-bit input
12+
sca_tdf::sca_out<double> mlt3_out; // MLT-3 output signal
13+
sca_tdf::sca_in<bool> valid; // Valid signal
14+
15+
sc_dt::sc_bv<5> code_out; // Internal signal for 5-bit code
16+
int currentLevel = 0;
17+
int nextLevel = 1;
18+
int bitCount = 0;
19+
int sampleCount = 0;
20+
int lastMlt3Out = 0;
21+
std::string lastCodeOut = "";
22+
23+
double next_mlt3_out = 0; // Variable to store the next MLT-3 output value
24+
25+
std::map<std::string, std::string> encoding_map;
26+
27+
sca_core::sca_time sample_time;
28+
29+
void set_attributes();
30+
void initialize();
31+
void processing();
32+
33+
ethernetEncoder(sc_core::sc_module_name name, sca_core::sca_time sample_time)
34+
: sca_tdf::sca_module(name), data_in("data_in"), mlt3_out("mlt3_out"), valid("valid"), sample_time(sample_time)
35+
{
36+
}
37+
};
38+
39+
#endif // ETHERNET_ENCODER_H
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#ifndef PACKET_GENERATOR_H
2+
#define PACKET_GENERATOR_H
3+
4+
#include <systemc-ams.h>
5+
6+
SCA_TDF_MODULE(packetGenerator)
7+
{
8+
public:
9+
#define N 16
10+
11+
// Main results from block
12+
sca_tdf::sca_out<bool> data_out_valid;
13+
sca_tdf::sca_out<sc_dt::sc_bv<4>> data_out;
14+
15+
// Signals for tracing the values
16+
sca_tdf::sca_out<bool> tmp_data_out_valid_;
17+
18+
sca_tdf::sca_out<bool> n1_data_out_valid_;
19+
sca_tdf::sca_out<sc_dt::sc_bv<4>> n1_data_out_;
20+
sca_tdf::sca_out<sc_dt::sc_bv<N>> n1_data_valid_;
21+
22+
sca_tdf::sca_out<bool> n2_data_out_valid_;
23+
sca_tdf::sca_out<sc_dt::sc_bv<4>> n2_data_out_;
24+
sca_tdf::sca_out<sc_dt::sc_bv<N>> n2_data_valid_;
25+
26+
sca_tdf::sca_out<sc_dt::sc_bv<N * 4>> data_in_;
27+
sca_tdf::sca_out<sc_dt::sc_bv<N>> data_in_valid_;
28+
29+
sca_tdf::sca_out<sc_dt::sc_bv<N * 4>> data_to_send_;
30+
sca_tdf::sca_out<sc_dt::sc_bv<N>> data_valid_to_send_;
31+
32+
sca_tdf::sca_out<sc_dt::sc_int<4>> n1_sigBitCount_;
33+
sca_tdf::sca_out<sc_dt::sc_int<4>> n2_sigBitCount_;
34+
sca_tdf::sca_out<sc_dt::sc_int<4>> sigBitCount;
35+
36+
sca_tdf::sca_out<sc_dt::sc_int<32>> remaining_bytes_to_send;
37+
38+
// Internal values to do the logic
39+
bool tmp_data_out_valid;
40+
41+
bool n1_data_out_valid;
42+
sc_dt::sc_bv<4> n1_data_out;
43+
sc_dt::sc_bv<N> n1_data_valid;
44+
sc_dt::sc_int<4> n1_sigBitCount;
45+
46+
bool n2_data_out_valid;
47+
sc_dt::sc_bv<4> n2_data_out;
48+
sc_dt::sc_bv<N> n2_data_valid;
49+
sc_dt::sc_int<4> n2_sigBitCount;
50+
51+
bool preamble_in_process;
52+
53+
// Data to be sent, set in fill_data()
54+
sc_dt::sc_bv<N * 4> data_in;
55+
sc_dt::sc_bv<N> data_in_valid;
56+
57+
sc_dt::sc_bv<N * 4> data_to_send;
58+
sc_dt::sc_bv<N> data_valid_to_send;
59+
60+
int bitCount;
61+
int actual_data_length;
62+
int bytes_sent;
63+
64+
unsigned char preamble_data[8] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBA};
65+
unsigned char* local_data;
66+
67+
sca_core::sca_time sample_time;
68+
69+
// Constructor with sample time argument
70+
packetGenerator(sc_core::sc_module_name name, sca_core::sca_time sample_time)
71+
: sca_tdf::sca_module(name)
72+
{
73+
bitCount = 0;
74+
this->sample_time = sample_time;
75+
76+
tmp_data_out_valid = false;
77+
n1_data_out_valid = false;
78+
n2_data_out_valid = false;
79+
n2_sigBitCount = 0;
80+
81+
preamble_in_process = false;
82+
}
83+
84+
void fill_data(unsigned char* data, int packet_length);
85+
void create_pack_of_data(unsigned char* data, int packet_length);
86+
87+
void processing();
88+
void set_attributes();
89+
};
90+
91+
#endif // PACKET_GENERATOR_H

0 commit comments

Comments
 (0)