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

Subversion Repositories s6soc

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

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

powered by: WebSVN 2.1.0

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