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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [rtl/] [altbusmaster.v] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    altbusmaster.v
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
//
39
`include "builddate.v"
40
//
41
`define IMPLEMENT_ONCHIP_RAM
42
`ifndef VERILATOR
43
`define FANCY_ICAP_ACCESS
44
`endif
45
`define FLASH_ACCESS
46 8 dgisselq
`define DBG_SCOPE       // About 204 LUTs, at 2^6 addresses
47
`define INCLUDE_RTC     // About 90 LUTs
48 5 dgisselq
module  altbusmaster(i_clk, i_rst,
49 8 dgisselq
                // DEPP I/O Control
50
                i_depp_astb_n, i_depp_dstb_n, i_depp_write_n,
51
                        i_depp_data, o_depp_data, o_depp_wait,
52
                // External UART interface
53 5 dgisselq
                i_rx_stb, i_rx_data, o_tx_stb, o_tx_data, i_tx_busy,
54
                        o_uart_rts,
55
                // 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
                // UART control
62
                o_uart_setup,
63
                // GPIO lines
64
                i_gpio, o_gpio);
65 8 dgisselq
        parameter       BUS_ADDRESS_WIDTH=23,
66
                        BAW=BUS_ADDRESS_WIDTH; // 24bits->2,258,23b->2181
67 5 dgisselq
        input                   i_clk, i_rst;
68 8 dgisselq
        // The bus commander, via an external DEPP port
69
        input                   i_depp_astb_n, i_depp_dstb_n, i_depp_write_n;
70
        input   wire    [7:0]    i_depp_data;
71
        output  wire    [7:0]    o_depp_data;
72
        output  wire            o_depp_wait;
73
        // Serial inputs
74 5 dgisselq
        input                   i_rx_stb;
75
        input           [7:0]    i_rx_data;
76 8 dgisselq
        output  reg             o_tx_stb;
77
        output  reg     [7:0]    o_tx_data;
78 5 dgisselq
        input                   i_tx_busy;
79
        output  wire            o_uart_rts;
80
        // SPI flash control
81
        output  wire            o_qspi_cs_n, o_qspi_sck;
82
        output  wire    [3:0]    o_qspi_dat;
83
        input           [3:0]    i_qspi_dat;
84
        output  wire    [1:0]    o_qspi_mod;
85
        // Board I/O
86
        input           [1:0]    i_btn;
87
        output  wire    [3:0]    o_led;
88
        output  wire            o_pwm;
89
        output  wire    [1:0]    o_pwm_aux;
90
        // Keypad
91
        input           [3:0]    i_kp_row;
92
        output  wire    [3:0]    o_kp_col;
93
        // UART control
94
        output  wire    [29:0]   o_uart_setup;
95
        // GPIO liines
96
        input           [15:0]   i_gpio;
97
        output  wire    [15:0]   o_gpio;
98
 
99
 
100
        //
101
        //
102
        // Master wishbone wires
103
        //
104
        //
105
        wire            wb_cyc, wb_stb, wb_we, wb_stall, wb_ack, wb_err;
106 8 dgisselq
        wire    [31:0]   wb_data, wb_idata, w_wbu_addr;
107 5 dgisselq
        wire    [(BAW-1):0]      wb_addr;
108
        wire    [5:0]            io_addr;
109
        assign  io_addr = {
110
                        wb_addr[22],    // Flash
111
                        wb_addr[13],    // RAM
112
                        wb_addr[11],    // RTC
113
                        wb_addr[10],    // CFG
114
                        wb_addr[ 9],    // SCOPE
115
                        wb_addr[ 8] };  // I/O
116
 
117
        // Wires going to devices
118
        // And then headed back home
119
        wire    w_interrupt;
120 8 dgisselq
`ifdef  WBUBUS
121 5 dgisselq
        //
122
        //
123
        // The BUS master (source): The WB to UART conversion bus
124
        //
125
        //
126
        wbubus busbdriver(i_clk, i_rx_stb, i_rx_data,
127
                        // The wishbone interface
128
                        wb_cyc, wb_stb, wb_we, w_wbu_addr, wb_data,
129
                                wb_ack, wb_stall, wb_err, wb_idata,
130
                        w_interrupt,
131
                        // Provide feedback to the UART
132
                        o_tx_stb, o_tx_data, i_tx_busy);
133
        assign  o_uart_rts = (~rx_rdy);
134 8 dgisselq
`else
135
        //
136
        //
137
        // Another BUS master (source): A conversion from DEPP to busmaster
138
        //
139
        //
140
        wbdeppsimple    deppdrive(i_clk,
141
                i_depp_astb_n, i_depp_dstb_n, i_depp_write_n,
142
                        i_depp_data, o_depp_data, o_depp_wait,
143
                wb_cyc, wb_stb, wb_we, w_wbu_addr, wb_data,
144
                        wb_ack, wb_stall, wb_err, wb_idata,
145
                        w_interrupt);
146
`endif
147 5 dgisselq
 
148
        generate
149 8 dgisselq
        if (BAW < 32)
150
                assign  wb_addr = w_wbu_addr[(BAW-1):0];
151 5 dgisselq
        else
152 8 dgisselq
                assign  wb_addr = w_wbu_addr;
153 5 dgisselq
        endgenerate
154
 
155
        wire    io_sel, flash_sel, flctl_sel, scop_sel, cfg_sel, mem_sel,
156
                        rtc_sel, none_sel, many_sel;
157
        wire    flash_ack, scop_ack, cfg_ack, mem_ack;
158
        wire    rtc_ack, rtc_stall;
159
`ifdef  INCLUDE_RTC
160
        assign  rtc_stall = 1'b0;
161
`endif
162
        wire    io_stall, flash_stall, scop_stall, cfg_stall, mem_stall;
163 8 dgisselq
        reg     io_ack;
164 5 dgisselq
 
165
        wire    [31:0]   flash_data, scop_data, cfg_data, mem_data, pwm_data,
166
                        spio_data, gpio_data, uart_data;
167
        reg     [31:0]   io_data;
168
        reg     [(BAW-1):0]      bus_err_addr;
169
 
170
        assign  wb_ack = (wb_cyc)&&((io_ack)||(scop_ack)||(cfg_ack)
171
`ifdef  INCLUDE_RTC
172
                                ||(rtc_ack)
173
`endif
174
                                ||(mem_ack)||(flash_ack)||((none_sel)&&(1'b1)));
175
        assign  wb_stall = ((io_sel)&&(io_stall))
176
                        ||((scop_sel)&&(scop_stall))
177
                        ||((cfg_sel)&&(cfg_stall))
178
                        ||((mem_sel)&&(mem_stall))
179
`ifdef  INCLUDE_RTC
180
                        ||((rtc_sel)&&(rtc_stall))
181
`endif
182
                        ||((flash_sel||flctl_sel)&&(flash_stall));
183
                        // (none_sel)&&(1'b0)
184
 
185
        /*
186
        assign  wb_idata = (io_ack)?io_data
187
                        : ((scop_ack)?scop_data
188
                        : ((cfg_ack)?cfg_data
189
                        : ((mem_ack)?mem_data
190
                        : ((flash_ack)?flash_data
191
                        : 32'h00))));
192
        */
193
        assign  wb_idata =  (io_ack|scop_ack)?((io_ack )? io_data  : scop_data)
194
                        : ((mem_ack|rtc_ack)?((mem_ack)?mem_data:rtc_data)
195 8 dgisselq
                        : ((cfg_ack) ? cfg_data : flash_data));//if (flash_ack)
196 5 dgisselq
        assign  wb_err = ((wb_cyc)&&(wb_stb)&&(none_sel || many_sel)) || many_ack;
197
 
198
        // Addresses ...
199
        //      0000 xxxx       configuration/control registers
200
        //      1 xxxx xxxx xxxx xxxx xxxx      Up-sampler taps
201
        assign  io_sel   =((wb_cyc)&&(io_addr[5:0]==6'h1));
202 8 dgisselq
        assign  scop_sel =((wb_cyc)&&(io_addr[5:0]==6'h2));
203
        assign  flctl_sel=((wb_cyc)&&(io_addr[5:0]==6'h3));
204
        assign  cfg_sel  =((wb_cyc)&&(io_addr[5:1]==5'h2));
205 5 dgisselq
        // zip_sel is not on the bus at this point
206
`ifdef  INCLUDE_RTC
207
        assign  rtc_sel  =((wb_cyc)&&(io_addr[5:3]==3'h1));
208
`endif
209
        assign  mem_sel  =((wb_cyc)&&(io_addr[5:4]==2'h1));
210
        assign  flash_sel=((wb_cyc)&&(io_addr[5]));
211
 
212
        assign  none_sel =((wb_cyc)&&(wb_stb)&&(io_addr==6'h0));
213
        assign  many_sel =((wb_cyc)&&(wb_stb)&&(
214
                         {3'h0, io_sel}
215
                        +{3'h0, flctl_sel}
216 8 dgisselq
                        +{3'h0, scop_sel}
217 5 dgisselq
                        +{3'h0, cfg_sel}
218 8 dgisselq
                        +{3'h0, rtc_sel}
219 5 dgisselq
                        +{3'h0, mem_sel}
220
                        +{3'h0, flash_sel} > 1));
221 8 dgisselq
        // assign       many_sel = 1'b0;
222 5 dgisselq
 
223
        wire    many_ack;
224
        assign  many_ack =((wb_cyc)&&(
225
                         {3'h0, io_ack}
226
                        +{3'h0, scop_ack}
227
                        +{3'h0, cfg_ack}
228
`ifdef  INCLUDE_RTC
229
                        +{3'h0, rtc_ack}
230
`endif
231
                        +{3'h0, mem_ack}
232
                        +{3'h0, flash_ack} > 1));
233
 
234
        wire            flash_interrupt, scop_interrupt, tmra_int, tmrb_int,
235
                        rtc_interrupt, gpio_int, pwm_int, keypad_int,button_int;
236
 
237
 
238
        //
239
        //
240
        //
241
        reg             rx_rdy;
242
        wire    [10:0]   int_vector;
243
        assign  int_vector = { gpio_int, pwm_int, keypad_int,
244 8 dgisselq
                                ~i_tx_busy, rx_rdy, tmrb_int, tmra_int,
245 5 dgisselq
                                rtc_interrupt, scop_interrupt,
246
                                wb_err, button_int };
247
 
248
        wire    [31:0]   pic_data;
249 8 dgisselq
        icontrol #(11)  pic(i_clk, 1'b0, (wb_stb)&&(io_sel)
250 5 dgisselq
                                        &&(wb_addr[3:0]==4'h0)&&(wb_we),
251
                        wb_data, pic_data, int_vector, w_interrupt);
252
 
253 8 dgisselq
        initial bus_err_addr = 0; // `DATESTAMP;
254 5 dgisselq
        always @(posedge i_clk)
255
                if (wb_err)
256
                        bus_err_addr <= wb_addr;
257
 
258
        wire            zta_ack, zta_stall, ztb_ack, ztb_stall;
259
        wire    [31:0]   timer_a, timer_b;
260 8 dgisselq
        ziptimer        #(32,20)
261
                zipt_a(i_clk, 1'b0, 1'b1, wb_cyc,
262 5 dgisselq
                                (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h2),
263
                                wb_we, wb_data, zta_ack, zta_stall, timer_a,
264
                                tmra_int);
265 8 dgisselq
        ziptimer        #(32,20)
266
                zipt_b(i_clk, 1'b0, 1'b1, wb_cyc,
267 5 dgisselq
                                (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h3),
268
                                wb_we, wb_data, ztb_ack, ztb_stall, timer_b,
269
                                tmrb_int);
270
 
271
        wire    [31:0]   rtc_data;
272
`ifdef  INCLUDE_RTC
273
        wire    rtcd_ack, rtcd_stall, ppd;
274
        // rtcdate      thedate(i_clk, ppd, wb_cyc, (wb_stb)&&(io_sel), wb_we,
275
                        // wb_data, rtcd_ack, rtcd_stall, date_data);
276
        reg     r_rtc_ack;
277
        initial r_rtc_ack = 1'b0;
278
        always @(posedge i_clk)
279
                r_rtc_ack <= ((wb_stb)&&(rtc_sel));
280
        assign  rtc_ack = r_rtc_ack;
281
 
282
        rtclight
283 8 dgisselq
                #(23'h35afe5,23,0,0)      // 80 MHz clock
284 5 dgisselq
                thetime(i_clk, wb_cyc,
285
                        ((wb_stb)&&(rtc_sel)), wb_we,
286
                        { 1'b0, wb_addr[1:0] }, wb_data, rtc_data,
287
                        rtc_interrupt, ppd);
288
`else
289
        assign  rtc_interrupt = 1'b0;
290
        assign  rtc_data = 32'h00;
291
        assign  rtc_ack  = 1'b0;
292
`endif
293
 
294
        always @(posedge i_clk)
295
                case(wb_addr[3:0])
296
                        4'h0: io_data <= pic_data;
297
                        4'h1: io_data <= { {(32-BAW){1'b0}}, bus_err_addr };
298
                        4'h2: io_data <= timer_a;
299
                        4'h3: io_data <= timer_b;
300
                        4'h4: io_data <= pwm_data;
301
                        4'h5: io_data <= spio_data;
302
                        4'h6: io_data <= gpio_data;
303
                        4'h7: io_data <= uart_data;
304
                        default: io_data <= `DATESTAMP;
305
                        // 4'h8: io_data <= `DATESTAMP;
306
                endcase
307
        always @(posedge i_clk)
308
                io_ack <= (wb_cyc)&&(wb_stb)&&(io_sel);
309
        assign  io_stall = 1'b0;
310
 
311
        wire    pwm_ack, pwm_stall;
312
        wbpwmaudio      theaudio(i_clk, wb_cyc,
313
                                ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h4)), wb_we,
314
                                1'b0, wb_data,
315
                                pwm_ack, pwm_stall, pwm_data, o_pwm, o_pwm_aux,
316
                                pwm_int);
317
 
318
        //
319
        // Special Purpose I/O: Keypad, button, LED status and control
320
        //
321
        spio    thespio(i_clk, wb_cyc,(wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h5),wb_we,
322
                        wb_data, spio_data, o_kp_col, i_kp_row, i_btn, o_led,
323
                        keypad_int, button_int);
324
 
325
        //
326
        // General purpose (sort of) I/O:  (Bottom two bits robbed in each
327
        // direction for an I2C link at the toplevel.v design)
328
        //
329
        wbgpio  #(16,16,16'hffff) thegpio(i_clk, wb_cyc,
330
                        (wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h6), wb_we,
331
                        wb_data, gpio_data, i_gpio, o_gpio, gpio_int);
332
 
333
        //
334
        //
335
        //      Rudimentary serial port control
336
        //
337
        reg     [7:0]    r_rx_data;
338
        // Baud rate is set by clock rate / baud rate.
339
        // Thus, 80MHz / 115200MBau
340
        //      = 694.4, or about 0x2b6. 
341
        // although the CPU might struggle to keep up at this speed without a
342
        // hardware buffer.
343
        //
344
        // We'll add the flag for two stop bits.
345 8 dgisselq
        // assign       o_uart_setup = 30'h080002b6; // 115200 MBaud @ an 80MHz clock
346
        assign  o_uart_setup = 30'h0000208d; // 9600 MBaud, 8N1
347 5 dgisselq
 
348 8 dgisselq
        initial o_tx_stb = 1'b0;
349
        initial o_tx_data = 8'h00;
350
        always @(posedge i_clk)
351
                if ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7)&&(wb_we))
352
                begin
353
                        o_tx_data <= wb_data[7:0];
354
                        o_tx_stb <= 1'b1;
355
                end
356
                else if ((o_tx_stb)&&(~i_tx_busy))
357
                        o_tx_stb <= 1'b0;
358
        initial rx_rdy = 1'b0;
359
        always @(posedge i_clk)
360
                if (i_rx_stb)
361
                        r_rx_data <= i_rx_data;
362
        always @(posedge i_clk)
363
        begin
364
                if((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7)&&(~wb_we))
365
                        rx_rdy <= i_rx_stb;
366
                else if (i_rx_stb)
367
                        rx_rdy <= (rx_rdy | i_rx_stb);
368
        end
369
        assign  o_uart_rts = (~rx_rdy);
370
        assign  uart_data = { 23'h0, ~rx_rdy, r_rx_data };
371
        //
372
        // uart_ack gets returned as part of io_ack, since that happens when
373
        // io_sel and wb_stb are defined
374
        //
375
        // always @(posedge i_clk)
376
                // uart_ack<= ((wb_stb)&&(io_sel)&&(wb_addr[3:0]==4'h7));
377 5 dgisselq
 
378
 
379
 
380
        //
381
        //      FLASH MEMORY CONFIGURATION ACCESS
382
        //
383
        wire    flash_cs_n, flash_sck, flash_mosi;
384
        wbqspiflashp #(24)      flashmem(i_clk,
385
                wb_cyc,(wb_stb&&flash_sel),(wb_stb)&&(flctl_sel),wb_we,
386 8 dgisselq
                        wb_addr[(24-3):0], wb_data,
387 5 dgisselq
                flash_ack, flash_stall, flash_data,
388
                o_qspi_sck, o_qspi_cs_n, o_qspi_mod, o_qspi_dat, i_qspi_dat,
389
                flash_interrupt);
390
 
391
        //
392
        //      MULTIBOOT/ICAPE2 CONFIGURATION ACCESS
393
        //
394
        wire    [31:0]   cfg_scope;
395
`ifdef  FANCY_ICAP_ACCESS
396
        wbicape6        fpga_cfg(i_clk, wb_cyc,(cfg_sel)&&(wb_stb), wb_we,
397
                                wb_addr[5:0], wb_data,
398
                                cfg_ack, cfg_stall, cfg_data,
399
                                cfg_scope);
400
`else
401
        reg     r_cfg_ack;
402
        always @(posedge i_clk)
403
                r_cfg_ack <= (wb_cyc)&&(cfg_sel)&&(wb_stb);
404
        assign  cfg_ack   = r_cfg_ack;
405
        assign  cfg_stall = 1'b0;
406
        assign  cfg_data  = 32'h00;
407
        assign  cfg_scope = 32'h00;
408
`endif
409
 
410
 
411
        //
412
        //      ON-CHIP RAM MEMORY ACCESS
413
        //
414 8 dgisselq
`ifdef  IMPLEMENT_ONCHIP_RAM
415 5 dgisselq
        memdev  #(12) ram(i_clk, wb_cyc, (wb_stb)&&(mem_sel), wb_we,
416
                        wb_addr[11:0], wb_data, mem_ack, mem_stall, mem_data);
417 8 dgisselq
`else
418
        assign  mem_data = 32'h00;
419
        assign  mem_stall = 1'b0;
420
        reg     r_mem_ack;
421
        always @(posedge i_clk)
422
                r_mem_ack <= (wb_cyc)&&(wb_stb)&&(mem_sel);
423
        assign  mem_ack = r_mem_ack;
424
`endif
425 5 dgisselq
 
426
        //
427
        //
428
        //      WISHBONE SCOPE
429
        //
430
        //
431
        //
432
        //
433
        wire    [31:0]   scop_cfg_data;
434
        wire            scop_cfg_ack, scop_cfg_stall, scop_cfg_interrupt;
435 8 dgisselq
`ifdef  DBG_SCOPE
436 5 dgisselq
        wire            scop_cfg_trigger;
437
        assign  scop_cfg_trigger = (wb_cyc)&&(wb_stb)&&(cfg_sel);
438
        wbscope #(5'ha) wbcfgscope(i_clk, 1'b1, scop_cfg_trigger, cfg_scope,
439
                // Wishbone interface
440 8 dgisselq
                i_clk, wb_cyc, (wb_stb)&&(scop_sel),
441 5 dgisselq
                                wb_we, wb_addr[0], wb_data,
442
                        scop_cfg_ack, scop_cfg_stall, scop_cfg_data,
443
                scop_cfg_interrupt);
444 8 dgisselq
`else
445
        reg     r_scop_cfg_ack;
446
        always @(posedge i_clk)
447
                r_scop_cfg_ack <= (wb_cyc)&&(wb_stb)&&(scop_sel);
448
        assign  scop_cfg_ack = r_scop_cfg_ack;
449
        assign  scop_cfg_data = 32'h000;
450
        assign  scop_cfg_stall= 1'b0;
451 5 dgisselq
`endif
452
 
453
        assign  scop_interrupt = scop_cfg_interrupt;
454
        assign  scop_ack   = scop_cfg_ack;
455
        assign  scop_stall = scop_cfg_stall;
456
        assign  scop_data  = scop_cfg_data;
457
 
458
endmodule
459
 

powered by: WebSVN 2.1.0

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