如何在SystemC中创建自定义渠道?

时间:2016-08-18 04:53:43

标签: c++ systemc

我正在尝试在System C中创建自定义渠道。渠道数据结构如下所示

struct Command {

int cmdType;
int lba;
double timestamp;
int size;

Command() { }

Command(const int c, const int l, const double ts, const int sz) {
make(c, l, ts, sz);
}

void make(const int c, const int l, const double ts, const int sz) {
cmdType = c;
lba = l;
timestamp = ts;
size = sz;
}

inline bool operator ==(const Command & command) const {
return (command.cmdType == cmdType && command.lba == lba
    && command.timestamp == timestamp
    && command.size == size); }
};

此通道的ostream和trace函数定义如下

inline ostream & operator <<(ostream & os, const Command command)
{

   os << "CmdType " << command.cmdType << endl;
   os << "Lba " << command.lba << endl;
   os << "Time " << command.timestamp <<endl;
   os << "Data " << command.size << endl;

   return os;
}



inline void sc_trace(sc_trace_file * &tf, const Command & command, string &name)
{
    sc_trace(tf, command.cmdType, name + ".cmdType");
    sc_trace(tf, command.lba, name + ".lba");
    sc_trace(tf, command.timestamp, name + ".timestamp");
    sc_trace(tf, command.size, name + ".size");
}

但是我收到编译错误

错误信息很长,但这是最后一部分

/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:312:6: note:   candidate expects 4 arguments, 3 provided
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:317:6: note: void sc_core::sc_trace(sc_core::sc_trace_file*, const sc_core::sc_signal_in_if<short int>&, const string&, int)
 void sc_trace( sc_trace_file* tf,
      ^
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:317:6: note:   candidate expects 4 arguments, 3 provided
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:322:6: note: void sc_core::sc_trace(sc_core::sc_trace_file*, const sc_core::sc_signal_in_if<int>&, const string&, int)
 void sc_trace( sc_trace_file* tf,
      ^
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:322:6: note:   candidate expects 4 arguments, 3 provided
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:327:6: note: void sc_core::sc_trace(sc_core::sc_trace_file*, const sc_core::sc_signal_in_if<long int>&, const string&, int)
 void sc_trace( sc_trace_file* tf,
      ^
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:327:6: note:   candidate expects 4 arguments, 3 provided
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:343:1: note: void sc_core::sc_trace(sc_core::sc_trace_file*, const unsigned int&, const string&, const char**)
 sc_trace( sc_trace_file* tf,
 ^
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:343:1: note:   candidate expects 4 arguments, 3 provided
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:351:13: note: void sc_core::sc_trace(sc_core::sc_trace_file*, const void*, const string&)
 extern void sc_trace( sc_trace_file* tf,
             ^
/home/user/user/systemc-2.3.1//include/sysc/tracing/sc_trace.h:351:13: note:   no known conversion for argument 2 from ‘const Command’ to ‘const void*’
In file included from /home/user/user/systemc-2.3.1//include/sysc/communication/sc_clock_ports.h:31:0,
                 from /home/user/user/systemc-2.3.1//include/systemc:79,
                 from /home/user/user/systemc-2.3.1//include/systemc.h:208,
                 from initiator.h:5,
                 from initiator.cpp:1:
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1808:1: note: template<class T> void sc_core::sc_trace(sc_core::sc_trace_file*, const sc_core::sc_inout<T>&, const string&)
 sc_trace( sc_trace_file* tf, const sc_inout<T>& port, 
 ^
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1808:1: note:   template argument deduction/substitution failed:
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1165:46: note:   ‘const Command’ is not derived from ‘const sc_core::sc_inout<T>’
      sc_trace( p->tf, iface->read(), p->name );
                                              ^
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1791:1: note: template<class T> void sc_core::sc_trace(sc_core::sc_trace_file*, const sc_core::sc_in<T>&, const string&)
 sc_trace(sc_trace_file* tf, const sc_in<T>& port, const std::string& name)
 ^
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1791:1: note:   template argument deduction/substitution failed:
/home/user/user/systemc-2.3.1//include/sysc/communication/sc_signal_ports.h:1165:46: note:   ‘const Command’ is not derived from ‘const sc_core::sc_in<T>’
      sc_trace( p->tf, iface->read(), p->name );
                                              ^

感谢有关如何解决此编译问题的帮助

这里是代码的简单版本---文件main.c

 #include <stdio.h>
 #include <csignal>
 #include "systemc.h"
 #include "producer.h"
 #include "consumer.h"
 #include "stdtype.h"
 #include <iomanip>
 #include <sstream>

 using namespace std;

 inline ostream & operator <<(ostream & os, const Command command)
 {
    os << "CmdType " << command.cmdType << endl;
    return os;
 }

 inline void sc_trace(sc_trace_file * tf, const Command & command, const string & name)
 {
    int* cmdType = (int*) &(command.cmdType);
    sc_trace(tf, cmdType, name + ".cmdType");
 }

 int sc_main(int arg_num, char *arg_vet[])
 {
    sc_clock clock("clock", 100, SC_PS);
    sc_signal <bool> reset;
    sc_signal <Command> cmd;
    Producer *prd;
    prd = new Producer("Producer");
    prd->clock(clock);
    prd->reset(reset);
    prd->cmd_tx(cmd);
    Consumer *con;
    con = new Consumer("Consumer");
    con->clock(clock);
    con->reset(reset);
    con->cmd_rx(cmd);
    sc_trace_file *tf = NULL;
    tf = sc_create_vcd_trace_file("trace");
    sc_trace(tf, reset, "reset");
    sc_trace(tf, clock, "clock");
    reset.write(1);
    sc_start(100, SC_NS);
    reset.write(0);
    sc_start(100, SC_NS);
    sc_close_vcd_trace_file(tf);
    return 0;
 }

文件consumer.h

 #ifndef __CONSUMER_H__
 #define __CONSUMER_H__

 #include <queue>
 #include <systemc.h>
 #include "stdtype.h"

 using namespace std;

 SC_MODULE(Consumer)
 {

    sc_in_clk clock;
    sc_in <bool> reset;

    sc_in <Command> cmd_rx;

    void ConsumerProcess();

    SC_CTOR(Consumer) {
    SC_METHOD(ConsumerProcess);
    sensitive << reset;
    sensitive << clock.pos();
    }

 };

#endif

文件producer.h

 #ifndef __PRODUCER_H__
 #define __PRODUCER_H__

 #include <queue>
 #include <systemc.h>
 #include "stdtype.h"

 using namespace std;

 SC_MODULE(Producer)
 {

    sc_in_clk clock;
    sc_in <bool> reset;

    sc_out <Command> cmd_tx;

    void ProducerProcess();

    SC_CTOR(Producer) {
    SC_METHOD(ProducerProcess);
    sensitive << reset;
    sensitive << clock.pos();
    }
 };

#endif

文件consumer.cpp

 #include "consumer.h"

 void Consumer:: ConsumerProcess(void)
 {
   cout << "con" << endl;
 }

文件producer.cpp

 #include "producer.h"

 void Producer:: ProducerProcess(void)
 {
   cout << "prd" << endl;
 }

和文件stdtype.h

#ifndef __STDTYPE_H__
#define __STDTYPE_H__

#include <queue>
#include <systemc.h>
struct Command {

    int cmdType;

    inline bool operator ==(const Command & command) const {
    return (command.cmdType == cmdType); }
};

#endif

在这里编译上面的代码是命令行:

  

g ++ -I。 -I $ SYSTEMC_HOME / include -L。 -L $ SYSTEMC_HOME / LIB-LINUX64   -Wl,-rpath = $ SYSTEMC_HOME / lib-linux64 -I / usr / local / include -L / usr / local / lib -lyaml-cpp -o main main.cpp producer.cpp consumer.cpp -lsystemc -lm

2 个答案:

答案 0 :(得分:0)

你确定sc_trace功能是对的吗? 为了使您的呼叫成功,至少需要两种类型的重载功能。当然,我没有想到隐式转换类。 无论如何,两个功能如下:

  1. sc_trace(sc_trace_file,int,string)
  2. sc_trace(sc_trace_file,double,string)
  3. `

        inline void sc_trace(sc_trace_file * &tf, const Command & command, string &name)
        {
            sc_trace(tf, command.cmdType, name + ".cmdType");     // 1
            sc_trace(tf, command.lba, name + ".lba");             // 1
            sc_trace(tf, command.timestamp, name + ".timestamp"); // 2
            sc_trace(tf, command.size, name + ".size");           // 1
        }
    

答案 1 :(得分:0)

找到了修复!!!

更改stdtype.h如下

#ifndef __STDTYPE_H__
#define __STDTYPE_H__

#include <queue>
#include <systemc.h>

#include <iomanip>
#include <sstream>

#include <map>
#include <utility>
#include <vector>
#include <string>

using namespace std;

struct Command {

    int cmdType;

    inline bool operator ==(const Command & command) const {
    return (command.cmdType == cmdType); }
};

inline ostream & operator <<(ostream & os, const Command & command)
{

    os << "CmdType " << command.cmdType << endl;

    return os;
}

inline void sc_trace(sc_trace_file * tf, const Command & command, const string & name)
{
    sc_trace(tf, command.cmdType, name + ".cmdType");
}

#endif

并从main.cpp中删除了这些函数,这解决了问题,我可以跟踪vcd文件中的通道,还添加了其他代码通过通道进行通信