如何在 SystemC 中使用结构作为信号类型?
How can I use an struct as a signal type in SystemC?
我试图在 SystemC 中模拟一个块,它添加两个像素 P1
和 P2
的红色分量,并始终保持像素 P1
的绿色和蓝色分量.我已通过以下方式将像素声明为结构及其重载函数:
struct pixel {
sc_uint<8> r;
sc_uint<8> g;
sc_uint<8> b;
pixel( sc_uint<8> _r = 0, sc_uint<8> _g = 0, sc_uint<8> _b = 0): r(_r), g(_g), b(_b) { }
bool operator == (const pixel &other) {
return (r == other.r) && (g == other.g) && (b == other.b);
}
// Displaying
friend ostream& operator << ( ostream& o, const pixel& P ) {
o << "{" << P.r << "," << P.g << "," << P.b << "}" ;
return o;
}
};
//Overload function
void sc_trace( sc_trace_file* _f, const pixel& _foo, const std::string& _s ) {
sc_trace( _f, _foo.r, _s + "_r" );
sc_trace( _f, _foo.g, _s + "_g" );
sc_trace( _f, _foo.b, _s + "_b" );
}
然后考虑到信号sc_in
的类型是pixel
,我编写了加法器模块,如下:
SC_MODULE(adder){
sc_in<pixel> pin1;
sc_in<pixel> pin2;
sc_out<pixel> pout;
SC_CTOR(adder){
SC_METHOD(addpixel);
sensitive << pin1 << pin2;
}
void addpixel(){
sc_uint<8> ir;
sc_uint<8> ig;
sc_uint<8> ib;
ir = pin1.r + pin2.r;
ig = pin1.g;
ib = pin1.b;
pout = pixels(ir,ig,ib);
cout << " P1 = " << pin1 << endl;
cout << " P2 = " << pin2 << endl;
}
};
我得到以下编译错误:
test.cpp:46:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘r’
ir = pin1.r + pin2.r;
^
test.cpp:46:22: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘r’
ir = pin1.r + pin2.r;
^
test.cpp:47:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘g’
ig = pin1.g;
^
test.cpp:48:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘b’
ib = pin1.b;
^
<builtin>: recipe for target 'test' failed
我想知道方法addpixel
如何访问像素的每个分量RGB并进行操作。如果我删除错误行,我会在终端中显示像素值 P1
和 P2
.
sc_in<pixel>
不是 pixel
。我猜你应该像这样通过 sc_in::read()
获取值:
void addpixel(){
sc_uint<8> ir;
sc_uint<8> ig;
sc_uint<8> ib;
pixel pin1_value = pin1.read();
pixel pin2_value = pin2.read();
ir = pin1_value.r + pin2_value.r;
ig = pin1_value.g;
ib = pin1_value.b;
pout = pixels(ir,ig,ib);
cout << " P1 = " << pin1_value << endl;
cout << " P2 = " << pin2_value << endl;
}
我试图在 SystemC 中模拟一个块,它添加两个像素 P1
和 P2
的红色分量,并始终保持像素 P1
的绿色和蓝色分量.我已通过以下方式将像素声明为结构及其重载函数:
struct pixel {
sc_uint<8> r;
sc_uint<8> g;
sc_uint<8> b;
pixel( sc_uint<8> _r = 0, sc_uint<8> _g = 0, sc_uint<8> _b = 0): r(_r), g(_g), b(_b) { }
bool operator == (const pixel &other) {
return (r == other.r) && (g == other.g) && (b == other.b);
}
// Displaying
friend ostream& operator << ( ostream& o, const pixel& P ) {
o << "{" << P.r << "," << P.g << "," << P.b << "}" ;
return o;
}
};
//Overload function
void sc_trace( sc_trace_file* _f, const pixel& _foo, const std::string& _s ) {
sc_trace( _f, _foo.r, _s + "_r" );
sc_trace( _f, _foo.g, _s + "_g" );
sc_trace( _f, _foo.b, _s + "_b" );
}
然后考虑到信号sc_in
的类型是pixel
,我编写了加法器模块,如下:
SC_MODULE(adder){
sc_in<pixel> pin1;
sc_in<pixel> pin2;
sc_out<pixel> pout;
SC_CTOR(adder){
SC_METHOD(addpixel);
sensitive << pin1 << pin2;
}
void addpixel(){
sc_uint<8> ir;
sc_uint<8> ig;
sc_uint<8> ib;
ir = pin1.r + pin2.r;
ig = pin1.g;
ib = pin1.b;
pout = pixels(ir,ig,ib);
cout << " P1 = " << pin1 << endl;
cout << " P2 = " << pin2 << endl;
}
};
我得到以下编译错误:
test.cpp:46:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘r’
ir = pin1.r + pin2.r;
^
test.cpp:46:22: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘r’
ir = pin1.r + pin2.r;
^
test.cpp:47:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘g’
ig = pin1.g;
^
test.cpp:48:13: error: ‘class sc_core::sc_in<pixel>’ has no member named ‘b’
ib = pin1.b;
^
<builtin>: recipe for target 'test' failed
我想知道方法addpixel
如何访问像素的每个分量RGB并进行操作。如果我删除错误行,我会在终端中显示像素值 P1
和 P2
.
sc_in<pixel>
不是 pixel
。我猜你应该像这样通过 sc_in::read()
获取值:
void addpixel(){
sc_uint<8> ir;
sc_uint<8> ig;
sc_uint<8> ib;
pixel pin1_value = pin1.read();
pixel pin2_value = pin2.read();
ir = pin1_value.r + pin2_value.r;
ig = pin1_value.g;
ib = pin1_value.b;
pout = pixels(ir,ig,ib);
cout << " P1 = " << pin1_value << endl;
cout << " P2 = " << pin2_value << endl;
}