Close

Creating Entities

A project log for TRCM

Attempt to reinvent the wheel of HDL

shaosSHAOS 08/12/2018 at 20:580 Comments

In order to make independent blocks that communicate with each other user should create derived class from class Entity for every such block:

class Unit1 : public Entity
{
 protected:

  // indecies:
  int i0,i1,i2;
  // inputs:
  Wire<8> net;
  Uint<8> bus;
  // outputs:
  Signal sig;

 public:

  Unit1()
  {
    // attach your entity to global wires
    i0 = at("bus",8,PULLUP);
    i1 = at("network",8);
    i2 = at("single");
  }

  void step()
  {
    // read your inputs
    for(int i=0;i<8;i++)
      bus[i] = io(i0+i).read();
    for(int i=0;i<8;i++)
      net[i] = io(i1+i).read();
    // do something
    sig[0] = TRUE;
    // apply your outputs
    io(i0) << sig[0];
    io(i0+1) << sig[0];
    io(i2) << sig[0];
    // additional trigger logic
    if(posedge(i1+5))
    {
       // here we can have logic that should work on positive edge of network[5]
    }
  }
};

In future method step() of each user entity (that executes 1 step of simulation) will run in a separate thread... 

Source code is available on GitLab: https://gitlab.com/ternary/trcm

Discussions