#include <stdio.h>
#include "parc.h"

using namespace parc;

pipe<int> chn;

module top {

public:
  l_signal<logic> reset;

  int i;

  process p1 {
  start:
    for (; i < 8 ; i++) {
      printf("p1> %d @ %d\n",i,Kern->Now().L());
      chn = i;
    }
  } a;

  process p2 {
    int d[2],r; 
  start:
    for (;;) {
      @(chn,posedge reset);
      if (reset.Active()) {
        printf("Reset!\n");
      } else {
        if (CHNS_DEAD == (r = chn.read(d,1))) break;
          printf("p2< %d @ %d\n",d[0],Kern->Now().L());
          wait(2);
      }
    }
    printf("p2: done\n");
  } b;

  process p3 {
  start:
    wait(15);
    reset = 1;
    printf("p3: done\n");
  } c;

  top() {
    i = 1;
  }
};

void test()
{
  top t;

  root()->StartAll();
}

int main(int argc,char **argv)
{
  test();
}