module: signal_source_clocked
timing_sensitivity:  posedge clk_in
parameters: int stype, int period_clk_samples
inputs: double phase, bool clk_in
outputs: double out, bool clk_out
classes: SigGen siggen1("square",10.0,1.0), List list1();
static_variables:  int clk_out_prev
init: 
clk_out_prev = 0;
clk_out = 0;

if (period_clk_samples < 2)
   {
    printf("error in 'signal_source_clocked':  period_clk_samples must be >= 2\n");
    printf("   -> in this case, period_clk_samples = %d\n", period_clk_samples);
    exit(1);
   }
if (stype == 0)
   siggen1.set("square",1.0/((double) period_clk_samples),1.0);
else if (stype == 1)
   siggen1.set("sine",1.0/((double) period_clk_samples),1.0);
else if (stype == 2)
   {
   list1.inp(1);
   list1.inp(1);
   siggen1.set("impulse",1.0/((double) period_clk_samples),1.0,list1);
   }
else if (stype == 3)
   siggen1.set("prbs",1.0/((double) period_clk_samples),1.0);
else if (stype == 4)
   siggen1.set("impulse",1.0/((double) period_clk_samples),1.0);

code:
double siggen1_out;

if (stype == 3)
   {
    clk_out = clk_out_prev;
    siggen1_out = siggen1.square;
    if (clk_out_prev == 0 && siggen1_out != -1.0)
        clk_out_prev = 1;
    else if (clk_out_prev == 1 && siggen1_out != 1.0)
        clk_out_prev = 0;
   }

siggen1.inp(phase);
out = siggen1.out;

if (stype != 3)
   {
    siggen1_out = siggen1.square;
    if (clk_out == 0 && siggen1_out != -1.0)
        clk_out = 1;
    else if (clk_out == 1 && siggen1_out != 1.0)
        clk_out = 0;
   }
