// Generated by WaveFormer Lite Version 11.11d at 15:18:44 on 8/9/2007
// Stimulator for stimulus

// Generation Settings:
//   Export type: Stimulus only (reactive export not enabled)
//                Delays, Samples, Markers, etc will not generate code.

// Clock Domains:

//   Unclocked
//   ---------
//     Signals:
//       INIT
//       DONE


`define TB_ABORT (3'b000)
`define TB_ONCE (3'b001)
`define TB_DONE (3'b010)
`define TB_LOOPING (3'b011)
`define TB_RESTART (3'b100)
`define TB_END (3'b101)
`timescale  1 ns /  1 ps

module stimulus(SDO, SCK, INIT, DONE);
  input SDO;
  output SCK;
  output INIT;
  output DONE;
  reg INIT_driver;
  reg DONE_driver;
  assign INIT = INIT_driver;
  assign DONE = DONE_driver;


  // Control Signal Declarations
  reg [2:0] tb_status;

  // Parm Declarations
  real SCK_MinHL;
  real SCK_MaxHL;
  real SCK_MinLH;
  real SCK_MaxLH;
  real SCK_JFall;
  real SCK_JRise;
  real SCK_Duty;
  real SCK_Period;
  real SCK_Offset;


  // The following initial block will start up the stimulator.
  initial
    begin
    AssignParms;
    tb_status <= `TB_ONCE;
    Unclocked;
    tb_status <= `TB_DONE;
    $display("Note: At %t: End of stimulus reached.  Use End Diagram Marker to extend or shorten stimulus.", $time);
    end

  // Parm Assignment Task
  task AssignParms;
    begin
    SCK_MinHL = 0.0;
    SCK_MaxHL = 0.0;
    SCK_MinLH = 0.0;
    SCK_MaxLH = 0.0;
    SCK_JFall = 0.0;
    SCK_JRise = 0.0;
    SCK_Duty = 50.0;
    SCK_Period = 100.0;
    SCK_Offset = 0.0;
    end
  endtask

  // Clocks

  // Clock Instantiation
  wire [63:0] SCK_Offset_bits = $realtobits(SCK_Offset);
  wire [63:0] SCK_Period_bits = $realtobits(SCK_Period);
  wire [63:0] SCK_Duty_bits = $realtobits(SCK_Duty);
  wire [63:0] SCK_JRise_bits = $realtobits(SCK_JRise);
  wire [63:0] SCK_JFall_bits = $realtobits(SCK_JFall);
  wire [63:0] SCK_MinLH_bits = $realtobits(SCK_MinLH);
  wire [63:0] SCK_MaxLH_bits = $realtobits(SCK_MaxLH);
  wire [63:0] SCK_MinHL_bits = $realtobits(SCK_MinHL);
  wire [63:0] SCK_MaxHL_bits = $realtobits(SCK_MaxHL);
  tb_clock_minmax #(1) tb_SCK(tb_status[1:0],
            SCK,
            SCK_Offset_bits,
            SCK_Period_bits,
            SCK_Duty_bits,
            SCK_MinLH_bits,
            SCK_MaxLH_bits,
            SCK_MinHL_bits,
            SCK_MaxHL_bits,
            SCK_JRise_bits,
            SCK_JFall_bits);

  // Clocked Sequences

  // Sequence: Unclocked

  // Drive signals to their initial values
  initial
    begin
    INIT_driver <= 1'b1;
    DONE_driver <= 1'b0;
    end

  task Unclocked;
    begin
    #666;
    INIT_driver <= 1'b0;
    #588;
    INIT_driver <= 1'b1;
    #449385761;
    end
  endtask
endmodule

// Clock models used by diagram.

// Copied contents of file: d:\Libero73\WFL\lib\verilog\tb_clock_minmax.v

module tb_clock_minmax(tb_status, CLK, offset_bits, period_bits, duty_bits, minLH_bits, maxLH_bits, minHL_bits, maxHL_bits, jRise_bits, jFall_bits);
  parameter initialize = 0;

  input [1:0] tb_status;
  output CLK;
  input [63:0] offset_bits;
  input [63:0] period_bits;
  input [63:0] duty_bits;
  input [63:0] minLH_bits;
  input [63:0] maxLH_bits;
  input [63:0] minHL_bits;
  input [63:0] maxHL_bits;
  input [63:0] jRise_bits;
  input [63:0] jFall_bits;

  reg  CLK;
  real offset;
  real period;
  real duty;
  real minLH;
  real maxLH;
  real minHL;
  real maxHL;
  real jRise;
  real jFall;
  real CLK_high;
  real CLK_low;
 
  task DriveLHInvalidRegion;
    begin
    if ( (jRise + maxLH - minLH) > 0.0 )
      begin
      CLK <= 1'bx;
      #((jRise + maxLH - minLH));
      end
    end
  endtask

  task DriveHLInvalidRegion;
    begin
    if ( (jFall + maxHL - minHL) > 0.0 )
      begin
      CLK <= 1'bx;
      #((jFall + maxHL - minHL));
      end
    end
  endtask

  always
    begin
    @(posedge tb_status[0])
    offset = $bitstoreal( offset_bits );
    period = $bitstoreal( period_bits );
    duty  = $bitstoreal( duty_bits );
    minLH = $bitstoreal( minLH_bits );
    maxLH = $bitstoreal( maxLH_bits );
    minHL = $bitstoreal( minHL_bits );
    maxHL = $bitstoreal( maxHL_bits );
    jRise = $bitstoreal( jRise_bits );
    jFall = $bitstoreal( jFall_bits );
    if (period <= 0.0)
      $display("Error: Period for clock %m is invalid (period=%f).  Clock will not be driven", period);
    else if (duty <= 0.0)
      $display("Error: Duty for clock %m is invalid (duty=%f).  Clock will not be driven", duty);
    else
      begin
      CLK_high = period * duty / 100;
      CLK_low = period - CLK_high;
      
      if ( (offset + (minLH - jRise/2)) >= 0.0 )
        begin
        if (initialize)
          CLK <= 1'b0; // drive initial state
        #(offset + (minLH - jRise/2))
        ;
        end
      else
        begin // wait for x
        if (initialize)
          CLK <= 1'bx; // in middle of X region, init to X
        #((jRise/2 + maxLH) + (offset))
        CLK <= 1'b1;
        #((CLK_high - (maxLH + jRise/2) + (minHL - jFall/2)))
        DriveHLInvalidRegion;
        CLK <= 1'b0;
        #((CLK_low - (maxHL + jFall/2) + (minLH - jRise/2)))
        ;
        end
  
      while ( tb_status[0] == 1'b1 )
        begin : clock_loop
        DriveLHInvalidRegion;
        CLK <= 1'b1;
        #((CLK_high - (maxLH + jRise/2) + (minHL - jFall/2)))
        DriveHLInvalidRegion;
        CLK <= 1'b0;
        #((CLK_low - (maxHL + jFall/2) + (minLH - jRise/2)))
        ;
        end
      end
    end
endmodule

// End of contents of file: d:\Libero73\WFL\lib\verilog\tb_clock_minmax.v

// Test Bench wrapper for stimulus and Model Under Test

module testbench;
  wire SDO;
  wire SCK;
  wire INIT;
  wire DONE;

  // Stimulator instance
  stimulus stimulus_0(.SDO(SDO),
            .SCK(SCK),
            .INIT(INIT),
            .DONE(DONE));

  // Instantiation of Model Under Test.
  MasterSerial MasterSerial_0(.SCK(SCK),
            .INIT(INIT),
            .DONE(DONE),
            .SDO(SDO));
endmodule
