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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [wboled.v] - Blame information for rev 26

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wboled.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
module  wboled(i_clk, i_cyc, i_stb, i_we, i_addr, i_data,
39
                        o_ack, o_stall, o_data,
40
                o_sck, o_cs_n, o_mosi, o_dbit,
41
                o_pwr, o_int);
42 26 dgisselq
        parameter       CBITS=4; // 2^4*2@6.25ns -> 200ns/clock > 150ns min
43 3 dgisselq
        input                   i_clk, i_cyc, i_stb, i_we;
44
        input           [1:0]    i_addr;
45
        input           [31:0]   i_data;
46
        output  reg             o_ack;
47
        output  wire            o_stall;
48
        output  reg     [31:0]   o_data;
49
        output  wire            o_sck, o_cs_n, o_mosi, o_dbit;
50
        output  reg     [2:0]    o_pwr;
51
        output  wire            o_int;
52
 
53
        reg             dev_wr, dev_dbit;
54
        reg     [31:0]   dev_word;
55
        reg     [1:0]    dev_len;
56
        wire            dev_busy;
57
        lloled  #(CBITS)
58
                lwlvl(i_clk, dev_wr, dev_dbit, dev_word, dev_len, dev_busy,
59
                        o_sck, o_cs_n, o_mosi, o_dbit);
60
 
61 21 dgisselq
`define EXTRA_WB_DELAY
62
`ifdef  EXTRA_WB_DELAY
63
        reg             r_wb_stb, r_wb_we;
64
        reg     [31:0]   r_wb_data;
65
        reg     [1:0]    r_wb_addr;
66
        always @(posedge i_clk)
67
                r_wb_stb <= i_stb;
68
        always @(posedge i_clk)
69
                r_wb_we <= i_we;
70
        always @(posedge i_clk)
71
                r_wb_data <= i_data;
72
        always @(posedge i_clk)
73
                r_wb_addr <= i_addr;
74
`else
75
        wire            r_wb_stb, r_wb_we;
76
        wire            r_wb_data;
77
        wire    [1:0]    r_wb_addr;
78
 
79
        assign  r_wb_stb  = i_stb;
80
        assign  r_wb_we   = i_we;
81
        assign  r_wb_data = i_data;
82
        assign  r_wb_addr = i_addr;
83
`endif
84
 
85
 
86
 
87 3 dgisselq
        reg             r_busy;
88
        reg     [3:0]    r_len;
89
        reg     [31:0]   r_a, r_b;
90
        always @(posedge i_clk)
91 21 dgisselq
                if ((r_wb_stb)&&(r_wb_we))
92 3 dgisselq
                begin
93 21 dgisselq
                        if (r_wb_addr[1:0]==2'b01)
94
                                r_a <= r_wb_data;
95
                        if (r_wb_addr[1:0]==2'b10)
96
                                r_b <= r_wb_data;
97 3 dgisselq
                end else if (r_cstb)
98
                begin
99
                        r_a <= 32'h00;
100
                        r_b <= 32'h00;
101
                end
102
 
103
        always @(posedge i_clk)
104
        begin
105 21 dgisselq
                case (r_wb_addr)
106 3 dgisselq
                2'b00: o_data <= { 13'h00, o_pwr, 8'h00, r_len, 3'h0, r_busy };
107
                2'b01: o_data <= r_a;
108
                2'b10: o_data <= r_b;
109
                2'b11: o_data <= { 13'h00, o_pwr, 8'h00, r_len, 3'h0, r_busy };
110
                endcase
111
        end
112
 
113
        initial o_ack = 1'b0;
114
        always @(posedge i_clk)
115 21 dgisselq
                o_ack <= r_wb_stb;
116 3 dgisselq
        assign  o_stall = 1'b0;
117
 
118
        reg     r_cstb, r_dstb, r_pstb;
119
        reg     [23:0]   r_data;
120
        initial r_cstb = 1'b0;
121
        initial r_dstb = 1'b0;
122
        initial r_pstb = 1'b0;
123
        always @(posedge i_clk)
124 21 dgisselq
                r_cstb <= (r_wb_stb)&&(r_wb_addr[1:0]==2'b00);
125 3 dgisselq
        always @(posedge i_clk)
126 21 dgisselq
                r_dstb <= (r_wb_stb)&&(r_wb_addr[1:0]==2'b11)&&(r_wb_data[22:20]==3'h0);
127 3 dgisselq
        always @(posedge i_clk)
128 21 dgisselq
                r_pstb <= (r_wb_stb)&&(r_wb_addr[1:0]==2'b11)&&(r_wb_data[22:20]!=3'h0);
129 3 dgisselq
        always @(posedge i_clk)
130 21 dgisselq
                r_data <= r_wb_data[23:0];
131 3 dgisselq
 
132
        initial o_pwr = 3'h0;
133
        always @(posedge i_clk)
134
                if (r_pstb)
135
                        o_pwr <= ((o_pwr)&(~r_data[22:20]))
136 21 dgisselq
                                        |((r_wb_data[18:16])&(r_data[22:20]));
137 3 dgisselq
 
138
        reg     [3:0]    b_len;
139
        always @(posedge i_clk)
140 21 dgisselq
                casez(r_wb_data[31:28])
141
                4'b000?: b_len <= (r_wb_data[16])? 4'h1:4'h2;
142 3 dgisselq
                4'b0010: b_len <= 4'h3;
143
                4'b0011: b_len <= 4'h4;
144
                4'b0100: b_len <= 4'h5;
145
                4'b0101: b_len <= 4'h6;
146
                4'b0110: b_len <= 4'h7;
147
                4'b0111: b_len <= 4'h8;
148
                4'b1000: b_len <= 4'h9;
149
                4'b1001: b_len <= 4'ha;
150
                4'b1010: b_len <= 4'hb;
151
                default: b_len <= 4'h0;
152
                endcase
153
 
154
        reg     [87:0]   r_sreg;
155
        initial r_busy = 1'b0;
156
        always @(posedge i_clk)
157
        if ((~r_busy)&&(r_cstb))
158
        begin
159
                dev_wr   <= 1'b0;
160
                dev_dbit <= 1'b0;
161
                r_sreg <= { r_data[23:0], r_a, r_b };
162
                r_len <= b_len;
163
                r_busy <= (b_len != 4'h0);
164
                if (b_len == 4'h1)
165
                        r_sreg[87:72] <= { r_data[7:0], r_data[7:0] };
166
                else if (b_len == 4'h2)
167
                        r_sreg[87:72] <= r_data[15:0];
168
                else
169
                        r_sreg[87:72] <= r_data[23:8];
170
        end else if ((~dev_busy)&&(r_dstb))
171
        begin
172
                dev_wr   <= 1'b0;
173
                dev_dbit <= 1'b1;
174
                r_sreg <= { r_data[15:0], 72'h00 };
175
                r_len <= 4'h2;
176
                r_busy <= 1'b1;
177
        end else if ((r_busy)&&(~dev_busy))
178
        begin
179
                dev_word <= r_sreg[87:56];
180
                r_sreg <= { r_sreg[55:0], 32'h00 };
181
                dev_len <= (r_len > 4'h4)? 2'b11:(r_len[1:0]+2'b11);
182
                r_len <= (r_len > 4'h4) ? (r_len-4'h4):0;
183
        end else if (r_busy)
184
                r_busy <= (r_len != 4'h0);
185
 
186
        assign  o_int = (~r_busy);
187
 
188
endmodule

powered by: WebSVN 2.1.0

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