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

Subversion Repositories s6soc

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

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

powered by: WebSVN 2.1.0

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