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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [trunk/] [RTL/] [buffers/] [RxFifoBI.v] - Blame information for rev 22

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

Line No. Rev Author Line
1 22 sfielding
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// RxfifoBI.v                                                   ////
4
////                                                              ////
5
//// This file is part of the usbhostslave opencores effort.
6
//// <http://www.opencores.org/cores//>                           ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
//// 
10
////                                                              ////
11
//// To Do:                                                       ////
12
//// 
13
////                                                              ////
14
//// Author(s):                                                   ////
15
//// - Steve Fielding, sfielding@base2designs.com                 ////
16
////                                                              ////
17
//////////////////////////////////////////////////////////////////////
18
////                                                              ////
19
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
20
////                                                              ////
21
//// This source file may be used and distributed without         ////
22
//// restriction provided that this copyright statement is not    ////
23
//// removed from the file and that any derivative work contains  ////
24
//// the original copyright notice and the associated disclaimer. ////
25
////                                                              ////
26
//// This source file is free software; you can redistribute it   ////
27
//// and/or modify it under the terms of the GNU Lesser General   ////
28
//// Public License as published by the Free Software Foundation; ////
29
//// either version 2.1 of the License, or (at your option) any   ////
30
//// later version.                                               ////
31
////                                                              ////
32
//// This source is distributed in the hope that it will be       ////
33
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
34
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
35
//// PURPOSE. See the GNU Lesser General Public License for more  ////
36
//// details.                                                     ////
37
////                                                              ////
38
//// You should have received a copy of the GNU Lesser General    ////
39
//// Public License along with this source; if not, download it   ////
40
//// from <http://www.opencores.org/lgpl.shtml>                   ////
41
////                                                              ////
42
//////////////////////////////////////////////////////////////////////
43
//
44
`include "timescale.v"
45
`include "wishBoneBus_h.v"
46
 
47
module RxfifoBI (
48
  address,
49
  writeEn,
50
  strobe_i,
51
  busClk,
52
  usbClk,
53
  rstSyncToBusClk,
54
  fifoSelect,
55
  fifoDataIn,
56
  busDataIn,
57
  busDataOut,
58
  fifoREn,
59
  forceEmptySyncToUsbClk,
60
  forceEmptySyncToBusClk,
61
  numElementsInFifo
62
  );
63
input [2:0] address;
64
input writeEn;
65
input strobe_i;
66
input busClk;
67
input usbClk;
68
input rstSyncToBusClk;
69
input [7:0] fifoDataIn;
70
input [7:0] busDataIn;
71
output [7:0] busDataOut;
72
output fifoREn;
73
output forceEmptySyncToUsbClk;
74
output forceEmptySyncToBusClk;
75
input [15:0] numElementsInFifo;
76
input fifoSelect;
77
 
78
 
79
wire [2:0] address;
80
wire writeEn;
81
wire strobe_i;
82
wire busClk;
83
wire usbClk;
84
wire rstSyncToBusClk;
85
wire [7:0] fifoDataIn;
86
wire [7:0] busDataIn;
87
reg [7:0] busDataOut;
88
reg fifoREn;
89
reg forceEmptySyncToUsbClk;
90
wire forceEmptySyncToBusClk;
91
wire [15:0] numElementsInFifo;
92
wire fifoSelect;
93
 
94
reg [5:0] forceEmptyShift;
95
reg forceEmpty;
96
reg forceEmptySyncToUsbClkFirst;
97
 
98
//sync write
99
always @(posedge busClk)
100
begin
101
  if (writeEn == 1'b1 && fifoSelect == 1'b1 &&
102
    address == `FIFO_CONTROL_REG && strobe_i == 1'b1 && busDataIn[0] == 1'b1)
103
    forceEmpty <= 1'b1;
104
  else
105
    forceEmpty <= 1'b0;
106
end
107
 
108
//generate 'forceEmptySyncToBusClk'
109
//assuming that 'busClk' < 5 * 'usbClk'. ie 'busClk' < 240MHz
110
always @(posedge busClk) begin
111
  if (rstSyncToBusClk == 1'b1)
112
    forceEmptyShift <= 6'b000000;
113
  else begin
114
    if (forceEmpty == 1'b1)
115
      forceEmptyShift <= 6'b111111;
116
    else
117
      forceEmptyShift <= {1'b0, forceEmptyShift[5:1]};
118
  end
119
end
120
assign forceEmptySyncToBusClk = forceEmptyShift[0];
121
 
122
// double sync across clock domains to generate 'forceEmptySyncToWrClk'
123
always @(posedge usbClk) begin
124
    forceEmptySyncToUsbClkFirst <= forceEmptySyncToBusClk;
125
    forceEmptySyncToUsbClk <= forceEmptySyncToUsbClkFirst;
126
end
127
 
128
// async read mux
129
always @(address or fifoDataIn or numElementsInFifo)
130
begin
131
  case (address)
132
      `FIFO_DATA_REG : busDataOut <= fifoDataIn;
133
      `FIFO_DATA_COUNT_MSB : busDataOut <= numElementsInFifo[15:8];
134
      `FIFO_DATA_COUNT_LSB : busDataOut <= numElementsInFifo[7:0];
135
      default: busDataOut <= 8'h00;
136
  endcase
137
end
138
 
139
//generate fifo read strobe
140
always @(address or writeEn or strobe_i or fifoSelect) begin
141
  if (address == `FIFO_DATA_REG &&   writeEn == 1'b0 &&
142
  strobe_i == 1'b1 &&   fifoSelect == 1'b1)
143
    fifoREn <= 1'b1;
144
  else
145
    fifoREn <= 1'b0;
146
end
147
 
148
 
149
endmodule

powered by: WebSVN 2.1.0

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