`timescale 1ns / 1ps
// (* use_dsp48	=	"yes"*)
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 		Churbanov S.
// 
// Create Date:    15:24:31 08/20/2019 
// Design Name: 
// Module Name:    gain_master 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.02 - File Modified
// Additional Comments: 16.09.2019 file modified in assotiate with task.
//
//////////////////////////////////////////////////////////////////////////////////
module GainControlWrapper
#(	
	parameter	AdcDataWidth		=	14,
	parameter	ThresholdWidth		=	24,
	parameter	PhIncWidth			=	32,
	parameter	IfNcoOutWidth		=	18,
	parameter	MeasPeriod			=	32
)	
(
	input	Rst_i,
	input	Clk_i,	
	input	StartMeas_i,
	
	input	[IfNcoOutWidth-1:0]	NcoSin_i,
	input	[IfNcoOutWidth-1:0]	NcoCos_i,
	
	input	[AdcDataWidth-1:0]		AdcData_i,
	
	input	[ThresholdWidth-1:0]	GainLowThreshold_i,
	input	[ThresholdWidth-1:0]	GainHighThreshold_i,
	input	GainAutoEn_i,
	input	GainManualState_i,
	
	output	AmpEnNewState_o,
	output	SensEn_o,
	output	MeasStart_o
);

//================================================================================
//  LOCALPARAM
	localparam	MultDataWidth	=	36;
	
//================================================================================
	wire	[MultDataWidth-1:0]	adcSin;
	wire	[MultDataWidth-1:0]	adcCos;

	wire	[MultDataWidth-1:0]	adcSinCut	=	adcSin	[MultDataWidth-1:0];
	wire	[MultDataWidth-1:0]	adcCosCut	=	adcCos	[MultDataWidth-1:0];
	wire	gainNewState;
//================================================================================
//  ASSIGNMENTS
	assign	AmpEnNewState_o	=	(GainAutoEn_i)?	gainNewState:GainManualState_i;
//================================================================================
//  CODING

MultModule		
#(	
	.AdcDataWidth	(AdcDataWidth),
	.IfNcoOutWidth	(IfNcoOutWidth)
)	
Adc1Mult	
(
	.Rst_i		(Rst_i),
	.Clk_i		(Clk_i),
	.AdcData_i	(AdcData_i),
	.Sin_i		(NcoSin_i),
	.Cos_i		(NcoCos_i),
	.AdcSin_o	(adcSin),
	.AdcCos_o	(adcCos)
);


GainControl		
#(	
	.AdcNcoMultWidth	(MultDataWidth),
	.ThresholdWidth		(ThresholdWidth),
	.AdcDataWidth		(AdcDataWidth),
	.MeasPeriod			(MeasPeriod)
)
GainMaster
(
	.Rst_i					(Rst_i),
	.StartMeas_i			(StartMeas_i),
	.GainAutoEn_i			(GainAutoEn_i),
	.Clk_i					(Clk_i),
	.AdcCos_i				(adcSin),
	.AdcSin_i				(adcCos),
	.GainLowThreshold_i		(GainLowThreshold_i),
	.GainHighThreshold_i	(GainHighThreshold_i),
	.GainNewState_o			(gainNewState),
	.SensEn_o				(SensEn_o),
	.MeasStart_o			(MeasStart_o)
); 
endmodule
