File: dtp.pml

package info (click to toggle)
spin 6.5.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,512 kB
  • sloc: ansic: 39,876; yacc: 1,021; makefile: 58; sh: 13
file content (397 lines) | stat: -rwxr-xr-x 5,823 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

mtype = {
/*1*/	ack,
/*2*/	can,
/*3*/	crcck,		/* checksum error */
/*4*/	data8,
/*5*/	last8,
/*6*/	nak,
/*7*/	query8,
/*8*/	rvnak,
/*9*/	zak
	};

chan StoC = [2] of { short, short };
chan CtoR = [2] of { short, short };
chan RtoC = [2] of { short, short };
chan RtoS = [2] of { short, short };

init {
	atomic {
	run sender(RtoS, StoC);
	run channel(StoC, CtoR);
	run receiver(CtoR, RtoS)
	}
}

proctype channel(chan inp, out)
{	short a, b; byte cnt;
	xr inp;
	xs out;
end:	do
	:: inp?a,b ->
		if
		:: out!a,b
		:: (cnt == 0 && a != zak) -> cnt = cnt+1; out!crcck,b
/*		:: (cnt == 0) -> cnt = cnt+1; out!-3,a
		:: (cnt == 0) -> cnt = cnt+1; out!-1,a
		:: (cnt == 0) -> cnt = cnt+1; out!-2,a
		:: (cnt == 0) -> cnt = cnt+1; out!-4,a
*/
		fi
	od
}

proctype sender(chan inp, out)
{	bit rcvrrdy;
	short state, queryt, datat, lastt;
	short t, type;
	short seqno, toff, offset, cnt, retries, maxretries;

	xs out;
start:
	atomic {
		offset	= 0;
		retries	= 0;
		maxretries = 6;
		rcvrrdy	= 0;
		state	= 2;
		datat	= data8;
		queryt	= query8;
		lastt	= last8;
		goto s1
	};

s1:
	if /* if we received an interrupt for incoming data */
	:: (len(inp)  > 0) -> state = 2
	:: (len(inp) == 0)
	fi;
	goto s2;

s2:
	if
	:: (state == 0) -> goto s3
	:: (state == 1) -> goto s4
	:: (state == 2) -> goto s7
	:: (state >= 3) -> goto s1
	fi;

s3:
	out!queryt,offset;
	state = 2;
	goto s1;

s4:
	atomic {
		if
		:: (offset < 3) -> type = datat
		:: (offset > 2) -> type = lastt
		fi;
		if
		:: (retries  > 0) -> type = queryt
		:: (retries <= 0)
		fi
	};
	out!type,offset;	/* it can fail, but ignore that */
	goto s6;
		
s5:
	out!can,-1;
	goto F;

s6:
	atomic {
		offset = offset + 1;	/* assume cnt > 0 */
		if
/*		:: goto s5		/* channel disconnected */
		:: (type == queryt || type == lastt) ->
			state = 2
		:: !(type == queryt || type == lastt)
		fi;
		goto s1
	};

s7:
	atomic {
		inp?t,seqno;
		if
		:: (t == zak) -> goto s8
		:: (t == ack) -> goto s9
		:: (t == nak) -> goto s12
		:: (t == -2) -> goto F		/* remote canceled */
		:: (t == -3) -> goto s13	/* serial port overrun or timeout */
		:: (t == crcck) -> goto s13
		:: !(t == zak
		||   t == ack
		||   t == nak
		||   t == -2
		||   t == -3
		||   t == crcck) ->
			goto s5
		fi
	};

s8:
	offset = seqno;
	out!zak,offset;
	goto S;

s9:
	toff = seqno;
	goto s10;

s10:
	atomic {
		retries = 0;
		if
		:: (offset > toff) ->	/* worthless ack */
			goto s1
		:: (offset <= toff) ->
			offset = toff;
			goto s11
		fi
	};

s11:
	atomic {
		if
		:: (!rcvrrdy) ->
			rcvrrdy = 1;
			maxretries = 5;
			/* ack/nak received - start transmit */
			retries = 0
		:: (rcvrrdy) ->
			skip
		fi;
		state = 1;
		goto s1
	};

s12:
	atomic {
		toff = seqno;
		if
		:: (toff >= offset) ->
			goto s10
		:: (toff < offset)
		fi;
		retries = retries+1;
		if
		:: (retries >= maxretries) ->
			goto s5
		:: (retries <  maxretries)
		fi;
		offset = toff;
		goto s11
	};

s13:
	atomic {
		if
		:: (retries >= maxretries) ->
			goto s5
		:: (retries <  maxretries) ->
			if
			:: (rcvrrdy) -> state = 1
			:: (!rcvrrdy) -> state = 0
			fi;
			goto s1
		fi
	};

F:	/* failure */
	assert(0);
S:	/* success */
	skip;
end:	do :: inp?t,seqno od
}

proctype receiver(chan inp, out)
{	short state, lasttyp;
	short offset, retries, lastack;
	short readStat, cnt, seqno;
	short rtype, type;
	short respreq, typ;

	xr inp;
start:
	atomic {
		offset	= 0;
		state	= 0;
		lasttyp	= 0;
		retries	= 0;
		lastack	= 0;
		rtype	= nak;
		readStat = 0;
		goto s4
	};

s2:
	if
	:: (readStat == -1
	||  readStat == -2
	||  readStat == -4) -> goto F
	:: (readStat == -3) -> goto s3
	:: (readStat >= 0) -> goto s4
	fi;

s3:
	atomic {
		if
	/*	:: rtype == rvnak -> goto s4	/* too soon */
		:: skip
		fi;
		retries = retries+1
	};
	if
	:: (retries >= 7) ->
		out!can,-1;
		goto F
	:: (retries < 7) ->
		skip
	fi;
	atomic {
		if
		:: (retries == 0) ->	/* how can it be zero ever? */
			state = 3
		:: (retries != 0) ->
			state = 0	/* send nak state */
		fi;
		goto s4
	};

s4:
	if
	:: (state == 0) -> goto s5
	:: (state == 1) -> goto s6
	:: (state == 2) -> goto s12
	:: (state >= 3) -> goto S
	fi;

s5:
	out!rtype,offset;
	state = 1;
	goto s4;

s6:
	atomic {
		inp?type,seqno;
		rtype = nak;	/* was:	rtype = rvnak */
		typ = ack;
		if
		:: (	type == -1
		|| 	type == -2)	-> goto s7
		:: (	type == -3
		||	type == crcck)	-> goto s3
		:: (	type == -4)	-> goto s11
		:: (	type == last8)	-> goto s8
		:: (	type == query8)	-> goto s9
		:: (	type == data8)	-> goto s10
		:: !(	type == -1
		||	type == -2
		||	type == -3 
		||	type == crcck
		||	type == -4
		||	type == last8
		||	type == query8
		||	type == data8) -> goto s11
		fi
	};

s7:
	readStat = type;
	goto s2;

s8:
	atomic {
		typ = zak;
		state = 2;
		goto s9
	};

s9:
	atomic {
		rtype = nak;
		respreq = 1;
		goto s10
	};

s10:
	atomic {
		if
		:: (seqno  > offset) ->
			goto s3
		:: (seqno == offset) ->
			cnt = 1
		:: (seqno  < offset) ->
			cnt = 0
		fi;
		if
		:: (cnt < 0) ->
			readStat = cnt;
			goto s2
		:: (cnt >= 0) ->
			skip
		fi;
		offset = offset + cnt
	};
	if
	:: (respreq) ->
		out!typ,offset;
		lastack = offset;
		lasttyp = typ
	:: !(respreq) ->
		skip
	fi;
	atomic {
		if
		:: (typ == zak) ->
			retries = -2
		:: (typ != zak) ->
			retries = 2
		fi;
		goto s4
	};

s11:
	out!can,-1;
	goto F;

s12:
	atomic {
		inp?type,seqno;
		if
		:: (type == -1) -> goto s13
		:: (type == -3) -> goto s13
		:: (type == -2) -> goto s11
		:: (type == -4) -> goto s11
		:: (type == query8
		||	type == last8
		||	type == data8
		||	type == crcck) -> goto s14
		:: !(type == -1
		||	type == -3
		||	type == -2
		||	type == -4
		||	type == query8
		||	type == last8
		||	type == data8
		||	type == crcck) -> goto S
		fi
	};

s13:
	readStat = type;
	goto s2;

s14:
	out!lasttyp,lastack;
	retries = -2;
	goto s4;

F:	assert(0);
S:	skip;
end:	do :: inp?type,seqno od
}