//================================================= file = process_csim.c =====
//=  A program to demonstate CSIM processes                                   =
//=============================================================================
//=  Notes: 1) Program does nothing "useful" other than demonstrate how       =
//=            processes are independent and how hold() makes time go by      =
//=---------------------------------------------------------------------------=
//= Example execution:                                                        =
//=                                                                           =
//=   Begin at time = 0.000000                                                =
//=   Hello from process #1 at time = 0.000000                                =
//=   Hello from process #1 at time = 1.000000                                =
//=   Hello from process #2 at time = 1.000000                                =
//=   Hello from process #1 at time = 2.000000                                =
//=   Hello from process #2 at time = 2.500000                                =
//=   Hello from process #1 at time = 3.000000                                =
//=   Hello from process #2 at time = 4.000000                                =
//=   Hello from process #1 at time = 4.000000                                =
//=   Hello from process #1 at time = 5.000000                                =
//=   Hello from process #2 at time = 5.500000                                =
//=   Hello from process #1 at time = 6.000000                                =
//=   Hello from process #2 at time = 7.000000                                =
//=   Hello from process #1 at time = 7.000000                                =
//=   Hello from process #1 at time = 8.000000                                =
//=   Hello from process #2 at time = 8.500000                                =
//=   Hello from process #1 at time = 9.000000                                =
//=   Hello from process #2 at time = 10.000000                               =
//=   Hello from process #2 at time = 11.500000                               =
//=   Hello from process #2 at time = 13.000000                               =
//=   Hello from process #2 at time = 14.500000                               =
//=   End at time = 101.000000                                                =
//=---------------------------------------------------------------------------=
//=  Build: standard CSIM build                                               =
//=---------------------------------------------------------------------------=
//=  Execute: process                                                         =
//=---------------------------------------------------------------------------=
//=  Author: Ken Christensen                                                  =
//=          University of South Florida                                      =
//=          WWW: http://www.csee.usf.edu/~christen                           =
//=          Email: christen@csee.usf.edu                                     =
//=---------------------------------------------------------------------------=
//=  History: KJC (06/09/09) - Genesis                                        =
//=============================================================================
//----- Includes --------------------------------------------------------------
#include <stdio.h>      // Needed for printf()
#include "csim.h"       // Needed for CSIM18 stuff

//----- Prototypes ------------------------------------------------------------
void process1(void);    // Process #1
void process2(void);    // Process #2

//=============================================================================
//==  Main program                                                           ==
//=============================================================================
void sim(void)
{
  // Create the main simulation process
  create("sim");

  // Output begin message and time
  printf("Begin at time = %f \n", clock);

  // Kick-off two independent processes with a hold between kick-offs
  process1();
  hold(1.0);
  process2();

  // Hold and then end
  hold(100.0);
  printf("End at time = %f \n", clock);
}

//=============================================================================
//==  CSIM process #1                                                        ==
//=============================================================================
void process1()
{
  int i;        // Loop counter

  // Create the process
  create("process1");

  // Loop 10 times holding between each iteration
  for (i=0; i<10; i++)
  {
    printf("Hello from process #1 at time = %f \n", clock);
    hold(1.0);
  }
}

//=============================================================================
//==  CSIM process #2                                                        ==
//=============================================================================
void process2()
{
  int i;        // Loop counter

  // Create the process
  create("process2");

  // Loop 10 times holding between each iteration
  for (i=0; i<10; i++)
  {
    printf("Hello from process #2 at time = %f \n", clock);
    hold(1.5);
  }
}

