Skip to content

Commit

Permalink
Merge pull request #29 from ErickOF/dev
Browse files Browse the repository at this point in the history
Integrating Ethernet AMS feature
  • Loading branch information
ErickOF authored Jul 23, 2024
2 parents cd22d5d + 9ddd598 commit 08eda6f
Show file tree
Hide file tree
Showing 11 changed files with 853 additions and 5 deletions.
5 changes: 3 additions & 2 deletions modules/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SYSTEMC?=$(SYSTEMC_HOME)
TARGET?=test
SYSTEMC_AMS?=$(SYSTEMC_AMS_HOME)

# Compiler
CC=g++
Expand All @@ -18,8 +19,8 @@ LIBS=-lsystemc -lm
SRCDIR=src
OBJDIR=obj
BINDIR=./
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2 -I$(SYSTEMC_AMS)/include/
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64 -L$(SYSTEMC_AMS)/lib-linux64/

ifdef USING_TLM_TB_EN
EDGE_DIR=../edge-detector
Expand Down
46 changes: 46 additions & 0 deletions modules/ams/a.gtkw
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[*]
[*] GTKWave Analyzer v3.3.104 (w)1999-2020 BSI
[*] Tue Jul 23 09:49:40 2024
[*]
[dumpfile] "/mnt/c/Users/Erick/Documents/Git/MP6160-ImageProcessingSystem/modules/ams/ips_ams.vcd"
[dumpfile_mtime] "Tue Jul 23 09:49:40 2024"
[dumpfile_size] 135676078
[savefile] "/mnt/c/Users/Erick/Documents/Git/MP6160-ImageProcessingSystem/modules/ams/a.gtkw"
[timestart] 1118089100
[size] 1908 999
[pos] -1 -1
*-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
[sst_width] 214
[signals_width] 224
[sst_expanded] 1
[sst_vpaned_height] 563
@28
SystemC_AMS.clk
@24
SystemC_AMS.v_count
SystemC_AMS.h_count
@28
SystemC_AMS.vsync
SystemC_AMS.hsync
@22
SystemC_AMS.tx_blue
SystemC_AMS.tx_green
SystemC_AMS.tx_red
@24
SystemC_AMS.ana_blue
SystemC_AMS.ana_green
SystemC_AMS.ana_red
@22
SystemC_AMS.rx_blue
SystemC_AMS.rx_green
SystemC_AMS.rx_red
SystemC_AMS.to_mem_blue
SystemC_AMS.to_mem_green
SystemC_AMS.to_mem_red
SystemC_AMS.address
@28
SystemC_AMS.we
@22
SystemC_AMS.rdata
[pattern_trace] 1
[pattern_trace] 0
62 changes: 62 additions & 0 deletions modules/ethernetAMS/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Include common Makefile
include ../Makefile

LIBS+=-lsystemc-ams

# Defining preprocessor directive for debug
ifdef IPS_DEBUG_EN
CFLAGS += -DIPS_DEBUG_EN
LFLAGS += -DIPS_DEBUG_EN
endif # IPS_DEBUG_EN

# Defining preprocessor directive for dumping enable
ifdef IPS_DUMP_EN
CFLAGS += -DIPS_DUMP_EN
LFLAGS += -DIPS_DUMP_EN
endif # IPS_DUMP_EN

# Defining preprocessor directive for normalizing the resulting magnitude
ifdef TEST_NORMALIZE_MAGNITUDE
CFLAGS += -DTEST_NORMALIZE_MAGNITUDE
LFLAGS += -DTEST_NORMALIZE_MAGNITUDE
endif # TEST_NORMALIZE_MAGNITUDE

# Defining preprocessor directive for using PV model
ifdef RGB2GRAY_PV_EN
CFLAGS += -DRGB2GRAY_PV_EN
LFLAGS += -DRGB2GRAY_PV_EN
endif # RGB2GRAY_PV_EN

# all: encoder_testbench decoder_testbench

# encoder_testbench: tb_ethernet_encoder.o ethernetEncoder.o InputSignalGenerator.o
# $(CXX) -o encoder_testbench tb_ethernet_encoder.o ethernetEncoder.o InputSignalGenerator.o $(CXXFLAGS) $(LDFLAGS)

# decoder_testbench: tb_ethernet_decoder.o ethernetEncoder.o ethernetDecoder.o InputSignalGenerator.o
# $(CXX) -o decoder_testbench tb_ethernet_decoder.o ethernetEncoder.o ethernetDecoder.o InputSignalGenerator.o $(CXXFLAGS) $(LDFLAGS)

# tb_ethernet_encoder.o: $(SRC_DIR)/tb_ethernet_encoder.cpp
# $(CXX) -c $(SRC_DIR)/tb_ethernet_encoder.cpp $(CXXFLAGS) -o tb_ethernet_encoder.o

# tb_ethernet_decoder.o: $(SRC_DIR)/tb_ethernet_decoder.cpp
# $(CXX) -c $(SRC_DIR)/tb_ethernet_decoder.cpp $(CXXFLAGS) -o tb_ethernet_decoder.o

# ethernetEncoder.o: $(SRC_DIR)/ethernetEncoder.cpp
# $(CXX) -c $(SRC_DIR)/ethernetEncoder.cpp $(CXXFLAGS) -o ethernetEncoder.o

# ethernetDecoder.o: $(SRC_DIR)/ethernetDecoder.cpp
# $(CXX) -c $(SRC_DIR)/ethernetDecoder.cpp $(CXXFLAGS) -o ethernetDecoder.o

# InputSignalGenerator.o: $(SRC_DIR)/InputSignalGenerator.cpp
# $(CXX) -c $(SRC_DIR)/InputSignalGenerator.cpp $(CXXFLAGS) -o InputSignalGenerator.o

# clean:
# rm -f *.o encoder_testbench decoder_testbench

# Run the compiled file
run:
@./test

# Show waveform
waveform:
@gtkwave rgb2gray.vcd
46 changes: 46 additions & 0 deletions modules/ethernetAMS/include/ethernetDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef ETHERNET_DECODER_H
#define ETHERNET_DECODER_H

#include <systemc-ams.h>
#include <map>
#include <systemc.h>
#include <deque>

SCA_TDF_MODULE(ethernetDecoder)
{
public:
sca_tdf::sca_in<double> mlt3_in; // MLT-3 input signal
sca_tdf::sca_out<sc_dt::sc_bv<4>> data_out; // 4-bit output

std::map<std::string, std::string> decoding_map;

void set_attributes();
void initialize();
void processing();

SCA_CTOR(ethernetDecoder)
: mlt3_in("mlt3_in"), data_out("data_out"), previous_level(0), bit_count(0), sample_count(0), found_sequence(false),
received_first_eight_decodes(false), data_length(0), decode_count(0)
{
}

private:
int previous_level;
int current_level;
int bit_count;
int sample_count;
std::deque<char> bit_sequence;
bool found_sequence;
const std::string target_sequence = "10110";
const std::string end_sequence = "10111";

bool check_sequence(const std::deque<char>& sequence);

// New members
bool received_first_eight_decodes;
int data_length;
sc_dt::sc_bv<4> first_eight_decodes[8];
int decode_count;
};

#endif // ETHERNET_DECODER_H
39 changes: 39 additions & 0 deletions modules/ethernetAMS/include/ethernetEncoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef ETHERNET_ENCODER_H
#define ETHERNET_ENCODER_H

#include <systemc-ams.h>
#include <map>
#include <systemc.h>

SCA_TDF_MODULE(ethernetEncoder)
{
public:
sca_tdf::sca_in<sc_dt::sc_bv<4>> data_in; // 4-bit input
sca_tdf::sca_out<double> mlt3_out; // MLT-3 output signal
sca_tdf::sca_in<bool> valid; // Valid signal

sc_dt::sc_bv<5> code_out; // Internal signal for 5-bit code
int currentLevel = 0;
int nextLevel = 1;
int bitCount = 0;
int sampleCount = 0;
int lastMlt3Out = 0;
std::string lastCodeOut = "";

double next_mlt3_out = 0; // Variable to store the next MLT-3 output value

std::map<std::string, std::string> encoding_map;

sca_core::sca_time sample_time;

void set_attributes();
void initialize();
void processing();

ethernetEncoder(sc_core::sc_module_name name, sca_core::sca_time sample_time)
: sca_tdf::sca_module(name), data_in("data_in"), mlt3_out("mlt3_out"), valid("valid"), sample_time(sample_time)
{
}
};

#endif // ETHERNET_ENCODER_H
91 changes: 91 additions & 0 deletions modules/ethernetAMS/include/packetGenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#ifndef PACKET_GENERATOR_H
#define PACKET_GENERATOR_H

#include <systemc-ams.h>

SCA_TDF_MODULE(packetGenerator)
{
public:
#define N 16

// Main results from block
sca_tdf::sca_out<bool> data_out_valid;
sca_tdf::sca_out<sc_dt::sc_bv<4>> data_out;

// Signals for tracing the values
sca_tdf::sca_out<bool> tmp_data_out_valid_;

sca_tdf::sca_out<bool> n1_data_out_valid_;
sca_tdf::sca_out<sc_dt::sc_bv<4>> n1_data_out_;
sca_tdf::sca_out<sc_dt::sc_bv<N>> n1_data_valid_;

sca_tdf::sca_out<bool> n2_data_out_valid_;
sca_tdf::sca_out<sc_dt::sc_bv<4>> n2_data_out_;
sca_tdf::sca_out<sc_dt::sc_bv<N>> n2_data_valid_;

sca_tdf::sca_out<sc_dt::sc_bv<N * 4>> data_in_;
sca_tdf::sca_out<sc_dt::sc_bv<N>> data_in_valid_;

sca_tdf::sca_out<sc_dt::sc_bv<N * 4>> data_to_send_;
sca_tdf::sca_out<sc_dt::sc_bv<N>> data_valid_to_send_;

sca_tdf::sca_out<sc_dt::sc_int<4>> n1_sigBitCount_;
sca_tdf::sca_out<sc_dt::sc_int<4>> n2_sigBitCount_;
sca_tdf::sca_out<sc_dt::sc_int<4>> sigBitCount;

sca_tdf::sca_out<sc_dt::sc_int<32>> remaining_bytes_to_send;

// Internal values to do the logic
bool tmp_data_out_valid;

bool n1_data_out_valid;
sc_dt::sc_bv<4> n1_data_out;
sc_dt::sc_bv<N> n1_data_valid;
sc_dt::sc_int<4> n1_sigBitCount;

bool n2_data_out_valid;
sc_dt::sc_bv<4> n2_data_out;
sc_dt::sc_bv<N> n2_data_valid;
sc_dt::sc_int<4> n2_sigBitCount;

bool preamble_in_process;

// Data to be sent, set in fill_data()
sc_dt::sc_bv<N * 4> data_in;
sc_dt::sc_bv<N> data_in_valid;

sc_dt::sc_bv<N * 4> data_to_send;
sc_dt::sc_bv<N> data_valid_to_send;

int bitCount;
int actual_data_length;
int bytes_sent;

unsigned char preamble_data[8] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xBA};
unsigned char* local_data;

sca_core::sca_time sample_time;

// Constructor with sample time argument
packetGenerator(sc_core::sc_module_name name, sca_core::sca_time sample_time)
: sca_tdf::sca_module(name)
{
bitCount = 0;
this->sample_time = sample_time;

tmp_data_out_valid = false;
n1_data_out_valid = false;
n2_data_out_valid = false;
n2_sigBitCount = 0;

preamble_in_process = false;
}

void fill_data(unsigned char* data, int packet_length);
void create_pack_of_data(unsigned char* data, int packet_length);

void processing();
void set_attributes();
};

#endif // PACKET_GENERATOR_H
Loading

0 comments on commit 08eda6f

Please sign in to comment.