Skip to content

Commit

Permalink
Merge pull request #25 from ErickOF/dev
Browse files Browse the repository at this point in the history
Project 2 integration
  • Loading branch information
ErickOF authored Jul 23, 2024
2 parents a83f376 + 094537e commit fe80709
Show file tree
Hide file tree
Showing 70 changed files with 4,670 additions and 174 deletions.
67 changes: 55 additions & 12 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,67 @@ on:
push:
branches:
- main
- dev
# - dev
pull_request:
branches:
- main
- dev
# - dev

jobs:
build:

runs-on: ubuntu-latest

env:
ACTIONS_STEP_DEBUG: true

steps:
- uses: actions/checkout@v4
- name: install dependencies
run: sudo apt-get install -y libopencv-dev
- name: compile compression
working-directory: ./modules/compression
run: make IPS_JPG_AT_EN=1 INCLUDE_OPENCV_PKG=1
- name: compile edge detector
working-directory: ./modules/edge-detector
run: make EDGE_DETECTOR_AT_EN=1 INCLUDE_OPENCV_PKG=1
- name: Checkout code
uses: actions/checkout@v4
#
# - name: Cache tools
# id: cache-deps
# uses: actions/cache@v2
# with:
# path: |
# /usr/local/systemc-3.0.0
# $HOME/systemc-3.0.0
# key: ${{ runner.os }}-build-${{ hashFiles('**/setup-dependencies.sh') }}
# restore-keys: |
# ${{ runner.os }}-build-
#
# - name: Install Dependencies
# if: steps.cache-deps.outputs.cache-hit != 'true'
# run: |
# set -x
# sudo apt-get install libopencv-dev
# cd $HOME
# rm -rf systemc-3.0.0
# git clone https://github.com/accellera-official/systemc.git systemc-3.0.0
# cd systemc-3.0.0
# ./config/bootstrap
# mkdir -p objdir
# cd objdir
# export CXX=g++
# ../configure --prefix=/usr/local/systemc-3.0.0
# mkdir -p examples/
# cp -r ../examples/* examples/
# make
# sudo make install
# export SYSTEMC_HOME=/usr/local/systemc-3.0.0
# export LD_LIBRARY_PATH=$SYSTEMC_HOME/lib-linux64
# - name: Compile Compression
# working-directory: ./modules/compression
# run: make IPS_JPG_AT_EN=1 INCLUDE_OPENCV_PKG=1
# - name: Compile Edge Detector
# working-directory: ./modules/edge-detector
# run: make EDGE_DETECTOR_AT_EN=1 INCLUDE_OPENCV_PKG=1
# - name: Compile Filter
# working-directory: ./modules/filter
# run: make IPS_FILTER_LT_EN=1 TEST_MODE_IMAGE=1 IPS_DUMP_EN=1 INCLUDE_OPENCV_PKG=1
# - name: Compile RGB2Gray
# working-directory: ./modules/rgb2gray
# run: make RGB2GRAY_PV_EN=1 INCLUDE_OPENCV_PKG=1
# - name: Compile Unification
# working-directory: ./modules/unification
# run: make IMG_UNIFICATE_PV_EN=1
#
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,6 @@ tools/datagen/src/imgs/*_sobel_*

# Ignore VCD files
*.vcd
test
test
*.zst
.vscode
40 changes: 37 additions & 3 deletions modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ TARGET?=test

# Compiler
CC=g++
CFLAGS=-Wall -I. -O3 -g -Wextra -Wunused-function
CFLAGS=-Wall -Wextra -fsanitize=address -fsanitize=undefined -I. -O3 -g

ifdef USE_CPP17
CFLAGS+=-std=c++17
endif
endif # USE_CPP17

# Target
LD=g++
LFLAGS=-Wall -I. -lm -g
LFLAGS=-Wall -fsanitize=address -fsanitize=undefined -I. -lm -g
LIBS=-lsystemc -lm

# Source directories
Expand All @@ -21,6 +21,17 @@ BINDIR=./
INCDIR=-I. -I./include -I$(SYSTEMC)/include -Ibasic_protocol -I$(SYSTEMC)/include/tlm_core/tlm_2
LIBDIR=-L. -L$(SYSTEMC)/lib-linux64

ifdef USING_TLM_TB_EN
EDGE_DIR=../edge-detector
GRAY_DIR=../rgb2gray
FILTER_DIR=../filter
UNIFICATION_DIR=../unification
COMPRESSION_DIR=../compression

SRCDIRS=$(SRCDIR) $(EDGE_DIR)/src $(GRAY_DIR)/src $(FILTER_DIR)/src $(UNIFICATION_DIR)/src $(COMPRESSION_DIR)/src
INCDIR+=-I$(EDGE_DIR)/include -I$(GRAY_DIR)/include -I$(FILTER_DIR)/include -I$(UNIFICATION_DIR)/include -I$(COMPRESSION_DIR)/include
endif # USING_TLM_TB_EN

ifdef INCLUDE_OPENCV
# Target
LIBS+=-lopencv_imgcodecs -lopencv_core -lopencv_highgui -lopencv_imgproc
Expand All @@ -35,15 +46,38 @@ LFLAGS += $(shell pkg-config --libs opencv4)
endif # INCLUDE_OPENCV_PKG
endif # INCLUDE_OPENCV

ifndef USING_TLM_TB_EN
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
else
SOURCES = $(wildcard *.cpp) $(foreach DIR, $(SRCDIRS), $(wildcard $(DIR)/*.cpp))
SOURCES_WITHOUT_PATH = $(notdir $(SOURCES))
INCLUDES := $(wildcard $(INCDIR)/*.hpp)
OBJECTS = $(SOURCES_WITHOUT_PATH:%.cpp=$(OBJDIR)/%.o)

VPATH = $(sort $(dir $(SOURCES)))
endif # USING_TLM_TB_EN

$(BINDIR)/$(TARGET): clean $(OBJECTS)
@$(LD) $(OBJECTS) $(LFLAGS) $(LIBS) $(LIBDIR) -o $@

ifndef USING_TLM_TB_EN
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
else
$(OBJECTS): $(OBJDIR)/%.o : %.cpp
@$(CC) $(CFLAGS) $(INCDIR) -c $< -o $@
endif # USING_TLM_TB_EN

valgrind:
valgrind --leak-check=full -s ./$(TARGET)

drmemory:
drmemory -- ./$(TARGET)

heaptrack:
heaptrack ./$(TARGET)

.PHONY: clean
clean:
Expand Down
27 changes: 27 additions & 0 deletions modules/adc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Include common Makefile
include ../Makefile

SRCDIR+=../../utils/src
INCDIR+=-I$(SYSTEMC_AMS_HOME)/include -I../utils/include
LIBDIR+=-L$(SYSTEMC_AMS_HOME)/lib-linux64
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

# Run the compiled file
run:
@./$(TARGET)

# Show waveform
waveform:
@gtkwave ips_adc.vcd
59 changes: 59 additions & 0 deletions modules/adc/include/adc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef IPS_ADC_MODEL_HPP
#define IPS_ADC_MODEL_HPP

#include <systemc-ams.h>
#include "vunit.hpp"


/**
* @brief Analog to Digital Converter module representation
* This module generates a N-bit digital signal based on the [Vmin, Vmax]
* voltage range
*
* @tparam BITS - the number of output bits of the digital code
* @tparam VMIN - lowest voltage value
* @tparam VMAX - highest voltage value
* @tparam VU - voltage unit based on VUnit
*/
template <unsigned int BITS = 8, int VMIN = 0, int VMAX = 5, VUnit VU = VUnit::v>
SCA_TDF_MODULE(adc)
{
protected:
// Min voltage value based on the voltage units
const double V_MIN = static_cast<double>(VMIN) / static_cast<double>(VU);
// Max voltage value based on the voltage units
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
// Max digital output code
const double MAX_DIG = static_cast<double>((1 << BITS) - 1);
public:
// Input analog voltage
sca_tdf::sca_in<double> in;
// Output digital code
sca_tdf::sca_out<sc_dt::sc_uint<BITS> > out;

/**
* @brief Construct a new adc object
*
*/
SCA_CTOR(adc) : in("in"), out("out") {
// Propagation time from input to output
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
}

/**
* @brief Convert the analog signal into digital signal
* The analog signal in a range from Vmin to Vmax is converted into a N-bit
* digital signal
*
*/
void processing()
{

double normalized_ana_in = (in.read() - V_MIN) / (V_MAX - V_MIN);
unsigned int dig_code = static_cast<unsigned int>(normalized_ana_in * MAX_DIG);

this->out.write(static_cast<sc_dt::sc_uint<BITS> >(dig_code));
}
};

#endif // IPS_ADC_MODEL_HPP
30 changes: 30 additions & 0 deletions modules/adc/include/seq_item_adc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef IPS_SEQ_ITEM_ADC_HPP
#define IPS_SEQ_ITEM_ADC_HPP

#include <cstdlib>


/**
* @brief This class is used to generate the analog signal for the test
*
* @tparam N
*/
template <unsigned int N>
SCA_TDF_MODULE(seq_item_adc)
{
public:
sca_tdf::sca_out<double> o_ana;
const int MAX_CODE = (1 << N);

SCA_CTOR(seq_item_adc)
{
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
}

void processing()
{
this->o_ana.write(static_cast<double>(rand() % MAX_CODE) / MAX_CODE);
}
};

#endif // IPS_SEQ_ITEM_ADC_HPP
43 changes: 43 additions & 0 deletions modules/adc/src/tb_adc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <systemc-ams.h>
#include "adc.hpp"
#include "seq_item_adc.hpp"

#define N 8


int sc_main(int, char*[])
{
// Max number of sequence items to test
const int MAX_SEQ_ITEMS = (1 << N) - 1;

// Signals to connect
sca_tdf::sca_signal<double> s_ana;
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig_out;

// DUT
adc<N> ips_adc("ips_adc");
ips_adc.in(s_ana);
ips_adc.out(s_dig_out);

// Sequence item generator for ADC
seq_item_adc<N> ips_seq_item_adc("ips_seq_item_adc");
ips_seq_item_adc.o_ana(s_ana);

// Dump waveform
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_adc");
sca_util::sca_trace(tf, s_ana, "in");
sca_util::sca_trace(tf, s_dig_out, "out");

// Start time
std::cout << "@" << sc_time_stamp() << std::endl;

// Run test
sc_start(MAX_SEQ_ITEMS * 0.1, SC_US);

// End time
std::cout << "@" << sc_time_stamp() << std::endl;

sca_util::sca_close_vcd_trace_file(tf);

return 0;
};
46 changes: 46 additions & 0 deletions modules/communication/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Include common Makefile
include ../Makefile

# 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 EDGE_DETECTOR_PV_EN
CFLAGS += -DEDGE_DETECTOR_PV_EN
LFLAGS += -DEDGE_DETECTOR_PV_EN
endif # EDGE_DETECTOR_PV_EN

# Defining preprocessor directive for using PV model
ifdef EDGE_DETECTOR_LT_EN
CFLAGS += -DEDGE_DETECTOR_LT_EN
LFLAGS += -DEDGE_DETECTOR_LT_EN
endif # EDGE_DETECTOR_LT_EN

# Defining preprocessor directive for using PV model
ifdef EDGE_DETECTOR_AT_EN
CFLAGS += -DEDGE_DETECTOR_AT_EN
LFLAGS += -DEDGE_DETECTOR_AT_EN
endif # EDGE_DETECTOR_AT_EN

# Run the compiled file
run:
@./test

# Show waveform
waveform:
@gtkwave edge_detector.vcd
Loading

0 comments on commit fe80709

Please sign in to comment.