mariaantoanet Posted April 9, 2019 Report Share Posted April 9, 2019 Hello friends. I have questions to ask for your help. I have a struct defined as struct pixel { sc_uint<8> r; sc_uint<8> g; sc_uint<8> b; }; Then I try to pass actual pixel values to the ports, defined as pixel data type in main.cpp sc_signal<pixel> p1; sc_signal<pixel> p2; p1.write(pixel(1, 2, 3)); p2.write(pixel(4, 5, 6)); But it seems p1.write() and p2.write() didn't initialize p1 and p2 correctly as I still see they don't have the expected pixel values (1,2,3) and (4,5,6). Do I need to use sc_interface to pass this customized data type around? Thank's a lot! Quote Link to comment Share on other sites More sharing options...
David Black Posted April 9, 2019 Report Share Posted April 9, 2019 sc_core::sc_signal<T> requires that you define the following: T::operator=(const T&) T::operator==(const T&) ostringstream&. operator<<( ostringstream&,const T& ) Quote Link to comment Share on other sites More sharing options...
Andy Goodrich Posted April 9, 2019 Report Share Posted April 9, 2019 I addition to the requirements mentioned by David, you need to define a constructor with 3 arguments for pixel, something like: struct pixel { sc_dt::sc_uint<8> r; sc_dt::sc_uint<8> g; sc_dt::sc_uint<8> b; pixel() :r(0), g(0), b(0) {} pixel( const sc_dt::sc_uint<8>& r_init, const sc_dt::sc_uint<8>& g_init, const sc_dt::sc_uint<8>& b_init ) : r(r_init), g(g_init), b(b_init) {} }; Quote Link to comment Share on other sites More sharing options...
karthickg Posted April 10, 2019 Report Share Posted April 10, 2019 Quote But it seems p1.write() and p2.write() didn't initialize p1 and p2 correctly as I still see they don't have the expected pixel values (1,2,3) and (4,5,6). I'm guessing you are trying to read the signal values immediately after calling write(). That won't return the values just written due to how update semantics work with primitive channels in SystemC. To make sure this is the cause of confusion, you can try creating a thread in your model where the signal values are written and read back after a delta-cycle wait: SC_MODULE(some_module) { sc_signal<pixel> p1; sc_signal<pixel> p2; void some_thread() { p1.write(pixel(1, 2, 3)); p2.write(pixel(4, 5, 6)); // Read and print p1 and p2 // Values won't be updated here wait(0, SC_NS); // Read and print p1 and p2 // Values will be updated here }; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.