OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [busmaster.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 2 dgisselq
//
3 4 dgisselq
// Filename:    busmaster.v
4 2 dgisselq
//
5 4 dgisselq
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6 2 dgisselq
//
7 46 dgisselq
// Purpose:     This is the highest level, simulatable, file in the S6SoC
8
//              project--of that portion of the project that includes the
9
//      ZipCPU.  This portion therefore contains references to all of the
10
//      masters (ZipCPU) and slaves (flash, block RAM, I/O, Scope) on the
11
//      wishbone bus, and connects them all together.  Hence, this contains
12
//      the wishbone interconnect logic as well.
13 2 dgisselq
//
14 4 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
15 2 dgisselq
//              Gisselquist Technology, LLC
16
//
17 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
18 2 dgisselq
//
19 46 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
20 2 dgisselq
//
21 4 dgisselq
// This program is free software (firmware): you can redistribute it and/or
22
// modify it under the terms of  the GNU General Public License as published
23
// by the Free Software Foundation, either version 3 of the License, or (at
24
// your option) any later version.
25
//
26
// This program is distributed in the hope that it will be useful, but WITHOUT
27
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
28
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29
// for more details.
30
//
31
// You should have received a copy of the GNU General Public License along
32
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
33
// target there if the PDF file isn't present.)  If not, see
34
// <http://www.gnu.org/licenses/> for a copy.
35
//
36
// License:     GPL, v3, as defined and found on www.gnu.org,
37
//              http://www.gnu.org/licenses/gpl.html
38
//
39
//
40
////////////////////////////////////////////////////////////////////////////////
41
//
42
//
43 2 dgisselq
`include "builddate.v"
44
//
45 16 dgisselq
`define IMPLEMENT_ONCHIP_RAM
46 2 dgisselq
`define FLASH_ACCESS
47 7 dgisselq
`define DBG_SCOPE       // About 204 LUTs, at 2^6 addresses
48 16 dgisselq
// `define      COMPRESSED_SCOPE
49 51 dgisselq
`define HAS_RXUART
50 16 dgisselq
`define INCLUDE_CPU_RESET_LOGIC
51 51 dgisselq
`define LOWLOGIC_FLASH  //      Saves about 154 LUTs
52
`define USE_LITE_UART   //      Saves about  55 LUTs
53 2 dgisselq
module  busmaster(i_clk, i_rst,
54 46 dgisselq
                i_uart, o_uart_rts_n, o_uart, i_uart_cts_n,
55 2 dgisselq
                // The SPI Flash lines
56
                o_qspi_cs_n, o_qspi_sck, o_qspi_dat, i_qspi_dat, o_qspi_mod,
57
                // The board I/O
58
                i_btn, o_led, o_pwm, o_pwm_aux,
59
                // Keypad connections
60
                i_kp_row, o_kp_col,
61
                // GPIO lines
62
                i_gpio, o_gpio);
63 46 dgisselq
        parameter       BUS_ADDRESS_WIDTH=23,
64
                        ZIP_ADDRESS_WIDTH=BUS_ADDRESS_WIDTH,
65
                        CMOD_ZIPCPU_RESET_ADDRESS=32'h1200000,
66
                        UART_SETUP = 31'd25;
67
        localparam      ZA=ZIP_ADDRESS_WIDTH,
68
                        BAW=BUS_ADDRESS_WIDTH; // 24bits->2,258,23b->2181
69
        // 2^14 bytes requires a LGMEMSZ of 14, and 12 address bits ranging from
70
        // 0 to 11.  As with many other devices, the wb_cyc line is more for
71
        // form than anything else--it is ignored by the memory itself.
72
        localparam      LGMEMSZ=14;     // Takes 8 BLKRAM16 elements for LGMEMSZ=14
73
        // As with the memory size, the flash size is also measured in log_2 of
74
        // the number of bytes.
75
        localparam      LGFLASHSZ = 24;
76 2 dgisselq
        input                   i_clk, i_rst;
77 46 dgisselq
        // UART parameters
78
        input                   i_uart, i_uart_cts_n;
79
        output  wire            o_uart, o_uart_rts_n;
80 2 dgisselq
        // SPI flash control
81 51 dgisselq
        output  wire            o_qspi_cs_n;
82
`ifdef  LOWLOGIC_FLASH
83
        output  wire    [1:0]    o_qspi_sck;
84
`else
85
        output  wire            o_qspi_sck;
86
`endif
87 2 dgisselq
        output  wire    [3:0]    o_qspi_dat;
88
        input           [3:0]    i_qspi_dat;
89
        output  wire    [1:0]    o_qspi_mod;
90
        // Board I/O
91
        input           [1:0]    i_btn;
92
        output  wire    [3:0]    o_led;
93
        output  wire            o_pwm;
94
        output  wire    [1:0]    o_pwm_aux;
95
        // Keypad
96
        input           [3:0]    i_kp_row;
97
        output  wire    [3:0]    o_kp_col;
98
        // GPIO liines
99
        input           [15:0]   i_gpio;
100
        output  wire    [15:0]   o_gpio;
101
 
102
 
103
        //
104
        //
105
        // Master wishbone wires
106
        //
107
        //
108
        wire            wb_cyc, wb_stb, wb_we, wb_stall, wb_ack, wb_err;
109
        wire    [31:0]   wb_data, wb_idata;
110 46 dgisselq
        wire    [3:0]    wb_sel;
111 2 dgisselq
        wire    [(BAW-1):0]      wb_addr;
112
 
113
        // Wires going to devices
114
        // And then headed back home
115
        wire    w_interrupt;
116
        // Oh, and the debug control for the ZIP CPU
117
        wire            zip_dbg_ack, zip_dbg_stall;
118
        wire    [31:0]   zip_dbg_data;
119
 
120
 
121
        //
122
        //
123
        // The BUS master (source): The ZipCPU
124
        //
125
        //
126
        wire            zip_cyc, zip_stb, zip_we, zip_cpu_int;
127
        wire    [(ZA-1):0]       w_zip_addr;
128
        wire    [(BAW-1):0]      zip_addr;
129 16 dgisselq
        wire    [31:0]           zip_data, zip_scope_data;
130 2 dgisselq
        // and then coming from devices
131
        wire            zip_ack, zip_stall, zip_err;
132
        wire    dwb_we, dwb_stb, dwb_cyc, dwb_ack, dwb_stall, dwb_err;
133
        wire    [(BAW-1):0]      dwb_addr;
134
        wire    [31:0]           dwb_odata;
135
 
136 46 dgisselq
        wire    cpu_reset, watchdog_int;
137 2 dgisselq
//
138 16 dgisselq
`ifdef  INCLUDE_CPU_RESET_LOGIC
139
        reg     btn_reset, x_button, r_button;
140
        initial btn_reset = 1'b0;
141
        initial x_button = 1'b0;
142
        initial r_button = 1'b0;
143
        always @(posedge i_clk)
144
        begin
145
                x_button <= i_btn[1];
146
                r_button <= x_button;
147 46 dgisselq
                btn_reset <= ((r_button)&&(zip_cpu_int))||(watchdog_int);
148 16 dgisselq
        end
149
        assign  cpu_reset = btn_reset;
150
`else
151 51 dgisselq
        assign  cpu_reset = (watchdog_int);
152 16 dgisselq
`endif
153
 
154 2 dgisselq
        zipbones #(CMOD_ZIPCPU_RESET_ADDRESS,ZA,6)
155 51 dgisselq
                swic(i_clk, cpu_reset, // 1'b0,
156 2 dgisselq
                        // Zippys wishbone interface
157 46 dgisselq
                        wb_cyc, wb_stb, wb_we, w_zip_addr, wb_data, wb_sel,
158 2 dgisselq
                                wb_ack, wb_stall, wb_idata, wb_err,
159
                        w_interrupt, zip_cpu_int,
160 16 dgisselq
                        // Debug wishbone interface -- not really used
161 2 dgisselq
                        1'b0, 1'b0,1'b0, 1'b0, 32'h00,
162 16 dgisselq
                                zip_dbg_ack, zip_dbg_stall, zip_dbg_data,
163
                        zip_scope_data);
164 2 dgisselq
        generate
165
        if (ZA < BAW)
166
                assign  wb_addr = { {(BAW-ZA){1'b0}}, w_zip_addr };
167
        else
168
                assign  wb_addr = w_zip_addr;
169
        endgenerate
170
 
171 46 dgisselq
 
172
        // Signals to build/detect bus errors
173
        wire    none_sel, many_sel;
174
 
175
        wire    io_sel, flash_sel, flctl_sel, scop_sel, mem_sel;
176 25 dgisselq
        wire    flash_ack, scop_ack, cfg_ack, mem_ack, many_ack;
177 2 dgisselq
        wire    io_stall, flash_stall, scop_stall, cfg_stall, mem_stall;
178 4 dgisselq
        reg     io_ack;
179 2 dgisselq
 
180
        wire    [31:0]   flash_data, scop_data, cfg_data, mem_data, pwm_data,
181
                        spio_data, gpio_data, uart_data;
182
        reg     [31:0]   io_data;
183
        reg     [(BAW-1):0]      bus_err_addr;
184 46 dgisselq
        //
185
        // wb_ack
186
        //
187
        // The returning wishbone ack is equal to the OR of every component that
188
        // might possibly produce an acknowledgement, gated by the CYC line.  To
189
        // add new components, OR their acknowledgements in here.
190
        //
191
        // Note the reference to none_sel.  If nothing is selected, the result
192
        // is an error.  Here, we do nothing more than insure that the erroneous
193
        // request produces an ACK ... if it was ever made, rather than stalling
194
        // the bus.
195
        //
196 2 dgisselq
 
197 46 dgisselq
 
198
        assign  wb_ack = (wb_cyc)&&((io_ack)||(scop_ack)
199 2 dgisselq
                                ||(mem_ack)||(flash_ack)||((none_sel)&&(1'b1)));
200 46 dgisselq
 
201
        //
202
        // wb_stall
203
        //
204
        // The returning wishbone stall line really depends upon what device
205
        // is requested.  Thus, if a particular device is selected, we return
206
        // the stall line for that device.
207
        //
208
        // To add a new device, simply and that devices select and stall lines
209
        // together, and OR the result with the massive OR logic below.
210
        //
211 2 dgisselq
        assign  wb_stall = ((io_sel)&&(io_stall))
212
                        ||((scop_sel)&&(scop_stall))
213
                        ||((mem_sel)&&(mem_stall))
214
                        ||((flash_sel||flctl_sel)&&(flash_stall));
215
                        // (none_sel)&&(1'b0)
216
 
217 46 dgisselq
        //
218
        // wb_idata
219
        //
220
        // This is the data returned on the bus.  Here, we select between a
221
        // series of bus sources to select what data to return.  The basic
222
        // logic is simply this: the data we return is the data for which the
223
        // ACK line is high.
224
        //
225
        // The last item on the list is chosen by default if no other ACK's are
226
        // true.  Although we might choose to return zeros in that case, by
227
        // returning something we can skimp a touch on the logic.
228
        //
229
        // To add another device, add another ack check, and another closing
230
        // parenthesis.
231
        //
232 2 dgisselq
        assign  wb_idata =  (io_ack|scop_ack)?((io_ack )? io_data  : scop_data)
233 46 dgisselq
                        : ((mem_ack)?(mem_data)
234
                        : flash_data);
235 2 dgisselq
 
236 46 dgisselq
        //
237
        // wb_err
238
        //
239
        // This is the bus error signal.  It should never be true, but practice
240
        // teaches us otherwise.  Here, we allow for three basic errors:
241
        //
242
        // 1. STB is true, but no devices are selected
243
        //
244
        //      This is the null pointer reference bug.  If you try to access
245
        //      something on the bus, at an address with no mapping, the bus
246
        //      should produce an error--such as if you try to access something
247
        //      at zero.
248
        //
249
        // 2. STB is true, and more than one device is selected
250
        //
251
        //      (This can be turned off, if you design this file well.  For
252
        //      this line to be true means you have a design flaw.)
253
        //
254
        // 3. If more than one ACK is every true at any given time.
255
        //
256
        //      This is a bug of bus usage, combined with a subtle flaw in the
257
        //      WB pipeline definition.  You can issue bus requests, one per
258
        //      clock, and if you cross device boundaries with your requests,
259
        //      you may have things come back out of order (not detected here)
260
        //      or colliding on return (detected here).  The solution to this
261
        //      problem is to make certain that any burst request does not cross
262
        //      device boundaries.  This is a requirement of whoever (or
263
        //      whatever) drives the bus.
264
        //
265
        assign  wb_err = ((wb_stb)&&(none_sel || many_sel)) || many_ack;
266
 
267 2 dgisselq
        // Addresses ...
268 46 dgisselq
        //
269
        // dev_sel
270
        //
271
        // The device select lines
272
        //
273
        //
274 2 dgisselq
 
275
 
276 46 dgisselq
        //
277
        // The skipaddr bitfield below is our cheaters way of handling
278
        // device selection.  We grab particular wires from the bus to do
279
        // this, and ignore all others.  While this may lead to some
280
        // surprising results for the CPU when it tries to access an
281
        // inappropriate address, it also minimizes our logic while also
282
        // placing every address at the right address.  The only problem is
283
        // ... devices will also be at some unexpected addresses, but ... this
284
        // is still within our spec.
285
        //
286
        wire    [3:0]    skipaddr;
287
        assign  skipaddr = {
288
                        wb_addr[(LGFLASHSZ-2)], // Flash
289
                        wb_addr[(LGMEMSZ-2)],   // RAM
290
                        wb_addr[ 9],            // SCOPE
291
                        wb_addr[ 8] };          // I/O
292
        //
293
        // This might not be the most efficient way in hardware, but it will
294
        // work for our purposes here.  There are two phantom bits for each
295
        // of these ... bits that tell the CPU which byte within the word, and
296
        // another phantom bit because we allocated a minimum of two words to
297
        // every device.
298
        //
299
        wire    idle_n;
300
`ifdef  ZERO_ON_IDLE
301
        assign idle_n = wb_stb;
302
`else
303
        assign idle_n = 1'b1;
304 2 dgisselq
`endif
305 46 dgisselq
 
306
// `define ZERO_ON_IDLE
307
`ifdef  ZERO_ON_IDLE
308
        assign  idle_n = (wb_cyc)&&(wb_stb);
309 25 dgisselq
`else
310 46 dgisselq
        assign  idle_n = 1'b1;
311 25 dgisselq
`endif
312 46 dgisselq
        assign  io_sel   =((idle_n)&&(skipaddr[3:0]==4'h1));
313
        assign  scop_sel =((idle_n)&&(skipaddr[3:1]==3'h1)); // = 4'h2
314
        assign  flctl_sel= 1'b0; // ((wb_cyc)&&(skipaddr[3:0]==4'h3));
315
        assign  mem_sel  =((idle_n)&&(skipaddr[3:2]==2'h1));
316
        assign  flash_sel=((idle_n)&&(skipaddr[3]));
317 2 dgisselq
 
318 46 dgisselq
        //
319
        // none_sel
320
        //
321
        // This wire is true if wb_stb is true and no device is selected.  This
322
        // is an error condition, but here we present the logic to test for it.
323
        //
324
        //
325
        // If you add another device, add another OR into the select lines
326
        // associated with this term.
327
        //
328
        assign  none_sel =((wb_stb)&&(skipaddr==4'h0));
329 2 dgisselq
 
330
        //
331 46 dgisselq
        // many_sel
332 2 dgisselq
        //
333 46 dgisselq
        // This should *never* be true .... unless you mess up your address
334
        // decoding logic.  Since I've done that before, I test/check for it
335
        // here.
336 2 dgisselq
        //
337 46 dgisselq
        // To add a new device here, simply add it to the list.  Make certain
338
        // that the width of the add, however, is greater than the number
339
        // of devices below.  Hence, for 3 devices, you will need an add
340
        // at least 3 bits in width, for 7 devices you will need at least 4
341
        // bits, etc.
342
        //
343
        // Because this add uses the {} operator, the individual components to
344
        // it are by default unsigned ... just as we would like.
345
        //
346
        // There's probably another easier/better/faster/cheaper way to do this,
347
        // but I haven't found any such that are also easier to adjust with
348
        // new devices.  I'm open to options.
349
        //
350
        assign  many_sel = 1'b0;
351
 
352
        //
353
        // many_ack
354
        //
355
        // Normally this would capture the error when multiple things creates acks
356
        // at the same time.  The S6 is small, though, and doesn't have the logic
357
        // we need to do this right.  Hence we just declare (and hope) that this
358
        // will never be true and work with that.
359
        //
360
        assign  many_ack = 1'b0;
361
 
362
 
363
        wire            flash_interrupt, scop_interrupt, timer_int,
364
                        gpio_int, pwm_int, keypad_int,button_int;
365
 
366
 
367
        //
368
        // bus_err_addr
369
        //
370
        // We'd like to know, after the fact, what (if any) address caused a
371
        // bus error.  So ... if we get a bus error, let's record the address
372
        // on the bus for later analysis.
373
        //
374
        initial bus_err_addr = 0;
375
        always @(posedge i_clk)
376
                if (wb_err)
377
                        bus_err_addr <= wb_addr;
378
        //
379
        // Interrupt processing
380
        //
381
        // The interrupt controller will be used to tell us if any interrupts
382
        // take place.  
383
        //
384
        // To add more interrupts, you can just add more wires to this
385
        // int_vector.
386
        // 
387 2 dgisselq
        reg             rx_rdy;
388
        wire    [10:0]   int_vector;
389 46 dgisselq
        assign  int_vector = {
390 25 dgisselq
                                        gpio_int, pwm_int, keypad_int,
391 46 dgisselq
                                (!tx_stb), rx_rdy,
392
                                1'b0, timer_int,
393
                                1'b0, scop_interrupt,
394 2 dgisselq
                                wb_err, button_int };
395
 
396
        wire    [31:0]   pic_data;
397 4 dgisselq
        icontrol #(11)  pic(i_clk, 1'b0, (wb_stb)&&(io_sel)
398 2 dgisselq
                                        &&(wb_addr[3:0]==4'h0)&&(wb_we),
399
                        wb_data, pic_data, int_vector, w_interrupt);
400
 
401 46 dgisselq
        wire    [31:0]   timer_data, watchdog_data;
402 2 dgisselq
        wire            zta_ack, zta_stall, ztb_ack, ztb_stall;
403 25 dgisselq
        ziptimer        #(32,31,1)
404 46 dgisselq
                thetimer(i_clk, 1'b0, 1'b1, wb_cyc,
405 2 dgisselq
                                (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h2),
406 46 dgisselq
                                wb_we, wb_data, zta_ack, zta_stall, timer_data,
407
                                timer_int);
408 25 dgisselq
        ziptimer        #(32,31,0)
409 46 dgisselq
                watchdog(i_clk, cpu_reset, 1'b1, wb_cyc,
410 2 dgisselq
                                (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h3),
411 46 dgisselq
                                wb_we, wb_data, ztb_ack, ztb_stall, watchdog_data,
412
                                watchdog_int);
413 2 dgisselq
 
414
        always @(posedge i_clk)
415
                case(wb_addr[3:0])
416
                        4'h0: io_data <= pic_data;
417 46 dgisselq
                        4'h1: io_data <= { {(30-BAW){1'b0}}, bus_err_addr, 2'b00 };
418
                        4'h2: io_data <= timer_data;
419
                        4'h3: io_data <= watchdog_data;
420 2 dgisselq
                        4'h4: io_data <= pwm_data;
421
                        4'h5: io_data <= spio_data;
422
                        4'h6: io_data <= gpio_data;
423
                        4'h7: io_data <= uart_data;
424
                        default: io_data <= `DATESTAMP;
425
                        // 4'h8: io_data <= `DATESTAMP;
426
                endcase
427
        always @(posedge i_clk)
428 46 dgisselq
                io_ack <= (wb_stb)&&(io_sel);
429 2 dgisselq
        assign  io_stall = 1'b0;
430
 
431
        wire    pwm_ack, pwm_stall;
432 12 dgisselq
        wbpwmaudio      #(14'd10000,2,0,14)
433
                theaudio(i_clk, wb_cyc,
434
                                ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h4)),
435
                                        wb_we, 1'b0, wb_data,
436
                                pwm_ack, pwm_stall, pwm_data, o_pwm,
437
                                        o_pwm_aux, //={pwm_shutdown_n,pwm_gain}
438
                                        pwm_int);
439 2 dgisselq
 
440
        //
441
        // Special Purpose I/O: Keypad, button, LED status and control
442
        //
443 16 dgisselq
        wire    [3:0]    w_led;
444 46 dgisselq
        spio    thespio(i_clk, wb_cyc,(wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h5),
445
                                wb_we, wb_data, spio_data,
446
                        o_kp_col, i_kp_row, i_btn, w_led,
447 2 dgisselq
                        keypad_int, button_int);
448 51 dgisselq
        assign  o_led = { w_led[3]|w_interrupt,w_led[2]|zip_cpu_int,
449
                        w_led[1], w_led[0] };
450 2 dgisselq
 
451
        //
452
        // General purpose (sort of) I/O:  (Bottom two bits robbed in each
453
        // direction for an I2C link at the toplevel.v design)
454
        //
455
        wbgpio  #(16,16,16'hffff) thegpio(i_clk, wb_cyc,
456
                        (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h6), wb_we,
457
                        wb_data, gpio_data, i_gpio, o_gpio, gpio_int);
458
 
459
        //
460
        //
461 46 dgisselq
        //      UART device: our console
462
        //
463
        //
464
        wire    [30:0]   uart_setup;
465
        //
466
        wire    rx_break, rx_parity_err, rx_frame_err, rx_ck_uart, rx_stb;
467
        wire    [7:0]    rx_data;
468
        //
469
        assign  uart_setup = UART_SETUP;
470
        //
471 51 dgisselq
`ifdef  HAS_RXUART
472
`ifdef  USE_LITE_UART
473
        rxuartlite      #(UART_SETUP[23:0])
474
                rcvuart(i_clk, i_uart, rx_stb, rx_data);
475
        assign  rx_break      = 1'b0;
476
        assign  rx_parity_err = 1'b0;
477
        assign  rx_frame_err  = 1'b0;
478
        assign  rx_ck_uart    = 1'b0;
479
`else
480 46 dgisselq
        rxuart  #(UART_SETUP)
481
                rcvuart(i_clk, 1'b0, uart_setup, i_uart, rx_stb, rx_data,
482
                        rx_break, rx_parity_err, rx_frame_err, rx_ck_uart);
483 51 dgisselq
`endif
484
`else
485
        assign  rx_break      = 1'b0;
486
        assign  rx_parity_err = 1'b0;
487
        assign  rx_frame_err  = 1'b0;
488
        assign  rx_ck_uart    = 1'b0;
489
        assign  rx_stb        = 1'b0;
490
        assign  rx_data       = 8'h0;
491
`endif
492 46 dgisselq
        //
493
        wire    tx_break, tx_busy;
494
        reg             tx_stb;
495
        reg     [7:0]    tx_data;
496
        assign  tx_break = 1'b0;
497 51 dgisselq
`ifdef  USE_LITE_UART
498
        txuartlite      #(UART_SETUP[23:0])
499
                tcvuart(i_clk, tx_stb, tx_data, o_uart, tx_busy);
500
`else
501 46 dgisselq
        txuart  #(UART_SETUP)
502
                tcvuart(i_clk, 1'b0, uart_setup, tx_break, tx_stb, tx_data,
503
                        i_uart_cts_n, o_uart, tx_busy);
504 51 dgisselq
`endif
505 46 dgisselq
 
506
        //
507 2 dgisselq
        //      Rudimentary serial port control
508
        //
509
        reg     [7:0]    r_rx_data;
510
        // Baud rate is set by clock rate / baud rate.
511
 
512 46 dgisselq
        initial tx_stb = 1'b0;
513
        initial tx_data = 8'h00;
514 2 dgisselq
        always @(posedge i_clk)
515 4 dgisselq
                if ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7)&&(wb_we))
516 2 dgisselq
                begin
517 46 dgisselq
                        tx_data <= wb_data[7:0];
518
                        tx_stb <= 1'b1;
519 2 dgisselq
                end
520 46 dgisselq
                else if ((tx_stb)&&(!tx_busy))
521
                        tx_stb <= 1'b0;
522 51 dgisselq
`ifdef  HAS_RXUART
523 2 dgisselq
        initial rx_rdy = 1'b0;
524
        always @(posedge i_clk)
525 46 dgisselq
                if (rx_stb)
526
                        r_rx_data <= rx_data;
527 2 dgisselq
        always @(posedge i_clk)
528
        begin
529 46 dgisselq
                if((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7)&&(!wb_we))
530
                        rx_rdy <= rx_stb;
531 51 dgisselq
                else
532 46 dgisselq
                        rx_rdy <= (rx_rdy | rx_stb);
533 2 dgisselq
        end
534 46 dgisselq
        assign  o_uart_rts_n = (rx_rdy);
535
        assign  uart_data = { 23'h0, !rx_rdy, r_rx_data };
536 51 dgisselq
`else
537
        assign  o_uart_rts_n = 1'b1;
538
        assign  uart_data = 32'h00;
539
`endif
540 4 dgisselq
        //
541
        // uart_ack gets returned as part of io_ack, since that happens when
542
        // io_sel and wb_stb are defined
543
        //
544
        // always @(posedge i_clk)
545
                // uart_ack<= ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7));
546 2 dgisselq
 
547
 
548
 
549
        //
550
        //      FLASH MEMORY CONFIGURATION ACCESS
551
        //
552 46 dgisselq
`ifdef  FLASH_ACCESS
553 51 dgisselq
`ifdef  LOWLOGIC_FLASH
554
        qflashxpress    flashmem(i_clk,
555
                wb_cyc,(wb_stb)&&(flash_sel),
556
                        wb_addr[(LGFLASHSZ-3):0],
557
                flash_ack, flash_stall, flash_data,
558
                o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat);
559
 
560
        assign  flash_interrupt = 1'b0;
561
`else
562 46 dgisselq
        wbqspiflash #(LGFLASHSZ)        flashmem(i_clk,
563 11 dgisselq
                wb_cyc,(wb_stb)&&(flash_sel),(wb_stb)&&(flctl_sel),wb_we,
564 46 dgisselq
                        wb_addr[(LGFLASHSZ-3):0], wb_data,
565 2 dgisselq
                flash_ack, flash_stall, flash_data,
566
                o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
567
                flash_interrupt);
568 51 dgisselq
`endif
569 2 dgisselq
`else
570 46 dgisselq
        reg     r_flash_ack;
571
        initial r_flash_ack = 1'b0;
572 2 dgisselq
        always @(posedge i_clk)
573 46 dgisselq
                r_flash_ack <= (wb_stb)&&((flash_sel)||(flctl_sel));
574
 
575
        assign  flash_ack = r_flash_ack;
576
        assign  flash_stall = 1'b0;
577
        assign  flash_data = 32'h0000;
578
        assign  flash_interrupt = 1'b0;
579
 
580
        assign  o_qspi_sck   = 1'b1;
581
        assign  o_qspi_cs_n  = 1'b1;
582
        assign  o_qspi_mod   = 2'b01;
583
        assign  o_qspi_dat   = 4'b1111;
584 2 dgisselq
`endif
585
 
586
        //
587
        //      ON-CHIP RAM MEMORY ACCESS
588
        //
589 4 dgisselq
`ifdef  IMPLEMENT_ONCHIP_RAM
590 46 dgisselq
        memdev  #(.LGMEMSZ(LGMEMSZ))
591
                ram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we,
592
                        wb_addr[(LGMEMSZ-3):0], wb_data, wb_sel,
593
                        mem_ack, mem_stall, mem_data);
594 4 dgisselq
`else
595
        assign  mem_data = 32'h00;
596
        assign  mem_stall = 1'b0;
597
        reg     r_mem_ack;
598
        always @(posedge i_clk)
599 46 dgisselq
                r_mem_ack <= (wb_stb)&&(mem_sel);
600 4 dgisselq
        assign  mem_ack = r_mem_ack;
601
`endif
602 2 dgisselq
 
603
        //
604
        //
605
        //      WISHBONE SCOPE
606
        //
607
        //
608
        //
609
        //
610 46 dgisselq
        wire    [31:0]   scop_cpu_data;
611
        wire            scop_cpu_ack, scop_cpu_stall, scop_cpu_interrupt;
612 7 dgisselq
`ifdef  DBG_SCOPE
613 16 dgisselq
        wire    scop_trigger = (zip_cpu_int) || (cpu_reset);
614
`ifdef  COMPRESSED_SCOPE
615
        wbscopc #(5'ha)
616
`else
617 46 dgisselq
        wbscope #(.LGMEM(5'h6), .HOLDOFFBITS(9))
618 16 dgisselq
`endif
619 46 dgisselq
        cpuscope(i_clk, 1'b1, scop_trigger,
620 28 dgisselq
`ifdef  COMPRESSED_SCOPE
621
                // cfg_scope[30:0],
622 16 dgisselq
                zip_scope_data[30:0],
623 28 dgisselq
`else
624
                // cfg_scope[31:0],
625
                zip_scope_data[31:0],
626
`endif
627 2 dgisselq
                // Wishbone interface
628 4 dgisselq
                i_clk, wb_cyc, (wb_stb)&&(scop_sel),
629 2 dgisselq
                                wb_we, wb_addr[0], wb_data,
630 46 dgisselq
                        scop_cpu_ack, scop_cpu_stall, scop_cpu_data,
631
                scop_cpu_interrupt);
632 4 dgisselq
`else
633 46 dgisselq
        reg     r_scop_cpu_ack;
634 4 dgisselq
        always @(posedge i_clk)
635 46 dgisselq
                r_scop_cpu_ack <= (wb_stb)&&(scop_sel);
636
        assign  scop_cpu_ack = r_scop_cpu_ack;
637
        assign  scop_cpu_data = 32'h000;
638
        assign  scop_cpu_stall= 1'b0;
639 2 dgisselq
`endif
640
 
641 46 dgisselq
        assign  scop_interrupt = scop_cpu_interrupt;
642
        assign  scop_ack   = scop_cpu_ack;
643
        assign  scop_stall = scop_cpu_stall;
644
        assign  scop_data  = scop_cpu_data;
645 2 dgisselq
 
646
endmodule
647
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.