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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [usbhostslave/] [RxfifoBI.v] - Blame information for rev 408

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 408 julius
//////////////////////////////////////////////////////////////////////
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 "usbhostslave_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
wire forceEmptySyncToUsbClk;
90
wire forceEmptySyncToBusClk;
91
wire [15:0] numElementsInFifo;
92
wire fifoSelect;
93
 
94
reg forceEmptyReg;
95
reg forceEmpty;
96
reg forceEmptyToggle;
97
reg [2:0] forceEmptyToggleSyncToUsbClk;
98
 
99
//sync write
100
always @(posedge busClk)
101
begin
102
  if (writeEn == 1'b1 && fifoSelect == 1'b1 &&
103
    address == `FIFO_CONTROL_REG && strobe_i == 1'b1 && busDataIn[0] == 1'b1)
104
    forceEmpty <= 1'b1;
105
  else
106
    forceEmpty <= 1'b0;
107
end
108
 
109
//detect rising edge of 'forceEmpty', and generate toggle signal
110
always @(posedge busClk) begin
111
  if (rstSyncToBusClk == 1'b1) begin
112
    forceEmptyReg <= 1'b0;
113
    forceEmptyToggle <= 1'b0;
114
  end
115
  else begin
116
    if (forceEmpty == 1'b1)
117
      forceEmptyReg <= 1'b1;
118
    else
119
      forceEmptyReg <= 1'b0;
120
    if (forceEmpty == 1'b1 && forceEmptyReg == 1'b0)
121
      forceEmptyToggle <= ~forceEmptyToggle;
122
  end
123
end
124
assign forceEmptySyncToBusClk = (forceEmpty == 1'b1 && forceEmptyReg == 1'b0) ? 1'b1 : 1'b0;
125
 
126
 
127
// double sync across clock domains to generate 'forceEmptySyncToUsbClk'
128
always @(posedge usbClk) begin
129
    forceEmptyToggleSyncToUsbClk <= {forceEmptyToggleSyncToUsbClk[1:0], forceEmptyToggle};
130
end
131
assign forceEmptySyncToUsbClk = forceEmptyToggleSyncToUsbClk[2] ^ forceEmptyToggleSyncToUsbClk[1];
132
 
133
// async read mux
134
always @(address or fifoDataIn or numElementsInFifo)
135
begin
136
  case (address)
137
      `FIFO_DATA_REG : busDataOut <= fifoDataIn;
138
      `FIFO_DATA_COUNT_MSB : busDataOut <= numElementsInFifo[15:8];
139
      `FIFO_DATA_COUNT_LSB : busDataOut <= numElementsInFifo[7:0];
140
      default: busDataOut <= 8'h00;
141
  endcase
142
end
143
 
144
//generate fifo read strobe
145
always @(address or writeEn or strobe_i or fifoSelect) begin
146
  if (address == `FIFO_DATA_REG &&   writeEn == 1'b0 &&
147
  strobe_i == 1'b1 &&   fifoSelect == 1'b1)
148
    fifoREn <= 1'b1;
149
  else
150
    fifoREn <= 1'b0;
151
end
152
 
153
 
154
endmodule

powered by: WebSVN 2.1.0

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