Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.naic.edu/~phil/hardware/pdev/fpga/gx/jfft/cmix/src/test.v
Дата изменения: Thu Jun 26 04:28:48 2008
Дата индексирования: Sat Sep 6 20:24:02 2008
Кодировка:

//
// Jeff Mock
// 2030 Gough
// San Francisco, CA 94109
// jeff@mock.com
// (c) 2004
//

module test (
ck,
reset,
sync_i,

a_re,
a_im,
x_re,
x_im,
);
parameter width = `WIDTH;
parameter owidth = `OWIDTH;

input ck;

output reset;
output sync_i;

output [width-1:0] a_re;
output [width-1:0] a_im;
input [owidth-1:0] x_re;
input [owidth-1:0] x_im;

// Cycle counter
//
integer cycle;
initial begin
cycle = 0;
forever @(posedge ck) begin
cycle = cycle + 1;
if (cycle == 100000) begin
$display("Runaway simulation.");
$finish;
end
`ifdef DEBUG
if ((cycle%100) == 0)
$display ("Cycle %d", cycle);
`endif
end
end

// Reset the hardware
//
reg sync_i;
reg reset;
initial begin
sync_i = 1'b0;
reset = 1'b0;
repeat (20)
@(posedge ck);
reset = 1'b1;
repeat (4)
@(posedge ck);
reset = 1'b0;
repeat (10)
@(posedge ck);
end

// Send signal file to FFT
//
reg [width-1:0] sigmem1[0:2*`SAMPLES - 1];
reg [width-1:0] a_re;
reg [width-1:0] a_im;
integer idx;

integer s1;

`ifdef SIG1
`else
`define SIG1 "sig1.mem"
`endif

`ifdef SIG2
`else
`define SIG2 "sig2.mem"
`endif

`ifdef MIXOUT
`else
`define MIXOUT "mix.out"
`endif

initial begin
idx = 0;
$readmemh(`SIG1, sigmem1);
end
always @(posedge ck) begin
if ($test$plusargs("p1zero")) begin
a_re = 0;
a_im = 0;
end else begin
if ($test$plusargs("p1step")) begin
if (cycle < 450) begin
a_re = 0;
a_im = 0;
end else begin
a_re = 100;
a_im = 100;
end
end else if ($test$plusargs("p1noise")) begin
s1 = $random(s1);
a_re = s1[width-1:0];
s1 = $random(s1);
a_im = s1[width-1:0];
end else begin
a_re = sigmem1[idx];
a_im = sigmem1[idx+1];
end
end
idx = idx+2;
end

//
integer socnt;
integer fcnt;
integer fd;
initial begin
fd = $fopen(`MIXOUT);
socnt = 0;
fcnt = 0;
end
always @(posedge ck) begin
socnt = socnt + 1;
if (socnt > 100) begin
fcnt = fcnt + 1;
$fdisplay(fd, "%x", x_re);
$fdisplay(fd, "%x", x_im);
if (fcnt == `SAMPLES) begin
// $display("Normal termination after %d frames", `FRAMES);
$fclose(fd);
$finish;
end
end
end
endmodule