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

Subversion Repositories spimaster

[/] [spimaster/] [trunk/] [RTL/] [sm_TxFifoBI.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// sm_TxfifoBI.v                                                ////
4
////                                                              ////
5
//// This file is part of the spiMaster 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) 2008 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 "spiMaster_defines.v"
46
 
47
module sm_TxfifoBI (
48
  address, writeEn, strobe_i,
49
  busClk,
50
  spiSysClk,
51
  rstSyncToBusClk,
52
  fifoSelect,
53
  busDataIn,
54
  busDataOut,
55
  fifoWEn,
56
  forceEmptySyncToSpiClk,
57
  forceEmptySyncToBusClk,
58
  numElementsInFifo
59
  );
60
input [2:0] address;
61
input writeEn;
62
input strobe_i;
63
input busClk;
64
input spiSysClk;
65
input rstSyncToBusClk;
66
input [7:0] busDataIn;
67
output [7:0] busDataOut;
68
output fifoWEn;
69
output forceEmptySyncToSpiClk;
70
output forceEmptySyncToBusClk;
71
input [15:0] numElementsInFifo;
72
input fifoSelect;
73
 
74
 
75
wire [2:0] address;
76
wire writeEn;
77
wire strobe_i;
78
wire busClk;
79
wire spiSysClk;
80
wire rstSyncToBusClk;
81
wire [7:0] busDataIn;
82
wire [7:0] busDataOut;
83
reg fifoWEn;
84
wire forceEmptySyncToSpiClk;
85
wire forceEmptySyncToBusClk;
86
wire [15:0] numElementsInFifo;
87
wire fifoSelect;
88
 
89
reg forceEmptyReg;
90
reg forceEmpty;
91
reg forceEmptyToggle;
92
reg [2:0] forceEmptyToggleSyncToSpiClk;
93
 
94
//sync write
95
always @(posedge busClk)
96
begin
97
  if (writeEn == 1'b1 && fifoSelect == 1'b1 &&
98
  address == `FIFO_CONTROL_REG && strobe_i == 1'b1 && busDataIn[0] == 1'b1)
99
    forceEmpty <= 1'b1;
100
  else
101
    forceEmpty <= 1'b0;
102
end
103
 
104
//detect rising edge of 'forceEmpty', and generate toggle signal
105
always @(posedge busClk) begin
106
  if (rstSyncToBusClk == 1'b1) begin
107
    forceEmptyReg <= 1'b0;
108
    forceEmptyToggle <= 1'b0;
109
  end
110
  else begin
111
    if (forceEmpty == 1'b1)
112
      forceEmptyReg <= 1'b1;
113
    else
114
      forceEmptyReg <= 1'b0;
115
    if (forceEmpty == 1'b1 && forceEmptyReg == 1'b0)
116
      forceEmptyToggle <= ~forceEmptyToggle;
117
  end
118
end
119
assign forceEmptySyncToBusClk = (forceEmpty == 1'b1 && forceEmptyReg == 1'b0) ? 1'b1 : 1'b0;
120
 
121
// double sync across clock domains to generate 'forceEmptySyncToSpiClk'
122
always @(posedge spiSysClk) begin
123
    forceEmptyToggleSyncToSpiClk <= {forceEmptyToggleSyncToSpiClk[1:0], forceEmptyToggle};
124
end
125
assign forceEmptySyncToSpiClk = forceEmptyToggleSyncToSpiClk[2] ^ forceEmptyToggleSyncToSpiClk[1];
126
 
127
// async read mux
128
assign busDataOut = 8'h00;
129
 
130
 
131
//generate fifo write strobe
132
always @(address or writeEn or strobe_i or fifoSelect or busDataIn) begin
133
  if (address == `FIFO_DATA_REG &&   writeEn == 1'b1 &&
134
  strobe_i == 1'b1 &&   fifoSelect == 1'b1)
135
    fifoWEn <= 1'b1;
136
  else
137
    fifoWEn <= 1'b0;
138
end
139
 
140
 
141
endmodule

powered by: WebSVN 2.1.0

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