Skip to content

Commit 7ba4c26

Browse files
committedJun 14, 2017
Initial work on bitstream programming. Not yet tested in hardware since it doesn't fit on my Zybo. Need to grab more JTAG dongles and test on an XC7A100T
1 parent ba95711 commit 7ba4c26

File tree

2 files changed

+84
-17
lines changed

2 files changed

+84
-17
lines changed
 

Diff for: ‎hdl/xc2c-model/XC2CDevice.v

+22-13
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ module XC2CDevice(
124124
integer i;
125125
initial begin
126126
for(i=0; i<MEM_DEPTH; i=i+1)
127-
//ram_bitstream[i] <= {SHREG_WIDTH{1'b1}}; //copied from blank EEPROM = all 1s
128-
ram_bitstream[i] <= {SHREG_WIDTH{1'b0}}; //default initial value
127+
ram_bitstream[i] <= {SHREG_WIDTH{1'b1}}; //copied from blank EEPROM = all 1s
129128
end
130129

131130
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -140,10 +139,26 @@ module XC2CDevice(
140139
wire[ADDR_BITS-1:0] config_read_addr;
141140
reg[SHREG_WIDTH-1:0] config_read_data = 0;
142141

143-
//Read the EEPROM
142+
wire config_write_en;
143+
wire[ADDR_BITS-1:0] config_write_addr;
144+
wire[SHREG_WIDTH-1:0] config_write_data;
145+
146+
//Read/write the EEPROM
144147
//TODO: add read enable?
145148
always @(posedge jtag_tck) begin
146149
config_read_data <= ram_bitstream[config_read_addr];
150+
151+
if(config_write_en)
152+
ram_bitstream[config_write_addr] <= config_write_data;
153+
154+
//Wipe the config memory
155+
//TODO: pipeline this or are we OK in one cycle?
156+
//If we go multicycle, how do we handle this with no clock? Real chip is self-timed internally
157+
if(config_erase) begin
158+
for(i=0; i<MEM_DEPTH; i=i+1)
159+
ram_bitstream[i] <= {SHREG_WIDTH{1'b1}};
160+
end
161+
147162
end
148163

149164
XC2CJTAG #(
@@ -161,20 +176,14 @@ module XC2CDevice(
161176
.config_read_addr(config_read_addr),
162177
.config_read_data(config_read_data),
163178

179+
.config_write_en(config_write_en),
180+
.config_write_addr(config_write_addr),
181+
.config_write_data(config_write_data),
182+
164183
.debug_led(debug_led),
165184
.debug_gpio(debug_gpio)
166185
);
167186

168-
always @(posedge jtag_tck) begin
169-
170-
//Wipe the config memory when asked
171-
//TODO: pipeline this or are we OK in one cycle?
172-
if(config_erase) begin
173-
for(i=0; i<MEM_DEPTH; i=i+1)
174-
ram_bitstream[i] <= {SHREG_WIDTH{1'b1}};
175-
end
176-
177-
end
178187

179188
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
180189
// The actual CPLD function blocks

Diff for: ‎hdl/xc2c-model/XC2CJTAG.v

+62-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module XC2CJTAG(
2424
tdi, tms, tck, tdo,
2525
config_erase,
2626
config_read_addr, config_read_data,
27+
config_write_en, config_write_addr, config_write_data,
2728

2829
debug_led, debug_gpio);
2930

@@ -49,9 +50,14 @@ module XC2CJTAG(
4950
//Status signals to the configuration memory
5051
output reg config_erase = 0; //Erases all config memory
5152
//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)
5355
input wire[SHREG_WIDTH-1:0] config_read_data;
5456

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+
5561
output reg[3:0] debug_led = 0;
5662
output reg[7:0] debug_gpio = 0;
5763

@@ -275,6 +281,12 @@ module XC2CJTAG(
275281
configured <= 0;
276282
end
277283

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+
278290
//TODO: copy EEPROM to RAM when we get an ISC_INIT command
279291

280292
end //end STATE_UPDATE_IR
@@ -487,6 +499,51 @@ module XC2CJTAG(
487499

488500
end
489501

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+
490547
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
491548
// TDO muxing
492549

@@ -501,9 +558,10 @@ module XC2CJTAG(
501558
//DR stuff
502559
else if(state == STATE_SHIFT_DR) begin
503560
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];
507565
endcase
508566
end
509567

0 commit comments

Comments
 (0)
Please sign in to comment.