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

Subversion Repositories spacewiresystemc

[/] [spacewiresystemc/] [trunk/] [systemC/] [spw_fsm.h] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 redbear
#ifndef SPW_FSM_T_H
2
#define SPW_FSM_T_H
3
 
4
#include <systemc.h>
5
 
6
#define ERROR_RESET 0
7
#define ERROR_WAIT  1
8
#define READY       2
9
#define STARTED     3
10
#define CONNECTING  4
11
#define RUN         5
12
 
13
class SPW_FSM_SC;
14
 
15
SC_MODULE(SPW_FSM_SC)
16
{
17
 
18
        /*FSM signal*/
19
        sc_in<bool> CLOCK;
20
        sc_in<bool> RESET;
21
        sc_in<bool> LINK_START;
22
        sc_in<bool> LINK_DISABLE;
23
        sc_in<bool> AUTO_START;
24
        sc_out<sc_uint<4> > FSM_SPW_OUT;
25
 
26
        /*Signal come from RX Receiver*/
27
        sc_in<bool> GOT_FCT_RX;
28
        sc_in<bool> GOT_TIMECODE_RX;
29
        sc_in<bool> GOTNCHAR_RX;
30
        sc_in<bool> GOTNULL_RX;
31
        sc_in<bool> GOTBIT_RX;
32
        sc_in<bool> CREDITERROR_RX;
33
        sc_in<bool> RXERROR_RX;
34
        sc_out<bool> ENABLE_RX;
35
 
36
        /*Signal come from TX Transmit*/
37
        sc_out<bool> ENABLE_TX;
38
        sc_out<bool> SEND_NULL_TX;
39
        sc_out<bool> SEND_FCT_TX;
40
        sc_out<bool> SEND_NCHAR_TX;
41
        sc_out<bool> SEND_TIMECODE_TX;
42
 
43
        /*RESET TX / RX*/
44
        sc_out<bool> RESET_TX;
45
        sc_out<bool> RESET_RX;
46
 
47
        bool After128;
48
 
49
        bool After64;
50
 
51
        sc_uint<4> state_fsm_spw;
52
 
53
        void FSM()
54
        {
55
 
56
                //cout << "STARTING FSM SPW SC" << endl;
57
 
58
                while(1)
59
                {
60
 
61
                        if(!RESET)
62
                        {
63
                                FSM_SPW_OUT = state_fsm_spw = ERROR_RESET;
64
                                ENABLE_TX       = false;
65
                                SEND_NULL_TX    = false;
66
                                SEND_FCT_TX     = false;
67
                                SEND_NCHAR_TX   = false;
68
                                SEND_TIMECODE_TX= false;
69
                                RESET_TX = true;
70
                                RESET_RX = true;
71
                        }else
72
                        {
73
                                FSM_SPW_OUT = state_fsm_spw;
74
 
75
                                switch(state_fsm_spw)
76
                                {
77
                                        case ERROR_RESET:
78
                                                RESET_TX = true;
79
                                                RESET_RX = true;
80
                                                ENABLE_TX = false;
81
                                                ENABLE_RX = false;
82
                                                if(After64 == true)
83
                                                {
84
                                                        state_fsm_spw = ERROR_WAIT;
85
                                                }
86
                                                //cout << "ERROR RESET" << endl;
87
                                        break;
88
                                        case ERROR_WAIT:
89
                                                RESET_TX  = true;
90
                                                ENABLE_TX = false;
91
                                                RESET_RX  = false;
92
                                                ENABLE_RX = true;
93
 
94
                                                if(After128 == true)
95
                                                {
96
                                                        state_fsm_spw = READY;
97
                                                }else if(RXERROR_RX || GOT_FCT_RX || GOTNCHAR_RX || GOT_TIMECODE_RX)
98
                                                {
99
                                                        state_fsm_spw = ERROR_RESET;
100
                                                }
101
 
102
                                                //cout << "ERROR WAIT" << endl;
103
                                        break;
104
                                        case READY:
105
                                                RESET_TX   = true;
106
                                                RESET_RX   = false;
107
                                                ENABLE_RX  = true;
108
                                                if(RXERROR_RX || GOT_FCT_RX || GOTNCHAR_RX || GOT_TIMECODE_RX)
109
                                                {
110
                                                        state_fsm_spw = ERROR_RESET;
111
                                                }
112
                                                else if((!LINK_DISABLE) && (LINK_START ||(AUTO_START && GOTNULL_RX)))
113
                                                {
114
                                                        state_fsm_spw = STARTED;
115
                                                }
116
 
117
                                                //cout << "READY" << endl;
118
                                        break;
119
                                        case STARTED:
120
                                                RESET_TX     = false;
121
                                                RESET_RX     = false;
122
                                                SEND_NULL_TX = true;
123
                                                ENABLE_TX    = true;
124
                                                ENABLE_RX    = true;
125
 
126
                                                if(RXERROR_RX || GOT_FCT_RX || GOTNCHAR_RX || GOT_TIMECODE_RX || After128 )
127
                                                {
128
                                                        state_fsm_spw = ERROR_RESET;
129
                                                }
130
                                                else if(GOTNULL_RX && GOTBIT_RX)
131
                                                {
132
                                                        state_fsm_spw = CONNECTING;
133
                                                }
134
                                                //cout << "STARTED" << endl;
135
                                        break;
136
                                        case CONNECTING:
137
 
138
                                                RESET_TX     = false;
139
                                                RESET_RX     = false;
140
                                                ENABLE_TX    = true;
141
                                                ENABLE_RX    = true;
142
 
143
                                                SEND_NULL_TX = true;
144
                                                SEND_FCT_TX  = true;
145
 
146
 
147
                                                if(RXERROR_RX || GOTNCHAR_RX || GOT_TIMECODE_RX || After128 )
148
                                                {
149
                                                        state_fsm_spw = ERROR_RESET;
150
                                                }else if(GOT_FCT_RX)
151
                                                {
152
                                                        state_fsm_spw = RUN;
153
                                                }
154
                                                //cout << "CONNECTING" << endl;
155
                                        break;
156
                                        case RUN:
157
 
158
                                                SEND_NULL_TX     = true;
159
                                                ENABLE_TX        = true;
160
                                                SEND_FCT_TX      = true;
161
                                                SEND_NCHAR_TX    = true;
162
                                                SEND_TIMECODE_TX = true;
163
                                                ENABLE_RX        = true;
164
 
165
                                                if(RXERROR_RX || CREDITERROR_RX || LINK_DISABLE)
166
                                                {
167
                                                        state_fsm_spw = ERROR_RESET;
168
                                                        //cout << "RX ERROR DETECTED" << endl;
169
                                                }
170
                                                else
171
                                                {
172
                                                        state_fsm_spw = RUN;
173
                                                }
174
 
175
                                                //cout << "RUN" << endl;
176
                                        break;
177
                                }
178
                        }
179
                        wait(1);
180
                }
181
        }
182
 
183
 
184
        void TIMER_ADTER128()
185
        {
186
                while(1)
187
                {
188
                  if(!RESET)
189
                  {
190
                        After128 = false;
191
                  }
192
                  else
193
                  {
194
                        if(state_fsm_spw == ERROR_WAIT || state_fsm_spw == STARTED || state_fsm_spw == CONNECTING)
195
                        {
196
                                After128 = false;
197
                                wait(639);
198
                                After128 = true;
199
                        }
200
                  }
201
                        wait(1);
202
                }
203
        }
204
 
205
        void TIMER_ADTER64()
206
        {
207
                while(1)
208
                {
209
                  if(!RESET)
210
                  {
211
                        After64 = false;
212
                  }
213
                  else
214
                  {
215
                        if(state_fsm_spw == ERROR_RESET)
216
                        {
217
                                After64 = false;
218
                                wait(319);
219
                                After64 = true;
220
                        }
221
                  }
222
                        wait(1);
223
                }
224
        }
225
 
226
 
227
        SC_CTOR(SPW_FSM_SC)
228
        {
229
                SC_CTHREAD(FSM,CLOCK.pos());
230
                SC_CTHREAD(TIMER_ADTER64,CLOCK.pos());
231
                SC_CTHREAD(TIMER_ADTER128,CLOCK.pos());
232
        }
233
 
234
};
235
 
236
#endif

powered by: WebSVN 2.1.0

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