Skip to content

Commit 169886d

Browse files
authored
Merge pull request #21 from ErickOF/feature-vga
Adding VGA, ADC, DAC modules and testbench
2 parents b5b3e3d + 5ca3318 commit 169886d

File tree

12 files changed

+575
-0
lines changed

12 files changed

+575
-0
lines changed

modules/adc/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
SRCDIR+=../../utils/src
5+
INCDIR+=-I$(SYSTEMC_AMS_HOME)/include -I../utils/include
6+
LIBDIR+=-L$(SYSTEMC_AMS_HOME)/lib-linux64
7+
LIBS+=-lsystemc-ams
8+
9+
# Defining preprocessor directive for debug
10+
ifdef IPS_DEBUG_EN
11+
CFLAGS += -DIPS_DEBUG_EN
12+
LFLAGS += -DIPS_DEBUG_EN
13+
endif # IPS_DEBUG_EN
14+
15+
# Defining preprocessor directive for dumping enable
16+
ifdef IPS_DUMP_EN
17+
CFLAGS += -DIPS_DUMP_EN
18+
LFLAGS += -DIPS_DUMP_EN
19+
endif # IPS_DUMP_EN
20+
21+
# Run the compiled file
22+
run:
23+
@./$(TARGET)
24+
25+
# Show waveform
26+
waveform:
27+
@gtkwave ips_adc.vcd

modules/adc/include/adc.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef IPS_ADC_MODEL_HPP
2+
#define IPS_ADC_MODEL_HPP
3+
4+
#include <systemc-ams.h>
5+
#include "vunit.hpp"
6+
7+
8+
/**
9+
* @brief Analog to Digital Converter module representation
10+
* This module generates a N-bit digital signal based on the [Vmin, Vmax]
11+
* voltage range
12+
*
13+
* @tparam BITS - the number of output bits of the digital code
14+
* @tparam VMIN - lowest voltage value
15+
* @tparam VMAX - highest voltage value
16+
* @tparam VU - voltage unit based on VUnit
17+
*/
18+
template <unsigned int BITS = 8, int VMIN = 0, int VMAX = 5, VUnit VU = VUnit::v>
19+
SCA_TDF_MODULE(adc)
20+
{
21+
protected:
22+
// Min voltage value based on the voltage units
23+
const double V_MIN = static_cast<double>(VMIN) / static_cast<double>(VU);
24+
// Max voltage value based on the voltage units
25+
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
26+
// Max digital output code
27+
const double MAX_DIG = static_cast<double>((1 << BITS) - 1);
28+
public:
29+
// Input analog voltage
30+
sca_tdf::sca_in<double> in;
31+
// Output digital code
32+
sca_tdf::sca_out<sc_dt::sc_uint<BITS> > out;
33+
34+
/**
35+
* @brief Construct a new adc object
36+
*
37+
*/
38+
SCA_CTOR(adc) : in("in"), out("out") {
39+
// Propagation time from input to output
40+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
41+
}
42+
43+
/**
44+
* @brief Convert the analog signal into digital signal
45+
* The analog signal in a range from Vmin to Vmax is converted into a N-bit
46+
* digital signal
47+
*
48+
*/
49+
void processing()
50+
{
51+
52+
double normalized_ana_in = (in.read() - V_MIN) / (V_MAX - V_MIN);
53+
unsigned int dig_code = static_cast<unsigned int>(normalized_ana_in * MAX_DIG);
54+
55+
this->out.write(static_cast<sc_dt::sc_uint<BITS> >(dig_code));
56+
}
57+
};
58+
59+
#endif // IPS_ADC_MODEL_HPP

modules/adc/include/seq_item_adc.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef IPS_SEQ_ITEM_ADC_HPP
2+
#define IPS_SEQ_ITEM_ADC_HPP
3+
4+
#include <cstdlib>
5+
6+
7+
/**
8+
* @brief This class is used to generate the analog signal for the test
9+
*
10+
* @tparam N
11+
*/
12+
template <unsigned int N>
13+
SCA_TDF_MODULE(seq_item_adc)
14+
{
15+
public:
16+
sca_tdf::sca_out<double> o_ana;
17+
const int MAX_CODE = (1 << N);
18+
19+
SCA_CTOR(seq_item_adc)
20+
{
21+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
22+
}
23+
24+
void processing()
25+
{
26+
this->o_ana.write(static_cast<double>(rand() % MAX_CODE) / MAX_CODE);
27+
}
28+
};
29+
30+
#endif // IPS_SEQ_ITEM_ADC_HPP

modules/adc/src/tb_adc.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <systemc-ams.h>
2+
#include "adc.hpp"
3+
#include "seq_item_adc.hpp"
4+
5+
#define N 8
6+
7+
8+
int sc_main(int, char*[])
9+
{
10+
// Max number of sequence items to test
11+
const int MAX_SEQ_ITEMS = (1 << N) - 1;
12+
13+
// Signals to connect
14+
sca_tdf::sca_signal<double> s_ana;
15+
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig_out;
16+
17+
// DUT
18+
adc<N> ips_adc("ips_adc");
19+
ips_adc.in(s_ana);
20+
ips_adc.out(s_dig_out);
21+
22+
// Sequence item generator for ADC
23+
seq_item_adc<N> ips_seq_item_adc("ips_seq_item_adc");
24+
ips_seq_item_adc.o_ana(s_ana);
25+
26+
// Dump waveform
27+
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_adc");
28+
sca_util::sca_trace(tf, s_ana, "in");
29+
sca_util::sca_trace(tf, s_dig_out, "out");
30+
31+
// Start time
32+
std::cout << "@" << sc_time_stamp() << std::endl;
33+
34+
// Run test
35+
sc_start(MAX_SEQ_ITEMS * 0.1, SC_US);
36+
37+
// End time
38+
std::cout << "@" << sc_time_stamp() << std::endl;
39+
40+
sca_util::sca_close_vcd_trace_file(tf);
41+
42+
return 0;
43+
};

modules/dac/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
SRCDIR+=../../utils/src
5+
INCDIR+=-I$(SYSTEMC_AMS_HOME)/include -I../utils/include
6+
LIBDIR+=-L$(SYSTEMC_AMS_HOME)/lib-linux64
7+
LIBS+=-lsystemc-ams
8+
9+
# Defining preprocessor directive for debug
10+
ifdef IPS_DEBUG_EN
11+
CFLAGS += -DIPS_DEBUG_EN
12+
LFLAGS += -DIPS_DEBUG_EN
13+
endif # IPS_DEBUG_EN
14+
15+
# Defining preprocessor directive for dumping enable
16+
ifdef IPS_DUMP_EN
17+
CFLAGS += -DIPS_DUMP_EN
18+
LFLAGS += -DIPS_DUMP_EN
19+
endif # IPS_DUMP_EN
20+
21+
# Run the compiled file
22+
run:
23+
@./$(TARGET)
24+
25+
# Show waveform
26+
waveform:
27+
@gtkwave ips_dac.vcd

modules/dac/include/dac.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef IPS_DAC_MODEL_HPP
2+
#define IPS_DAC_MODEL_HPP
3+
4+
#include <systemc-ams.h>
5+
#include "vunit.hpp"
6+
7+
8+
/**
9+
* @brief Digital to Analog Converter module representation
10+
* This module generates an analog signal based on the [Vmin, Vmax] voltage
11+
* range
12+
*
13+
* @tparam BITS - the number of output bits of the digital code
14+
* @tparam VMIN - lowest voltage value
15+
* @tparam VMAX - highest voltage value
16+
* @tparam VU - voltage unit based on VUnit
17+
*/
18+
template <unsigned int BITS = 8, int VMIN = 0, int VMAX = 5, VUnit VU = VUnit::v>
19+
SCA_TDF_MODULE(dac)
20+
{
21+
protected:
22+
// Min voltage value based on the voltage units
23+
const double V_MIN = static_cast<double>(VMIN) / static_cast<double>(VU);
24+
// Max voltage value based on the voltage units
25+
const double V_MAX = static_cast<double>(VMAX) / static_cast<double>(VU);
26+
// Max digital output code
27+
const double MAX_DIG = static_cast<double>((1 << BITS) - 1);
28+
public:
29+
// Input digital code
30+
sca_tdf::sca_in<sc_dt::sc_uint<BITS> > in;
31+
// Output analog voltage
32+
sca_tdf::sca_out<double> out;
33+
34+
/**
35+
* @brief Construct a new dac object
36+
*
37+
*/
38+
SCA_CTOR(dac) : in("in"), out("out")
39+
{
40+
// Propagation time from input to output
41+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
42+
}
43+
44+
/**
45+
* @brief Convert the digital signal into analog signal
46+
* The N-bit digital code is converted into an analog signal in a voltage
47+
* range from Vmin to Vmax
48+
*
49+
*/
50+
void processing()
51+
{
52+
double dig_in = static_cast<double>(this->in.read().to_uint());
53+
double ana_out = V_MIN + (dig_in / MAX_DIG) * (V_MAX - V_MIN);
54+
55+
this->out.write(ana_out);
56+
}
57+
};
58+
59+
#endif // IPS_DAC_MODEL_HPP

modules/dac/include/seq_item_dac.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef IPS_SEQ_ITEM_DAC_HPP
2+
#define IPS_SEQ_ITEM_DAC_HPP
3+
4+
#include <cstdlib>
5+
6+
7+
/**
8+
* @brief This class is used to generate the digital code for the test
9+
*
10+
* @tparam N
11+
*/
12+
template <unsigned int N>
13+
SCA_TDF_MODULE(seq_item_dac)
14+
{
15+
public:
16+
sca_tdf::sca_out<sc_dt::sc_uint<N> > o_dig;
17+
18+
SCA_CTOR(seq_item_dac)
19+
{
20+
set_timestep(sca_core::sca_time(0.1, sc_core::SC_US));
21+
}
22+
23+
void processing()
24+
{
25+
this->o_dig.write(static_cast<sc_dt::sc_uint<N> >(rand() % (1 << N)));
26+
}
27+
};
28+
29+
#endif // IPS_SEQ_ITEM_DAC_HPP

modules/dac/src/tb_dac.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <systemc-ams.h>
2+
#include "dac.hpp"
3+
#include "seq_item_dac.hpp"
4+
5+
#define N 8
6+
7+
8+
int sc_main(int, char*[])
9+
{
10+
// Max number of sequence items to test
11+
const int MAX_SEQ_ITEMS = (1 << N) - 1;
12+
13+
// Signals to connect
14+
sca_tdf::sca_signal<sc_dt::sc_uint<N> > s_dig;
15+
sca_tdf::sca_signal<double> s_ana_out;
16+
17+
// DUT
18+
dac<N> ips_dac("ips_dac");
19+
ips_dac.in(s_dig);
20+
ips_dac.out(s_ana_out);
21+
22+
// Sequence item generator for DAC
23+
seq_item_dac<N> ips_seq_item_dac("ips_seq_item_dac");
24+
ips_seq_item_dac.o_dig(s_dig);
25+
26+
// Dump waveform
27+
sca_util::sca_trace_file* tf = sca_util::sca_create_vcd_trace_file("ips_dac");
28+
sca_util::sca_trace(tf, s_dig, "in");
29+
sca_util::sca_trace(tf, s_ana_out, "out");
30+
31+
// Start time
32+
std::cout << "@" << sc_time_stamp() << std::endl;
33+
34+
// Run test
35+
sc_start(MAX_SEQ_ITEMS * 0.1, SC_US);
36+
37+
// End time
38+
std::cout << "@" << sc_time_stamp() << std::endl;
39+
40+
sca_util::sca_close_vcd_trace_file(tf);
41+
42+
return 0;
43+
};

modules/utils/include/vunit.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef IPS_VUnit_HPP
2+
#define IPS_VUnit_HPP
3+
4+
5+
/**
6+
* @brief Presents the voltage units
7+
*
8+
*/
9+
enum class VUnit {
10+
// Normal volts
11+
v = 1,
12+
// Milivolts
13+
mv = 1000,
14+
// Microvolts
15+
uv = 1000000,
16+
};
17+
18+
#endif // IPS_VUnit_HPP

modules/vga/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Include common Makefile
2+
include ../Makefile
3+
4+
INCDIR+=-I$(SYSTEMC_AMS_HOME)/include
5+
LIBDIR+=-L$(SYSTEMC_AMS_HOME)/lib-linux64
6+
LIBS+=-lsystemc-ams
7+
8+
# Defining preprocessor directive for debug
9+
ifdef IPS_DEBUG_EN
10+
CFLAGS += -DIPS_DEBUG_EN
11+
LFLAGS += -DIPS_DEBUG_EN
12+
endif # IPS_DEBUG_EN
13+
14+
# Defining preprocessor directive for dumping enable
15+
ifdef IPS_DUMP_EN
16+
CFLAGS += -DIPS_DUMP_EN
17+
LFLAGS += -DIPS_DUMP_EN
18+
endif # IPS_DUMP_EN
19+
20+
# Run the compiled file
21+
run:
22+
@./$(TARGET)
23+
24+
# Show waveform
25+
waveform:
26+
@gtkwave ips_vga.vcd

0 commit comments

Comments
 (0)