1 | /* This model has for each component a failure mode that allows the |
---|
2 | component to nondeterministically fail, from which it can not |
---|
3 | recover. Each model has a failure mode that is realistic. */ |
---|
4 | |
---|
5 | /************************************************************************/ |
---|
6 | typedef enum{conduct,open} WR; |
---|
7 | typedef enum{discharged, charged} CH; |
---|
8 | typedef enum{pulling,neutral} RL; |
---|
9 | typedef enum{lit,unlit} LP; |
---|
10 | typedef enum{B,middle,C} CT; |
---|
11 | typedef enum{present1,present2, absent} TR; |
---|
12 | typedef enum{on,off} TS; |
---|
13 | typedef enum{good, faulty1, faulty2} FT; |
---|
14 | typedef enum{go,stop} IN; |
---|
15 | typedef enum{stop1, stop2, go1, go2, go3, go4} ST; |
---|
16 | typedef enum{t1, t2, t3, t4, t5, t6, t7, t8,t9,t10} TRS; |
---|
17 | |
---|
18 | module dchek(clk); |
---|
19 | input clk; |
---|
20 | |
---|
21 | WR wire track1, track2, track3; |
---|
22 | CH wire charger; |
---|
23 | RL wire relay; |
---|
24 | LP wire lamp; |
---|
25 | CT wire contact; |
---|
26 | TR wire train; |
---|
27 | TS wire ts_power; |
---|
28 | IN wire interpretation; |
---|
29 | |
---|
30 | track_mod trk1(clk,track1); |
---|
31 | track_mod trk2(clk,track2); |
---|
32 | track_mod trk3(clk,track3); |
---|
33 | charger_mod chg(clk,ts_power,lamp,charger); |
---|
34 | relay_mod rly(clk,charger,relay); |
---|
35 | lamp_mod lmp(clk,contact,track3,ts_power,charger,lamp); |
---|
36 | contact_mod cnt(clk,relay,contact); |
---|
37 | train_mod trn(clk,train); |
---|
38 | track_system_mod tsm(clk,track1,track2,train,contact,ts_power); |
---|
39 | interpretation_mod int(clk,lamp,interpretation); |
---|
40 | |
---|
41 | property_mod prop(clk, train, interpretation); |
---|
42 | |
---|
43 | endmodule /* dychek */ |
---|
44 | |
---|
45 | /************************************************************************/ |
---|
46 | module track_mod(clk, track); |
---|
47 | input clk; |
---|
48 | output track; |
---|
49 | WR wire track; |
---|
50 | FT reg state; |
---|
51 | FT wire r_state; |
---|
52 | initial state = good; |
---|
53 | assign r_state = $ND(good,faulty1); |
---|
54 | assign track = (state == good)?conduct:open; |
---|
55 | |
---|
56 | always @(posedge clk) begin |
---|
57 | if (state == faulty1) begin |
---|
58 | state = faulty1; |
---|
59 | // track = open; |
---|
60 | end |
---|
61 | if (state == good) begin |
---|
62 | state = r_state; |
---|
63 | // track = conduct; |
---|
64 | end |
---|
65 | end |
---|
66 | endmodule /* track_mod */ |
---|
67 | |
---|
68 | /************************************************************************/ |
---|
69 | module charger_mod (clk,ts_power,lamp, out); |
---|
70 | input clk,ts_power,lamp; |
---|
71 | output out; |
---|
72 | TS wire ts_power; |
---|
73 | LP wire lamp; |
---|
74 | CH wire out; |
---|
75 | CH reg charger; |
---|
76 | FT reg state; |
---|
77 | FT wire r_state; |
---|
78 | initial state = good; |
---|
79 | initial charger = discharged; |
---|
80 | assign r_state = $ND(good,faulty1,faulty2); |
---|
81 | assign out = state == faulty1?discharged: |
---|
82 | state == faulty2?charged: |
---|
83 | charger; |
---|
84 | |
---|
85 | always @(posedge clk) begin |
---|
86 | if (state == faulty1) begin |
---|
87 | state = faulty1; |
---|
88 | // out = discharged; |
---|
89 | end |
---|
90 | if (state == faulty2) begin |
---|
91 | state = faulty2; |
---|
92 | // out = charged; |
---|
93 | end |
---|
94 | if (state == good) begin |
---|
95 | state = r_state; |
---|
96 | // out = charger; |
---|
97 | if (ts_power == on) charger = charged; |
---|
98 | else if (lamp == lit) charger = discharged; |
---|
99 | else charger = charger; |
---|
100 | end |
---|
101 | end |
---|
102 | endmodule /* charger_mod */ |
---|
103 | |
---|
104 | /************************************************************************/ |
---|
105 | module relay_mod (clk, charger, relay); |
---|
106 | input clk, charger; |
---|
107 | output relay; |
---|
108 | CH wire charger; |
---|
109 | RL wire relay; |
---|
110 | FT reg state; |
---|
111 | FT wire r_state; |
---|
112 | initial state = good; |
---|
113 | assign r_state = $ND(good,faulty1,faulty2); |
---|
114 | assign relay = state == faulty1?neutral: |
---|
115 | state == faulty2?pulling: |
---|
116 | state == good && charger == charged?pulling:neutral; |
---|
117 | |
---|
118 | always @(posedge clk) begin |
---|
119 | if (state == faulty1) begin |
---|
120 | state = faulty1; |
---|
121 | // relay = neutral; |
---|
122 | end |
---|
123 | if (state == faulty2) begin |
---|
124 | state = faulty2; |
---|
125 | // relay = pulling; |
---|
126 | end |
---|
127 | if (state == good) begin |
---|
128 | state = r_state; |
---|
129 | // if (charger == charged) relay = pulling; |
---|
130 | // else relay = neutral; |
---|
131 | end |
---|
132 | end |
---|
133 | endmodule /* relay_mod */ |
---|
134 | |
---|
135 | /************************************************************************/ |
---|
136 | module contact_mod(clk,relay,contact); |
---|
137 | input clk,relay; |
---|
138 | output contact; |
---|
139 | RL wire relay; |
---|
140 | CT wire contact; |
---|
141 | FT reg state; |
---|
142 | FT wire r_state; |
---|
143 | initial state = good; |
---|
144 | assign r_state = $ND(good,faulty1,faulty2); |
---|
145 | assign contact = state == faulty1?B: |
---|
146 | state == faulty2?C: |
---|
147 | state == good && relay == pulling?C:B; |
---|
148 | |
---|
149 | always @(posedge clk) begin |
---|
150 | if (state == faulty1) begin |
---|
151 | state = faulty1; |
---|
152 | // contact = B; |
---|
153 | end |
---|
154 | if (state == faulty2) begin |
---|
155 | state = faulty2; |
---|
156 | // contact = C; |
---|
157 | end |
---|
158 | if (state == good) begin |
---|
159 | state = r_state; |
---|
160 | // if (relay == pulling) contact = C; |
---|
161 | // else contact = B; |
---|
162 | end |
---|
163 | end |
---|
164 | endmodule /* contact_mod */ |
---|
165 | |
---|
166 | /************************************************************************/ |
---|
167 | module train_mod (clk, out); |
---|
168 | input clk; |
---|
169 | output out; |
---|
170 | TR wire out; |
---|
171 | TRS reg train; |
---|
172 | TRS wire r1_train; |
---|
173 | TRS wire r2_train; |
---|
174 | TRS wire r3_train; |
---|
175 | TRS wire r4_train; |
---|
176 | TRS wire r5_train; |
---|
177 | TRS wire r6_train; |
---|
178 | TRS wire r7_train; |
---|
179 | TRS wire r8_train; |
---|
180 | TRS wire r9_train; |
---|
181 | TRS wire r10_train; |
---|
182 | initial train = t1; |
---|
183 | assign r1_train = $ND(t1,t2); |
---|
184 | assign r2_train = $ND(t2,t3); |
---|
185 | assign r3_train = $ND(t3,t4); |
---|
186 | assign r4_train = $ND(t4,t5); |
---|
187 | assign r5_train = $ND(t5,t6); |
---|
188 | assign r6_train = $ND(t6,t7); |
---|
189 | assign r7_train = $ND(t7,t8); |
---|
190 | assign r8_train = $ND(t8,t9); |
---|
191 | assign r9_train = $ND(t9,t10); |
---|
192 | assign r10_train = $ND(t10,t1); |
---|
193 | assign out = (train == t1)? absent : present1; |
---|
194 | |
---|
195 | always @(posedge clk) begin |
---|
196 | case (train) |
---|
197 | t1: train = r1_train; |
---|
198 | t2: train = r2_train; |
---|
199 | t3: train = r3_train; |
---|
200 | t4: train = r4_train; |
---|
201 | t5: train = r5_train; |
---|
202 | t6: train = r6_train; |
---|
203 | t7: train = r7_train; |
---|
204 | t8: train = r8_train; |
---|
205 | t9: train = r9_train; |
---|
206 | t10: train = r10_train; |
---|
207 | endcase |
---|
208 | end |
---|
209 | endmodule /* train_mod */ |
---|
210 | |
---|
211 | /************************************************************************/ |
---|
212 | module lamp_mod (clk, contact, wire3, ts_power, charger, lamp); |
---|
213 | input clk, contact, wire3, ts_power, charger; |
---|
214 | output lamp; |
---|
215 | CT wire contact; |
---|
216 | WR wire wire3; |
---|
217 | CH wire charger; |
---|
218 | TS wire ts_power; |
---|
219 | LP wire lamp; |
---|
220 | FT reg state; |
---|
221 | FT wire r_state; |
---|
222 | initial state = good; |
---|
223 | assign r_state = $ND(good,faulty1,faulty2); |
---|
224 | assign lamp = state == faulty1? unlit: |
---|
225 | state == faulty2? lit: |
---|
226 | state == good && ((contact == C)&&(wire3 == conduct)&& |
---|
227 | ((ts_power == on) | (charger == charged)))?lit:unlit; |
---|
228 | |
---|
229 | always @(posedge clk) begin |
---|
230 | if (state == faulty1) begin |
---|
231 | state = faulty1; |
---|
232 | // lamp = unlit; |
---|
233 | end |
---|
234 | if (state == faulty2) begin |
---|
235 | state = faulty2; |
---|
236 | // lamp = lit; |
---|
237 | end |
---|
238 | if (state == good) begin |
---|
239 | state = r_state; |
---|
240 | // if ((contact == C)&&(wire3 == conduct)&& |
---|
241 | // ((ts_power == on) | (charger == charged))) |
---|
242 | // lamp = lit; |
---|
243 | // else lamp = unlit; |
---|
244 | end |
---|
245 | end |
---|
246 | endmodule /* lamp_mod */ |
---|
247 | |
---|
248 | /************************************************************************/ |
---|
249 | module track_system_mod (clk, wire1, wire2, train, contact, ts_power); |
---|
250 | input clk, wire1, wire2, contact, train; |
---|
251 | output ts_power; |
---|
252 | TR wire train; |
---|
253 | WR wire wire1, wire2; |
---|
254 | CT wire contact; |
---|
255 | TS wire ts_power; |
---|
256 | FT reg state; |
---|
257 | FT wire r_state; |
---|
258 | initial state = good; |
---|
259 | assign r_state = $ND(good,faulty1,faulty2); |
---|
260 | assign ts_power = state == faulty1?on: |
---|
261 | state == faulty2?off: |
---|
262 | state == good && ((wire1 == conduct) && (wire2 == conduct) && |
---|
263 | ((train != absent) | (contact == B)))?on:off; |
---|
264 | |
---|
265 | always @(posedge clk) begin |
---|
266 | if (state == faulty1) begin |
---|
267 | state = faulty1; |
---|
268 | // ts_power = on; |
---|
269 | end |
---|
270 | if (state == faulty2) begin |
---|
271 | state = faulty2; |
---|
272 | // ts_power = off; |
---|
273 | end |
---|
274 | if (state == good) begin |
---|
275 | state = r_state; |
---|
276 | // if ((wire1 == conduct) && (wire2 == conduct) && |
---|
277 | // ((train != absent) | (contact == B))) |
---|
278 | // ts_power = on; |
---|
279 | // else ts_power = off; |
---|
280 | end |
---|
281 | end |
---|
282 | endmodule /* track_system_mod */ |
---|
283 | |
---|
284 | /************************************************************************/ |
---|
285 | module interpretation_mod (clk, lamp, out); |
---|
286 | input clk, lamp; |
---|
287 | output out; |
---|
288 | LP wire lamp; |
---|
289 | IN wire out; |
---|
290 | ST reg state; |
---|
291 | initial state = stop1; |
---|
292 | |
---|
293 | assign out = state == go3 | state == go4?go:stop; |
---|
294 | |
---|
295 | always @(posedge clk) begin |
---|
296 | case(state) |
---|
297 | stop1: begin |
---|
298 | if (lamp == lit) state = stop2; |
---|
299 | else state = stop1; |
---|
300 | end |
---|
301 | |
---|
302 | stop2: begin |
---|
303 | if (lamp == unlit) state = go1; |
---|
304 | else state = stop1; |
---|
305 | end |
---|
306 | |
---|
307 | go1: begin |
---|
308 | if (lamp == lit) state = go2; |
---|
309 | else state = stop1; |
---|
310 | end |
---|
311 | |
---|
312 | go2: begin |
---|
313 | if (lamp == unlit) state = go3; |
---|
314 | else state = stop1; |
---|
315 | end |
---|
316 | |
---|
317 | go3: begin |
---|
318 | if (lamp == lit) state = go4; |
---|
319 | else state = stop1; |
---|
320 | end |
---|
321 | |
---|
322 | go4: begin |
---|
323 | if (lamp == unlit) state = go3; |
---|
324 | else state = stop1; |
---|
325 | end |
---|
326 | endcase |
---|
327 | // if ((state == go3) | (state == go4)) out = go; |
---|
328 | /* if (state == go3 | go4) out = go; */ |
---|
329 | // else out = stop; |
---|
330 | end |
---|
331 | endmodule /* interpretation_mod */ |
---|
332 | |
---|
333 | typedef enum{good,bad} STT; |
---|
334 | |
---|
335 | /************************************************************************/ |
---|
336 | module property_mod (clk, train, interpretation); |
---|
337 | input clk,train,interpretation; |
---|
338 | TR wire train; |
---|
339 | IN wire interpretation; |
---|
340 | STT reg state; |
---|
341 | initial state = good; |
---|
342 | |
---|
343 | always @(posedge clk) begin |
---|
344 | if (((train == present2)&&(interpretation == go)) | (state == bad)) |
---|
345 | state = bad; |
---|
346 | else state = good; |
---|
347 | end |
---|
348 | endmodule /* property_mod */ |
---|
349 | |
---|
350 | /* we want to put a cycle set around state = good, so that if ever |
---|
351 | state gets to bad it is a non-safe failure. */ |
---|
352 | |
---|
353 | /************************************************************************/ |
---|