Jump to content

causma

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. causma

    sc_signal not updating to its new_value

    Dear Philipp, that's great!!! Thank you very much. This helped much more!!! In effect, an sc_singal is updated only if the newer value is different wrt the current one, consequently a broken operator== doesn't help! Thank you again! Best, Matteo
  2. causma

    sc_signal not updating to its new_value

    Dear Dakupoto, Thank you really so much. It helps a lot! I'll try this way! Best,
  3. causma

    sc_signal not updating to its new_value

    Dear Dakupoto, Thank you for answering. I understand your point. But I am not just looking to bypass the problem, otherwise I would have used the standard types provided with SystemC. I would like to understand why my piece of code is not working. In fact, if I run the same code with: sc_signal<bool> data; sc_signal<sc_uint<5> > data0;I get : SystemC 2.3.1-Accellera --- Sep 20 2014 12:00:32 Copyright (c) 1996-2014 by all Contributors, ALL RIGHTS RESERVED data 0 name = signal_0 value = 0 new value = 1 data0 0 name = signal_1 value = 0 new value = 6 data1 (5,1,1,1,1,1) name = signal_2 value = (5,1,1,1,1,1) new value = (5,5,3,1,2,3) data2 (1,1,1) name = signal_3 value = (1,1,1) new value = (1,64,130) Simulation... data 1 <-- Update to the right value name = signal_0 value = 1 new value = 0 data0 6 <-- OK name = signal_1 value = 6 new value = 0 data1 (5,5,3,1,2,3) <-- OK name = signal_2 value = (5,5,3,1,2,3) new value = (5,0,0,0,0,0) data2 (1,1,1) <-- Not OK name = signal_3 value = (1,1,1) new value = (1,0,0) Simulation... data 0 <-- OK name = signal_0 value = 0 new value = 0 data0 0 <-- OK name = signal_1 value = 0 new value = 0 data1 (5,5,3,1,2,3) <-- Not OK name = signal_2 value = (5,5,3,1,2,3) new value = (5,0,0,0,0,0) data2 (1,1,1) <-- Not OK name = signal_3 value = (1,1,1) new value = (1,0,0) Finally, my question is: where is the problem ? - in the definition of my custom type / usage of static matrices; ‚Äč - there are some constraints related to sc_signal / systemC / C++, I am ignoring; - a specialization of the sc_signal::write () method that is required for my own custom type. Thank you in advance.
  4. Dear All, I created a class BusAssembly, which basically contains a matrix of sc_uint<>, and I provided it with operator= , ==, >> and sc_trace. In a simple sc_main I defined some variables with type sc_signal<BusAssembly<W,Dim0,Dim1> > . Then I assinged them with a static matrix. (Both by = or .write()) Now, the new_value of the sc_signal variables is correctly assigned, but after a while of simulaiton, their current value is not updated to it. Surprisingly it is only working for the fisrt assignment occurrence. SystemC 2.3.1-Accellera --- Sep 20 2014 12:00:32 Copyright (c) 1996-2014 by all Contributors, ALL RIGHTS RESERVED data1 (5,1,1,1,1,1) name = signal_0 value = (5,1,1,1,1,1) new value = (5,5,3,1,2,3) data2 (1,1,1) name = signal_1 value = (1,1,1) new value = (1,64,130) data1 (5,5,3,1,2,3) <-- After simulation data1 is OK name = signal_0 value = (5,5,3,1,2,3) new value = (5,0,0,0,0,0) data2 (1,1,1) <-- data2 is not name = signal_1 value = (1,1,1) new value = (1,0,0) data1 (5,5,3,1,2,3) <-- data1 is not name = signal_0 value = (5,5,3,1,2,3) new value = (5,0,0,0,0,0) data2 (1,1,1) <-- neither data2 name = signal_1 value = (1,1,1) new value = (1,0,0) What am I mistaken with ? Thank you in advance. Please find here the sc_main code: #include <iostream> #include "frames.h" using namespace std; int sc_main(int argc, char *argv[]) { // Testbench internal variables static const sc_uint<4> a[5][1] = {{5},{3},{1},{2},{3}}; static const sc_uint<4> b[5][1] = {{0},{0},{0},{0},{0}}; static const sc_uint<8> c[1][2] = {{64,130}}; static const sc_uint<8> d[1][2] = {{0,0}}; sc_signal<BusAssembly<4,5> > data1; sc_signal<BusAssembly<8,1,2> > data2; sc_clock clk("clk",10,SC_NS,true); data1.write(a); cout << "data1 " << data1 << "\n"; data1.dump(); data2.write(c); cout << "data2 " << data2 << "\n"; data2.dump(); sc_start(20,SC_NS); data1 = b; cout << "data1 " << data1 << "\n"; data1.dump(); data2 = d; cout << "data2 " << data2 << "\n"; data2.dump(); sc_start(20,SC_NS); data1.dump(); data2.dump(); return EXIT_SUCCESS; } And the Class definition one "frames.h" : #include <exception> #include "systemc.h" #include <stdio.h> template <int W=8, unsigned short Dim0=1, unsigned short Dim1=1> class BusAssembly { private: static const unsigned short dim = Dim0; public: sc_uint<W> value[Dim0][Dim1]; BusAssembly() { for (unsigned short i=0; i<Dim0; i++) for (unsigned short j=0; j<Dim1; j++) value[i][j] = 1; } BusAssembly(const sc_uint<W> t[][Dim1]) { for (unsigned short i=0; i<Dim0; i++) for (unsigned short j=0; j<Dim1; j++) value[i][j] = t[i][j]; } // Assignment operator BusAssembly& operator = (const BusAssembly& v) { if (this == &v) return *this; if (dim == v.dim) { for (unsigned short i=0; i<Dim0; i++) for (unsigned short j=0; j<Dim1; j++) value[i][j] = v.value[i][j]; // cout << *this << "\n"; return *this; } else throw "Assignment Error: Dimensions must match!"; } bool operator == (const BusAssembly& v) const { bool end = true; if (dim == v.dim) { for (unsigned short i=0; i<Dim0 && end; i++) for (unsigned short j=0; j<Dim1 && end; j++) end = (value[i][j] != v.value[i][j]); return end; } else throw "Assignment Error: Dimensions must match!"; } inline friend void sc_trace (sc_trace_file *tf, const BusAssembly& v, const std::string& NAME) { // sc_trace(tf,v.dim, NAME + ".dim"); for (unsigned short i=0; i<Dim0; i++) for (unsigned short j=0; j<Dim1; j++) { std::stringstream str; str << NAME << ".value(" << i << ")(" << j << ")"; sc_trace(tf,v.value[i][j],str.str()); } } inline friend ostream& operator << (ostream& os, const BusAssembly& v) { os << "(" << v.dim ; for (unsigned short i=0; i<Dim0; i++) for (unsigned short j=0; j<Dim1; j++) os << "," << v.value[i][j]; os << ")"; return os; } };
×