// ************************************************************************** //
//                                                                            //
//    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:                       //
//                                                                            //
//                +-----------------------------------+                       //
//                |              +-----+              |                       //
//             x1 |  +-----+  +->|     | x3  +-----+  |                       //
//                +->| Inc |--o  | Add |---->| Buf |--o---> y                 // 
//                   +-----+  +->|     |     +-----+                          //
//                           x2  +-----+                                      //
//                                                                            //
// This program should generates the sequence of powers of 2 (minus 2), i.e.  //
// the numbers 0,2,6,14,30,.. whenever y triggers the computation.            //
// ************************************************************************** //

import BasicNodes.*;
macro val(x) = x.0;
macro clk(x) = x.1;

module PowersOf2(event ?clk_y,event int !val_y) {
    event(int * bool) x1,x2,x3;
       Buf(x3,x1,0);
    || Inc(x1,x2);
    || Add(x2,x2,x3);
    || CpyOut(clk(x1),clk_y,val(x1),val_y);
}
// ************************************************************************** //
// This input trace is not clock consistent and will lead to val(x2)=⊤ in the //
// second macro step of the Quartz program.                                   //
// ************************************************************************** //
drivenby t1 {
    int i;
    while(i<100) {
        clk_y  = true;
        next(i) = i+1;
        pause;
    }
}