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

Subversion Repositories spimaster

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
 
2
//////////////////////////////////////////////////////////////////////
3
////                                                              ////
4
//// readWriteSPIWireData.v                      ////
5
////                                                              ////
6
//// This file is part of the spiMaster opencores effort.
7
//// <http://www.opencores.org/cores//>                           ////
8
////                                                              ////
9
//// Module Description:                                          ////
10
//// Wait for TX data bytes. When data is ready generate
11
////  SPI TX data, SPI CLK, and read SPI RX data
12
//// 
13
////                                                              ////
14
//// To Do:                                                       ////
15
//// 
16
////                                                              ////
17
//// Author(s):                                                   ////
18
//// - Steve Fielding, sfielding@base2designs.com                 ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE. See the GNU Lesser General Public License for more  ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from <http://www.opencores.org/lgpl.shtml>                   ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
//
47
`include "timescale.v"
48
`include "spiMaster_defines.v"
49
 
50
module readWriteSPIWireData (clk, clkDelay, rst, rxDataOut, rxDataRdySet, spiClkOut, spiDataIn, spiDataOut, txDataEmpty, txDataFull, txDataFullClr, txDataIn);
51
input   clk;
52
input   [7:0]clkDelay;
53
input   rst;
54
input   spiDataIn;
55
input   txDataFull;
56
input   [7:0]txDataIn;
57
output  [7:0]rxDataOut;
58
output  rxDataRdySet;
59
output  spiClkOut;
60
output  spiDataOut;
61
output  txDataEmpty;
62
output  txDataFullClr;
63
 
64
wire    clk;
65
wire    [7:0]clkDelay;
66
wire    rst;
67
reg     [7:0]rxDataOut, next_rxDataOut;
68
reg     rxDataRdySet, next_rxDataRdySet;
69
reg     spiClkOut, next_spiClkOut;
70
wire    spiDataIn;
71
reg     spiDataOut, next_spiDataOut;
72
reg     txDataEmpty, next_txDataEmpty;
73
wire    txDataFull;
74
reg     txDataFullClr, next_txDataFullClr;
75
wire    [7:0]txDataIn;
76
 
77
// diagram signals declarations
78
reg  [3:0]bitCnt, next_bitCnt;
79
reg  [7:0]clkDelayCnt, next_clkDelayCnt;
80
reg  [7:0]rxDataShiftReg, next_rxDataShiftReg;
81
reg  [7:0]txDataShiftReg, next_txDataShiftReg;
82
 
83
// BINARY ENCODED state machine: rwSPISt
84
// State codes definitions:
85
`define WT_TX_DATA 2'b00
86
`define CLK_HI 2'b01
87
`define CLK_LO 2'b10
88
`define ST_RW_WIRE 2'b11
89
 
90
reg [1:0]CurrState_rwSPISt, NextState_rwSPISt;
91
 
92
// Diagram actions (continuous assignments allowed only: assign ...)
93
// diagram ACTION
94
 
95
 
96
// Machine: rwSPISt
97
 
98
// NextState logic (combinatorial)
99 3 sfielding
always @ (txDataFull or txDataIn or clkDelayCnt or clkDelay or txDataShiftReg or rxDataShiftReg or spiDataIn or bitCnt or rxDataRdySet or txDataEmpty or txDataFullClr or spiClkOut or spiDataOut or rxDataOut or CurrState_rwSPISt)
100 2 sfielding
begin
101
  NextState_rwSPISt <= CurrState_rwSPISt;
102
  // Set default values for outputs and signals
103
  next_rxDataRdySet <= rxDataRdySet;
104
  next_txDataEmpty <= txDataEmpty;
105
  next_txDataShiftReg <= txDataShiftReg;
106
  next_rxDataShiftReg <= rxDataShiftReg;
107
  next_bitCnt <= bitCnt;
108
  next_clkDelayCnt <= clkDelayCnt;
109
  next_txDataFullClr <= txDataFullClr;
110
  next_spiClkOut <= spiClkOut;
111
  next_spiDataOut <= spiDataOut;
112
  next_rxDataOut <= rxDataOut;
113
  case (CurrState_rwSPISt)  // synopsys parallel_case full_case
114
    `WT_TX_DATA:
115
    begin
116
      next_rxDataRdySet <= 1'b0;
117
      next_txDataEmpty <= 1'b1;
118
      if (txDataFull == 1'b1)
119
      begin
120
        NextState_rwSPISt <= `CLK_HI;
121
        next_txDataShiftReg <= txDataIn;
122
        next_rxDataShiftReg <= 8'h00;
123
        next_bitCnt <= 4'h0;
124
        next_clkDelayCnt <= 8'h00;
125
        next_txDataFullClr <= 1'b1;
126
        next_txDataEmpty <= 1'b0;
127
      end
128
    end
129
    `CLK_HI:
130
    begin
131
      next_clkDelayCnt <= clkDelayCnt + 1'b1;
132
      next_txDataFullClr <= 1'b0;
133
      next_rxDataRdySet <= 1'b0;
134
      if (clkDelayCnt == clkDelay)
135
      begin
136
        NextState_rwSPISt <= `CLK_LO;
137
        next_spiClkOut <= 1'b0;
138
        next_spiDataOut <= txDataShiftReg[7];
139
        next_txDataShiftReg <= {txDataShiftReg[6:0], 1'b0};
140 3 sfielding
        next_rxDataShiftReg <= {rxDataShiftReg[6:0], spiDataIn};
141 2 sfielding
        next_clkDelayCnt <= 8'h00;
142
      end
143
    end
144
    `CLK_LO:
145
    begin
146
      next_clkDelayCnt <= clkDelayCnt + 1'b1;
147
      if ((bitCnt == 4'h8) && (txDataFull == 1'b1))
148
      begin
149
        NextState_rwSPISt <= `CLK_HI;
150
        next_rxDataRdySet <= 1'b1;
151
        next_rxDataOut <= rxDataShiftReg;
152
        next_txDataShiftReg <= txDataIn;
153
        next_bitCnt <= 3'b000;
154
        next_clkDelayCnt <= 8'h00;
155
        next_txDataFullClr <= 1'b1;
156
      end
157
      else if (bitCnt == 4'h8)
158
      begin
159
        NextState_rwSPISt <= `WT_TX_DATA;
160
        next_rxDataRdySet <= 1'b1;
161
        next_rxDataOut <= rxDataShiftReg;
162
      end
163
      else if (clkDelayCnt == clkDelay)
164
      begin
165
        NextState_rwSPISt <= `CLK_HI;
166
        next_spiClkOut <= 1'b1;
167
        next_bitCnt <= bitCnt + 1'b1;
168
        next_clkDelayCnt <= 8'h00;
169
      end
170
    end
171
    `ST_RW_WIRE:
172
    begin
173
      next_bitCnt <= 4'h0;
174
      next_clkDelayCnt <= 8'h00;
175
      next_txDataFullClr <= 1'b0;
176
      next_rxDataRdySet <= 1'b0;
177
      next_txDataShiftReg <= 8'h00;
178
      next_rxDataShiftReg <= 8'h00;
179
      next_rxDataOut <= 8'h00;
180
      next_spiDataOut <= 1'b0;
181
      next_spiClkOut <= 1'b0;
182
      next_txDataEmpty <= 1'b0;
183
      NextState_rwSPISt <= `WT_TX_DATA;
184
    end
185
  endcase
186
end
187
 
188
// Current State Logic (sequential)
189
always @ (posedge clk)
190
begin
191
  if (rst == 1'b1)
192
    CurrState_rwSPISt <= `ST_RW_WIRE;
193
  else
194
    CurrState_rwSPISt <= NextState_rwSPISt;
195
end
196
 
197
// Registered outputs logic
198
always @ (posedge clk)
199
begin
200
  if (rst == 1'b1)
201
  begin
202
    rxDataRdySet <= 1'b0;
203
    txDataEmpty <= 1'b0;
204
    txDataFullClr <= 1'b0;
205
    spiClkOut <= 1'b0;
206
    spiDataOut <= 1'b0;
207
    rxDataOut <= 8'h00;
208
    txDataShiftReg <= 8'h00;
209
    rxDataShiftReg <= 8'h00;
210
    bitCnt <= 4'h0;
211
    clkDelayCnt <= 8'h00;
212
  end
213
  else
214
  begin
215
    rxDataRdySet <= next_rxDataRdySet;
216
    txDataEmpty <= next_txDataEmpty;
217
    txDataFullClr <= next_txDataFullClr;
218
    spiClkOut <= next_spiClkOut;
219
    spiDataOut <= next_spiDataOut;
220
    rxDataOut <= next_rxDataOut;
221
    txDataShiftReg <= next_txDataShiftReg;
222
    rxDataShiftReg <= next_rxDataShiftReg;
223
    bitCnt <= next_bitCnt;
224
    clkDelayCnt <= next_clkDelayCnt;
225
  end
226
end
227
 
228
endmodule

powered by: WebSVN 2.1.0

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