[59] | 1 | module control
|
---|
| 2 | (
|
---|
| 3 | input wire clk,
|
---|
| 4 | input wire rx_empty, tx_full,
|
---|
| 5 | input wire [7:0] rx_data,
|
---|
| 6 | input wire [1:0] mux_max_byte,
|
---|
| 7 | input wire [15:0] mux_min_addr, mux_max_addr,
|
---|
| 8 | input wire [7:0] mux_q,
|
---|
| 9 |
|
---|
| 10 | output wire mux_reset,
|
---|
| 11 | output wire mux_type,
|
---|
| 12 | output wire [1:0] mux_chan,
|
---|
| 13 | output wire [1:0] mux_byte,
|
---|
| 14 | output wire [15:0] mux_addr,
|
---|
| 15 | output wire rx_rdreq,
|
---|
| 16 | output wire tx_wrreq,
|
---|
| 17 | output wire [7:0] tx_data,
|
---|
| 18 | output wire led
|
---|
| 19 | );
|
---|
| 20 |
|
---|
| 21 | reg [23:0] rx_counter;
|
---|
| 22 | reg [10:0] tst_counter;
|
---|
| 23 | reg [15:0] int_addr, int_max_addr;
|
---|
| 24 |
|
---|
| 25 | reg int_rdreq, int_wrreq;
|
---|
| 26 | reg int_type, int_reset;
|
---|
| 27 | reg [1:0] int_chan, int_byte, int_max_byte;
|
---|
| 28 | reg [7:0] int_data;
|
---|
| 29 | reg int_led;
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | reg [3:0] state;
|
---|
| 33 |
|
---|
| 34 | always @(posedge clk)
|
---|
| 35 | begin
|
---|
| 36 | if (~rx_empty)
|
---|
| 37 | begin
|
---|
| 38 | int_led <= 1'b0;
|
---|
| 39 | rx_counter <= 24'd0;
|
---|
| 40 | end
|
---|
| 41 | else
|
---|
| 42 | begin
|
---|
| 43 | if (&rx_counter)
|
---|
| 44 | begin
|
---|
| 45 | int_led <= 1'b1;
|
---|
| 46 | end
|
---|
| 47 | else
|
---|
| 48 | begin
|
---|
| 49 | rx_counter <= rx_counter + 24'd1;
|
---|
| 50 | end
|
---|
| 51 | end
|
---|
| 52 |
|
---|
| 53 | case(state)
|
---|
| 54 | 1:
|
---|
| 55 | begin
|
---|
| 56 | int_rdreq <= 1'b1;
|
---|
| 57 | int_wrreq <= 1'b0;
|
---|
| 58 | int_type <= 1'b0;
|
---|
| 59 | int_chan <= 2'd0;
|
---|
| 60 | int_byte <= 2'd0;
|
---|
| 61 | int_reset <= 1'b0;
|
---|
| 62 | state <= 4'd2;
|
---|
| 63 | end
|
---|
| 64 |
|
---|
| 65 | 2:
|
---|
| 66 | begin
|
---|
| 67 | if (~rx_empty)
|
---|
| 68 | begin
|
---|
| 69 | case (rx_data)
|
---|
| 70 | 8'h40, 8'h41, 8'h42, 8'h43, 8'h50, 8'h51, 8'h52, 8'h53:
|
---|
| 71 | begin
|
---|
| 72 | int_rdreq <= 1'b0;
|
---|
| 73 | int_type <= rx_data[4];
|
---|
| 74 | int_chan <= rx_data[1:0];
|
---|
| 75 | int_reset <= 1'b1;
|
---|
| 76 | state <= 4'd1;
|
---|
| 77 | end
|
---|
| 78 |
|
---|
| 79 | 8'h60, 8'h61, 8'h62, 8'h63, 8'h70, 8'h71, 8'h72, 8'h73:
|
---|
| 80 | begin
|
---|
| 81 | int_rdreq <= 1'b0;
|
---|
| 82 | int_type <= rx_data[4];
|
---|
| 83 | int_chan <= rx_data[1:0];
|
---|
| 84 | state <= 4'd3;
|
---|
| 85 | end
|
---|
| 86 |
|
---|
| 87 | 8'h30:
|
---|
| 88 | begin
|
---|
| 89 | int_rdreq <= 1'b0;
|
---|
| 90 | state <= 4'd1;
|
---|
| 91 | end
|
---|
| 92 |
|
---|
| 93 | 8'h31:
|
---|
| 94 | begin
|
---|
| 95 | int_rdreq <= 1'b0;
|
---|
| 96 | tst_counter <= 11'd0;
|
---|
| 97 | state <= 4'd6;
|
---|
| 98 | end
|
---|
| 99 | endcase
|
---|
| 100 | end
|
---|
| 101 | end
|
---|
| 102 | // mux transfer
|
---|
| 103 | 3:
|
---|
| 104 | begin
|
---|
| 105 | int_addr <= mux_min_addr;
|
---|
| 106 | int_max_addr <= mux_min_addr + mux_max_addr;
|
---|
| 107 | int_max_byte <= mux_max_byte;
|
---|
| 108 | int_byte <= 2'd0;
|
---|
| 109 | state <= 4'd4;
|
---|
| 110 | end
|
---|
| 111 |
|
---|
| 112 | 4:
|
---|
| 113 | begin
|
---|
| 114 | int_wrreq <= 1'b0;
|
---|
| 115 | state <= 4'd5;
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | 5:
|
---|
| 119 | begin
|
---|
| 120 | if (~tx_full)
|
---|
| 121 | begin
|
---|
| 122 | int_data <= mux_q;
|
---|
| 123 | int_wrreq <= 1'b1;
|
---|
| 124 | if ((int_byte == int_max_byte) && (int_addr == int_max_addr))
|
---|
| 125 | begin
|
---|
| 126 | state <= 4'd1;
|
---|
| 127 | end
|
---|
| 128 | else
|
---|
| 129 | begin
|
---|
| 130 | state <= 4'd4;
|
---|
| 131 | if (int_byte == int_max_byte)
|
---|
| 132 | begin
|
---|
| 133 | int_addr <= int_addr + 16'd1;
|
---|
| 134 | int_byte <= 2'd0;
|
---|
| 135 | end
|
---|
| 136 | else
|
---|
| 137 | begin
|
---|
| 138 | int_byte <= int_byte + 2'd1;
|
---|
| 139 | end
|
---|
| 140 | end
|
---|
| 141 | end
|
---|
| 142 | end
|
---|
| 143 |
|
---|
| 144 | // tst transfer
|
---|
| 145 | 6:
|
---|
| 146 | begin
|
---|
| 147 | int_data <= tst_counter;
|
---|
| 148 | int_wrreq <= 1'b1;
|
---|
| 149 | tst_counter <= tst_counter + 11'd1;
|
---|
| 150 | state <= 4'd8;
|
---|
| 151 | end
|
---|
| 152 | 7:
|
---|
| 153 | begin
|
---|
| 154 | if (~tx_full)
|
---|
| 155 | begin
|
---|
| 156 | int_data <= tst_counter;
|
---|
| 157 | if (tst_counter == 11'd0)
|
---|
| 158 | begin
|
---|
| 159 | state <= 4'd9;
|
---|
| 160 | end
|
---|
| 161 | else
|
---|
| 162 | begin
|
---|
| 163 | tst_counter <= tst_counter + 11'd1;
|
---|
| 164 | end
|
---|
| 165 | end
|
---|
| 166 | end
|
---|
| 167 | 8:
|
---|
| 168 | begin
|
---|
| 169 | if (~tx_full)
|
---|
| 170 | begin
|
---|
| 171 | int_wrreq <= 1'b0;
|
---|
| 172 | state <= 4'd1;
|
---|
| 173 | end
|
---|
| 174 | end
|
---|
| 175 |
|
---|
| 176 | default:
|
---|
| 177 | begin
|
---|
| 178 | state <= 4'd1;
|
---|
| 179 | end
|
---|
| 180 | endcase
|
---|
| 181 | end
|
---|
| 182 |
|
---|
| 183 | assign mux_reset = int_reset;
|
---|
| 184 | assign mux_type = int_type;
|
---|
| 185 | assign mux_chan = int_chan;
|
---|
| 186 | assign mux_byte = int_byte;
|
---|
| 187 | assign mux_addr = int_addr;
|
---|
| 188 | assign rx_rdreq = int_rdreq & (~rx_empty);
|
---|
| 189 | assign tx_wrreq = int_wrreq & (~tx_full);
|
---|
| 190 | assign tx_data = int_data;
|
---|
| 191 | assign led = int_led;
|
---|
| 192 |
|
---|
| 193 | endmodule
|
---|