@@ -37,6 +37,7 @@ module top(
37
37
38
38
wire reset = 0 ;
39
39
40
+ /*
40
41
reg [31:0] counter;
41
42
always @(posedge clk_48)
42
43
counter <= counter + 1;
@@ -45,6 +46,9 @@ module top(
45
46
wire pwm_g;
46
47
pwm pwm_g_driver(clk_48, 1, pwm_g);
47
48
assign led_g = !(counter[25:23] == 0 && pwm_g);
49
+ */
50
+ assign led_g = 1 ;
51
+
48
52
49
53
// generate a 3 MHz/12 MHz serial clock from the 48 MHz clock
50
54
// this is the 3 Mb/s maximum supported by the FTDI chip
@@ -81,7 +85,17 @@ module top(
81
85
82
86
assign debug0 = serial_txd;
83
87
*/
88
+
89
+ // Emlated 256 bytes of flash ROM
90
+ reg [23 :0 ] read_addr;
91
+ reg [7 :0 ] flash_rom[0 :255 ];
92
+ wire [7 :0 ] flash_data = flash_rom[read_addr[7 :0 ]];
93
+
94
+ // initialize the flash_rom
95
+ initial $readmemb ("flash.bin" , flash_rom);
96
+
84
97
// Connect the SPI port to the decoder
98
+ reg spi_tx_strobe;
85
99
wire spi_rx_strobe;
86
100
wire [7 :0 ] spi_rx_data;
87
101
@@ -98,47 +112,35 @@ module top(
98
112
*/
99
113
100
114
wire spi_cs_in = gpio_36;
101
- /*
102
- SB_IO #(
103
- .PIN_TYPE(1), // input
104
- .PULLUP(1), // pullup enabled
105
- ) spi_cs_buffer (
106
- .PACKAGE_PIN(gpio_36),
107
- .D_IN_0(spi_cs_in)
108
- );
109
- */
110
115
111
116
// copy the incoming CS pin to the outbound CS
112
117
assign gpio_43 = gpio_36;
113
118
114
- spi_device #(.MONITOR( 1 )) spi0 (
119
+ spi_device spi0 (
115
120
.mclk(clk_48),
116
121
.reset(reset),
117
122
.spi_cs(spi_cs_in),
118
123
.spi_clk(gpio_28),
119
124
.spi_mosi(gpio_38),
120
- .spi_miso(gpio_42),
125
+ .spi_miso_in(gpio_42),
126
+ // .spi_miso_out(),
127
+ .spi_tx_data(flash_data),
128
+ .spi_tx_strobe(spi_tx_strobe),
121
129
.spi_rx_strobe(spi_rx_strobe),
122
130
.spi_rx_data(spi_rx_data)
123
131
);
124
132
125
133
reg [12 :0 ] bytes;
126
- reg newline;
127
- reg spi_ready;
134
+ reg [15 :0 ] serial_out;
135
+ reg do_serial;
136
+ reg do_hex;
128
137
reg spi_cs_buf;
129
138
reg spi_cs_prev;
130
139
reg spi_cs_sync;
131
140
132
141
assign led_b = spi_cs_sync; // idles high
133
142
134
143
reg read_in_progress;
135
- reg [23 :0 ] read_addr;
136
- reg [7 :0 ] flash_rom[0 :255 ];
137
- wire [7 :0 ] flash_data = flash_rom[read_addr[7 :0 ]];
138
-
139
- // initialize the flash_rom
140
- initial $readmemb ("flash.bin" , flash_rom);
141
-
142
144
// watch for new commands on the SPI bus, print first x bytes
143
145
always @(posedge clk_48)
144
146
begin
@@ -148,8 +150,8 @@ module top(
148
150
spi_cs_sync <= spi_cs_prev;
149
151
150
152
// Default is no output from the SPI bus
151
- newline <= 0 ;
152
- spi_ready <= 0 ;
153
+ do_serial <= 0 ;
154
+ do_hex <= 0 ;
153
155
154
156
if (reset) begin
155
157
// nothing to do
@@ -158,54 +160,63 @@ module top(
158
160
// falling edge of the CS, reset the transaction
159
161
bytes <= 0 ;
160
162
if (read_in_progress) begin
161
- newline <= 1 ;
162
- spi_ready <= 1 ;
163
+ serial_out = " \r\n " ;
164
+ do_serial <= 1 ;
163
165
end
164
166
read_in_progress <= 0 ;
165
167
end else
166
168
if (spi_cs_sync && !spi_cs_prev) begin
167
169
// rising edge of the CS, send newline if we
168
170
// have received a non-zero number of bytes
169
- if (read_in_progress) begin
170
- newline <= 1 ;
171
- spi_ready <= 1 ;
172
- end
173
171
read_in_progress <= 0 ;
174
172
end else
175
173
if (spi_rx_strobe) begin
176
174
// new byte on the wire; print the first four bytes
177
175
// parse the command in the first byte
178
176
if (bytes == 0 && spi_rx_data == 3 ) begin
179
- // spi_ready <= 1;
180
177
read_in_progress <= 1 ;
181
178
end else
182
179
if (bytes <= 3 && read_in_progress)
183
180
begin
184
- spi_ready <= 1 ;
185
181
read_addr <= { read_addr[15 :8 ], spi_rx_data };
186
- // if (bytes == 3 && read_addr[
182
+ do_serial <= 1 ;
183
+ do_hex <= 1 ;
187
184
end else
188
185
if (read_in_progress)
189
186
begin
190
- spi_tx_data <= flash_rom[read_addr];
191
187
read_addr <= read_addr + 1 ;
192
188
end
193
189
194
190
bytes <= bytes + 1 ;
191
+ end else begin
192
+ /*
193
+ if (read_addr == 24'hFFB880) begin
194
+ // disable flash address overlays
195
+ do_overlay <= 0;
196
+ do_serial <= 1;
197
+ serial_out <= "--";
198
+ end else
199
+ if (read_addr == 24'hFFB800) begin
200
+ // enable overlay
201
+ do_overlay <= 1;
202
+ do_serial <= 1;
203
+ serial_out <= "++";
204
+ end
205
+ */
195
206
end
196
207
end
197
208
209
+
198
210
reg fifo_read_strobe;
199
211
wire fifo_available;
200
212
201
213
fifo_spram_16to8 buffer (
202
214
.clk(clk_48),
203
215
.reset(reset),
204
- .write_data( newline ? "\r\n " : {
205
- hexdigit(spi_rx_data[7 :4 ]),
206
- hexdigit(spi_rx_data[3 :0 ])
207
- }),
208
- .write_strobe(spi_ready),
216
+ .write_data(do_hex
217
+ ? { hexdigit(spi_rx_data[7 :4 ]), hexdigit(spi_rx_data[3 :0 ]) }
218
+ : serial_out),
219
+ .write_strobe(do_serial) ,
209
220
.data_available(fifo_available),
210
221
.read_data(uart_txd),
211
222
.read_strobe(fifo_read_strobe)
@@ -219,7 +230,7 @@ module top(
219
230
// single port fifo can't read/write the same cycle
220
231
if (fifo_available
221
232
&& uart_txd_ready
222
- && ! spi_ready
233
+ && ! do_serial
223
234
&& ! uart_txd_strobe
224
235
) begin
225
236
fifo_read_strobe <= 1 ;
0 commit comments