| 1 |
3 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//
|
| 3 |
|
|
// Filename: wboled.v
|
| 4 |
|
|
//
|
| 5 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
| 6 |
|
|
//
|
| 7 |
34 |
dgisselq |
// Purpose: To provide a *very* simplified controller for a PMod OLEDrgb.
|
| 8 |
|
|
// This controller implements four registers (described below),
|
| 9 |
|
|
// although it might feel like only two in practice. As with all of our
|
| 10 |
|
|
// other wishbone work, all transactions are 32-bits--even though, as an
|
| 11 |
|
|
// example, the data word for the device is only ever 16-bits long.
|
| 12 |
3 |
dgisselq |
//
|
| 13 |
34 |
dgisselq |
// The device control, outlined below, is also colored by two facts:
|
| 14 |
|
|
// 1. There is no means to read from the device. Sure, the chip on the
|
| 15 |
|
|
// PMod has a full read/write bus, but it hasn't been entirely
|
| 16 |
|
|
// wired to the PMod pins. This was probably done so that the
|
| 17 |
|
|
// interface could handle the paucity of pins available, but for
|
| 18 |
|
|
// whatever reason, there's no way to read from the device.
|
| 19 |
|
|
// 2. The device is controlled by a SPI port, but with an extra wire that
|
| 20 |
|
|
// determines whether or not you are writing to the control or the
|
| 21 |
|
|
// data port on the device. Hence the four wire SPI protocol has
|
| 22 |
|
|
// lost the MISO wire and gained a Data / Control (N) (or dcn)
|
| 23 |
|
|
// wire.
|
| 24 |
|
|
// 3. As implemented, the device also has two power control wires and a
|
| 25 |
|
|
// reset wire. The reset wire is negative logic. Without setting
|
| 26 |
|
|
// the PMOD-Enable wire high, the board has no power. The
|
| 27 |
|
|
// VCCEN pin is not to be set high without PMOD-Enable high.
|
| 28 |
|
|
// Finally, setting reset low (with PMod-Enable high), places the
|
| 29 |
|
|
// device into a reset condition.
|
| 30 |
|
|
//
|
| 31 |
|
|
// The design of the controller, as with the design of other controllers
|
| 32 |
|
|
// we have built, is focused around the design principles:
|
| 33 |
|
|
// 1. Use the bottom 23 bits of a word for the command, if possible.
|
| 34 |
|
|
// Such commands can be loaded into registers with simple LDI
|
| 35 |
|
|
// instructions. Even better, restrict any status results from the
|
| 36 |
|
|
// device to 18 bits, so that instructions that use immediates
|
| 37 |
|
|
// such as TEST #,Rx, can use these immediates.
|
| 38 |
|
|
// 2. Protect against inadvertant changes to the power port. For this,
|
| 39 |
|
|
// we insist that a minimum of two bits be high to change the
|
| 40 |
|
|
// power port bits, and that just reading from the port and
|
| 41 |
|
|
// writing back with a changed power bit is not sufficient to
|
| 42 |
|
|
// change the power.
|
| 43 |
|
|
// 3. Permit atomic changes to the individual power control bits,
|
| 44 |
|
|
// by outlining which exact bits change upon any write, and
|
| 45 |
|
|
// permitting only the bits specified to change.
|
| 46 |
|
|
// 4. Don't stall the bus. So, if a command comes in and the
|
| 47 |
|
|
// device is busy, we'll ignore the command. It is up to the
|
| 48 |
|
|
// user to make certain the device isn't fed faster than it is
|
| 49 |
|
|
// able. (Perhaps the user wishes to add a FIFO?)
|
| 50 |
|
|
// 5. Finally, build this so that either a FIFO or DMA could control it.
|
| 51 |
|
|
//
|
| 52 |
|
|
// Registers:
|
| 53 |
|
|
// 0. Control -- There are several types of control commands to/from
|
| 54 |
|
|
// the device, all separated and determined by how many bytes are
|
| 55 |
|
|
// to be sent to the device for the said command. Commands written
|
| 56 |
|
|
// to the control port of the device are initiated by writes
|
| 57 |
|
|
// to this register.
|
| 58 |
|
|
//
|
| 59 |
|
|
// - Writes of all { 24'h00, data[7:0] } send the single byte
|
| 60 |
|
|
// data[7:0] to the device.
|
| 61 |
|
|
// - Writes of { 16'h01, data[15:0] } send two bytes,
|
| 62 |
|
|
// data[15:0], to the device.
|
| 63 |
|
|
// - Writes of { 4'h2, 4'hx, data[23:0] } send three bytes,
|
| 64 |
|
|
// data[23:0], to the device.
|
| 65 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send four bytes,
|
| 66 |
|
|
// data[23:0], then r_a[31:24] to the device.
|
| 67 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send five bytes,
|
| 68 |
|
|
// data[23:0], then r_a[31:16] to the device.
|
| 69 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send six bytes,
|
| 70 |
|
|
// data[23:0], then r_a[31:8] to the device.
|
| 71 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send seven bytes,
|
| 72 |
|
|
// data[23:0], then r_a[31:0] to the device.
|
| 73 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send eight bytes,
|
| 74 |
|
|
// data[23:0], r_a[31:16], then r_b[31:24] to the device.
|
| 75 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send nine bytes,
|
| 76 |
|
|
// data[23:0], r_a[31:16], then r_b[31:16] to the device.
|
| 77 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send ten bytes,
|
| 78 |
|
|
// data[23:0], r_a[31:16], then r_b[31:8] to the device.
|
| 79 |
|
|
// - Writes of { 4'h3, 4'hx, data[23:0] } send eleven bytes,
|
| 80 |
|
|
// data[23:0], r_a[31:16], then r_b[31:0] to the device.
|
| 81 |
|
|
//
|
| 82 |
|
|
// 1. A This register is used, just like the B register below, for
|
| 83 |
|
|
// setting up commands that send multiple bytes to the device.
|
| 84 |
|
|
// Be aware that the high order bits/bytes will be sent first.
|
| 85 |
|
|
// This is one of the few registers that may be read with meaning.
|
| 86 |
|
|
// Once the word is written, however, the register is cleared.
|
| 87 |
|
|
//
|
| 88 |
|
|
// 2. B This is the same as the A register, save on writes the A
|
| 89 |
|
|
// register will be written first before any bits from the B
|
| 90 |
|
|
// register. As with the A register, this value is cleared upon
|
| 91 |
|
|
// any write--regardless of whether its value is used in the
|
| 92 |
|
|
// write.
|
| 93 |
|
|
//
|
| 94 |
|
|
// 3. Data --- This is both the data and the power control register.
|
| 95 |
|
|
//
|
| 96 |
|
|
// To write data to the graphics data RAM within the device,
|
| 97 |
|
|
// simply write a 16'bit word: { 16'h00, data[15:0] } to this
|
| 98 |
|
|
// port.
|
| 99 |
|
|
//
|
| 100 |
|
|
// To change the three power bits, {reset, vccen, pmoden},
|
| 101 |
|
|
// you must also set a 1'b1 in the corresponding bit position from
|
| 102 |
|
|
// bit 16-18. Hence a:
|
| 103 |
|
|
//
|
| 104 |
|
|
// 32'h010001 sets the pmod enable bit, whereas 32'h010000 clears
|
| 105 |
|
|
// it.
|
| 106 |
|
|
// 32'h020002 sets the vcc bit, whereas 32'h010000 clears it.
|
| 107 |
|
|
//
|
| 108 |
|
|
// Multiple of the power bits can be changed at once. Each
|
| 109 |
|
|
// respective bit is only changed if it's change enable bit is
|
| 110 |
|
|
// also high.
|
| 111 |
|
|
//
|
| 112 |
|
|
//
|
| 113 |
|
|
//
|
| 114 |
3 |
dgisselq |
// Creator: Dan Gisselquist, Ph.D.
|
| 115 |
|
|
// Gisselquist Technology, LLC
|
| 116 |
|
|
//
|
| 117 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 118 |
|
|
//
|
| 119 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
| 120 |
|
|
//
|
| 121 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 122 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 123 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 124 |
|
|
// your option) any later version.
|
| 125 |
|
|
//
|
| 126 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 127 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 128 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 129 |
|
|
// for more details.
|
| 130 |
|
|
//
|
| 131 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 132 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
| 133 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 134 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 135 |
|
|
//
|
| 136 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 137 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 138 |
|
|
//
|
| 139 |
|
|
//
|
| 140 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 141 |
|
|
//
|
| 142 |
|
|
//
|
| 143 |
|
|
module wboled(i_clk, i_cyc, i_stb, i_we, i_addr, i_data,
|
| 144 |
|
|
o_ack, o_stall, o_data,
|
| 145 |
|
|
o_sck, o_cs_n, o_mosi, o_dbit,
|
| 146 |
|
|
o_pwr, o_int);
|
| 147 |
36 |
dgisselq |
parameter CBITS=4, // 2^4*13ns -> 208ns/clock > 150ns min
|
| 148 |
34 |
dgisselq |
EXTRA_BUS_CLOCK = 0;
|
| 149 |
3 |
dgisselq |
input i_clk, i_cyc, i_stb, i_we;
|
| 150 |
|
|
input [1:0] i_addr;
|
| 151 |
|
|
input [31:0] i_data;
|
| 152 |
|
|
output reg o_ack;
|
| 153 |
|
|
output wire o_stall;
|
| 154 |
|
|
output reg [31:0] o_data;
|
| 155 |
|
|
output wire o_sck, o_cs_n, o_mosi, o_dbit;
|
| 156 |
|
|
output reg [2:0] o_pwr;
|
| 157 |
|
|
output wire o_int;
|
| 158 |
|
|
|
| 159 |
|
|
reg dev_wr, dev_dbit;
|
| 160 |
|
|
reg [31:0] dev_word;
|
| 161 |
|
|
reg [1:0] dev_len;
|
| 162 |
|
|
wire dev_busy;
|
| 163 |
|
|
lloled #(CBITS)
|
| 164 |
|
|
lwlvl(i_clk, dev_wr, dev_dbit, dev_word, dev_len, dev_busy,
|
| 165 |
|
|
o_sck, o_cs_n, o_mosi, o_dbit);
|
| 166 |
|
|
|
| 167 |
34 |
dgisselq |
wire wb_stb, wb_we;
|
| 168 |
|
|
wire [31:0] wb_data;
|
| 169 |
|
|
wire [1:0] wb_addr;
|
| 170 |
21 |
dgisselq |
|
| 171 |
34 |
dgisselq |
// I've thought about bumping this from a clock at <= 100MHz up to a
|
| 172 |
|
|
// clock near 200MHz. Doing so requires an extra clock to come off
|
| 173 |
|
|
// the bus--the bus fanout is just too wide otherwise. However,
|
| 174 |
|
|
// if you don't need to ... why take the extra clock cycle? Hence
|
| 175 |
|
|
// this little snippet of code allows the rest of the controller
|
| 176 |
|
|
// to work at 200MHz or 100MHz as need be.
|
| 177 |
|
|
generate
|
| 178 |
|
|
if (EXTRA_BUS_CLOCK != 0)
|
| 179 |
|
|
begin
|
| 180 |
|
|
reg r_wb_stb, r_wb_we;
|
| 181 |
|
|
reg [31:0] r_wb_data;
|
| 182 |
|
|
reg [1:0] r_wb_addr;
|
| 183 |
|
|
always @(posedge i_clk)
|
| 184 |
|
|
r_wb_stb <= i_stb;
|
| 185 |
|
|
always @(posedge i_clk)
|
| 186 |
|
|
r_wb_we <= i_we;
|
| 187 |
|
|
always @(posedge i_clk)
|
| 188 |
|
|
r_wb_data <= i_data;
|
| 189 |
|
|
always @(posedge i_clk)
|
| 190 |
|
|
r_wb_addr <= i_addr;
|
| 191 |
21 |
dgisselq |
|
| 192 |
34 |
dgisselq |
assign wb_stb = r_wb_stb;
|
| 193 |
|
|
assign wb_we = r_wb_we;
|
| 194 |
|
|
assign wb_data = r_wb_data;
|
| 195 |
|
|
assign wb_addr = r_wb_addr;
|
| 196 |
|
|
end else begin
|
| 197 |
|
|
assign wb_stb = i_stb;
|
| 198 |
|
|
assign wb_we = i_we;
|
| 199 |
|
|
assign wb_data = i_data;
|
| 200 |
|
|
assign wb_addr = i_addr;
|
| 201 |
|
|
end endgenerate
|
| 202 |
21 |
dgisselq |
|
| 203 |
|
|
|
| 204 |
34 |
dgisselq |
|
| 205 |
3 |
dgisselq |
reg r_busy;
|
| 206 |
|
|
reg [3:0] r_len;
|
| 207 |
34 |
dgisselq |
|
| 208 |
|
|
|
| 209 |
|
|
//
|
| 210 |
|
|
// Handle registers A & B. These are set either upon a write, or
|
| 211 |
|
|
// cleared (set to zero) upon any command to the control register.
|
| 212 |
|
|
//
|
| 213 |
3 |
dgisselq |
reg [31:0] r_a, r_b;
|
| 214 |
|
|
always @(posedge i_clk)
|
| 215 |
34 |
dgisselq |
if ((wb_stb)&&(wb_we))
|
| 216 |
3 |
dgisselq |
begin
|
| 217 |
34 |
dgisselq |
if (wb_addr[1:0]==2'b01)
|
| 218 |
|
|
r_a <= wb_data;
|
| 219 |
|
|
if (wb_addr[1:0]==2'b10)
|
| 220 |
|
|
r_b <= wb_data;
|
| 221 |
3 |
dgisselq |
end else if (r_cstb)
|
| 222 |
|
|
begin
|
| 223 |
|
|
r_a <= 32'h00;
|
| 224 |
|
|
r_b <= 32'h00;
|
| 225 |
|
|
end
|
| 226 |
|
|
|
| 227 |
34 |
dgisselq |
//
|
| 228 |
|
|
// Handle reads from our device. These really aren't all that
|
| 229 |
|
|
// interesting, but ... we can do them anyway. We attempt to provide
|
| 230 |
|
|
// some sort of useful value here. For example, upon reading r_a or
|
| 231 |
|
|
// r_b, you can read the current value(s) of those register(s).
|
| 232 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 233 |
|
|
begin
|
| 234 |
34 |
dgisselq |
case (wb_addr)
|
| 235 |
|
|
2'b00: o_data <= { 13'h00, o_pwr, 8'h00, r_len, 1'b0, o_dbit, !o_cs_n, r_busy };
|
| 236 |
3 |
dgisselq |
2'b01: o_data <= r_a;
|
| 237 |
|
|
2'b10: o_data <= r_b;
|
| 238 |
34 |
dgisselq |
2'b11: o_data <= { 16'h00, 13'h0, o_pwr };
|
| 239 |
3 |
dgisselq |
endcase
|
| 240 |
|
|
end
|
| 241 |
|
|
|
| 242 |
|
|
initial o_ack = 1'b0;
|
| 243 |
|
|
always @(posedge i_clk)
|
| 244 |
34 |
dgisselq |
o_ack <= wb_stb;
|
| 245 |
3 |
dgisselq |
assign o_stall = 1'b0;
|
| 246 |
|
|
|
| 247 |
34 |
dgisselq |
reg r_cstb, r_dstb, r_pstb, r_pre_busy;
|
| 248 |
|
|
reg [18:0] r_data;
|
| 249 |
3 |
dgisselq |
initial r_cstb = 1'b0;
|
| 250 |
|
|
initial r_dstb = 1'b0;
|
| 251 |
|
|
initial r_pstb = 1'b0;
|
| 252 |
34 |
dgisselq |
initial r_pre_busy = 1'b0; // Used to clear the interrupt a touch earlier
|
| 253 |
|
|
|
| 254 |
|
|
// The control strobe. This will be true if we need to command a
|
| 255 |
|
|
// control interaction.
|
| 256 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 257 |
34 |
dgisselq |
r_cstb <= (wb_stb)&&(wb_we)&&(wb_addr[1:0]==2'b00);
|
| 258 |
|
|
|
| 259 |
|
|
// The data strobe, true if we need to command a data interaction.
|
| 260 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 261 |
34 |
dgisselq |
r_dstb <= (wb_stb)&&(wb_we)&&(wb_addr[1:0]==2'b11)&&(wb_data[18:16]==3'h0);
|
| 262 |
|
|
|
| 263 |
|
|
// The power strobe. True if we are about to adjust the power and/or
|
| 264 |
|
|
// reset bits.
|
| 265 |
|
|
always @(posedge i_clk) // Power strobe, change power settings
|
| 266 |
|
|
r_pstb <= (wb_stb)&&(wb_we)&&(wb_addr[1:0]==2'b11)&&(wb_data[18:16]!=3'h0);
|
| 267 |
|
|
|
| 268 |
|
|
// Pre-busy: true if either r_cstb or r_dstb is true, and true on the
|
| 269 |
|
|
// same clock they are true. This is to support our interrupt, by
|
| 270 |
|
|
// clearing the interrupt one clock earlier--lest the DMA decide to send
|
| 271 |
|
|
// two words our way instead of one.
|
| 272 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 273 |
34 |
dgisselq |
r_pre_busy <= (wb_stb)&&(wb_we)&&
|
| 274 |
|
|
((wb_addr[1:0]==2'b11)||(wb_addr[1:0]==2'b00));
|
| 275 |
|
|
|
| 276 |
|
|
// But ... to use these strobe values, we are now one more clock
|
| 277 |
|
|
// removed from the bus. We need something that matches this, so let's
|
| 278 |
|
|
// delay our bus data one more clock 'til the time when we actually use
|
| 279 |
|
|
// it.
|
| 280 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 281 |
34 |
dgisselq |
r_data <= wb_data[18:0];
|
| 282 |
3 |
dgisselq |
|
| 283 |
|
|
initial o_pwr = 3'h0;
|
| 284 |
|
|
always @(posedge i_clk)
|
| 285 |
|
|
if (r_pstb)
|
| 286 |
34 |
dgisselq |
o_pwr <= ((o_pwr)&(~r_data[18:16]))
|
| 287 |
|
|
|((r_data[2:0])&(r_data[18:16]));
|
| 288 |
3 |
dgisselq |
|
| 289 |
34 |
dgisselq |
// Sadly, because our commands can have a whole slew of different
|
| 290 |
|
|
// lengths, and because these lengths can be ... difficult to
|
| 291 |
|
|
// decipher from the command (especially the first two lengths),
|
| 292 |
|
|
// this quick case statement is needed to decode the amount of bytes
|
| 293 |
|
|
// that will be sent.
|
| 294 |
3 |
dgisselq |
reg [3:0] b_len;
|
| 295 |
|
|
always @(posedge i_clk)
|
| 296 |
34 |
dgisselq |
casez(wb_data[31:28])
|
| 297 |
|
|
4'b0000: b_len <= (wb_data[16])? 4'h2:4'h1;
|
| 298 |
|
|
4'b0001: b_len <= 4'h2;
|
| 299 |
3 |
dgisselq |
4'b0010: b_len <= 4'h3;
|
| 300 |
|
|
4'b0011: b_len <= 4'h4;
|
| 301 |
|
|
4'b0100: b_len <= 4'h5;
|
| 302 |
|
|
4'b0101: b_len <= 4'h6;
|
| 303 |
|
|
4'b0110: b_len <= 4'h7;
|
| 304 |
|
|
4'b0111: b_len <= 4'h8;
|
| 305 |
|
|
4'b1000: b_len <= 4'h9;
|
| 306 |
|
|
4'b1001: b_len <= 4'ha;
|
| 307 |
|
|
4'b1010: b_len <= 4'hb;
|
| 308 |
|
|
default: b_len <= 4'h0;
|
| 309 |
|
|
endcase
|
| 310 |
|
|
|
| 311 |
34 |
dgisselq |
//
|
| 312 |
|
|
// On the next clock, we're going to set our data register to
|
| 313 |
|
|
// whatever's in register A, and B, and ... something of the data
|
| 314 |
|
|
// written to the control register. Because this must all be
|
| 315 |
|
|
// written on the most-significant bits of a word, we pause a moment
|
| 316 |
|
|
// here to move the control word that was writen to our bus up
|
| 317 |
|
|
// by an amount given by the length of our message. That way, you
|
| 318 |
|
|
// can write to the bottom bits of the register, and yet still end
|
| 319 |
|
|
// up in the top several bits of the following register.
|
| 320 |
|
|
//
|
| 321 |
|
|
reg [23:0] c_data;
|
| 322 |
|
|
always @(posedge i_clk)
|
| 323 |
|
|
if (wb_data[31:29] != 3'h0)
|
| 324 |
|
|
c_data <= wb_data[23:0];
|
| 325 |
|
|
else if (wb_data[16])
|
| 326 |
|
|
c_data <= { wb_data[15:0], 8'h00 };
|
| 327 |
|
|
else
|
| 328 |
|
|
c_data <= { wb_data[7:0], 16'h00 };
|
| 329 |
|
|
|
| 330 |
|
|
//
|
| 331 |
|
|
// Finally, after massaging the incoming data off our bus, we finally
|
| 332 |
|
|
// get to controlling the lower level controller and sending the
|
| 333 |
|
|
// data to the device itself.
|
| 334 |
|
|
//
|
| 335 |
|
|
// The basic idea is this: we use r_busy to know if we are in the
|
| 336 |
|
|
// middle of an operation, or whether or not we will be responsive to
|
| 337 |
|
|
// the bus. r_sreg holds the data we wish to send, and r_len the
|
| 338 |
|
|
// number of bytes within r_sreg that remain to be sent. The controller
|
| 339 |
|
|
// will accept up to 32-bits at a time, so once we issue a command
|
| 340 |
|
|
// (dev_wr & !dev_busy), we transition to either the next command.
|
| 341 |
|
|
// Once all the data has been sent, and the device is now idle, we
|
| 342 |
|
|
// clear r_busy and therefore become responsive to the bus again.
|
| 343 |
|
|
//
|
| 344 |
|
|
//
|
| 345 |
|
|
reg [87:0] r_sreg; // Composed of 24-bits, 32-bits, and 32-bits
|
| 346 |
3 |
dgisselq |
initial r_busy = 1'b0;
|
| 347 |
34 |
dgisselq |
initial dev_wr = 1'b1;
|
| 348 |
3 |
dgisselq |
always @(posedge i_clk)
|
| 349 |
|
|
begin
|
| 350 |
34 |
dgisselq |
dev_wr <= 1'b0;
|
| 351 |
|
|
if ((~r_busy)&&(r_cstb))
|
| 352 |
|
|
begin
|
| 353 |
|
|
dev_dbit <= 1'b0;
|
| 354 |
|
|
r_sreg <= { c_data[23:0], r_a, r_b };
|
| 355 |
|
|
r_len <= b_len;
|
| 356 |
|
|
r_busy <= (b_len != 4'h0);
|
| 357 |
|
|
end else if ((~r_busy)&&(r_dstb))
|
| 358 |
|
|
begin
|
| 359 |
|
|
dev_dbit <= 1'b1;
|
| 360 |
|
|
r_sreg <= { r_data[15:0], 72'h00 };
|
| 361 |
|
|
r_len <= 4'h2;
|
| 362 |
|
|
r_busy <= 1'b1;
|
| 363 |
|
|
end else if ((r_busy)&&(!dev_busy))
|
| 364 |
|
|
begin
|
| 365 |
|
|
// Issue the command to write up to 32-bits at a time
|
| 366 |
|
|
dev_wr <= (r_len != 4'h0);
|
| 367 |
|
|
dev_word <= r_sreg[87:56];
|
| 368 |
|
|
r_sreg <= { r_sreg[55:0], 32'h00 };
|
| 369 |
|
|
dev_len <= (r_len > 4'h4)? 2'b11:(r_len[1:0]+2'b11);
|
| 370 |
|
|
if (dev_wr)
|
| 371 |
|
|
r_len <= (r_len > 4'h4) ? (r_len-4'h4):0;
|
| 372 |
|
|
r_busy <= (dev_wr)||(r_len != 4'h0)&&(!dev_wr);
|
| 373 |
|
|
end else if (r_busy) // & dev_busy
|
| 374 |
|
|
begin
|
| 375 |
|
|
dev_wr <= (r_len != 4'h0);
|
| 376 |
|
|
dev_len <= (r_len > 4'h4)? 2'b11:(r_len[1:0]+2'b11);
|
| 377 |
|
|
end
|
| 378 |
|
|
end
|
| 379 |
3 |
dgisselq |
|
| 380 |
34 |
dgisselq |
//
|
| 381 |
|
|
// Here, we pick a self-clearing interrupt input. This will set the
|
| 382 |
|
|
// interrupt any time we are idle, and will automatically clear itself
|
| 383 |
|
|
// any time we become busy. This should be sufficient to allow the
|
| 384 |
|
|
// DMA controller to send things to the card.
|
| 385 |
|
|
//
|
| 386 |
|
|
// Of course ... if you are not running in any sort of interrupt mode,
|
| 387 |
|
|
// you *could* just ignore this line and poll the busy bit instead.
|
| 388 |
|
|
//
|
| 389 |
|
|
assign o_int = (~r_busy)&&(!r_pre_busy);
|
| 390 |
3 |
dgisselq |
|
| 391 |
|
|
endmodule
|