@@ -24,6 +24,7 @@ module XC2CJTAG(
24
24
tdi, tms, tck, tdo,
25
25
config_erase,
26
26
config_read_addr, config_read_data,
27
+ config_write_en, config_write_addr, config_write_data,
27
28
28
29
debug_led, debug_gpio);
29
30
@@ -49,9 +50,14 @@ module XC2CJTAG(
49
50
// Status signals to the configuration memory
50
51
output reg config_erase = 0 ; // Erases all config memory
51
52
// This takes 100 ms IRL but for now we'll model it instantly
52
- output reg [ADDR_BITS- 1 :0 ] config_read_addr = 0 ; // Address for reading the bitstream (real, not gray code)
53
+
54
+ output reg [ADDR_BITS- 1 :0 ] config_read_addr = 0 ; // Address for reading the bitstream (real, not gray code)
53
55
input wire [SHREG_WIDTH- 1 :0 ] config_read_data;
54
56
57
+ output reg config_write_en = 0 ;
58
+ output reg [ADDR_BITS- 1 :0 ] config_write_addr = 0 ;
59
+ output reg [SHREG_WIDTH- 1 :0 ] config_write_data = 0 ;
60
+
55
61
output reg [3 :0 ] debug_led = 0 ;
56
62
output reg [7 :0 ] debug_gpio = 0 ;
57
63
@@ -275,6 +281,12 @@ module XC2CJTAG(
275
281
configured <= 0 ;
276
282
end
277
283
284
+ // DEBUG: declare us configured as soon as we get a PROGRAM instruction
285
+ // TODO: check DONE / transfer bits first
286
+ if (ir_shreg == INST_ISC_PROGRAM) begin
287
+ configured <= 1 ;
288
+ end
289
+
278
290
// TODO: copy EEPROM to RAM when we get an ISC_INIT command
279
291
280
292
end // end STATE_UPDATE_IR
@@ -487,6 +499,51 @@ module XC2CJTAG(
487
499
488
500
end
489
501
502
+ // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
503
+ // Config memory writes
504
+
505
+ reg [SHREG_WIDTH + ADDR_BITS - 1 : 0 ] isc_write_shreg = 0 ;
506
+
507
+ // Gray coded write address: left N bits of the shift register
508
+ wire [ADDR_BITS- 1 :0 ] isc_write_addr_gray = isc_write_shreg[SHREG_WIDTH + : ADDR_BITS];
509
+
510
+ // Convert Gray code to normal
511
+ reg [ADDR_BITS- 1 :0 ] isc_write_addr_normal;
512
+ always @(* ) begin
513
+ isc_write_addr_normal[ADDR_BITS- 1 ] <= isc_write_addr_gray[ADDR_BITS- 1 ];
514
+ for (i= ADDR_BITS- 2 ; i>= 0 ; i= i- 1 )
515
+ isc_write_addr_normal[i] <= isc_write_addr_gray[i] ^ isc_write_addr_normal[i+ 1 ];
516
+ end
517
+
518
+ always @(posedge tck) begin
519
+
520
+ config_write_en <= 0 ;
521
+
522
+ if (ir == INST_ISC_PROGRAM) begin
523
+ case (state)
524
+
525
+ // Capture data is ignored
526
+ STATE_CAPTURE_DR: begin
527
+ isc_write_shreg <= 0 ;
528
+ end // end STATE_CAPTURE_DR
529
+
530
+ // Read the new bitstream
531
+ STATE_SHIFT_DR: begin
532
+ isc_write_shreg <= {tdi, isc_write_shreg[SHREG_WIDTH + ADDR_BITS - 1 : 1 ]};
533
+ end // end STATE_SHIFT_DR
534
+
535
+ // Update: commit the write to bitstream
536
+ STATE_UPDATE_DR: begin
537
+ config_write_en <= 1 ;
538
+ config_write_addr <= isc_write_addr_normal;
539
+ config_write_data <= isc_write_shreg[SHREG_WIDTH- 1 : 0 ];
540
+ end // end STATE_UPDATE_DR
541
+
542
+ endcase
543
+ end
544
+
545
+ end
546
+
490
547
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
491
548
// TDO muxing
492
549
@@ -501,9 +558,10 @@ module XC2CJTAG(
501
558
// DR stuff
502
559
else if (state == STATE_SHIFT_DR) begin
503
560
case (ir)
504
- INST_BYPASS: tdo <= bypass_shreg;
505
- INST_IDCODE: tdo <= idcode_shreg[0 ];
506
- INST_ISC_READ: tdo <= isc_read_shreg[0 ];
561
+ INST_BYPASS: tdo <= bypass_shreg;
562
+ INST_IDCODE: tdo <= idcode_shreg[0 ];
563
+ INST_ISC_READ: tdo <= isc_read_shreg[0 ];
564
+ INST_ISC_PROGRAM: tdo <= isc_write_shreg[0 ];
507
565
endcase
508
566
end
509
567
0 commit comments