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

Subversion Repositories socwire

[/] [socwire/] [trunk/] [CODEC/] [state_machine.vhd] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 bjoerno
---====================== Start Software License ========================---
2
--==                                                                    ==--
3
--== This license governs the use of this software, and your use of     ==--
4
--== this software constitutes acceptance of this license. Agreement    ==--
5
--== with all points is required to use this software.                  ==--
6
--==                                                                    ==--
7
--== 1. This source file may be used and distributed without            ==--
8
--== restriction provided that this software license statement is not   ==--
9
--== removed from the file and that any derivative work contains the    ==--
10
--== original software license notice and the associated disclaimer.    ==--
11
--==                                                                    ==--
12
--== 2. This source file is free software; you can redistribute it      ==--
13
--== and/or modify it under the restriction that UNDER NO CIRCUMTANCES  ==--
14
--== this Software is to be used to CONSTRUCT a SPACEWIRE INTERFACE     ==--
15
--== This implies modification and/or derivative work of this Software. ==--
16
--==                                                                    ==--
17
--== 3. This source is distributed in the hope that it will be useful,  ==--
18
--== but WITHOUT ANY WARRANTY; without even the implied warranty of     ==--
19
--== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               ==--
20
--==                                                                    ==--
21
--== Your rights under this license are terminated immediately if you   ==--
22
--== breach it in any way.                                              ==--
23
--==                                                                    ==--
24
---======================= End Software License =========================---
25
 
26
 
27
---====================== Start Copyright Notice ========================---
28
--==                                                                    ==--
29
--== Filename ..... state_machine.vhd                                   ==--
30
--== Download ..... http://www.ida.ing.tu-bs.de                         ==--
31
--== Company ...... IDA TU Braunschweig, Prof. Dr.-Ing. Harald Michalik ==--
32
--== Authors ...... Björn Osterloh, Karel Kotarowski                    ==--
33
--== Contact ...... Björn Osterloh (b.osterloh@tu-bs.de)                ==--
34
--== Copyright .... Copyright (c) 2008 IDA                              ==--
35
--== Project ...... SoCWire CODEC                                       ==--
36
--== Version ...... 1.00                                                ==--
37
--== Conception ... 11 November 2008                                    ==--
38
--== Modified ..... N/A                                                 ==--
39
--==                                                                    ==--
40
---======================= End Copyright Notice =========================---
41
 
42
LIBRARY IEEE;
43
USE IEEE.STD_LOGIC_1164.ALL;
44
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
45
USE WORK.ALL;
46
 
47
 
48
ENTITY state_machine IS
49
  GENERIC(
50
             speed : NATURAL RANGE 1 TO 100;
51
                         after64   : NATURAL RANGE 1 TO 6400;
52
                         after128  : NATURAL RANGE 1 TO 12800
53
         );
54
  PORT(
55
       --==  General Interface (Sync Rst, 50MHz Clock) ==--
56
 
57
       rst       : IN  STD_LOGIC;
58
       clk       : IN  STD_LOGIC;
59
 
60
       --== Link Enable Interface ==--
61
 
62
       socw_en    : IN  STD_LOGIC;
63
       socw_dis   : IN  STD_LOGIC;
64
 
65
       --== SoCWire Interface ==--
66
 
67
       state     : OUT STD_LOGIC_VECTOR(2 DOWNTO 0);
68
 
69
       --== Character Interface ==--
70
 
71
       got_null  : IN  STD_LOGIC;
72
       got_fct   : IN  STD_LOGIC;
73
       got_nchar : IN  STD_LOGIC;
74
 
75
       --== Error Interface ==--
76
 
77
       err_par   : IN  STD_LOGIC;
78
       err_esc   : IN  STD_LOGIC;
79
       err_dsc   : IN  STD_LOGIC;
80
       err_fct   : IN  STD_LOGIC;
81
       err_nchar : IN  STD_LOGIC;
82
 
83
       --== Active Interface ==--
84
 
85
       active    : OUT STD_LOGIC
86
      );
87
END state_machine;
88
 
89
 
90
ARCHITECTURE rtl OF state_machine IS
91
 
92
---==========================---
93
--== Constants Declarations ==--
94
---==========================---
95
 
96
CONSTANT st_error_reset : STD_LOGIC_VECTOR(2 DOWNTO 0) := "000";
97
CONSTANT st_error_wait  : STD_LOGIC_VECTOR(2 DOWNTO 0) := "001";
98
CONSTANT st_ready       : STD_LOGIC_VECTOR(2 DOWNTO 0) := "010";
99
CONSTANT st_started     : STD_LOGIC_VECTOR(2 DOWNTO 0) := "011";
100
CONSTANT st_connecting  : STD_LOGIC_VECTOR(2 DOWNTO 0) := "100";
101
CONSTANT st_run         : STD_LOGIC_VECTOR(2 DOWNTO 0) := "101";
102
CONSTANT st_unknown_1   : STD_LOGIC_VECTOR(2 DOWNTO 0) := "110";
103
CONSTANT st_unknown_2   : STD_LOGIC_VECTOR(2 DOWNTO 0) := "111";
104
 
105
---=======================---
106
--== Signal Declarations ==--
107
---=======================---
108
 
109
SIGNAL state_i    : STD_LOGIC_VECTOR(2 DOWNTO 0);
110
SIGNAL state_d    : STD_LOGIC_VECTOR(2 DOWNTO 0);
111
SIGNAL watchdog_r : STD_LOGIC;
112
SIGNAL watchdog_d : STD_LOGIC_VECTOR(13 DOWNTO 0);
113
SIGNAL watchdog   : STD_LOGIC_VECTOR(13 DOWNTO 0);
114
 
115
 
116
BEGIN
117
 
118
  ---=====================---
119
  --== Synchronous Logic ==--
120
  ---=====================---
121
 
122
  PROCESS (clk)
123
  BEGIN
124
  IF RISING_EDGE(clk) THEN
125
        IF rst = '0' THEN
126
                state_i <= state_d;
127
                watchdog <= watchdog_d;
128
        ELSE
129
                state_i <= (others => '0');
130
                watchdog <= (others => '0');
131
        END IF;
132
  END IF;
133
  END PROCESS;
134
 
135
 
136
  ---===========================---
137
  --== SoCWire State Machine ==--
138
  ---===========================---
139
 
140
  PROCESS(state_i, watchdog, got_fct, got_nchar, err_par, err_esc, err_dsc, err_fct, err_nchar, socw_en, got_null, socw_dis)
141
  BEGIN
142
    CASE state_i IS
143
 
144
      WHEN st_error_reset =>
145
 
146
        IF (watchdog =  after64 / speed - 1) THEN -- 6.4us Passed
147
          state_d <= st_error_wait;
148
          watchdog_r <= '1';
149
        ELSE
150
          state_d <= st_error_reset;
151
          watchdog_r <= '0';
152
        END IF;
153
 
154
      WHEN st_error_wait =>
155
 
156
        IF (got_fct = '1') OR (got_nchar = '1') OR
157
           (err_par = '1') OR (err_esc = '1') OR (err_dsc = '1') THEN
158
          state_d <= st_error_reset;
159
          watchdog_r <= '1';
160
        ELSIF (watchdog = after128 / speed - 1) THEN -- 12.8us Passed
161
          state_d <= st_ready;
162
          watchdog_r <= '0';
163
        ELSE
164
          state_d <= st_error_wait;
165
          watchdog_r <= '0';
166
        END IF;
167
 
168
      WHEN st_ready =>
169
 
170
        IF (got_fct = '1') OR (got_nchar = '1') OR
171
           (err_par = '1') OR (err_esc = '1') OR (err_dsc = '1') THEN
172
          state_d <= st_error_reset;
173
          watchdog_r <= '1';
174
        ELSIF (socw_en = '1') THEN
175
          state_d <= st_started;
176
          watchdog_r <= '1';
177
        ELSE
178
          state_d <= st_ready;
179
          watchdog_r <= '0';
180
        END IF;
181
 
182
      WHEN st_started =>
183
 
184
        IF (got_nchar = '1') OR
185
           (err_par = '1') OR (err_esc = '1') OR (err_dsc = '1') THEN
186
          state_d <= st_error_reset;
187
          watchdog_r <= '1';
188
        ELSIF (watchdog = after128 / speed - 1) THEN -- 12.8us Passed
189
          state_d <= st_error_reset;
190
          watchdog_r <= '1';
191
        ELSIF (got_null = '1') THEN
192
          state_d <= st_connecting;
193
          watchdog_r <= '1';
194
        ELSE
195
          state_d <= st_started;
196
          watchdog_r <= '0';
197
        END IF;
198
 
199
      WHEN st_connecting =>
200
 
201
        IF (got_nchar = '1') OR
202
           (err_par = '1') OR (err_esc = '1') OR (err_dsc = '1') THEN
203
          state_d <= st_error_reset;
204
          watchdog_r <= '1';
205
        ELSIF (watchdog = after128 / speed - 1) THEN -- 12.8us Passed  
206
          state_d <= st_error_reset;
207
          watchdog_r <= '1';
208
        ELSIF (got_fct = '1') THEN
209
          state_d <= st_run;
210
          watchdog_r <= '1';
211
        ELSE
212
          state_d <= st_connecting;
213
          watchdog_r <= '0';
214
        END IF;
215
 
216
      WHEN st_run =>
217
 
218
        IF (err_fct = '1') OR (err_nchar = '1') OR
219
           (err_par = '1') OR (err_esc = '1') OR
220
           (err_dsc = '1') OR (socw_dis = '1') THEN
221
          state_d <= st_error_reset;
222
          watchdog_r <= '1';
223
        ELSE
224
          state_d <= st_run;
225
          watchdog_r <= '0';
226
        END IF;
227
 
228
      WHEN OTHERS =>
229
        state_d <= st_error_reset;
230
        watchdog_r <= '1';
231
 
232
    END CASE;
233
 
234
  END PROCESS;
235
 
236
 
237
    ---====================---
238
  --== Watchdog Counter ==--
239
  ---====================---
240
 
241
  PROCESS(watchdog_r, watchdog, state_i)
242
  BEGIN
243
    IF (watchdog_r = '1') OR (state_i = st_run) OR (state_i = st_ready) THEN
244
      watchdog_d <= (others => '0');
245
    ELSE
246
      watchdog_d <= watchdog + 1;
247
    END IF;
248
  END PROCESS;
249
 
250
 
251
  ---======================================---
252
  --== Shared Internal & External Signals ==--
253
  ---======================================---
254
 
255
  state <= state_i;
256
 
257
  active <= '1' WHEN (state_i = st_Run) ELSE '0';
258
 
259
END rtl;

powered by: WebSVN 2.1.0

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