HOME       UP       PREV       NEXT (Timed Transactions: Adding delays to TLM calls.)  

CSharp Implementation

Here is an approximate skeleton of the structure of the sockets in C\#.

// Skeleton outline of the TLM2 socket structure for blocking transport only.
// This is a skeleton in that the other socket and channel types are missing and b_transact has no payload.
class TLM2_Sockets_Skeleton
{
  public interface b_transimple_target_socket_callback_t
  {
    void b_transact();
  }


  public class simple_initiator_socket
  {
    simple_target_socket who;

    public void bind(simple_target_socket whom) {   who = whom;   }
    
    public void b_transact()  { who.b_transact();   }
  }

  public class simple_target_socket
  {
    b_transimple_target_socket_callback_t who;

    public void b_transact()  {  who.b_transact();   }

    public void register_cb(b_transimple_target_socket_callback_t s) {  who = s;   }
  }
}

// An initator
class CPU
{
  public TLM2_Sockets_Skeleton.simple_initiator_socket m0 = new TLM2_Sockets_Skeleton.simple_initiator_socket();
  public TLM2_Sockets_Skeleton.simple_initiator_socket m1 = new TLM2_Sockets_Skeleton.simple_initiator_socket();

  public void step() // Cycle callable bus functional model
  { ...
    m0.b_transact(...);
    ...
  }
}

// Class defining the RAM target. The IO would be very similar.
class RAM : TLM2_Sockets_Skeleton.b_transimple_target_socket_callback_t
{  // A target has a target socket
  public TLM2_Sockets_Skeleton.simple_target_socket s0 = new TLM2_Sockets_Skeleton.simple_target_socket();

  public RAM() // Constructor
  { s0.register_cb(this);
  }

  public void b_transact()
  { Console.WriteLine("Got To RAM");
    ...
  }
}


class Bench
{ static CPU the_cpu = new CPU();
  static RAM the_ram = new RAM();
  static RAM the_io  = new IO();
  public static void wBench()  // Constructor-like
  {
    the_cpu.m0.bind(the_ram.s0);
    the_cpu.m1.bind(the_io.s0);
  }


  public static void Main()
  {
    wBench();
    Console.WriteLine("Starting");
    the_cpu.step();
  }
}

The simple initiator and target sockets illustrated in this skeleton offer no significant benefits. The benefit arises in real implementations where other features are present and adherence to the coding standard arises from the type checker.


25: (C) 2008-18, DJ Greaves, University of Cambridge, Computer Laboratory.