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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [fastio.v] - Blame information for rev 33

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    fastio.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
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
`include "builddate.v"
39
//
40
module  fastio(i_clk,
41
                // Board level I/O
42
                i_sw, i_btn, o_led,
43
                o_clr_led0, o_clr_led1, o_clr_led2, o_clr_led3,
44
                // Board level PMod I/O
45
                i_aux_rx, o_aux_tx, o_aux_cts, i_gps_rx, o_gps_tx,
46
                // i_gpio, o_gpio,
47
                // Wishbone control
48
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr,
49
                        i_wb_data, o_wb_ack, o_wb_stall, o_wb_data,
50
                // Cross-board I/O
51
                i_rtc_ppd, i_buserr, i_other_ints, o_bus_int, o_board_ints);
52 17 dgisselq
        parameter       AUXUART_SETUP = 30'd1736, // 115200 baud from 200MHz clk
53 25 dgisselq
                        GPSUART_SETUP = 30'd20833, // 9600 baud from 200MHz clk
54
                        EXTRACLOCK = 1; // Do we need an extra clock to process?
55 3 dgisselq
        input                   i_clk;
56
        // Board level I/O
57
        input           [3:0]    i_sw;
58
        input           [3:0]    i_btn;
59
        output  wire    [3:0]    o_led;
60
        output  reg     [2:0]    o_clr_led0;
61
        output  reg     [2:0]    o_clr_led1;
62
        output  reg     [2:0]    o_clr_led2;
63
        output  reg     [2:0]    o_clr_led3;
64
        // Board level PMod I/O
65
        //
66
        // Auxilliary UART I/O
67
        input           i_aux_rx;
68
        output  wire    o_aux_tx, o_aux_cts;
69
        //
70
        // GPS UART I/O
71
        input           i_gps_rx;
72
        output  wire    o_gps_tx;
73
        //
74
        // GPIO
75
        // input        [(NGPI-1):0]    i_gpio;
76
        // output reg   [(NGPO-1):0]    o_gpio;
77
        //
78
        // Wishbone inputs
79
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
80
        input           [4:0]    i_wb_addr;
81
        input           [31:0]   i_wb_data;
82
        // Wishbone outputs
83
        output  reg             o_wb_ack;
84
        output  wire            o_wb_stall;
85
        output  reg     [31:0]   o_wb_data;
86
        // A strobe at midnight, to keep the calendar on "time"
87
        input                   i_rtc_ppd;
88
        // Address of the last bus error
89
        input           [31:0]   i_buserr;
90
        //
91
        // Interrupts -- both the output bus interrupt, as well as those
92
        //      internally generated interrupts which may be used elsewhere
93
        //      in the design
94
        input   wire    [8:0]    i_other_ints;
95
        output  wire            o_bus_int;
96
        output  wire    [5:0]    o_board_ints; // Button and switch interrupts
97
 
98 25 dgisselq
        wire    [31:0]   w_wb_data;
99
        wire    [4:0]    w_wb_addr;
100
        wire            w_wb_stb;
101
 
102
        generate
103
        if (EXTRACLOCK == 0)
104 3 dgisselq
        begin
105 25 dgisselq
                assign  w_wb_data = i_wb_data;
106
                assign  w_wb_addr = i_wb_addr;
107
                assign  w_wb_stb = (i_wb_stb)&&(i_wb_we);
108
        end else begin
109
                reg             last_wb_stb;
110
                reg     [4:0]    last_wb_addr;
111
                reg     [31:0]   last_wb_data;
112
                initial last_wb_stb = 1'b0;
113
                always @(posedge i_clk)
114
                begin
115
                        last_wb_addr <= i_wb_addr;
116
                        last_wb_data <= i_wb_data;
117
                        last_wb_stb  <= (i_wb_stb)&&(i_wb_we);
118
                end
119 3 dgisselq
 
120 25 dgisselq
                assign  w_wb_data = last_wb_data;
121
                assign  w_wb_addr = last_wb_addr;
122
                assign  w_wb_stb  = last_wb_stb;
123
        end endgenerate
124
 
125 3 dgisselq
        wire    [31:0]   pic_data;
126
        reg     sw_int, btn_int;
127
        wire    pps_int, rtc_int, netrx_int, nettx_int,
128
                auxrx_int, auxtx_int, gpio_int, flash_int, scop_int,
129
                gpsrx_int, sd_int, oled_int, zip_int;
130
        assign { zip_int, oled_int, rtc_int, sd_int,
131
                        nettx_int, netrx_int, scop_int, flash_int,
132
                        pps_int } = i_other_ints;
133
 
134 17 dgisselq
        //
135
        // The BUS Interrupt controller
136
        //
137 3 dgisselq
        icontrol #(15)  buspic(i_clk, 1'b0,
138 25 dgisselq
                (w_wb_stb)&&(w_wb_addr==5'h1),
139 3 dgisselq
                        i_wb_data, pic_data,
140
                { zip_int, oled_int, sd_int,
141
                        gpsrx_int, scop_int, flash_int, gpio_int,
142
                        auxtx_int, auxrx_int, nettx_int, netrx_int,
143
                        rtc_int, pps_int, sw_int, btn_int },
144
                        o_bus_int);
145
 
146
        // 
147
        // PWR Count
148
        // 
149
        // A 32-bit counter that starts at power up and never resets.  It's a
150
        // read only counter if you will.
151
        reg     [31:0]   pwr_counter;
152
        initial pwr_counter = 32'h00;
153
        always @(posedge i_clk)
154
                pwr_counter <= pwr_counter+32'h001;
155
 
156
        //
157
        // BTNSW
158
        //
159
        // The button and switch control register
160
        wire    [31:0]   w_btnsw;
161
        reg     [3:0]    r_sw,  swcfg,  swnow,  swlast;
162
        reg     [3:0]    r_btn, btncfg, btnnow, btnlast, btnstate;
163
        initial btn_int = 1'b0;
164
        initial sw_int  = 1'b0;
165
        always @(posedge i_clk)
166
        begin
167
                r_sw <= i_sw;
168
                swnow <= r_sw;
169
                swlast<= swnow;
170
                sw_int <= |((swnow^swlast)|swcfg);
171
 
172 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h4))
173
                        swcfg <= ((w_wb_data[3:0])&(w_wb_data[11:8]))
174
                                        |((~w_wb_data[3:0])&(swcfg));
175 3 dgisselq
 
176
                r_btn <= i_btn;
177
                btnnow <= r_btn;
178
                btn_int <= |(btnnow&btncfg);
179 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h4))
180 3 dgisselq
                begin
181 25 dgisselq
                        btncfg <= ((w_wb_data[7:4])&(w_wb_data[15:12]))
182
                                        |((~w_wb_data[7:4])&(btncfg));
183
                        btnstate<= (btnnow)|((btnstate)&(~w_wb_data[7:4]));
184 3 dgisselq
                end else
185
                        btnstate <= (btnstate)|(btnnow);
186
        end
187
        assign  w_btnsw = { 8'h00, btnnow, 4'h0, btncfg, swcfg, btnstate, swnow };
188
 
189
        //
190
        // LEDCTRL
191
        //
192
        reg     [3:0]    r_leds;
193
        wire    [31:0]   w_ledreg;
194
        initial r_leds = 4'h0;
195
        always @(posedge i_clk)
196 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h5))
197
                        r_leds <= ((w_wb_data[7:4])&(w_wb_data[3:0]))
198
                                |((~w_wb_data[7:4])&(r_leds));
199 3 dgisselq
        assign  o_led = r_leds;
200
        assign  w_ledreg = { 28'h0, r_leds  };
201
 
202
        //
203
        // GPIO
204
        //
205
        // Not used (yet), but this interface should allow us to control up to
206
        // 16 GPIO inputs, and another 16 GPIO outputs.  The interrupt trips
207
        // when any of the inputs changes.  (Sorry, which input isn't (yet)
208
        // selectable.)
209
        //
210
        assign  gpio_int = 1'b0;
211
 
212
        //
213
        // AUX (UART) SETUP
214
        //
215
        // Set us up for 4Mbaud, 8 data bits, no stop bits.
216
        reg     [29:0]   aux_setup;
217
        initial aux_setup = AUXUART_SETUP;
218
        always @(posedge i_clk)
219 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h6))
220
                        aux_setup[29:0] <= w_wb_data[29:0];
221 3 dgisselq
 
222
        //
223
        // GPSSETUP
224
        //
225
        // Set us up for 9600 kbaud, 8 data bits, no stop bits.
226
        reg     [29:0]   gps_setup;
227
        initial gps_setup = GPSUART_SETUP;
228
        always @(posedge i_clk)
229 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h7))
230
                        gps_setup[29:0] <= w_wb_data[29:0];
231 3 dgisselq
 
232
        //
233
        // CLR LEDs
234
        //
235
 
236
        // CLR LED 0
237
        wire    [31:0]   w_clr_led0;
238
        reg     [8:0]    r_clr_led0_r, r_clr_led0_g, r_clr_led0_b;
239
        initial r_clr_led0_r = 9'h003; // Color LED on the far right
240
        initial r_clr_led0_g = 9'h000;
241
        initial r_clr_led0_b = 9'h000;
242
        always @(posedge i_clk)
243 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h8))
244 3 dgisselq
                begin
245 25 dgisselq
                        r_clr_led0_r <= { w_wb_data[26], w_wb_data[23:16] };
246
                        r_clr_led0_g <= { w_wb_data[25], w_wb_data[15: 8] };
247
                        r_clr_led0_b <= { w_wb_data[24], w_wb_data[ 7: 0] };
248 3 dgisselq
                end
249
        assign  w_clr_led0 = { 5'h0,
250
                        r_clr_led0_r[8], r_clr_led0_g[8], r_clr_led0_b[8],
251
                        r_clr_led0_r[7:0], r_clr_led0_g[7:0], r_clr_led0_b[7:0]
252
                };
253
        always @(posedge i_clk)
254
                o_clr_led0 <= { (pwr_counter[8:0] < r_clr_led0_r),
255
                                (pwr_counter[8:0] < r_clr_led0_g),
256
                                (pwr_counter[8:0] < r_clr_led0_b) };
257
 
258
        // CLR LED 1
259
        wire    [31:0]   w_clr_led1;
260
        reg     [8:0]    r_clr_led1_r, r_clr_led1_g, r_clr_led1_b;
261
        initial r_clr_led1_r = 9'h007;
262
        initial r_clr_led1_g = 9'h000;
263
        initial r_clr_led1_b = 9'h000;
264
        always @(posedge i_clk)
265 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h9))
266 3 dgisselq
                begin
267 25 dgisselq
                        r_clr_led1_r <= { w_wb_data[26], w_wb_data[23:16] };
268
                        r_clr_led1_g <= { w_wb_data[25], w_wb_data[15: 8] };
269
                        r_clr_led1_b <= { w_wb_data[24], w_wb_data[ 7: 0] };
270 3 dgisselq
                end
271
        assign  w_clr_led1 = { 5'h0,
272
                        r_clr_led1_r[8], r_clr_led1_g[8], r_clr_led1_b[8],
273
                        r_clr_led1_r[7:0], r_clr_led1_g[7:0], r_clr_led1_b[7:0]
274
                };
275
        always @(posedge i_clk)
276
                o_clr_led1 <= { (pwr_counter[8:0] < r_clr_led1_r),
277
                                (pwr_counter[8:0] < r_clr_led1_g),
278
                                (pwr_counter[8:0] < r_clr_led1_b) };
279
        // CLR LED 0
280
        wire    [31:0]   w_clr_led2;
281
        reg     [8:0]    r_clr_led2_r, r_clr_led2_g, r_clr_led2_b;
282
        initial r_clr_led2_r = 9'h00f;
283
        initial r_clr_led2_g = 9'h000;
284
        initial r_clr_led2_b = 9'h000;
285
        always @(posedge i_clk)
286 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'ha))
287 3 dgisselq
                begin
288 25 dgisselq
                        r_clr_led2_r <= { w_wb_data[26], w_wb_data[23:16] };
289
                        r_clr_led2_g <= { w_wb_data[25], w_wb_data[15: 8] };
290
                        r_clr_led2_b <= { w_wb_data[24], w_wb_data[ 7: 0] };
291 3 dgisselq
                end
292
        assign  w_clr_led2 = { 5'h0,
293
                        r_clr_led2_r[8], r_clr_led2_g[8], r_clr_led2_b[8],
294
                        r_clr_led2_r[7:0], r_clr_led2_g[7:0], r_clr_led2_b[7:0]
295
                };
296
        always @(posedge i_clk)
297
                o_clr_led2 <= { (pwr_counter[8:0] < r_clr_led2_r),
298
                                (pwr_counter[8:0] < r_clr_led2_g),
299
                                (pwr_counter[8:0] < r_clr_led2_b) };
300
        // CLR LED 3
301
        wire    [31:0]   w_clr_led3;
302
        reg     [8:0]    r_clr_led3_r, r_clr_led3_g, r_clr_led3_b;
303
        initial r_clr_led3_r = 9'h01f; // LED is on far left
304
        initial r_clr_led3_g = 9'h000;
305
        initial r_clr_led3_b = 9'h000;
306
        always @(posedge i_clk)
307 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'hb))
308 3 dgisselq
                begin
309 25 dgisselq
                        r_clr_led3_r <= { w_wb_data[26], w_wb_data[23:16] };
310
                        r_clr_led3_g <= { w_wb_data[25], w_wb_data[15: 8] };
311
                        r_clr_led3_b <= { w_wb_data[24], w_wb_data[ 7: 0] };
312 3 dgisselq
                end
313
        assign  w_clr_led3 = { 5'h0,
314
                        r_clr_led3_r[8], r_clr_led3_g[8], r_clr_led3_b[8],
315
                        r_clr_led3_r[7:0], r_clr_led3_g[7:0], r_clr_led3_b[7:0]
316
                };
317
        always @(posedge i_clk)
318
                o_clr_led3 <= { (pwr_counter[8:0] < r_clr_led3_r),
319
                                (pwr_counter[8:0] < r_clr_led3_g),
320
                                (pwr_counter[8:0] < r_clr_led3_b) };
321
 
322
        //
323
        // The Calendar DATE
324
        //
325
        wire    [31:0]   date_data;
326
`define GET_DATE
327
`ifdef  GET_DATE
328
        wire    date_ack, date_stall;
329
        rtcdate thedate(i_clk, i_rtc_ppd,
330 25 dgisselq
                i_wb_cyc, w_wb_stb, (w_wb_addr==5'hc), w_wb_data,
331 3 dgisselq
                        date_ack, date_stall, date_data);
332
`else
333
        assign  date_data = 32'h20160000;
334
`endif
335
 
336
        //////
337
        //
338
        // The auxilliary UART
339
        //
340
        //////
341
 
342 17 dgisselq
        //
343
        // First the Auxilliary UART receiver
344
        //
345 3 dgisselq
        wire    auxrx_stb, auxrx_break, auxrx_perr, auxrx_ferr, auxck_uart;
346
        wire    [7:0]    rx_data_aux_port;
347
        rxuart  auxrx(i_clk, 1'b0, aux_setup, i_aux_rx,
348
                        auxrx_stb, rx_data_aux_port, auxrx_break,
349
                        auxrx_perr, auxrx_ferr, auxck_uart);
350
 
351
        wire    [31:0]   auxrx_data;
352
        reg     [11:0]   r_auxrx_data;
353
        always @(posedge i_clk)
354
                if (auxrx_stb)
355
                begin
356
                        r_auxrx_data[11] <= auxrx_break;
357
                        r_auxrx_data[10] <= auxrx_ferr;
358
                        r_auxrx_data[ 9] <= auxrx_perr;
359
                        r_auxrx_data[7:0]<= rx_data_aux_port;
360
                end
361
        always @(posedge i_clk)
362 17 dgisselq
                if(((i_wb_stb)&&(~i_wb_we)&&(i_wb_addr == 5'h0e))||(auxrx_stb))
363 25 dgisselq
                        r_auxrx_data[8] <= !auxrx_stb;
364 3 dgisselq
        assign  o_aux_cts = auxrx_stb;
365
        assign  auxrx_data = { 20'h00, r_auxrx_data };
366
        assign  auxrx_int = r_auxrx_data[8];
367
 
368 17 dgisselq
        //
369
        // Then the auxilliary UART transmitter
370
        //
371 3 dgisselq
        wire    auxtx_busy;
372
        reg     [7:0]    r_auxtx_data;
373
        reg             r_auxtx_stb, r_auxtx_break;
374
        wire    [31:0]   auxtx_data;
375
        txuart  auxtx(i_clk, 1'b0, aux_setup,
376
                        r_auxtx_break, r_auxtx_stb, r_auxtx_data,
377
                        o_aux_tx, auxtx_busy);
378
        always @(posedge i_clk)
379 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h0f))
380 3 dgisselq
                begin
381 25 dgisselq
                        r_auxtx_stb <= (!r_auxtx_break)&&(!w_wb_data[9]);
382
                        r_auxtx_data <= w_wb_data[7:0];
383
                        r_auxtx_break<= w_wb_data[9];
384 3 dgisselq
                end else if (~auxtx_busy)
385
                begin
386
                        r_auxtx_stb <= 1'b0;
387
                        r_auxtx_data <= 8'h0;
388
                end
389
        assign  auxtx_data = { 20'h00,
390
                auxck_uart, o_aux_tx, r_auxtx_break, auxtx_busy,
391
                r_auxtx_data };
392
        assign  auxtx_int = ~auxtx_busy;
393
 
394
        //////
395
        //
396
        // The GPS UART
397
        //
398
        //////
399
 
400
        // First the receiver
401
        wire    gpsrx_stb, gpsrx_break, gpsrx_perr, gpsrx_ferr, gpsck_uart;
402
        wire    [7:0]    rx_data_gps_port;
403
        rxuart  gpsrx(i_clk, 1'b0, gps_setup, i_gps_rx,
404
                        gpsrx_stb, rx_data_gps_port, gpsrx_break,
405
                        gpsrx_perr, gpsrx_ferr, gpsck_uart);
406
 
407
        wire    [31:0]   gpsrx_data;
408
        reg     [11:0]   r_gpsrx_data;
409
        always @(posedge i_clk)
410
                if (gpsrx_stb)
411
                begin
412
                        r_gpsrx_data[11] <= gpsrx_break;
413
                        r_gpsrx_data[10] <= gpsrx_ferr;
414
                        r_gpsrx_data[ 9] <= gpsrx_perr;
415
                        r_gpsrx_data[7:0]<= rx_data_gps_port;
416
                end
417
        always @(posedge i_clk)
418 17 dgisselq
                if(((i_wb_stb)&&(~i_wb_we)&&(i_wb_addr == 5'h10))||(gpsrx_stb))
419 3 dgisselq
                        r_gpsrx_data[8] <= gpsrx_stb;
420
        assign  gpsrx_data = { 20'h00, r_gpsrx_data };
421
        assign  gpsrx_int = r_gpsrx_data[8];
422
 
423
 
424
        // Then the transmitter
425
        reg             r_gpstx_break, r_gpstx_stb;
426
        reg     [7:0]    r_gpstx_data;
427
        wire            gpstx_busy;
428
        wire    [31:0]   gpstx_data;
429
        txuart  gpstx(i_clk, 1'b0, gps_setup,
430
                        r_gpstx_break, r_gpstx_stb, r_gpstx_data,
431
                        o_gps_tx, gpstx_busy);
432
        always @(posedge i_clk)
433 25 dgisselq
                if ((w_wb_stb)&&(w_wb_addr == 5'h11))
434 3 dgisselq
                begin
435
                        r_gpstx_stb <= 1'b1;
436 25 dgisselq
                        r_gpstx_data <= w_wb_data[7:0];
437
                        r_gpstx_break<= w_wb_data[9];
438 3 dgisselq
                end else if (~gpstx_busy)
439
                begin
440
                        r_gpstx_stb <= 1'b0;
441
                        r_gpstx_data <= 8'h0;
442
                end
443
        assign  gpstx_data = { 20'h00,
444
                gpsck_uart, o_gps_tx, r_gpstx_break, gpstx_busy,
445
                r_gpstx_data };
446
 
447
        always @(posedge i_clk)
448
                case(i_wb_addr)
449
                5'h00: o_wb_data <= `DATESTAMP;
450
                5'h01: o_wb_data <= pic_data;
451
                5'h02: o_wb_data <= i_buserr;
452
                5'h03: o_wb_data <= pwr_counter;
453
                5'h04: o_wb_data <= w_btnsw;
454
                5'h05: o_wb_data <= w_ledreg;
455
                5'h06: o_wb_data <= { 2'b00, aux_setup };
456
                5'h07: o_wb_data <= { 2'b00, gps_setup };
457
                5'h08: o_wb_data <= w_clr_led0;
458
                5'h09: o_wb_data <= w_clr_led1;
459
                5'h0a: o_wb_data <= w_clr_led2;
460
                5'h0b: o_wb_data <= w_clr_led3;
461
                5'h0c: o_wb_data <= date_data;
462 17 dgisselq
                // 5'h0d: o_wb_data <= gpio_data;
463
                5'h0e: o_wb_data <= auxrx_data;
464
                5'h0f: o_wb_data <= auxtx_data;
465 3 dgisselq
                5'h10: o_wb_data <= gpsrx_data;
466
                5'h11: o_wb_data <= gpstx_data;
467
                // 5'hf: UART_SETUP
468
                // 4'h6: GPIO
469
                // ?? : GPS-UARTRX
470
                // ?? : GPS-UARTTX
471
                default: o_wb_data <= 32'h00;
472
                endcase
473
 
474
        assign  o_wb_stall = 1'b0;
475
        always @(posedge i_clk)
476
                o_wb_ack <= (i_wb_stb);
477
        assign  o_board_ints = { gpio_int, auxrx_int, auxtx_int, gpsrx_int, sw_int, btn_int };
478
 
479
 
480
endmodule

powered by: WebSVN 2.1.0

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