@@ -90,28 +90,53 @@ module XC2CBitstream(
90
90
// TODO
91
91
92
92
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
93
- // JTAG access
93
+ // JTAG access - we have a separate, untouched copy of the raw bitstream (including transfer bits etc) for readouts
94
+
95
+ // KNOWN ISSUE: partial bitstream writes after an erase are not correctly emulated by this code.
96
+ // The entire bitstream must be written in one go to get correct readback.
97
+ // Note that actual device behavior is correct, only readback is busticated.
98
+ reg read_as_blank = 0 ;
99
+
100
+ reg [SHREG_WIDTH- 1 :0 ] config_read_data_raw = 0 ;
101
+ reg [SHREG_WIDTH- 1 :0 ] ram_bitstream_for_readback[MEM_DEPTH- 1 :0 ];
102
+
103
+ initial begin
104
+ for (row= 0 ; row< MEM_DEPTH; row= row+ 1 )
105
+ ram_bitstream_for_readback[row] <= {SHREG_WIDTH{1'b1 }}; // copied from blank EEPROM = all 1s
106
+ end
94
107
95
108
// Read/write the EEPROM
96
109
// TODO: add read enable?
97
110
always @(posedge jtag_tck) begin
98
111
99
112
if (config_read_en)
100
- config_read_data <= ram_bitstream [config_read_addr];
113
+ config_read_data_raw <= ram_bitstream_for_readback [config_read_addr];
101
114
102
- if (config_write_en)
103
- ram_bitstream[config_write_addr] <= config_write_data;
115
+ if (config_write_en) begin
116
+ ram_bitstream[config_write_addr] <= config_write_data;
117
+ ram_bitstream_for_readback[config_write_addr] <= config_write_data;
118
+ read_as_blank <= 0 ;
119
+ end
104
120
105
121
// Wipe the config memory
106
122
// TODO: go multicycle?
107
123
// If we go multicycle, how do we handle this with no clock? Real chip is self-timed internally
108
124
if (config_erase) begin
125
+ read_as_blank <= 1 ;
109
126
for (row= 0 ; row< MEM_DEPTH; row= row+ 1 )
110
- ram_bitstream[row] <= {SHREG_WIDTH{1'b1 }};
127
+ ram_bitstream[row] <= {SHREG_WIDTH{1'b1 }};
111
128
end
112
129
113
130
end
114
131
132
+ // Muxing for readout
133
+ always @(* ) begin
134
+ if (read_as_blank)
135
+ config_read_data <= {SHREG_WIDTH{1'b1 }};
136
+ else
137
+ config_read_data <= config_read_data_raw;
138
+ end
139
+
115
140
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116
141
// Shuffle the bitstream out to various IP blocks
117
142
0 commit comments