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

Subversion Repositories spacewiresystemc

[/] [spacewiresystemc/] [trunk/] [rtl/] [RTL_VB/] [fsm_spw.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 5 redbear
//+FHDR------------------------------------------------------------------------
2
//Copyright (c) 2013 Latin Group American Integhrated Circuit, Inc. All rights reserved
3
//GLADIC Open Source RTL
4
//-----------------------------------------------------------------------------
5
//FILE NAME      :
6
//DEPARTMENT     : IC Design / Verification
7
//AUTHOR         : Felipe Fernandes da Costa
8
//AUTHOR’S EMAIL :
9
//-----------------------------------------------------------------------------
10
//RELEASE HISTORY
11
//VERSION DATE AUTHOR DESCRIPTION
12
//1.0 YYYY-MM-DD name
13
//-----------------------------------------------------------------------------
14
//KEYWORDS : General file searching keywords, leave blank if none.
15
//-----------------------------------------------------------------------------
16
//PURPOSE  : ECSS_E_ST_50_12C_31_july_2008
17
//-----------------------------------------------------------------------------
18
//PARAMETERS
19
//PARAM NAME            RANGE   : DESCRIPTION : DEFAULT : UNITS
20
//e.g.DATA_WIDTH        [32,16] : width of the data : 32:
21
//-----------------------------------------------------------------------------
22
//REUSE ISSUES
23
//Reset Strategy        :
24
//Clock Domains         :
25
//Critical Timing       :
26
//Test Features         :
27
//Asynchronous I/F      :
28
//Scan Methodology      :
29
//Instantiations        :
30
//Synthesizable (y/n)   :
31
//Other                 :
32
//-FHDR------------------------------------------------------------------------
33
 
34
`timescale 1ns/1ns
35
 
36
module FSM_SPW (
37
                input  pclk,
38
                input  resetn,
39
 
40
                //fsm status control
41
                input  auto_start,
42
                input  link_start,
43
                input  link_disable,
44
 
45
                //rx status input control
46
                input  rx_error,
47
                input  rx_credit_error,
48
                input  rx_got_bit,
49
                input  rx_got_null,
50
                input  rx_got_nchar,
51
                input  rx_got_time_code,
52
                input  rx_got_fct,
53
                output rx_resetn,
54
 
55
                //tx status control
56
                output enable_tx,
57
                output send_null_tx,
58
                output send_fct_tx,
59
 
60
                output [5:0] fsm_state
61
 
62
              );
63
 
64
localparam [5:0]  error_reset   = 6'b00_0000,
65
                  error_wait    = 6'b00_0001,
66
                  ready         = 6'b00_0010,
67
                  started       = 6'b00_0100,
68
                  connecting    = 6'b00_1000,
69
                  run           = 6'b01_0000;
70
 
71
        reg [5:0] state_fsm;
72
        reg [5:0] next_state_fsm;
73
 
74
        reg [11:0] after128us;
75
        reg [11:0] after64us;
76
        reg [11:0] after850ns;
77
 
78
//
79
assign enable_tx    = (!resetn | state_fsm == error_reset | state_fsm == error_wait)?1'b0:1'b1;
80
 
81
//
82
assign rx_resetn    = (state_fsm == error_reset)?1'b0:1'b1;
83
 
84
//
85 12 redbear
assign send_null_tx = (state_fsm == started | state_fsm == connecting | state_fsm == run)?1'b1:1'b0;
86 5 redbear
 
87
//
88
assign send_fct_tx  = (state_fsm == connecting | state_fsm == run)?1'b1:1'b0;
89
 
90
//
91
assign fsm_state    = state_fsm;
92
 
93
always@(*)
94
begin
95
 
96
        next_state_fsm = state_fsm;
97
 
98
        case(state_fsm)
99
        error_reset:
100
        begin
101
 
102
                if(after64us == 12'd639)
103
                begin
104
                        next_state_fsm = error_wait;
105
                end
106
                else
107
                begin
108
                        next_state_fsm = error_reset;
109
                end
110
 
111
        end
112
        error_wait:
113
        begin
114
 
115
                if(after128us == 12'd1279)
116
                begin
117
                        next_state_fsm = ready;
118
                end
119
                else if(rx_error | rx_got_fct | rx_got_nchar | rx_got_time_code)
120
                begin
121
                        next_state_fsm = error_reset;
122
                end
123
 
124
        end
125
        ready:
126
        begin
127
 
128
                if(rx_error | rx_got_fct | rx_got_nchar | rx_got_time_code)
129
                begin
130
                        next_state_fsm = error_reset;
131
                end
132
                else if((!link_disable) && (link_start |(auto_start && rx_got_null)))
133
                begin
134
                        next_state_fsm = started;
135
                end
136
 
137
        end
138
        started:
139
        begin
140
 
141
                if(rx_error | rx_got_fct | rx_got_nchar | rx_got_time_code | after128us == 12'd1279 )
142
                begin
143
                        next_state_fsm = error_reset;
144
                end
145
                else if(rx_got_null && rx_got_bit)
146
                begin
147
                        next_state_fsm = connecting;
148
                end
149
 
150
        end
151
        connecting:
152
        begin
153
 
154
                if(rx_error | rx_got_nchar | rx_got_time_code | after128us == 12'd1279 )
155
                begin
156
                        next_state_fsm = error_reset;
157
                end
158
                else if(rx_got_fct)
159
                begin
160
                        next_state_fsm = run;
161
                end
162
 
163
        end
164
        run:
165
        begin
166
 
167
                if(rx_error | rx_credit_error | link_disable  | after850ns == 12'd85)
168
                begin
169
                        next_state_fsm = error_reset;
170
                end
171
                else
172
                begin
173
                        next_state_fsm = run;
174
                end
175
 
176
        end
177
        endcase
178
end
179
 
180
always@(posedge pclk)
181
begin
182
        if(!resetn)
183
        begin
184
                state_fsm <= error_reset;
185
        end
186
        else
187
        begin
188
 
189
                state_fsm <= next_state_fsm;
190
 
191
                case(state_fsm)
192
                error_reset:
193
                begin
194
                end
195
                error_wait:
196
                begin
197
                end
198
                ready:
199
                begin
200
                end
201
                started:
202
                begin
203
                end
204
                connecting:
205
                begin
206
                end
207
                run:
208
                begin
209
                end
210
                endcase
211
        end
212
end
213
 
214
always@(posedge pclk)
215
begin
216
 
217
        if(!resetn)
218
        begin
219
                after128us <= 12'd0;
220
        end
221
        else
222
        begin
223
                if(state_fsm == error_wait | state_fsm == started | state_fsm == connecting)
224
                begin
225
                        if(after128us < 12'd1279)
226
                                after128us <= after128us + 12'd1;
227
                        else
228
                                after128us <= 12'd0;
229
                end
230
                else
231
                begin
232
                                after128us <= 12'd0;
233
                end
234
        end
235
 
236
end
237
 
238
always@(posedge pclk)
239
begin
240
 
241
        if(!resetn)
242
        begin
243
                after64us <= 12'd0;
244
        end
245
        else
246
        begin
247
                if(state_fsm == error_reset && (auto_start | link_start))
248
                begin
249
                        if(after64us < 12'd639)
250
                                after64us <= after64us + 12'd1;
251
                        else
252
                                after64us <= 12'd0;
253
                end
254
                else
255
                begin
256
                        after64us <= 12'd0;
257
                end
258
        end
259
 
260
end
261
 
262
always@(posedge pclk)
263
begin
264
 
265
        if(!resetn | rx_got_bit)
266
        begin
267
                after850ns <= 12'd0;
268
        end
269
        else
270
        begin
271 12 redbear
                if(after850ns < 12'd85 && state_fsm == run)
272 5 redbear
                        after850ns <= after850ns + 12'd1;
273
                else
274
                        after850ns <= 12'd0;
275
        end
276
 
277
end
278
 
279
endmodule

powered by: WebSVN 2.1.0

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