- Timestamp:
- Nov 19, 2009, 12:09:21 AM (15 years ago)
- Location:
- trunk/MultiChannelUSB
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/Paella.v
r63 r65 42 42 43 43 // Turn output ports off 44 /* 44 45 assign RAM_CLK = 1'b0; 45 46 assign RAM_CE1 = 1'b0; 46 47 assign RAM_WE = 1'b0; 47 48 assign RAM_ADDR = 20'h00000; 49 */ 50 assign RAM_CLK = CLK_50MHz; 51 assign RAM_CE1 = 1'b0; 48 52 49 53 // Turn inout ports to tri-state … … 55 59 assign USB_PA3 = 1'bz; 56 60 assign USB_PA7 = 1'bz; 57 assign RAM_DQAP = 1'bz;58 assign RAM_DQA = 8'bz;59 assign RAM_DQBP = 1'bz;60 assign RAM_DQB = 8'bz;61 // assign RAM_DQAP = 1'bz; 62 // assign RAM_DQA = 8'bz; 63 // assign RAM_DQBP = 1'bz; 64 // assign RAM_DQB = 8'bz; 61 65 62 66 assign USB_PA2 = ~usb_rden; … … 300 304 endcase 301 305 end 302 306 303 307 control control_unit ( 304 308 .clk(CLK_50MHz), … … 318 322 .tx_wrreq(usb_tx_wrreq), 319 323 .tx_data(usb_tx_data), 324 .ram_we(RAM_WE), 325 .ram_addr(RAM_ADDR), 326 .ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}), 320 327 .led(LED)); 321 328 -
trunk/MultiChannelUSB/control.v
r59 r65 16 16 output wire tx_wrreq, 17 17 output wire [7:0] tx_data, 18 output wire ram_we, 19 output wire [19:0] ram_addr, 20 inout wire [17:0] ram_data, 18 21 output wire led 19 22 ); 20 23 21 reg [23:0] rx_counter; 24 reg [23:0] led_counter; 25 reg [18:0] ram_counter; 22 26 reg [10:0] tst_counter; 23 27 reg [15:0] int_addr, int_max_addr; … … 30 34 31 35 36 wire crc_error = 1'b0; 37 reg crc_reset; 38 reg [2:0] byte_counter; 39 reg [4:0] idle_counter; 40 32 41 reg [3:0] state; 42 43 wire [15:0] src, dst; 44 45 reg [15:0] memory [15:0]; 46 reg [7:0] buffer [7:0]; 47 48 assign src = (buffer[0][7]) ? memory[buffer[3][3:0]] : {buffer[2], buffer[3]}; 49 assign dst = {1'b0, buffer[0][6:0], buffer[1]}; 50 51 reg int_ram_we; 52 reg [17:0] int_ram_data; 53 wire [17:0] int_ram_q; 54 wire [17:0] opt_ram_we; 55 assign ram_we = ~int_ram_we; 56 assign int_ram_q = ram_data; 57 // assign ram_data = int_ram_we ? int_ram_data : 18'bz; 58 assign ram_addr = {ram_counter[18:5],1'd0,ram_counter[4:0]}; 59 60 genvar j; 61 generate 62 for (j = 0; j < 18; j = j + 1) 63 begin : SRAM_WE 64 assign opt_ram_we[j] = int_ram_we; 65 assign ram_data[j] = opt_ram_we[j] ? int_ram_data[j] : 1'bz; 66 end 67 endgenerate 33 68 34 69 always @(posedge clk) … … 37 72 begin 38 73 int_led <= 1'b0; 39 rx_counter <= 24'd0;74 led_counter <= 24'd0; 40 75 end 41 76 else 42 77 begin 43 if (& rx_counter)78 if (&led_counter) 44 79 begin 45 80 int_led <= 1'b1; … … 47 82 else 48 83 begin 49 rx_counter <= rx_counter + 24'd1;84 led_counter <= led_counter + 24'd1; 50 85 end 51 86 end 52 87 53 88 case(state) 54 1:89 0: 55 90 begin 56 91 int_rdreq <= 1'b1; … … 60 95 int_byte <= 2'd0; 61 96 int_reset <= 1'b0; 62 state <= 4'd2; 63 end 64 97 crc_reset <= 1'b0; 98 int_ram_we <= 1'b0; 99 int_ram_data <= 16'd0; 100 ram_counter <= 19'd0; 101 idle_counter <= 5'd0; 102 byte_counter <= 3'd0; 103 state <= 4'd1; 104 end 105 106 1: 107 begin 108 // read 8 bytes 109 if (~rx_empty) 110 begin 111 idle_counter <= 5'd0; 112 byte_counter <= byte_counter + 3'd1; 113 buffer[byte_counter] <= rx_data; 114 if (&byte_counter) 115 begin 116 int_rdreq <= 1'b0; 117 state <= 4'd2; 118 end 119 end 120 else if(|byte_counter) 121 begin 122 idle_counter <= idle_counter + 5'd1; 123 if (&idle_counter) 124 begin 125 int_rdreq <= 1'b0; 126 crc_reset <= 1'b1; 127 state <= 4'd0; 128 end 129 end 130 end 131 65 132 2: 66 133 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]; 134 crc_reset <= 1'b1; 135 if (~crc_error) 136 begin 137 memory[dst[3:0]] <= src; 138 139 case (dst) 140 16'h0000: 141 begin 142 state <= 4'd0; 143 end 144 145 16'h0001: 146 begin 147 int_type <= src[4]; 148 int_chan <= src[1:0]; 75 149 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]; 150 state <= 4'd0; 151 end 152 153 16'h0002: 154 begin 155 int_type <= src[4]; 156 int_chan <= src[1:0]; 84 157 state <= 4'd3; 85 158 end 86 159 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; 160 16'h0003: 161 begin 96 162 tst_counter <= 11'd0; 97 163 state <= 4'd6; 98 164 end 165 16'h0004: 166 begin 167 int_ram_we <= 1'b1; 168 int_ram_data <= 18'd0; 169 ram_counter <= 19'd0; 170 state <= 4'd9; 171 end 99 172 endcase 100 173 end 101 174 end 175 102 176 // mux transfer 103 177 3: 104 178 begin 179 crc_reset <= 1'b0; 105 180 int_addr <= mux_min_addr; 106 181 int_max_addr <= mux_min_addr + mux_max_addr; … … 124 199 if ((int_byte == int_max_byte) && (int_addr == int_max_addr)) 125 200 begin 126 state <= 4'd 1;201 state <= 4'd0; 127 202 end 128 203 else … … 145 220 6: 146 221 begin 222 crc_reset <= 1'b0; 147 223 int_data <= tst_counter; 148 224 int_wrreq <= 1'b1; 149 225 tst_counter <= tst_counter + 11'd1; 150 state <= 4'd 8;226 state <= 4'd7; 151 227 end 152 228 7: … … 155 231 begin 156 232 int_data <= tst_counter; 157 if ( tst_counter == 11'd0)158 begin 159 state <= 4'd 9;233 if (&tst_counter) 234 begin 235 state <= 4'd8; 160 236 end 161 237 else … … 170 246 begin 171 247 int_wrreq <= 1'b0; 172 state <= 4'd1; 248 state <= 4'd0; 249 end 250 end 251 // ram transfer 252 9: 253 begin 254 crc_reset <= 1'b0; 255 state <= 4'd10; 256 end 257 10: 258 begin 259 int_ram_data[8:1] <= ram_counter[7:0]; 260 // int_ram_data[8:1] <= 8'd0; 261 if (&ram_counter) 262 begin 263 state <= 4'd11; 264 end 265 else 266 begin 267 state <= 4'd9; 268 ram_counter <= ram_counter + 19'd1; 269 end 270 end 271 11: 272 begin 273 int_ram_we <= 1'b0; 274 int_ram_data <= 18'd0; 275 ram_counter <= 19'd0; 276 state <= 4'd12; 277 end 278 12: 279 begin 280 int_wrreq <= 1'b0; 281 state <= 4'd13; 282 end 283 13: 284 begin 285 state <= 4'd14; 286 end 287 14: 288 begin 289 if (~tx_full) 290 begin 291 int_data <= int_ram_q[8:1]; 292 int_wrreq <= 1'b1; 293 if (&ram_counter) 294 begin 295 state <= 4'd0; 296 end 297 else 298 begin 299 state <= 4'd12; 300 ram_counter <= ram_counter + 19'd1; 301 end 173 302 end 174 303 end … … 176 305 default: 177 306 begin 178 state <= 4'd 1;307 state <= 4'd0; 179 308 end 180 309 endcase
Note:
See TracChangeset
for help on using the changeset viewer.