| `timescale 1ns / 1ns |
|
|
| |
| module spi_eater( |
| input clk, |
| input pace, |
| |
| output sclk, |
| output mosi, |
| input miso, |
| output [5:0] ctl_bits, |
| |
| input [8:0] fdata, |
| input empty, |
| output pull_fifo, |
| |
| output [7:0] result, |
| output result_we |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| reg old_pace = 0; |
| wire tick1 = ~pace & old_pace; |
| wire tick2 = pace & ~old_pace; |
| reg pull_fifo_r = 0, mode=0, running=0; |
| reg [2:0] bit_cnt = 0; |
| reg [7:0] shift_reg = 0; |
| reg [7:0] ctrl_reg = 0; |
| wire want_another = mode | (bit_cnt==7); |
| reg push_result=0; |
| reg miso_hold=0; |
| always @(posedge clk) begin |
| old_pace <= pace; |
| pull_fifo_r <= tick1 & ~empty & want_another; |
| if (tick2) miso_hold <= miso; |
| if (tick1 & want_another) running <= ~empty; |
| if (tick1 & want_another & ~empty ) mode <= fdata[8]; |
| if (tick1) shift_reg <= {shift_reg[6:0],miso_hold}; |
| if (tick1 & want_another & ~empty & ~fdata[8]) shift_reg <= fdata[7:0]; |
| if (tick1 & want_another & ~empty & fdata[8]) ctrl_reg <= fdata[7:0]; |
| if (tick1 & ~mode) bit_cnt <= bit_cnt+1; |
| push_result <= tick1 & ctrl_reg[7] & ~mode & (bit_cnt==7); |
| end |
| assign pull_fifo = pull_fifo_r; |
| assign result_we = push_result; |
| assign result = shift_reg; |
|
|
| |
| |
| |
| assign sclk = running & ~mode & old_pace; |
| assign mosi = shift_reg[7]; |
| assign ctl_bits = ctrl_reg[5:0]; |
|
|
| endmodule |
|
|