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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [rtl/] [wbicapesimple.v] - Blame information for rev 70

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

Line No. Rev Author Line
1 21 dgisselq
///////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbicapesimple.v
4
//
5
// Project:     Wishbone to ICAPE_SPARTAN6 interface conversion
6
//
7
// Purpose:     This is a companion project to the ICAPE2 conversion, instead
8
//              involving a conversion from a 32-bit WISHBONE bus to read
9
//      and write the ICAPE_SPARTAN6 program.  Since this is a simple interface
10
//      only, the smarts have been stripped out of it.  Therefore, if you wish
11
//      to write to or read from particular registers, you will need to do all
12
//      the sequencing yourself.
13
//
14
//
15
// Creator:     Dan Gisselquist, Ph.D.
16
//              Gisselquist Technology, LLC
17
//
18
///////////////////////////////////////////////////////////////////////////
19
//
20
// Copyright (C) 2015, Gisselquist Technology, LLC
21
//
22
// This program is free software (firmware): you can redistribute it and/or
23
// modify it under the terms of  the GNU General Public License as published
24
// by the Free Software Foundation, either version 3 of the License, or (at
25
// your option) any later version.
26
//
27
// This program is distributed in the hope that it will be useful, but WITHOUT
28
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
29
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
30
// for more details.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
///////////////////////////////////////////////////////////////////////////
37
//
38
module  wbicapesimple(i_clk,
39
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_data,
40
                        o_wb_ack, o_wb_stall, o_wb_data, icap_dbg);
41
        input                   i_clk;
42
        // Wishbone inputs
43
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
44
        input           [15:0]   i_wb_data;
45
        // Wishbone outputs
46
        output  reg             o_wb_ack;
47
        output  wire            o_wb_stall;
48
        output  reg     [15:0]   o_wb_data;
49
        output  wire    [25:0]   icap_dbg;
50
 
51
 
52
        // Divide our clock by 8.  Thus, a 100 MHz clock with a 10 ns period
53
        // gets divided down to an 80 ns period, which is greater than the 
54
        // minimum 50 ns as per the data sheet.
55
        reg     [2:0]    clk_divider;
56
        initial clk_divider=0;
57
        always @(posedge i_clk)
58
                clk_divider <= clk_divider + 3'h1;
59
 
60
        reg     icap_posedge, icap_preedge;
61
        initial icap_posedge = 0;
62
        always @(posedge i_clk)
63
                icap_posedge <= (clk_divider == 3'b011);
64
        initial icap_preedge = 0;
65
        always @(posedge i_clk)
66
                icap_preedge <= (clk_divider == 3'b010);
67
                // icap_posedge <= (&clk_divider);
68
 
69
        wire    icap_clk;
70
        assign  icap_clk = clk_divider[2];
71
 
72
        reg             icap_ce_n, icap_we_n;
73
        reg     [15:0]   icap_data_i;
74
 
75
 
76
        wire            icap_busy;
77
        wire    [15:0]   icap_data_o;
78
        ICAP_SPARTAN6   icap_inst(
79
                .BUSY(icap_busy), // Active high, low during all writes
80
                .O(icap_data_o),
81
                .CE(icap_ce_n),
82
                .CLK(icap_clk),
83
                .I(icap_data_i),
84
                .WRITE(icap_we_n));
85
 
86
        // assign       o_wb_stall = (i_wb_cyc)&&((~icap_posedge)||((~icap_ce_n)&&(icap_busy)));
87
 
88
        wire    [15:0]   brev_i_wb_data;
89
        assign  brev_i_wb_data[ 0] = i_wb_data[ 7];
90
        assign  brev_i_wb_data[ 1] = i_wb_data[ 6];
91
        assign  brev_i_wb_data[ 2] = i_wb_data[ 5];
92
        assign  brev_i_wb_data[ 3] = i_wb_data[ 4];
93
        assign  brev_i_wb_data[ 4] = i_wb_data[ 3];
94
        assign  brev_i_wb_data[ 5] = i_wb_data[ 2];
95
        assign  brev_i_wb_data[ 6] = i_wb_data[ 1];
96
        assign  brev_i_wb_data[ 7] = i_wb_data[ 0];
97
        //
98
        assign  brev_i_wb_data[ 8] = i_wb_data[15];
99
        assign  brev_i_wb_data[ 9] = i_wb_data[14];
100
        assign  brev_i_wb_data[10] = i_wb_data[13];
101
        assign  brev_i_wb_data[11] = i_wb_data[12];
102
        assign  brev_i_wb_data[12] = i_wb_data[11];
103
        assign  brev_i_wb_data[13] = i_wb_data[10];
104
        assign  brev_i_wb_data[14] = i_wb_data[ 9];
105
        assign  brev_i_wb_data[15] = i_wb_data[ 8];
106
        //
107
 
108
        initial icap_data_i = 0;
109
        always @(posedge i_clk)
110
                if (icap_preedge)
111
                begin
112
                        if (~i_wb_cyc)
113
                                icap_data_i <= 16'hffff;
114
                        else if ((icap_ce_n)||(~icap_busy))
115
                                icap_data_i <= brev_i_wb_data[15:0];
116
                end
117
 
118
        initial icap_we_n = 1'b1;
119
        always @(posedge i_clk)
120
                if ((icap_preedge)&&((icap_ce_n)||(~icap_busy)))
121
                        icap_we_n <= ~i_wb_we;
122
        initial icap_ce_n = 1'b1;
123
        always @(posedge i_clk)
124
                if ((icap_preedge)&&((icap_ce_n)||(~icap_busy)))
125
                        icap_ce_n <= ~((i_wb_cyc)&&(i_wb_stb));
126
                else if ((icap_preedge)&&(~i_wb_cyc))
127
                        icap_ce_n <= 1'b1;
128
        //initial       r_wb_stall = 1'b0;
129
        //always @(posedge i_clk)
130
                //r_wb_stall <= (~icap_posedge)&&(
131
                                        //&&(icap_preedge)&&(~icap_busy));
132
        // assign       o_wb_stall = (i_wb_cyc)&&((~icap_posedge)||((~icap_ce_n)&&(icap_busy)));
133
        assign  o_wb_stall = (~icap_posedge)
134
                                ||((i_wb_cyc)&&(~icap_ce_n)&&(icap_busy));
135
        initial o_wb_ack = 1'b0;
136
        always @(posedge i_clk)
137
                o_wb_ack <= ((~icap_ce_n)&&(i_wb_cyc)
138
                                        &&(icap_preedge)&&(~icap_busy));
139
 
140
        wire    [15:0]   brev_icap_data;
141
        assign  brev_icap_data[ 0] = icap_data_o[ 7];
142
        assign  brev_icap_data[ 1] = icap_data_o[ 6];
143
        assign  brev_icap_data[ 2] = icap_data_o[ 5];
144
        assign  brev_icap_data[ 3] = icap_data_o[ 4];
145
        assign  brev_icap_data[ 4] = icap_data_o[ 3];
146
        assign  brev_icap_data[ 5] = icap_data_o[ 2];
147
        assign  brev_icap_data[ 6] = icap_data_o[ 1];
148
        assign  brev_icap_data[ 7] = icap_data_o[ 0];
149
        //
150
        assign  brev_icap_data[ 8] = icap_data_o[15];
151
        assign  brev_icap_data[ 9] = icap_data_o[14];
152
        assign  brev_icap_data[10] = icap_data_o[13];
153
        assign  brev_icap_data[11] = icap_data_o[12];
154
        assign  brev_icap_data[12] = icap_data_o[11];
155
        assign  brev_icap_data[13] = icap_data_o[10];
156
        assign  brev_icap_data[14] = icap_data_o[ 9];
157
        assign  brev_icap_data[15] = icap_data_o[ 8];
158
        //
159
        initial o_wb_data = 16'h000;
160
        always @(posedge i_clk)
161
                if ((icap_posedge)&&((icap_ce_n)||(~icap_busy)))
162
                        o_wb_data <= brev_icap_data;
163
 
164
        assign  icap_dbg[25:0] = {
165
                        i_wb_cyc,i_wb_stb, i_wb_we, o_wb_ack, o_wb_stall,
166
                        icap_posedge, icap_clk, icap_ce_n, icap_busy, icap_we_n,
167
                        (icap_we_n)?icap_data_o : icap_data_i };
168
 
169
endmodule
170
 

powered by: WebSVN 2.1.0

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