Skip to content

Commit

Permalink
improving C++ tb
Browse files Browse the repository at this point in the history
  • Loading branch information
davideschiavone committed Feb 2, 2024
1 parent 8cd358d commit 6adf95d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
4 changes: 4 additions & 0 deletions core-v-mini-mcu.core
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ filesets:

tb-verilator:
files:
- tb/XHEEP_CmdLineOptions.hh: { is_include_file: true }
- tb/XHEEP_CmdLineOptions.cpp
- tb/tb_top.cpp
file_type: cppSource

Expand All @@ -203,6 +205,8 @@ filesets:

tb-sc-verilator:
files:
- tb/XHEEP_CmdLineOptions.hh: { is_include_file: true }
- tb/XHEEP_CmdLineOptions.cpp
- tb/tb_sc_top.cpp
file_type: cppSource

Expand Down
13 changes: 7 additions & 6 deletions tb/XHEEP_CmdLineOptions.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "XHEEP_CmdLineOptions.hh"
#include <iostream>
#include <string>

XHEEP_CmdLineOptions::XHEEP_CmdLineOptions(int argc, char* argv[]) // define default constructor
{
this->run_all = false;
this->argc = argc;
this->argv = argv;

}

std::string XHEEP_CmdLineOptions::getCmdOption(int argc, char* argv[], const std::string& option)
Expand All @@ -29,7 +29,8 @@ bool XHEEP_CmdLineOptions::get_use_openocd()

std::string arg_openocd = this->getCmdOption(this->argc, this->argv, "+openOCD=");;

use_openocd = false;
bool use_openocd = false;

if(arg_openocd.empty()){
std::cout<<"[TESTBENCH]: No OpenOCD is used"<<std::endl;
} else {
Expand All @@ -44,7 +45,7 @@ bool XHEEP_CmdLineOptions::get_use_openocd()
std::string XHEEP_CmdLineOptions::get_firmware()
{

std::string firmware; = this->getCmdOption(this->argc, this->argv, "+firmware=");;
std::string firmware = this->getCmdOption(this->argc, this->argv, "+firmware=");

if(firmware.empty()){
std::cout<<"[TESTBENCH]: No firmware specified"<<std::endl;
Expand All @@ -59,7 +60,7 @@ std::string XHEEP_CmdLineOptions::get_firmware()
unsigned int XHEEP_CmdLineOptions::get_max_sim_time(bool& run_all)
{

std::string arg_max_sim_time; = this->getCmdOption(this->argc, this->argv, "+max_sim_time=");;
std::string arg_max_sim_time = this->getCmdOption(this->argc, this->argv, "+max_sim_time=");
unsigned int max_sim_time;

max_sim_time = 0;
Expand Down Expand Up @@ -95,5 +96,5 @@ unsigned int XHEEP_CmdLineOptions::get_boot_sel()
}
}

return boot_sel
return boot_sel;
}
10 changes: 6 additions & 4 deletions tb/XHEEP_CmdLineOptions.hh
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#ifndef XHEEP_TB_UTIL_H
#define XHEEP_TB_UTIL_H

#include <iostream>

class XHEEP_CmdLineOptions // declare Calculator class
{

public: // public members
XHEEP_CmdLineOptions(int argc, char* argv[])(); // default constructor
XHEEP_CmdLineOptions(int argc, char* argv[]); // default constructor

std:string getCmdOption(int argc, char* argv[], const std::string& option); // get options from cmd lines
std::string getCmdOption(int argc, char* argv[], const std::string& option); // get options from cmd lines
bool get_use_openocd();
std::string get_firmware();
unsigned int get_max_sim_time(bool& run_all);
unsigned int get_boot_sel()
unsigned int get_boot_sel();
int argc;
char* argv[];
char** argv;

};

Expand Down
19 changes: 19 additions & 0 deletions tb/tb_sc_top.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "systemc.h"
#include <stdlib.h>
#include <iostream>
#include "XHEEP_CmdLineOptions.hh"


SC_MODULE(testbench)
Expand Down Expand Up @@ -44,6 +45,24 @@ int sc_main (int argc, char * argv[])

Verilated::commandArgs(argc, argv);

XHEEP_CmdLineOptions* cmd_lines_options = new XHEEP_CmdLineOptions(argc,argv);

use_openocd = cmd_lines_options->get_use_openocd();
firmware = cmd_lines_options->get_firmware();

if(firmware.empty() && use_openocd==false)
exit(EXIT_FAILURE);

max_sim_time = cmd_lines_options->get_max_sim_time(run_all);

boot_sel = cmd_lines_options->get_boot_sel();

if(boot_sel == 1) {
std::cout<<"[TESTBENCH]: ERROR: Executing from SPI is not supported (yet) in Verilator"<<std::endl;
std::cout<<"exit simulation..."<<std::endl;
exit(EXIT_FAILURE);
}

Vtestharness dut("testharness");

testbench tb("testbench");
Expand Down
4 changes: 2 additions & 2 deletions tb/tb_top.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main (int argc, char * argv[])
dut->trace (m_trace, 99);
m_trace->open ("waveform.vcd");

XHEEP_CmdLineOptions* cmd_lines_options = new XHEEP_CmdLineOptions(arcg,argv);
XHEEP_CmdLineOptions* cmd_lines_options = new XHEEP_CmdLineOptions(argc,argv);

use_openocd = cmd_lines_options->get_use_openocd();
firmware = cmd_lines_options->get_firmware();
Expand All @@ -58,7 +58,7 @@ int main (int argc, char * argv[])
if(boot_sel == 1) {
std::cout<<"[TESTBENCH]: ERROR: Executing from SPI is not supported (yet) in Verilator"<<std::endl;
std::cout<<"exit simulation..."<<std::endl;
return -1;
exit(EXIT_FAILURE);
}

svSetScope(svGetScopeFromName("TOP.testharness"));
Expand Down

0 comments on commit 6adf95d

Please sign in to comment.