-- This system executes two threads, one on each of two
-- processors. This system uses the platform, client, and 
-- server packages.
-------------------------------------------------------------- 
system DemoSystem
end DemoSystem;

system implementation DemoSystem.impl
  subcomponents
    lan: bus platform::DefaultBus.impl;
    ------
    clientProcessor1: processor platform::DefaultProcessor.impl;
    clientProcess1: process Client::DefaultClientProcess.impl;
    clientMemory1: memory platform::DefaultMemory.impl;
    clientBus1: bus platform::DefaultBus.impl;
    ------
    ------
    serverProcessor1: processor platform::DefaultProcessor.impl;
    serverProcess1: process ServerType::DefaultServerProcess.impl;
    serverMemory1: memory platform::DefaultMemory.impl;
    serverBus1: bus platform::DefaultBus.impl;
  ------
  connections
    connection1: event data port clientProcess1.get -> 
serverProcess1.put {
      Latency => 10 Us;
      };
    connection2: event data port serverProcess1.get -> 
clientProcess1.put {
      Latency => 10 Us;
      };
    bus access lan -> serverProcessor1.busAcc;
    bus access lan -> clientProcessor1.busAcc;
  properties
    Actual_Memory_Binding =>  reference clientmemory1 applies to 
clientProcess1;
    ------
    ------
    Actual_Processor_Binding =>  reference clientprocessor1 applies to 
clientProcess1.clientThread;
    Actual_Processor_Binding =>  reference clientprocessor1 applies to 
clientProcess1.serverThread;
    ------
    ------


package Client
public
  thread interactWithServer
    features
      receiveData: in event data port;
      requestData: out event data port;
  end interactWithServer;
  
  thread implementation interactWithServer.basic
    properties
      Period => 120 Ms;
      Compute_Execution_Time => 30 Ms .. 40 Ms;
      Dispatch_Protocol => Periodic;
    annex behavior {** 
				compute(5ms); 
				--raise(requestData);
				compute(10ms); 
				--raise(requestData);
				compute(15ms); 
				raise(requestData); 
    
    **};
  end interactWithServer.basic;
  
  thread interactWithClient
    features
      receiveData: in event data port;
      requestData: out event data port;
  end interactWithClient;
  
  thread implementation interactWithClient.basic
    properties
      Period => 120 Ms;
      Compute_Execution_Time => 30 Ms .. 40 Ms;
      Dispatch_Protocol => Periodic;
    annex behavior {** 
				compute(5ms); 
				compute(10ms); 
				compute(15ms); 
				raise(requestData); 
			
    
    **};
  end interactWithClient.basic;
  
  process DefaultClientProcess
    features
      put: in event data port;
      get: out event data port;
      putEvent: in event port;
      getEvent: out event port;
  end DefaultClientProcess;
  
  process implementation DefaultClientProcess.impl
    subcomponents
      serverThread: thread interactWithServer.basic in modes 
(initialPhase, secondPhase);
      clientThread: thread interactWithClient.basic in modes 
(thirdPhase);
    connections
      connection: event data port put -> serverThread.receiveData in 
modes (initialPhase, secondPhase);
      connection2: event data port put -> clientThread.receiveData in 
modes (thirdPhase);
      --connection1: event data port clientThread.requestData -> get;
    modes
      initialPhase: initial mode ;
      secondPhase: mode ;
      thirdPhase: mode ;
      initialPhase -[ putEvent ]-> secondPhase;
      secondPhase -[ putEvent ]-> thirdPhase;
  end DefaultClientProcess.impl;
end Client;


package ServerType
public
  thread interactWithClient
    features
      receiveRequest: in event data port;
      sendToClient: out event data port;
  end interactWithClient;
  
  thread implementation interactWithClient.basic
    properties
      Period => 120 Ms;
      Compute_Execution_Time => 30 Ms .. 60 Ms;
      Dispatch_Protocol => Periodic;
    annex behavior {**
				
				compute(5ms); 
				--raise(sendToClient);
				--pend(receiveRequest);
				compute(10ms); 
				--raise(sendToClient);
				--pend(receiveRequest);
				compute(35ms); 
				raise(sendToClient); 
			
    **};
  end interactWithClient.basic;
  
  process DefaultServerProcess
    features
      put: in event data port;
      get: out event data port;
  end DefaultServerProcess;
  
  process implementation DefaultServerProcess.impl
    subcomponents
      serverThread: thread interactWithClient.basic;
    connections
      connection: event data port put -> serverThread.receiveRequest;
      connection1: event data port serverThread.sendToClient -> get;
  end DefaultServerProcess.impl;
end ServerType;


------------------------------------------------------
--This is a package that provides the elements 
--necessary to define a runtime environment that
--works with the ADeS simulator.
------------------------------------------------------ 
package platform
public
  -- Description of the memory onto which the process is bound 
  ------------------------------------------------------ 
  memory DefaultMemory
  end DefaultMemory;
  
  memory implementation DefaultMemory.impl
  end DefaultMemory.impl;
  
  -- Description of the bus onto which connections are bound 
  ---------------------------------------------------------- 
  bus DefaultBus
  end DefaultBus;
  
  bus implementation DefaultBus.impl
    properties
      Propagation_Delay => 5 Ms .. 5 Ms;
  end DefaultBus.impl;
  
  -- Description of a processor to execute the threads 
  ------------------------------------------- 
  processor DefaultProcessor
    features
      busAcc: requires bus access DefaultBus.impl;
  end DefaultProcessor;
  
  processor implementation DefaultProcessor.impl
    subcomponents
      mem: memory DefaultMemory.impl;
    properties
      Scheduling_Protocol => RMS;
  end DefaultProcessor.impl;
end platform;



