// Company:         TAIR
// Engineer:        Chigrinskiy A.  
// 
// Create Date:     18/04/2024 
// Design Name: 
// Module Name:     DDSWrapper
// Project Name:    SB_TMSG44V1_FPGA
// Target Devices:  Board: SB_TMSG44v1. FPGA: GW1N-LV9PG256C6/I5
// Tool versions:
// Description:    This module is a wrapper for the Fifo, Fifo Controller and SPI Master modules.
//
// Dependencies:  
// Revision: 
// Revision 1.0 - File Created
// Additional Comments: 
//
////////////////////////////////////////////////////////////////////////////////////////////
module PotWrapper #(
    parameter IN_WIDTH = 24,
    parameter WR_NUM = 1,
    parameter OUT_WIDTH = 16,
    parameter DATA_WIDTH = 16
)(
    input WrClk_i,
    input RdClk_i,
    input Rst_i,
    input [IN_WIDTH-1:0] Data_i,
    input Val_i,

    output Ss_o,
    output Sck_o,
    output Mosi_o

);
//================================================================================
//	                                REG/WIRE
//================================================================================    
wire [OUT_WIDTH-1:0] dataFromPotFifoCtrl;
wire [OUT_WIDTH-1:0] dataFromPotFifo;
wire readEnPot;
wire writeEnPot;
wire valRdDataPOT;
wire busySpiMPot;
wire potFifoFull;
wire potFifoEmpty;

//==========================================================================//
//									CODING									//
//==========================================================================//
FifoCtrl #(
	.IN_WIDTH		(24),
	.WR_NUM			(1),
	.OUT_WIDTH		(16)
) FifoCtrlPot
(
	.WrClk_i		(WrClk_i),
	.RdClk_i		(RdClk_i),
	.Rst_i			(Rst_i),
	.Data_i			(Data_i),
	.Val_i			(Val_i),
	.BusySpiM_i		(busySpiMPot),
	.FifoFull_i		(potFifoFull),
	.FifoEmpty_i	(potFifoEmpty),
	.Data_o			(dataFromPotFifoCtrl),
	.ReadEn_o		(readEnPot),
	.WriteEn_o		(writeEnPot),
	.ValRdData_o	(valRdDataPOT)
);

Fifo16x3 FifoPot_inst (
	.Data	(dataFromPotFifoCtrl),
	.WrClk	(WrClk_i),
	.RdClk	(RdClk_i),
	.Reset	(Rst_i),
	.WrEn	(writeEnPot),
	.RdEn	(readEnPot),
	.Full	(potFifoFull),
	.Empty	(potFifoEmpty),
	.Q		(dataFromPotFifo)
);

SpiM #(
	.DATA_WIDTH	(16)
)SpiMPot(
	.Clk_i		(RdClk_i),
	.Rst_i		(Rst_i),
	.Val_i		(valRdDataPOT),
	.SpiData_i	(dataFromPotFifo),
	.Busy_o	    (busySpiMPot),
	.Ss_o		(Ss_o),
	.Mosi_o		(Mosi_o),
	.Sck_o		(Sck_o)
);

endmodule