// 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 DDSWrapper #(
    parameter IN_WIDTH = 24,
    parameter WR_NUM = 3,
    parameter OUT_WIDTH = 64,
    parameter DATA_WIDTH = 64
)(
    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] dataFromDdsFifoCtrl;
wire [OUT_WIDTH-1:0] dataFromDdsFifo;
wire readEnDds;
wire writeEnDds;
wire valRdDataDDS;
wire busySpiMDds;
wire ddsFifoFull;
wire ddsFifoEmpty;

//==========================================================================//
//									CODING									//
//==========================================================================//
FifoCtrl #(
	.IN_WIDTH		(24),
	.WR_NUM			(3),
	.OUT_WIDTH		(64)
) FifoCtrlDDS
(
	.WrClk_i		(WrClk_i),
	.RdClk_i		(RdClk_i),
	.Rst_i			(Rst_i),
	.Data_i			(Data_i),
	.Val_i			(Val_i),
	.BusySpiM_i		(busySpiMDds),
	.FifoFull_i		(ddsFifoFull),
	.FifoEmpty_i	(ddsFifoEmpty),
	.Data_o			(dataFromDdsFifoCtrl),
	.ReadEn_o		(readEnDds),
	.WriteEn_o		(writeEnDds),
	.ValRdData_o	(valRdDataDDS)
);

FifoDDS FifoDDS_inst (
	.Data	(dataFromDdsFifoCtrl),
	.WrClk	(WrClk_i),
	.RdClk	(RdClk_i),
	.Reset	(Rst_i),
	.WrEn	(writeEnDds),
	.RdEn	(readEnDds),
	.Full	(ddsFifoFull),
	.Empty	(ddsFifoEmpty),
	.Q		(dataFromDdsFifo)
);

SpiM #(
	.DATA_WIDTH	(64)
)SpiMDDS(
	.Clk_i		(RdClk_i),
	.Rst_i		(Rst_i),
	.Val_i		(valRdDataDDS),
	.SpiData_i	(dataFromDdsFifo),
	.Busy_o	    (busySpiMDds),
	.Ss_o		(Ss_o),
	.Mosi_o		(Mosi_o),
	.Sck_o		(Sck_o)
);

endmodule