HOME       UP       PREV       NEXT (Get Started Experiment 2/2)  

Second Test File hworld2.cpp

A second example can be copied from SOCDAM /toyclasses/class1/hworld2.cpp.

Full src file »hworld2.cpp.

Illustrating the sc_uint fixed-field operators.

SC_MODULE(fivebitcounter)
{
  sc_in  clk, reset, load;
  sc_out  > q;
  sc_out  > parallelin;

  SC_CTOR(fivebitcounter)
  {
    void clkme();
    SC_METHOD(clkme); sensitive << clk.pos() << reset.pos();
  }

  
  void clkme()
  {
    if (reset.read()) q = 0;
    else if (load.read()) q = parallelin.read();
    else
      {
        int nv = q.read() + 1;
        printf("Five  pending set to %i\n", nv);
        q = nv;
      }
  }
};

Console output log: note the 32 becomes a zero when stored in the field.

   Five  pending set to 31
   Toggle at 4200 ns
   Toggle at 4250 ns
   Five  pending set to 32
   Toggle at 4300 ns
   Toggle at 4350 ns
   Five  pending set to 1
   Toggle at 4400 ns

(C) 2008-10, DJ Greaves, University of Cambridge, Computer Laboratory.