Adapted simple_system to demonstrate use of tlm_target by reference and

by ingeritance
This commit is contained in:
Eyck Jentzsch 2017-09-19 17:02:23 +02:00
parent 7c32c6aab2
commit 792a40d3f1
13 changed files with 104 additions and 46 deletions

View File

@ -163,7 +163,6 @@
<buildTargets>
<target name="all" path="build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -171,12 +170,19 @@
</target>
<target name="all VERBOSE=1" path="build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all VERBOSE=1</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="build" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

View File

@ -26,7 +26,6 @@ add_executable (simple_system
sc_main.cpp
)
# Link the executable to the sc_components library. Since the sc_components library has
# public include directories we will use those link directories when building
# simple_system

View File

@ -19,18 +19,16 @@
#include <util/bit_field.h>
#include <sysc/register.h>
#include <sysc/tlmtarget.h>
#include <sysc/utilities.h>
#include <sysc/tlm_target.h>
namespace sysc {
template<unsigned BUSWIDTH=32>
class gpio_regs :
public sc_core::sc_module,
public sysc::tlm_target<BUSWIDTH>,
public sysc::resetable
{
protected:
{
public:
// storage declarations
uint32_t r_value;
@ -86,17 +84,19 @@ protected:
sysc::sc_register<uint32_t> out_xor;
gpio_regs(sc_core::sc_module_name nm);
protected:
sc_core::sc_time clk;
template<unsigned BUSWIDTH=32>
void registerResources(sysc::tlm_target<BUSWIDTH>& target);
};
}
//////////////////////////////////////////////////////////////////////////////
// member functions
//////////////////////////////////////////////////////////////////////////////
template<unsigned BUSWIDTH>
gpio_regs<BUSWIDTH>::gpio_regs(sc_core::sc_module_name nm)
inline sysc::gpio_regs::gpio_regs(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
, sysc::tlm_target<BUSWIDTH>(clk)
, NAMED(value, r_value, 0, *this)
, NAMED(input_en, r_input_en, 0, *this)
, NAMED(output_en, r_output_en, 0, *this)
@ -115,24 +115,27 @@ gpio_regs<BUSWIDTH>::gpio_regs(sc_core::sc_module_name nm)
, NAMED(iof_sel, r_iof_sel, 0, *this)
, NAMED(out_xor, r_out_xor, 0, *this)
{
this->socket_map.addEntry(&value, 0x0UL, 0x4UL);
this->socket_map.addEntry(&input_en, 0x4UL, 0x4UL);
this->socket_map.addEntry(&output_en, 0x8UL, 0x4UL);
this->socket_map.addEntry(&port, 0xcUL, 0x4UL);
this->socket_map.addEntry(&pue, 0x10UL, 0x4UL);
this->socket_map.addEntry(&ds, 0x14UL, 0x4UL);
this->socket_map.addEntry(&rise_ie, 0x18UL, 0x4UL);
this->socket_map.addEntry(&rise_ip, 0x1cUL, 0x4UL);
this->socket_map.addEntry(&fall_ie, 0x20UL, 0x4UL);
this->socket_map.addEntry(&fall_ip, 0x24UL, 0x4UL);
this->socket_map.addEntry(&high_ie, 0x28UL, 0x4UL);
this->socket_map.addEntry(&high_ip, 0x2cUL, 0x4UL);
this->socket_map.addEntry(&low_ie, 0x30UL, 0x4UL);
this->socket_map.addEntry(&low_ip, 0x34UL, 0x4UL);
this->socket_map.addEntry(&iof_en, 0x38UL, 0x4UL);
this->socket_map.addEntry(&iof_sel, 0x3cUL, 0x4UL);
this->socket_map.addEntry(&out_xor, 0x40UL, 0x4UL);
}
template<unsigned BUSWIDTH>
inline void sysc::gpio_regs::registerResources(sysc::tlm_target<BUSWIDTH>& target) {
target.addResource(value, 0x0UL, 0x4UL);
target.addResource(input_en, 0x4UL, 0x4UL);
target.addResource(output_en, 0x8UL, 0x4UL);
target.addResource(port, 0xcUL, 0x4UL);
target.addResource(pue, 0x10UL, 0x4UL);
target.addResource(ds, 0x14UL, 0x4UL);
target.addResource(rise_ie, 0x18UL, 0x4UL);
target.addResource(rise_ip, 0x1cUL, 0x4UL);
target.addResource(fall_ie, 0x20UL, 0x4UL);
target.addResource(fall_ip, 0x24UL, 0x4UL);
target.addResource(high_ie, 0x28UL, 0x4UL);
target.addResource(high_ip, 0x2cUL, 0x4UL);
target.addResource(low_ie, 0x30UL, 0x4UL);
target.addResource(low_ip, 0x34UL, 0x4UL);
target.addResource(iof_en, 0x38UL, 0x4UL);
target.addResource(iof_sel, 0x3cUL, 0x4UL);
target.addResource(out_xor, 0x40UL, 0x4UL);
}
#endif // _GPIO_REGS_H_

View File

@ -19,8 +19,8 @@
#include <util/bit_field.h>
#include <sysc/register.h>
#include <sysc/tlmtarget.h>
#include <sysc/utilities.h>
#include <sysc/tlm_target.h>
namespace sysc {

View File

@ -19,8 +19,8 @@
#include <util/bit_field.h>
#include <sysc/register.h>
#include <sysc/tlmtarget.h>
#include <sysc/utilities.h>
#include <sysc/tlm_target.h>
namespace sysc {

View File

@ -15,22 +15,35 @@
////////////////////////////////////////////////////////////////////////////////
#include "gpio.h"
#include "gen/gpio_regs.h"
#include "sysc/utilities.h"
namespace sysc {
gpio::gpio(sc_core::sc_module_name nm)
: gpio_regs<>(nm)
: sc_core::sc_module(nm)
, tlm_target<>(clk)
, NAMED(clk_i)
, NAMEDD(gpio_regs, regs)
{
regs->registerResources(*this);
SC_METHOD(clock_cb);
sensitive<<clk_i;
SC_METHOD(reset_cb);
sensitive<<rst_i;
}
gpio::~gpio() {
}
void gpio::clock_cb() {
this->clk=clk_i.read();
}
void gpio::reset_cb() {
if(rst_i.read())
regs->reset_start();
else
regs->reset_stop();
}
} /* namespace sysc */

View File

@ -17,18 +17,24 @@
#ifndef _GPIO_H_
#define _GPIO_H_
#include "gen/gpio_regs.h"
#include <sysc/tlm_target.h>
namespace sysc {
class gpio: public gpio_regs<> {
class gpio_regs;
class gpio: public sc_core::sc_module, public tlm_target<> {
public:
SC_HAS_PROCESS(gpio);
sc_core::sc_in<sc_core::sc_time> clk_i;
sc_core::sc_in<bool> rst_i;
gpio(sc_core::sc_module_name nm);
virtual ~gpio();
protected:
void clock_cb();
void reset_cb();
sc_core::sc_time clk;
std::unique_ptr<gpio_regs> regs;
};
} /* namespace sysc */

View File

@ -22,8 +22,11 @@
#include "simple_system.h"
#include <sysc/tracer.h>
#include "sysc/scv_tr_db.h"
#include <sysc/scv_tr_db.h>
#include <sr_report/sr_report.h>
#include <boost/program_options.hpp>
#include <sysc/report.h>
#include <sstream>
using namespace sysc;
namespace po = boost::program_options;
@ -35,6 +38,8 @@ const size_t ERROR_UNHANDLED_EXCEPTION = 2;
} // namespace
int sc_main(int argc, char* argv[]){
// sc_report_handler::set_handler(my_report_handler);
sysc::Logger::reporting_level()=log::DEBUG;
///////////////////////////////////////////////////////////////////////////
// CLI argument parsing
///////////////////////////////////////////////////////////////////////////
@ -66,11 +71,13 @@ int sc_main(int argc, char* argv[]){
// instantiate top level
///////////////////////////////////////////////////////////////////////////
simple_system i_simple_system("i_simple_system");
//sr_report_handler::add_sc_object_to_filter(&i_simple_system.i_master, sc_core::SC_WARNING, sc_core::SC_MEDIUM);
///////////////////////////////////////////////////////////////////////////
// run simulation
///////////////////////////////////////////////////////////////////////////
sc_start(sc_core::sc_time(100, sc_core::SC_NS));
if(!sc_end_of_simulation_invoked()) sc_stop();
return 0;
}

View File

@ -32,6 +32,7 @@ simple_system::simple_system(sc_core::sc_module_name nm)
, NAMED(i_spi)
, NAMED(i_gpio)
, NAMED(s_clk)
, NAMED(s_rst)
{
i_master.intor(i_router.target[0]);
size_t i=0;
@ -43,10 +44,17 @@ simple_system::simple_system(sc_core::sc_module_name nm)
i_uart.clk_i(s_clk);
i_spi.clk_i(s_clk);
i_gpio.clk_i(s_clk);
s_clk.write(sc_core::sc_time(10, sc_core::SC_NS));
s_clk.write(10_ns);
i_gpio.rst_i(s_rst);
i_master.rst_i(s_rst);
SC_THREAD(gen_reset);
}
simple_system::~simple_system() {
void simple_system::gen_reset() {
s_rst=true;
wait(10_ns);
s_rst=false;
}
} /* namespace sysc */

View File

@ -37,15 +37,19 @@ namespace sysc {
class simple_system: public sc_core::sc_module {
public:
SC_HAS_PROCESS(simple_system);
test_initiator i_master;
router<> i_router;
uart i_uart;
spi i_spi;
gpio i_gpio;
sc_core::sc_signal<sc_core::sc_time> s_clk;
sc_core::sc_signal<bool> s_rst;
simple_system(sc_core::sc_module_name nm);
virtual ~simple_system();
protected:
void gen_reset();
#include "gen/e300_plat_t.h"
};

View File

@ -21,6 +21,7 @@
*/
#include "test_initiator.h"
#include <sr_report/sr_report.h>
#include <sysc/utilities.h>
#include <array>
@ -29,15 +30,19 @@ namespace sysc {
test_initiator::test_initiator(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
, NAMED(intor)
, NAMED(rst_i)
{
SC_THREAD(run);
}
void test_initiator::run() {
wait(10, sc_core::SC_NS);
if(rst_i.read()==false) wait(rst_i.posedge_event());
wait(rst_i.negedge_event());
wait(10_ns);
tlm::tlm_generic_payload gp;
std::array<uint8_t, 4> data;
srInfo()("group", "comm")("read access");
gp.set_command(tlm::TLM_READ_COMMAND);
gp.set_address(0x10012000);
gp.set_data_ptr(data.data());
@ -45,7 +50,13 @@ void test_initiator::run() {
gp.set_streaming_width(4);
sc_core::sc_time delay;
intor->b_transport(gp, delay);
wait(10, sc_core::SC_NS);
wait(10_ns);
srWarn()("group", "comm")("write access");
gp.set_command(tlm::TLM_WRITE_COMMAND);
gp.set_address(0x10012000);
data[0]=0xA5;
intor->b_transport(gp, delay);
wait(10_ns);
}
} /* namespace sysc */

View File

@ -23,8 +23,8 @@
#ifndef _TEST_INITIATOR_H_
#define _TEST_INITIATOR_H_
#include <sysc/utilities.h>
#include <tlm_utils/simple_initiator_socket.h>
#include <systemc>
namespace sysc {
@ -33,6 +33,7 @@ public:
SC_HAS_PROCESS(test_initiator);
tlm_utils::simple_initiator_socket<test_initiator, 32> intor;
sc_core::sc_in<bool> rst_i;
test_initiator(sc_core::sc_module_name nm);
protected:
void run();

@ -1 +1 @@
Subproject commit 5f7387ab7e3dfc2ff6a7cac6fbe834ed7ec8ae36
Subproject commit 48428f097659421db15d1eeac3a74fdd653db6e5