// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// This module implements the following SIGNAL program:                       //
//                                                                            //
//                                                                            //
//                   +-----+                                                  //
//                +->| Buf |--+                                               //
//                |  +-----+  |                                               //
//                |           | x3                                            //
//                |  +-----+  |                                               //
//                o--| Inc |<-+                                               //
//                |  +-----+                                                  //
//             x2 |                +-----+                                    //
//                o--------------->|     | x5 +--------+                      //
//                |            x4  | Add |--->| CpyOut |---> y                //
//                |  +-----+   +-->|     |    +--------+                      //
//                +->|     |   |   +-----+                                    //
//      +-------+    | Def |---+                                              //    
//  x ->| CpyIn |--->|     |                                                  //
//      +-------+ x1 +-----+                                                  //
//                                                                            //
// The input driven style will set the clock of x1, and therefore the clock of//
// x4 will be set as well. The adder will therefore set clk(x2) and clk(x5),  //
// and clk(x2) will set clk(x3). The Add node will set clk(x2)=clk(x4), so    //
// that the val(x) is ignored, and instead a value val(x2) used forwarded by  //
// the Default node. If there is however no input tick of x, then no          //
// computation takes place.                                                   //
// ************************************************************************** //

import BasicNodes.*;

macro val(x) = x.0;
macro clk(x) = x.1;

module Causality(event(int* bool) ?x,event ?clk_y,event int !val_y) {
    event(int * bool) x1,x2,x3,x4,x5;
       CpyIn(x,x1);
    || Inc(x3,x2);
    || Buf(x2,x3,0);
    || Default(x2,x1,x4);
    || Add(x2,x4,x5);
    || CpyOut(clk(x5),clk_y,val(x5),val_y);
}
// ************************************************************************** //
drivenby t1 {
    val(x) = 0;
    clk(x) = true;
    pause;
    val(x) = 0;
    clk(x) = true;
    pause;
    val(x) = 0;
    clk(x) = true;
}