HOME       UP       PREV       NEXT (SystemC Structural Netlist)  

Example (Counter)

SC_MODULE(mycounter) // An example of a leaf module (no subcomponents).
   sc_in  < bool       > clk, reset;
   sc_out < sc_int<10> > myout;

   void m()  // Internal behaviour, invoked as an SC_METHOD.
      myout =  (reset) ? 0: (myout.read()+1); // Use .read() since sc_out makes a signal.

   SC_CTOR(mycounter)  // Constructor
     { SC_METHOD(m);   // 
       sensitive << clk.pos();
// Complete example is on course web site and also on PWF.

SystemC enables a user class to be defined using the the SC_MODULE macro.

Modules inherit various attributes appropriate for an hierarchic hardware design including an instance name, a type name and channel binding capability.

The sensitive construct registers a callback with the EDS kernel that says when the code inside the module should be run.

An unattractive feature of SystemC is the need to use the .read() method when reading a signal.

5: (C) 2008-11, DJ Greaves, University of Cambridge, Computer Laboratory.