1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/src/mio/hdl/mrx_protocol.v

105 lines
2.7 KiB
Coq
Raw Normal View History

2016-02-26 22:51:35 -05:00
module mrx_protocol (/*AUTOARG*/
// Outputs
fifo_access, fifo_packet,
// Inputs
rx_clk, nreset, datasize, lsbfirst, io_access, io_packet
2016-02-26 22:51:35 -05:00
);
//#####################################################################
//# INTERFACE
//#####################################################################
//parameters
parameter PW = 104; // packet width (core)
parameter NMIO = 8; // io packet width
parameter CW = $clog2(2*PW/NMIO); // transfer count width
2016-02-26 22:51:35 -05:00
//clock and reset
input rx_clk; // rx clock
input nreset; // async active low reset
2016-02-26 22:51:35 -05:00
//config
input [7:0] datasize; // dynamic width of output data
input lsbfirst;
2016-02-26 22:51:35 -05:00
//16 bit interface
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
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-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
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
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;
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
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),
.SW(2*NMIO))
2016-03-20 22:36:33 -04:00
ser2par (// Outputs
.dout (fifo_packet[PW-1:0]),
// Inputs
.clk (rx_clk),
.din (io_packet[2*NMIO-1:0]),
2016-03-20 22:36:33 -04:00
.lsbfirst (lsbfirst),
.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