Changeset 90 for trunk/MultiChannelUSB/control.v
- Timestamp:
- Feb 27, 2010, 10:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/control.v
r87 r90 1 1 module control 2 2 ( 3 input wire clk, 4 5 output wire cfg_reset, 6 input wire [15:0] cfg_src_data, 7 output wire [15:0] cfg_src_addr, cfg_dst_data, cfg_dst_addr, 3 input wire clock, reset, 8 4 9 5 input wire rx_empty, tx_full, 10 6 input wire [7:0] rx_data, 11 7 12 input wire [1:0] mux_max_byte, 13 input wire [15:0] mux_min_addr, mux_max_addr, 14 input wire [7:0] mux_q, 15 16 output wire mux_reset, 17 output wire mux_type, 18 output wire [1:0] mux_chan, 19 output wire [1:0] mux_byte, 20 output wire [15:0] mux_addr, 21 22 output wire rx_rdreq, 23 output wire tx_wrreq, 8 output wire rx_rdreq, tx_wrreq, 24 9 output wire [7:0] tx_data, 25 10 26 output wire ram_we, 27 output wire [19:0] ram_addr, 28 inout wire [17:0] ram_data, 29 30 input wire ept_data_ready, 31 input wire [47:0] ept_data, 32 33 output wire i2c_wrreq, 34 output wire [15:0] i2c_data, 35 input wire i2c_full, 11 output wire bus_wren, 12 output wire [31:0] bus_addr, 13 output wire [15:0] bus_mosi, 14 15 input wire [15:0] bus_miso, 16 input wire bus_busy, 36 17 37 18 output wire led … … 39 20 40 21 reg [23:0] led_counter; 41 reg [19:0] ram_counter; 42 reg [10:0] tst_counter; 43 reg [15:0] int_addr, int_max_addr; 22 23 reg int_bus_wren; 24 reg [31:0] int_bus_addr; 25 reg [31:0] int_bus_cntr; 26 reg [15:0] int_bus_mosi; 44 27 45 28 reg int_rdreq, int_wrreq; 46 reg int_type, int_reset;47 reg [1:0] int_chan, int_byte, int_max_byte;48 29 reg [7:0] int_data; 49 30 reg int_led; 50 31 51 reg [15:0] int_i2c_data;52 reg int_i2c_wrreq;53 54 reg [47:0] int_ept_data;55 56 reg int_cfg_reset;57 reg [15:0] int_dst_data, int_dst_addr;58 59 wire crc_error = 1'b0;60 reg crc_reset;61 32 reg [1:0] byte_counter; 62 33 reg [4:0] idle_counter; 63 34 64 35 reg [4:0] state; 65 66 wire [15:0] src, dst; 36 37 reg [31:0] address, counter; 38 39 reg [15:0] prefix; 40 41 wire [15:0] dest, data; 67 42 68 43 reg [7:0] buffer [3:0]; 69 44 70 assign src = (buffer[0][7]) ? cfg_src_data : {buffer[2], buffer[3]}; 71 assign dst = {1'b0, buffer[0][6:0], buffer[1]}; 72 73 reg int_ram_we; 74 reg [17:0] int_ram_data; 75 wire [17:0] int_ram_q; 76 wire [17:0] opt_ram_we; 77 assign ram_we = ~int_ram_we; 78 assign int_ram_q = ram_data; 79 // assign ram_data = int_ram_we ? int_ram_data : 18'bz; 80 // assign ram_addr = {ram_counter[18:5],1'd0,ram_counter[4:0]}; 81 assign ram_addr = ram_counter; 82 83 genvar j; 84 generate 85 for (j = 0; j < 18; j = j + 1) 86 begin : SRAM_WE 87 assign opt_ram_we[j] = int_ram_we; 88 assign ram_data[j] = opt_ram_we[j] ? int_ram_data[j] : 1'bz; 89 end 90 endgenerate 91 92 always @(posedge clk) 45 assign dest = {buffer[0], buffer[1]}; 46 assign data = {buffer[2], buffer[3]}; 47 48 always @(posedge clock) 93 49 begin 94 50 if (~rx_empty) … … 114 70 int_rdreq <= 1'b1; 115 71 int_wrreq <= 1'b0; 116 int_type <= 1'b0;117 int_chan <= 2'd0;118 int_byte <= 2'd0;119 int_reset <= 1'b0;120 crc_reset <= 1'b0;121 int_ram_we <= 1'b0;122 int_ram_data <= 16'd0;123 ram_counter <= 20'd0;124 72 idle_counter <= 5'd0; 125 73 byte_counter <= 2'd0; 126 int_cfg_reset <= 1'b0;127 74 state <= 5'd1; 128 75 end … … 130 77 1: 131 78 begin 132 // read 8bytes79 // read 4 bytes 133 80 if (~rx_empty) 134 81 begin … … 148 95 begin 149 96 int_rdreq <= 1'b0; 150 crc_reset <= 1'b1;151 97 state <= 5'd0; 152 98 end … … 156 102 2: 157 103 begin 158 crc_reset <= 1'b1; 159 if (~crc_error) 160 begin 161 int_dst_addr <= dst; 162 int_dst_data <= src; 163 // memory[dst[3:0]] <= src; 164 165 case (dst) 166 16'h0000: 167 begin 168 int_cfg_reset <= 1'b1; 169 state <= 5'd0; 170 end 171 172 16'h0001: 173 begin 174 int_type <= src[4]; 175 int_chan <= src[1:0]; 176 int_reset <= 1'b1; 177 state <= 5'd0; 178 end 179 180 16'h0002: 181 begin 182 int_type <= src[4]; 183 int_chan <= src[1:0]; 184 state <= 5'd3; 185 end 186 187 16'h0003: 188 begin 189 tst_counter <= 11'd0; 190 state <= 5'd7; 191 end 192 16'h0004: 193 begin 194 int_ram_we <= 1'b1; 195 int_ram_data <= 18'd0; 196 ram_counter <= 20'd0; 197 state <= 5'd10; 198 end 199 16'h0005: 200 begin 201 int_i2c_data <= src; 202 int_i2c_wrreq <= 1'b1; 203 state <= 5'd16; 204 end 205 16'h0006: 206 begin 207 int_ram_we <= 1'b1; 208 int_ram_data <= 18'd0; 209 ram_counter <= 20'd0; 210 state <= 5'd17; 211 end 212 213 default: 214 begin 215 state <= 5'd0; 216 end 217 endcase 218 end 219 end 220 221 // mux transfer 104 case (dest) 105 16'h0000: 106 begin 107 // reset 108 prefix <= 16'd0; 109 state <= 5'd0; 110 end 111 112 113 16'h0001: 114 begin 115 // prefix register 116 prefix <= data; 117 state <= 5'd0; 118 end 119 120 121 16'h0002: 122 begin 123 // address register 124 address <= {prefix, data}; 125 prefix <= 16'd0; 126 state <= 5'd0; 127 end 128 129 16'h0003: 130 begin 131 // counter register 132 counter <= {prefix, data}; 133 prefix <= 16'd0; 134 state <= 5'd0; 135 end 136 137 16'h0004: 138 begin 139 // single write 140 int_bus_addr <= address; 141 int_bus_mosi <= data; 142 int_bus_wren <= 1'b1; 143 prefix <= 16'd0; 144 state <= 5'd3; 145 end 146 147 16'h0005: 148 begin 149 // multi read 150 int_bus_addr <= address; 151 int_bus_cntr <= counter; 152 int_bus_wren <= 1'b0; 153 prefix <= 16'd0; 154 state <= 5'd4; 155 end 156 157 default: 158 begin 159 prefix <= 16'd0; 160 state <= 5'd0; 161 end 162 endcase 163 end 164 165 // single write 222 166 3: 223 167 begin 224 crc_reset <= 1'b0; 225 int_addr <= mux_min_addr; 226 int_max_addr <= mux_min_addr + mux_max_addr; 227 int_max_byte <= mux_max_byte; 228 int_byte <= 2'd0; 229 state <= 5'd4; 230 end 231 168 if (~bus_busy) 169 begin 170 int_bus_addr <= 32'd0; 171 int_bus_mosi <= 16'd0; 172 int_bus_wren <= 1'b0; 173 state <= 5'd0; 174 end 175 end 176 177 // multi read 232 178 4: 233 179 begin 234 int_wrreq <= 1'b0; 235 state <= 5'd5; 180 if (bus_busy) 181 begin 182 buffer[0] <= 8'd1; 183 buffer[1] <= 8'd0; 184 int_bus_cntr <= 32'd0; 185 state <= 5'd7; 186 end 187 else 188 begin 189 buffer[0] <= 8'd2; 190 buffer[1] <= 8'd0; 191 state <= 5'd6; 192 end 236 193 end 237 194 238 195 5: 239 196 begin 197 buffer[0] <= bus_miso[7:0]; 198 buffer[1] <= bus_miso[15:8]; 240 199 state <= 5'd6; 241 200 end … … 243 202 6: 244 203 begin 204 int_bus_addr <= int_bus_addr + 32'd1; 205 state <= 5'd7; 206 end 207 208 7: 209 begin 245 210 if (~tx_full) 246 211 begin 247 int_data <= mux_q;212 int_data <= buffer[0]; 248 213 int_wrreq <= 1'b1; 249 if ((int_byte == int_max_byte) && (int_addr == int_max_addr)) 250 begin 251 state <= 5'd0; 214 state <= 5'd8; 215 end 216 end 217 218 8: 219 begin 220 int_data <= buffer[1]; 221 state <= 5'd9; 222 end 223 224 9: 225 begin 226 if (~tx_full) 227 begin 228 int_wrreq <= 1'b0; 229 if (|int_bus_cntr) 230 begin 231 state <= 5'd5; 232 int_bus_cntr <= int_bus_cntr - 32'd1; 252 233 end 253 234 else 254 235 begin 255 state <= 5'd4; 256 if (int_byte == int_max_byte) 257 begin 258 int_addr <= int_addr + 16'd1; 259 int_byte <= 2'd0; 260 end 261 else 262 begin 263 int_byte <= int_byte + 2'd1; 264 end 265 end 266 end 267 end 268 269 // tst transfer 270 7: 271 begin 272 crc_reset <= 1'b0; 273 int_data <= tst_counter; 274 int_wrreq <= 1'b1; 275 tst_counter <= tst_counter + 11'd1; 276 state <= 5'd8; 277 end 278 8: 279 begin 280 if (~tx_full) 281 begin 282 int_data <= tst_counter; 283 if (&tst_counter) 284 begin 285 state <= 5'd9; 286 end 287 else 288 begin 289 tst_counter <= tst_counter + 11'd1; 290 end 291 end 292 end 293 9: 294 begin 295 if (~tx_full) 296 begin 297 int_wrreq <= 1'b0; 298 state <= 5'd0; 299 end 300 end 301 // ram transfer 302 10: 303 begin 304 crc_reset <= 1'b0; 305 state <= 5'd11; 306 end 307 11: 308 begin 309 int_ram_data[8:1] <= ram_counter[7:0]; 310 // int_ram_data[8:1] <= 8'd0; 311 if (&ram_counter[18:0]) 312 begin 313 state <= 5'd12; 314 end 315 else 316 begin 317 state <= 5'd10; 318 ram_counter <= ram_counter + 20'd1; 319 end 320 end 321 12: 322 begin 323 int_ram_we <= 1'b0; 324 int_ram_data <= 18'd0; 325 ram_counter <= 20'd0; 326 state <= 5'd13; 327 end 328 13: 329 begin 330 int_wrreq <= 1'b0; 331 state <= 5'd14; 332 end 333 14: 334 begin 335 state <= 5'd15; 336 end 337 15: 338 begin 339 if (~tx_full) 340 begin 341 int_data <= int_ram_q[8:1]; 342 int_wrreq <= 1'b1; 343 if (&ram_counter[18:0]) 344 begin 345 state <= 5'd0; 346 end 347 else 348 begin 349 state <= 5'd13; 350 ram_counter <= ram_counter + 20'd1; 351 end 352 end 353 end 354 355 // i2c write 356 16: 357 begin 358 crc_reset <= 1'b0; 359 if (~i2c_full) 360 begin 361 int_i2c_wrreq <= 1'b0; 362 state <= 5'd0; 363 end 364 end 365 366 // long sample transfer 367 17: 368 begin 369 crc_reset <= 1'b0; 370 if (ept_data_ready) 371 begin 372 ram_counter <= ram_counter + 20'd1; 373 int_ept_data <= ept_data; 374 state <= 5'd18; 375 end 376 end 377 18: 378 begin 379 int_ram_data[8:1] <= int_ept_data[7:0]; 380 int_ram_data[17:10] <= int_ept_data[15:8]; 381 ram_counter <= ram_counter + 20'd1; 382 state <= 5'd19; 383 end 384 19: 385 begin 386 int_ram_data[8:1] <= int_ept_data[23:16]; 387 int_ram_data[17:10] <= int_ept_data[31:24]; 388 ram_counter <= ram_counter + 20'd1; 389 state <= 5'd20; 390 end 391 392 20: 393 begin 394 int_ram_data[8:1] <= int_ept_data[39:32]; 395 int_ram_data[17:10] <= int_ept_data[47:40]; 396 if (&ram_counter) 397 begin 398 int_ram_we <= 1'b0; 399 ram_counter <= 19'd0; 400 state <= 5'd21; 401 end 402 else 403 begin 404 state <= 5'd17; 405 end 406 end 407 408 21: 409 begin 410 int_wrreq <= 1'b0; 411 state <= 5'd22; 412 end 413 414 22: 415 begin 416 state <= 5'd23; 417 end 418 419 23: 420 begin 421 if (~tx_full) 422 begin 423 int_data <= int_ram_q[8:1]; 424 int_wrreq <= 1'b1; 425 state <= 5'd24; 426 end 427 end 428 429 24: 430 begin 431 int_data <= int_ram_q[17:10]; 432 state <= 5'd25; 433 end 434 435 25: 436 begin 437 if (~tx_full) 438 begin 439 int_wrreq <= 1'b0; 440 if (&ram_counter) 441 begin 442 state <= 5'd0; 443 end 444 else 445 begin 446 state <= 5'd21; 447 ram_counter <= ram_counter + 20'd1; 236 state <= 5'd0; 448 237 end 449 238 end … … 456 245 endcase 457 246 end 458 459 assign cfg_reset = int_cfg_reset; 460 assign cfg_src_addr = {buffer[2], buffer[3]}; 461 assign cfg_dst_data = int_dst_data; 462 assign cfg_dst_addr = int_dst_addr; 463 assign mux_reset = int_reset; 464 assign mux_type = int_type; 465 assign mux_chan = int_chan; 466 assign mux_byte = int_byte; 467 assign mux_addr = int_addr; 247 248 assign bus_wren = int_bus_wren; 249 assign bus_addr = int_bus_addr; 250 assign bus_mosi = int_bus_mosi; 468 251 assign rx_rdreq = int_rdreq & (~rx_empty); 469 252 assign tx_wrreq = int_wrreq & (~tx_full); 470 253 assign tx_data = int_data; 471 assign i2c_wrreq = int_i2c_wrreq;472 assign i2c_data = int_i2c_data;473 254 assign led = int_led; 474 255
Note:
See TracChangeset
for help on using the changeset viewer.