Merged r9433:9527 from features/gr-usrp2 into trunk. Adds usrp2 and gr-usrp2 top...
[debian/gnuradio] / usrp2 / fpga / opencores / sd_interface / RTL / wishBoneBI.v
1 //////////////////////////////////////////////////////////////////////\r
2 ////                                                              ////\r
3 //// wishBoneBI.v                                                 ////\r
4 ////                                                              ////\r
5 //// This file is part of the usbhostslave opencores effort.\r
6 //// <http://www.opencores.org/cores//>                           ////\r
7 ////                                                              ////\r
8 //// Module Description:                                          ////\r
9 //// \r
10 ////                                                              ////\r
11 //// To Do:                                                       ////\r
12 //// \r
13 ////                                                              ////\r
14 //// Author(s):                                                   ////\r
15 //// - Steve Fielding, sfielding@base2designs.com                 ////\r
16 ////                                                              ////\r
17 //////////////////////////////////////////////////////////////////////\r
18 ////                                                              ////\r
19 //// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////\r
20 ////                                                              ////\r
21 //// This source file may be used and distributed without         ////\r
22 //// restriction provided that this copyright statement is not    ////\r
23 //// removed from the file and that any derivative work contains  ////\r
24 //// the original copyright notice and the associated disclaimer. ////\r
25 ////                                                              ////\r
26 //// This source file is free software; you can redistribute it   ////\r
27 //// and/or modify it under the terms of the GNU Lesser General   ////\r
28 //// Public License as published by the Free Software Foundation; ////\r
29 //// either version 2.1 of the License, or (at your option) any   ////\r
30 //// later version.                                               ////\r
31 ////                                                              ////\r
32 //// This source is distributed in the hope that it will be       ////\r
33 //// useful, but WITHOUT ANY WARRANTY; without even the implied   ////\r
34 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////\r
35 //// PURPOSE. See the GNU Lesser General Public License for more  ////\r
36 //// details.                                                     ////\r
37 ////                                                              ////\r
38 //// You should have received a copy of the GNU Lesser General    ////\r
39 //// Public License along with this source; if not, download it   ////\r
40 //// from <http://www.opencores.org/lgpl.shtml>                   ////\r
41 ////                                                              ////\r
42 //////////////////////////////////////////////////////////////////////\r
43 //\r
44 `include "timescale.v"\r
45 `include "spiMaster_defines.v"\r
46 \r
47  \r
48 module wishBoneBI (\r
49   clk, rst,\r
50   address, dataIn, dataOut, writeEn, \r
51   strobe_i,\r
52   ack_o,\r
53   ctrlStsRegSel, \r
54   rxFifoSel, txFifoSel,\r
55   dataFromCtrlStsReg,\r
56   dataFromRxFifo,\r
57   dataFromTxFifo  \r
58   );\r
59 input clk;\r
60 input rst;\r
61 input [7:0] address;\r
62 input [7:0] dataIn;\r
63 output [7:0] dataOut;\r
64 input strobe_i;\r
65 output ack_o;\r
66 input writeEn;\r
67 output ctrlStsRegSel;\r
68 output rxFifoSel;\r
69 output txFifoSel;\r
70 input [7:0] dataFromCtrlStsReg;\r
71 input [7:0] dataFromRxFifo;\r
72 input [7:0] dataFromTxFifo;\r
73 \r
74 \r
75 wire clk;\r
76 wire rst;\r
77 wire [7:0] address;\r
78 wire [7:0] dataIn;\r
79 reg [7:0] dataOut;\r
80 wire writeEn;\r
81 wire strobe_i;\r
82 reg ack_o;\r
83 reg ctrlStsRegSel;\r
84 reg rxFifoSel;\r
85 reg txFifoSel;\r
86 wire [7:0] dataFromCtrlStsReg;\r
87 wire [7:0] dataFromRxFifo;\r
88 wire [7:0] dataFromTxFifo;\r
89 \r
90 //internal wires and regs\r
91 reg ack_delayed;\r
92 reg ack_immediate;\r
93 \r
94 //address decode and data mux\r
95 always @(address or\r
96   dataFromCtrlStsReg or\r
97   dataFromRxFifo or\r
98   dataFromTxFifo)\r
99 begin\r
100   ctrlStsRegSel <= 1'b0;\r
101   rxFifoSel <= 1'b0;\r
102   txFifoSel <= 1'b0;\r
103   case (address & `ADDRESS_DECODE_MASK)\r
104     `CTRL_STS_REG_BASE : begin\r
105       ctrlStsRegSel <= 1'b1;\r
106       dataOut <= dataFromCtrlStsReg;\r
107     end\r
108     `RX_FIFO_BASE : begin\r
109       rxFifoSel <= 1'b1;\r
110       dataOut <= dataFromRxFifo;\r
111     end\r
112     `TX_FIFO_BASE : begin\r
113       txFifoSel <= 1'b1;\r
114       dataOut <= dataFromTxFifo;\r
115     end\r
116     default: \r
117       dataOut <= 8'h00;\r
118   endcase\r
119 end\r
120 \r
121 //delayed ack\r
122 always @(posedge clk) begin\r
123   ack_delayed <= strobe_i;\r
124 end\r
125 \r
126 //immediate ack\r
127 always @(strobe_i) begin\r
128   ack_immediate <= strobe_i;\r
129 end \r
130 \r
131 //select between immediate and delayed ack\r
132 always @(writeEn or address or ack_delayed or ack_immediate) begin\r
133   if (writeEn == 1'b0 &&\r
134       (address == `RX_FIFO_BASE + `FIFO_DATA_REG ||\r
135        address == `TX_FIFO_BASE + `FIFO_DATA_REG) )\r
136   begin\r
137     ack_o <= ack_delayed;\r
138   end\r
139   else\r
140   begin\r
141     ack_o <= ack_immediate;\r
142   end\r
143 end\r
144 \r
145 endmodule\r