【问题标题】:How to create a custom channel in SystemC?如何在 SystemC 中创建自定义频道?
【发布时间】:2016-08-21 07:25:39
【问题描述】:

我正在尝试在 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;
 }

文件消费者.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

文件生产者.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

文件消费者.cpp

 #include "consumer.h"

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

文件生产者.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/包括-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

【问题讨论】:

    标签: c++ systemc


    【解决方案1】:

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

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

    `

        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
        }
    

    【讨论】:

    • 谢谢您的回复,能详细点吗?我的跟踪适用于标准通道,例如: sc_trace(tf, clock, "clock");但是,当我尝试添加自定义频道时,我遇到了这个问题
    • 如果有帮助,我已经更新了问题中的更多详细信息和简单形式的代码
    【解决方案2】:

    找到解决方法!!!

    把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 文件中跟踪通道,还添加了其他代码以通过通道进行通信

    【讨论】:

      猜你喜欢
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多