// Company:         TAIR
// Engineer:        Chigrinskiy A.  
// 
// Create Date:     18/04/2024 
// Design Name: 
// Module Name:     LmxWrapper
// Project Name:    SB_TMSG44V1_FPGA
// Target Devices:  Board: SB_TMSG44v1. FPGA: GW1N-LV9PG256C6/I5
// Tool versions:
// Description:    This module is a wrapper for the LMX Fifo, LMX Fifo Controller and SPI Master modules.
//
// Dependencies:  
// Revision: 
// Revision 1.0 - File Created
// Additional Comments: 
//
////////////////////////////////////////////////////////////////////////////////////////////
module LmxWrapper #(
    parameter IN_WIDTH = 24,
    parameter WR_NUM = 1,
    parameter OUT_WIDTH = 24,
    parameter DATA_WIDTH = 24
)(
    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] dataFromLmxFifoCtrl;
wire [OUT_WIDTH-1:0] dataFromLmxFifo;
wire readEnLmx;
wire writeEnLmx;
wire valRdDataLMX;
wire busySpiMLmx;
wire lmxFifoFull;
wire lmxFifoEmpty;

//==========================================================================//
//									CODING									//
//==========================================================================//
FifoCtrl #(
	.IN_WIDTH		(24),
	.WR_NUM			(1),
	.OUT_WIDTH		(24)
) FifoCtrlLmx
(
	.WrClk_i		(WrClk_i),
	.RdClk_i		(RdClk_i),
	.Rst_i			(Rst_i),
	.Data_i			(Data_i),
	.Val_i			(Val_i),
	.BusySpiM_i		(busySpiMLmx),
	.FifoFull_i		(lmxFifoFull),
	.FifoEmpty_i	(lmxFifoEmpty),
	.Data_o			(dataFromLmxFifoCtrl),
	.ReadEn_o		(readEnLmx),
	.WriteEn_o		(writeEnLmx),
	.ValRdData_o	(valRdDataLMX)
);

FifoLMX FifoLMX_inst (
	.Data	(dataFromLmxFifoCtrl),
	.WrClk	(WrClk_i),
	.RdClk	(RdClk_i),
	.Reset	(Rst_i),
	.WrEn	(writeEnLmx),
	.RdEn	(readEnLmx),
	.Full	(lmxFifoFull),
	.Empty	(lmxFifoEmpty),
	.Q		(dataFromLmxFifo)
);

SpiM #(
	.DATA_WIDTH	(24)
)SpiMLmx(
	.Clk_i		(RdClk_i),
	.Rst_i		(Rst_i),
	.Val_i		(valRdDataLMX),
	.SpiData_i	(dataFromLmxFifo),
	.Busy_o	    (busySpiMLmx),
	.Ss_o		(Ss_o),
	.Mosi_o		(Mosi_o),
	.Sck_o		(Sck_o)
);

endmodule