module WinCalcTb();

reg	Clk_i;
reg	WindClk;
reg	Rst_i;
reg	[31:0]	WinValue_i;
reg	WinType_i;
reg	CalcWind_i;
reg	Val;

always	#10 Clk_i	=	~Clk_i;
always	#2.5	WindClk	=	~WindClk;	

parameter	WV	=	32;

initial	begin
	Rst_i	=	1;
	Clk_i	=	1;
	WindClk	=	1;
	WinValue_i	=	0;
	WinType_i	=	0;
	CalcWind_i	=	0;
	#200
	Rst_i	=	0;
end


// localparam	[31:0]	win_start_value	=	32'h02AAAAAB;
// localparam	[31:0]	win_step_value	=	32'h05555555;

localparam	[31:0]	win_start_value	=	32'h0;
localparam	[31:0]	win_step_value	=	32'h4325c53;
localparam	[31:0]	winPointsNum	=	32'h3D;

reg	[31:0]	pointsCnt;
reg	[31:0]	tb_cnt;

always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		if	(CalcWind_i)	begin
			if	(pointsCnt	!=	winPointsNum-1)	begin
				pointsCnt	<=	pointsCnt+1;
			end	else	begin
				pointsCnt	<=	0;
			end
		end	else	begin
			pointsCnt	<=	0;
		end
	end	else	begin
		pointsCnt	<=	0;
	end
end

always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		tb_cnt	<=	tb_cnt+1;
	end	else	begin
		tb_cnt	<=	0;
	end
end

always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		if	(tb_cnt	==	50)	begin
			CalcWind_i	<=	1;
		end	else	if	(pointsCnt	==	winPointsNum-1)	begin
			CalcWind_i	<=	0;
		end
	end
end

reg		[WV-1:0]	windArg;				
// reg		[WV-1:0]	win_value_reg;				
// wire	[WV-1:0]	win_value;					
// wire	[WV	 :0]	win_next_value;				

// assign	win_next_value			=	win_value_reg	+	win_step_value;
// assign	win_value				=	(CalcWind_i)	?	win_next_value	:	win_start_value;
	
 // always	@(posedge	Clk_i)	begin
	// if	(!Rst_i)	begin
		// win_value_reg	<=	win_value;
	// end	else	begin
		// win_value_reg	<=	48'b0;
	// end
// end

	
 always	@(posedge	Clk_i)	begin
	if	(!Rst_i)	begin
		if	(CalcWind_i)	begin
			windArg	<=	windArg+win_step_value;
		end	else	begin
			windArg	<=	win_start_value;
		end
	end	else	begin
		windArg	<=	0;
	end
end
	
Win_calc	WinCalcInst
(
	.clk_i			(Clk_i),
	.wind_clk		(WindClk),
	.reset_i		(Rst_i),
	.win_value_i	(windArg),
	.win_type_i		(WinType_i),		
	.calc_wind_i	(CalcWind_i),
	.win_o			()
);
endmodule