Skip to content

Commit

Permalink
[+] Run full asic_top simulation in systemc. Previously only workgrou…
Browse files Browse the repository at this point in the history
…p was simulated

[!] Fix critical bug with array index in ax2apb_bus module (systemc)
  • Loading branch information
sergeykhbr committed Jun 15, 2023
1 parent d829605 commit dec9b8a
Show file tree
Hide file tree
Showing 22 changed files with 1,137 additions and 10 deletions.
4 changes: 2 additions & 2 deletions debugger/cmake/cpu_sysc_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ file(GLOB_RECURSE cpu_sysc_plugin_src
LIST_DIRECTORIES false
${src_top}/debugger/src/common/*.cpp
${src_top}/debugger/src/common/*.h
${src_top}/sc/rtl/*.cpp
${src_top}/sc/rtl/*.h
${src_top}/sc/*.cpp
${src_top}/sc/*.h
${src_top}/debugger/src/cpu_sysc_plugin/*.cpp
${src_top}/debugger/src/cpu_sysc_plugin/*.h
${CMAKE_CURRENT_SOURCE_DIR}/exportmap.def
Expand Down
54 changes: 49 additions & 5 deletions debugger/src/cpu_sysc_plugin/cpu_riscv_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,16 @@ void CpuRiscV_RTL::postinitService() {
wrapper_->setPLIC(iirqext_);
wrapper_->setClockHz(freqHz_.to_int());
wrapper_->generateVCD(i_vcd_, o_vcd_);
dmislv_->setBaseAddress(dmibar_.to_uint64());
dmislv_->setLength(4096);
group0_->generateVCD(i_vcd_, o_vcd_);
if (dmislv_) {
dmislv_->setBaseAddress(dmibar_.to_uint64());
dmislv_->setLength(4096);
}
if (group0_) {
group0_->generateVCD(i_vcd_, o_vcd_);
}
if (asic0_) {
asic0_->generateVCD(i_vcd_, o_vcd_);
}

if (!run()) {
RISCV_error("Can't create thread.", NULL);
Expand All @@ -129,6 +136,7 @@ void CpuRiscV_RTL::createSystemC() {
registerInterface(static_cast<ICpuRiscV *>(wrapper_));
registerInterface(static_cast<IResetListener *>(wrapper_));
w_clk = wrapper_->o_clk;
wrapper_->o_rst(w_rst);
wrapper_->o_sys_nrst(w_sys_nrst);
wrapper_->o_dmi_nrst(w_dmi_nrst);
wrapper_->o_msti(msti);
Expand All @@ -149,6 +157,7 @@ void CpuRiscV_RTL::createSystemC() {
tapbb_->o_tdo(w_tdi);
tapbb_->i_tdi(w_tdo);

#if 0
dmislv_ = new BusSlave("dmislv");
registerPortInterface("dmi", static_cast<IMemoryOperation *>(dmislv_));
dmislv_->i_clk(wrapper_->o_clk),
Expand Down Expand Up @@ -187,6 +196,34 @@ void CpuRiscV_RTL::createSystemC() {
group0_->o_dmi_apbo(wb_dmi_apbo);
group0_->o_dmreset(w_ndmreset);

asic0_ = 0;
#else
asic0_ = new asic_top("tt",
CFG_BOOTROM_FILE_HEX,
3);

asic0_->i_rst(w_rst);
asic0_->i_sclk_p(wrapper_->o_clk);
asic0_->i_sclk_n(wrapper_->o_clk);
asic0_->io_gpio(wb_gpio);
asic0_->i_jtag_trst(w_trst);
asic0_->i_jtag_tck(w_tck);
asic0_->i_jtag_tms(w_tms);
asic0_->i_jtag_tdi(w_tdi);
asic0_->o_jtag_tdo(w_tdo);
asic0_->o_jtag_vref(w_jtag_vref);
asic0_->i_uart1_rd(w_uart1_rd);
asic0_->o_uart1_td(wuart1_td);
asic0_->o_spi_cs(w_spi_cs);
asic0_->o_spi_sclk(w_spi_sclk);
asic0_->o_spi_mosi(w_spi_mosi);
asic0_->i_spi_miso(w_spi_miso);
asic0_->i_sd_detected(w_sd_detected);
asic0_->i_sd_protect(w_sd_protect);

dmislv_ = 0;
group0_ = 0;
#endif

#ifdef DBG_ICACHE_LRU_TB
ICacheLru_tb *tb = new ICacheLru_tb("tb");
Expand All @@ -205,8 +242,15 @@ void CpuRiscV_RTL::createSystemC() {
void CpuRiscV_RTL::deleteSystemC() {
delete wrapper_;
delete tapbb_;
delete dmislv_;
delete group0_;
if (dmislv_) {
delete dmislv_;
}
if (group0_) {
delete group0_;
}
if (asic0_) {
delete asic0_;
}
}

void CpuRiscV_RTL::hapTriggered(EHapType type,
Expand Down
14 changes: 14 additions & 0 deletions debugger/src/cpu_sysc_plugin/cpu_riscv_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "bus_slv.h"
#include "ambalib/types_amba.h"
#include "riverlib/workgroup.h"
#include "../prj/impl/asic/asic_top.h"
#include <systemc.h>

namespace debugger {
Expand Down Expand Up @@ -111,10 +112,22 @@ class CpuRiscV_RTL : public IService,
IMemoryOperation *ibus_;

sc_signal<bool> w_clk;
sc_signal<bool> w_rst;
sc_signal<bool> w_sys_nrst;
sc_signal<bool> w_dmi_nrst;
sc_signal<sc_uint<64>> wb_mtimer;

sc_signal<sc_uint<12>> wb_gpio;
sc_signal<bool> w_jtag_vref;
sc_signal<bool> w_uart1_rd;
sc_signal<bool> wuart1_td;
sc_signal<bool> w_spi_cs;
sc_signal<bool> w_spi_sclk;
sc_signal<bool> w_spi_mosi;
sc_signal<bool> w_spi_miso;
sc_signal<bool> w_sd_detected;
sc_signal<bool> w_sd_protect;

// AXI4 input structure:
sc_signal<dev_config_type> xcfg;
// Interrupt lines:
Expand Down Expand Up @@ -152,6 +165,7 @@ class CpuRiscV_RTL : public IService,
TapBitBang *tapbb_;
BusSlave *dmislv_;
Workgroup *group0_;
asic_top *asic0_;
};

DECLARE_CLASS(CpuRiscV_RTL)
Expand Down
3 changes: 3 additions & 0 deletions debugger/src/cpu_sysc_plugin/rtl_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern bool dbg_e_valid;

RtlWrapper::RtlWrapper(IFace *parent, sc_module_name name) : sc_module(name),
o_clk("clk", 10, SC_NS),
o_rst("o_rst"),
o_sys_nrst("o_sys_nrst"),
o_dmi_nrst("o_dmi_nrst"),
o_msti("o_msti"),
Expand Down Expand Up @@ -220,6 +221,8 @@ void RtlWrapper::comb() {
wb_wstrb = vb_wstrb;

o_dmi_nrst = r.nrst.read()[1].to_bool();
o_rst = !(r.nrst.read()[1].to_bool()
&& !i_ndmreset.read());
o_sys_nrst = r.nrst.read()[1].to_bool()
&& !i_ndmreset.read();

Expand Down
1 change: 1 addition & 0 deletions debugger/src/cpu_sysc_plugin/rtl_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RtlWrapper : public sc_module,
public ICpuRiscV {
public:
sc_clock o_clk;
sc_out<bool> o_rst;
sc_out<bool> o_sys_nrst;
sc_out<bool> o_dmi_nrst;
// Timer:
Expand Down
43 changes: 43 additions & 0 deletions sc/prj/common/vips/clk/vip_clk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Copyright 2022 Sergey Khabarov, [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "vip_clk.h"
#include "api_core.h"

namespace debugger {

vip_clk::vip_clk(sc_module_name name,
double half_period)
: sc_module(name),
o_clk("o_clk") {

half_period_ = half_period;

SC_METHOD(comb);
}

void vip_clk::generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd) {
if (o_vcd) {
sc_trace(o_vcd, o_clk, o_clk.name());
}

}

void vip_clk::comb() {
}

} // namespace debugger

41 changes: 41 additions & 0 deletions sc/prj/common/vips/clk/vip_clk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright 2022 Sergey Khabarov, [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once

#include <systemc.h>

namespace debugger {

SC_MODULE(vip_clk) {
public:
sc_out<bool> o_clk;

void comb();

SC_HAS_PROCESS(vip_clk);

vip_clk(sc_module_name name,
double half_period);

void generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd);

private:
double half_period_;

};

} // namespace debugger

49 changes: 49 additions & 0 deletions sc/prj/common/vips/sdcard/vip_sdcard_top.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright 2022 Sergey Khabarov, [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "vip_sdcard_top.h"
#include "api_core.h"

namespace debugger {

vip_sdcard_top::vip_sdcard_top(sc_module_name name,
int half_period)
: sc_module(name),
i_rstn("i_rstn"),
i_rx("i_rx") {

half_period_ = half_period;

SC_METHOD(comb);
sensitive << i_rstn;
sensitive << i_rx;
sensitive << w_clk;
sensitive << wb_rdata;
}

void vip_sdcard_top::generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd) {
if (o_vcd) {
sc_trace(o_vcd, i_rstn, i_rstn.name());
sc_trace(o_vcd, i_rx, i_rx.name());
}

}

void vip_sdcard_top::comb() {
}

} // namespace debugger

45 changes: 45 additions & 0 deletions sc/prj/common/vips/sdcard/vip_sdcard_top.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright 2022 Sergey Khabarov, [email protected]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#pragma once

#include <systemc.h>

namespace debugger {

SC_MODULE(vip_sdcard_top) {
public:
sc_in<bool> i_rstn;
sc_in<bool> i_rx;

void comb();

SC_HAS_PROCESS(vip_sdcard_top);

vip_sdcard_top(sc_module_name name,
int half_period);

void generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd);

private:
int half_period_;

sc_signal<bool> w_clk;
sc_signal<sc_uint<8>> wb_rdata;

};

} // namespace debugger

Loading

0 comments on commit dec9b8a

Please sign in to comment.