2016-02-26 22:51:35 -05:00
|
|
|
module mrx_protocol (/*AUTOARG*/
|
|
|
|
// Outputs
|
|
|
|
fifo_access, fifo_packet,
|
|
|
|
// Inputs
|
2016-03-21 13:50:23 -04:00
|
|
|
rx_clk, nreset, datasize, lsbfirst, io_access, io_packet
|
2016-02-26 22:51:35 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
//#####################################################################
|
|
|
|
//# INTERFACE
|
|
|
|
//#####################################################################
|
|
|
|
|
|
|
|
//parameters
|
2016-03-25 15:35:48 -04:00
|
|
|
parameter PW = 104; // packet width (core)
|
|
|
|
parameter NMIO = 8; // io packet width
|
2016-04-14 21:46:14 +02:00
|
|
|
parameter CW = $clog2(2*PW/NMIO); // transfer count width
|
2016-02-26 22:51:35 -05:00
|
|
|
|
|
|
|
//clock and reset
|
2016-03-25 15:35:48 -04:00
|
|
|
input rx_clk; // rx clock
|
|
|
|
input nreset; // async active low reset
|
2016-02-26 22:51:35 -05:00
|
|
|
|
|
|
|
//config
|
2016-03-25 15:35:48 -04:00
|
|
|
input [7:0] datasize; // dynamic width of output data
|
|
|
|
input lsbfirst;
|
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
//16 bit interface
|
2016-03-25 15:35:48 -04:00
|
|
|
input io_access; // access signal from IO
|
|
|
|
input [2*NMIO-1:0] io_packet; // data from IO
|
2016-03-20 22:36:33 -04:00
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
//wide input interface
|
2016-03-25 15:35:48 -04:00
|
|
|
output fifo_access; // access for fifo
|
|
|
|
output [PW-1:0] fifo_packet; // packet for fifo
|
2016-03-20 22:36:33 -04:00
|
|
|
|
|
|
|
//#####################################################################
|
|
|
|
//# BODY
|
|
|
|
//#####################################################################
|
2016-02-26 22:51:35 -05:00
|
|
|
|
|
|
|
//regs
|
2016-03-20 22:36:33 -04:00
|
|
|
reg [2:0] mrx_state;
|
|
|
|
reg [CW-1:0] mrx_count;
|
|
|
|
reg fifo_access;
|
2016-06-19 17:10:51 -04:00
|
|
|
wire shift;
|
|
|
|
wire transfer_done;
|
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
|
|
|
|
//##########################
|
|
|
|
//# STATE MACHINE
|
|
|
|
//##########################
|
2016-03-20 22:36:33 -04:00
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
`define MRX_IDLE 3'b000
|
|
|
|
`define MRX_BUSY 3'b001
|
|
|
|
|
2016-03-21 13:50:23 -04:00
|
|
|
always @ (posedge rx_clk or negedge nreset)
|
2016-02-26 22:51:35 -05:00
|
|
|
if(!nreset)
|
|
|
|
mrx_state[2:0] <= `MRX_IDLE;
|
|
|
|
else
|
|
|
|
case (mrx_state[2:0])
|
|
|
|
`MRX_IDLE: mrx_state[2:0] <= io_access ? `MRX_BUSY : `MRX_IDLE;
|
|
|
|
`MRX_BUSY: mrx_state[2:0] <= ~io_access ? `MRX_IDLE : `MRX_BUSY;
|
|
|
|
default: mrx_state[2:0] <= 'b0;
|
|
|
|
endcase // case (mrx_state[2:0])
|
|
|
|
|
2016-03-20 22:36:33 -04:00
|
|
|
//tx word counter
|
2016-03-21 13:50:23 -04:00
|
|
|
always @ (posedge rx_clk)
|
2016-02-26 22:51:35 -05:00
|
|
|
if((mrx_state[2:0]==`MRX_IDLE) | transfer_done)
|
|
|
|
mrx_count[CW-1:0] <= datasize[CW-1:0];
|
|
|
|
else if(mrx_state[2:0]==`MRX_BUSY)
|
|
|
|
mrx_count[CW-1:0] <= mrx_count[CW-1:0] - 1'b1;
|
|
|
|
|
2016-03-21 11:27:35 -04:00
|
|
|
assign transfer_done = (mrx_count[CW-1:0]==1'b1) & (mrx_state[2:0]==`MRX_BUSY);
|
|
|
|
assign shift = (mrx_state[2:0]==`MRX_BUSY);
|
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
//pipeline access signal
|
2016-03-21 13:50:23 -04:00
|
|
|
always @ (posedge rx_clk or negedge nreset)
|
2016-02-26 22:51:35 -05:00
|
|
|
if(!nreset)
|
|
|
|
fifo_access <= 'b0;
|
|
|
|
else
|
|
|
|
fifo_access <= transfer_done;
|
|
|
|
|
2016-03-20 22:36:33 -04:00
|
|
|
//##########################
|
|
|
|
//# SHIFT REGISTER
|
|
|
|
//##########################
|
|
|
|
|
|
|
|
oh_ser2par #(.PW(PW),
|
2016-03-25 15:35:48 -04:00
|
|
|
.SW(2*NMIO))
|
2016-03-20 22:36:33 -04:00
|
|
|
|
|
|
|
ser2par (// Outputs
|
|
|
|
.dout (fifo_packet[PW-1:0]),
|
|
|
|
// Inputs
|
2016-03-21 13:50:23 -04:00
|
|
|
.clk (rx_clk),
|
2016-03-25 15:35:48 -04:00
|
|
|
.din (io_packet[2*NMIO-1:0]),
|
2016-03-20 22:36:33 -04:00
|
|
|
.lsbfirst (lsbfirst),
|
2016-03-21 11:27:35 -04:00
|
|
|
.shift (shift)
|
2016-03-20 22:36:33 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
endmodule // mrx_protocol
|
2016-03-20 22:36:33 -04:00
|
|
|
// Local Variables:
|
|
|
|
// verilog-library-directories:("." "../../common/hdl")
|
|
|
|
// End:
|
|
|
|
|
2016-02-26 22:51:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|