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

Subversion Repositories openarty

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

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
        parameter       CBITS=4; // 2^4*2@5ns -> 160ns/clock > 150ns min
43
        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
        reg             r_busy;
62
        reg     [3:0]    r_len;
63
        reg     [31:0]   r_a, r_b;
64
        always @(posedge i_clk)
65
                if ((i_stb)&&(i_we))
66
                begin
67
                        if (i_addr[1:0]==2'b01)
68
                                r_a <= i_data;
69
                        if (i_addr[1:0]==2'b10)
70
                                r_b <= i_data;
71
                end else if (r_cstb)
72
                begin
73
                        r_a <= 32'h00;
74
                        r_b <= 32'h00;
75
                end
76
 
77
        always @(posedge i_clk)
78
        begin
79
                case (i_addr)
80
                2'b00: o_data <= { 13'h00, o_pwr, 8'h00, r_len, 3'h0, r_busy };
81
                2'b01: o_data <= r_a;
82
                2'b10: o_data <= r_b;
83
                2'b11: o_data <= { 13'h00, o_pwr, 8'h00, r_len, 3'h0, r_busy };
84
                endcase
85
        end
86
 
87
        initial o_ack = 1'b0;
88
        always @(posedge i_clk)
89
                o_ack <= i_stb;
90
        assign  o_stall = 1'b0;
91
 
92
        reg     r_cstb, r_dstb, r_pstb;
93
        reg     [23:0]   r_data;
94
        initial r_cstb = 1'b0;
95
        initial r_dstb = 1'b0;
96
        initial r_pstb = 1'b0;
97
        always @(posedge i_clk)
98
                r_cstb <= (i_stb)&&(i_addr[1:0]==2'b00);
99
        always @(posedge i_clk)
100
                r_dstb <= (i_stb)&&(i_addr[1:0]==2'b11)&&(i_data[22:20]==3'h0);
101
        always @(posedge i_clk)
102
                r_pstb <= (i_stb)&&(i_addr[1:0]==2'b11)&&(i_data[22:20]!=3'h0);
103
        always @(posedge i_clk)
104
                r_data <= i_data[23:0];
105
 
106
        initial o_pwr = 3'h0;
107
        always @(posedge i_clk)
108
                if (r_pstb)
109
                        o_pwr <= ((o_pwr)&(~r_data[22:20]))
110
                                        |((i_data[18:16])&(r_data[22:20]));
111
 
112
        reg     [3:0]    b_len;
113
        always @(posedge i_clk)
114
                casez(i_data[31:28])
115
                4'b000?: b_len <= (i_data[16])? 4'h1:4'h2;
116
                4'b0010: b_len <= 4'h3;
117
                4'b0011: b_len <= 4'h4;
118
                4'b0100: b_len <= 4'h5;
119
                4'b0101: b_len <= 4'h6;
120
                4'b0110: b_len <= 4'h7;
121
                4'b0111: b_len <= 4'h8;
122
                4'b1000: b_len <= 4'h9;
123
                4'b1001: b_len <= 4'ha;
124
                4'b1010: b_len <= 4'hb;
125
                default: b_len <= 4'h0;
126
                endcase
127
 
128
        reg     [87:0]   r_sreg;
129
        initial r_busy = 1'b0;
130
        always @(posedge i_clk)
131
        if ((~r_busy)&&(r_cstb))
132
        begin
133
                dev_wr   <= 1'b0;
134
                dev_dbit <= 1'b0;
135
                r_sreg <= { r_data[23:0], r_a, r_b };
136
                r_len <= b_len;
137
                r_busy <= (b_len != 4'h0);
138
                if (b_len == 4'h1)
139
                        r_sreg[87:72] <= { r_data[7:0], r_data[7:0] };
140
                else if (b_len == 4'h2)
141
                        r_sreg[87:72] <= r_data[15:0];
142
                else
143
                        r_sreg[87:72] <= r_data[23:8];
144
        end else if ((~dev_busy)&&(r_dstb))
145
        begin
146
                dev_wr   <= 1'b0;
147
                dev_dbit <= 1'b1;
148
                r_sreg <= { r_data[15:0], 72'h00 };
149
                r_len <= 4'h2;
150
                r_busy <= 1'b1;
151
        end else if ((r_busy)&&(~dev_busy))
152
        begin
153
                dev_word <= r_sreg[87:56];
154
                r_sreg <= { r_sreg[55:0], 32'h00 };
155
                dev_len <= (r_len > 4'h4)? 2'b11:(r_len[1:0]+2'b11);
156
                r_len <= (r_len > 4'h4) ? (r_len-4'h4):0;
157
        end else if (r_busy)
158
                r_busy <= (r_len != 4'h0);
159
 
160
        assign  o_int = (~r_busy);
161
 
162
endmodule

powered by: WebSVN 2.1.0

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