Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / tools / stateflow / models / model_stopwatch.ml @ 8446bf03

History | View | Annotate | Download (7.31 KB)

1
open Datatype
2
open Basetypes
3
(* open Transformer2 *)
4
open SF
5

    
6
let verbose = false
7
let actionv x = no_action (*TODO if verbose then action x else no_action*)
8
let action x = no_action (* TODO *)
9
let condition x = condition {
10
  expr = Corelang.mkexpr Location.dummy_loc (Lustre_types.Expr_const (Corelang.const_of_bool true));
11
  cinputs = [];
12
  coutputs = [];
13
  cvariables = [];
14
}
15
let name = "stopwatch"
16

    
17
let model =
18
  let smain    = "main" in
19
  let sstop    = "stop" in
20
  let sreset   = "reset" in
21
  let slapstop = "lap_stop" in
22
  let srun     = "run" in
23
  let srunning = "running" in
24
  let slap     = "lap" in
25

    
26
  let tinitstop = {
27
    event = no_event;
28
    condition = no_condition;
29
    condition_act  = actionv "ac_cond_init_stop";
30
    transition_act = actionv "ac_trans_init_stop";
31
    dest = DPath [smain;sstop];
32
  }
33
  in
34
  let tinitreset = {
35
    event = no_event;
36
    condition = no_condition;
37
    condition_act  = actionv "ac_cond_init_reset";
38
    transition_act = actionv "ac_cond_init_stop";
39
    dest = DPath [smain;sstop;sreset];
40
  }
41
  in
42
  let treset = {
43
    event = event "LAP";
44
    condition = no_condition;
45
    condition_act  = action "reset counter";
46
    transition_act = actionv "ac_trans_reset_junction";
47
    dest = DJunction "jreset" (* [smain;sstop;sreset]; ou bien mettre une junction.  Verifier
48
				 si il y a des effets de bords non
49
				 desirés de fermeture/ouverture de
50
				 noeud *)
51
  }
52
  in
53
  let treset_start  = {
54
    event = event "START";
55
    condition = no_condition;
56
    condition_act  = actionv "ac_cond_reset->running";
57
    transition_act = actionv "ac_trans_reset->running";
58
    dest = DPath [smain;srun;srunning];
59
  }
60
  in
61

    
62
  let tlapstop_lap  = {
63
    event = event "LAP";
64
    condition = no_condition;
65
    condition_act  = actionv "ac_cond_lap_stop->reset";
66
    transition_act = actionv "ac_trans_lap_stop->reset";
67
    dest = DPath [smain;sstop;sreset];
68
  }
69
  in
70

    
71
  let tlapstop_start  = {
72
    event = event "START";
73
    condition = no_condition;
74
    condition_act  = actionv "ac_cond_lap_stop->lap";
75
    transition_act = actionv "ac_trans_lap_stop->lap";
76
    dest = DPath [smain;srun;slap];
77
  }
78
  in
79
  let ttic   = {
80
    event = event "TIC";
81
    condition = no_condition;
82
    condition_act  = action "cent+=1";
83
    transition_act = actionv "ac_trans_->J1";
84
    dest = DJunction "j1";
85
  }
86
  in
87
  let trunning_start  = {
88
    event = event "START";
89
    condition = no_condition;
90
    condition_act  = actionv "ac_cond_running->reset";
91
    transition_act = actionv "ac_trans_running->reset";
92
    dest = DPath [smain;sstop;sreset];
93
  }
94
  in
95
  let tlap_start  = {
96
    event = event "START";
97
    condition = no_condition;
98
    condition_act  = actionv "ac_cond_lap->lap_stop";
99
    transition_act = actionv "ac_trans_lap->lap_stop";
100
    dest = DPath [smain;sstop;slapstop];
101
  }
102
  in
103
  let tlap_lap  = {
104
    event = event "LAP";
105
    condition = no_condition;
106
    condition_act  = actionv "ac_cond_lap->running";
107
    transition_act = actionv "ac_trans_lap->running";
108
    dest = DPath [smain;srun;srunning];
109
  }
110
  in
111
  let trunning_lap  = {
112
    event = event "LAP";
113
    condition = no_condition;
114
    condition_act  = actionv "ac_cond_running->lap";
115
    transition_act = actionv "ac_trans_running->lap";
116
    dest = DPath [smain;srun;slap];
117
  }
118
  in
119
  let tj1j2 = {
120
    event = no_event;
121
    condition = condition "cent==100";
122
    condition_act  = action "cont=0;sec+=1";
123
    transition_act = actionv "ac_trans_J1->J2";
124
    dest = DJunction "j2";
125
  }
126
  in
127
  let tj1j3 =    {
128
    event = no_event;
129
    condition = condition "cent!=100";
130
    condition_act  = actionv "ac_cond_J1->J3";
131
    transition_act = actionv "ac_trans_J1->J3";
132
    dest = DJunction "j3";
133
  }
134
  in
135
  let tj2j3gauche   = {
136
    event = no_event;
137
    condition = condition "sec!=60";
138
    condition_act  = actionv "ac_cond_J2->J3_left";
139
    transition_act = actionv "ac_trans_J2->J3_left";
140
    dest = DJunction "j3";
141
  }
142
  in
143
  let tj2j3droite    = {
144
    event = no_event;
145
    condition = condition "sec==60";
146
    condition_act  = action "sec=0; min+=1";
147
    transition_act = actionv "ac_trans_J2->J3_right";
148
    dest = (*DPath [smain;srun];*) DJunction "j3";
149
  }
150
  in
151
  let def_main = {
152
    state_actions = {
153
      entry_act  = actionv "ac_main_entry";
154
      during_act = actionv "ac_main_during";
155
      exit_act   = actionv "ac_main_exit";
156
    };
157
    outer_trans = [];
158
    inner_trans = [];
159
    internal_composition = Or ([tinitstop], [sstop; srun])
160
  }
161
  in
162

    
163
  let def_stop = {
164
    state_actions = {
165
      entry_act  = actionv "ac_stop_entry";
166
      during_act = actionv "ac_stop_during";
167
      exit_act   = actionv "ac_stop_exit";
168
    };
169
    outer_trans = [];
170
    inner_trans = [];
171
    internal_composition = Or ([tinitreset], [sreset; slapstop])
172
  }
173
  in
174

    
175
  let def_reset = {
176
    state_actions = {
177
      entry_act  = actionv "ac_reset_entry";
178
      during_act = actionv "ac_reset_during";
179
      exit_act   = actionv "ac_reset_exit";
180
    };
181
    outer_trans = [treset_start];
182
    inner_trans = [treset];
183
    internal_composition = Or ([treset_start], [])
184
  }
185
  in
186

    
187
  let def_lapstop = {
188
    state_actions = {
189
      entry_act  = actionv "ac_lapstop_entry";
190
      during_act = actionv "ac_lapstop_during";
191
      exit_act   = actionv "ac_lapstop_exit";
192
    };
193
    outer_trans = [tlapstop_lap; tlapstop_start];
194
    inner_trans = [];
195
    internal_composition = Or ([], [])
196
  }
197
  in
198

    
199
  let def_run = {
200
    state_actions = {
201
      entry_act  = actionv "ac_run_entry";
202
      during_act = actionv "ac_run_during";
203
      exit_act   = actionv "ac_run_exit";
204
    };
205
    outer_trans = [];
206
    inner_trans = [ttic];
207
    internal_composition = Or ([], [srunning; slap])
208
  }
209
  in
210

    
211
  let def_running = {
212
    state_actions = {
213
      entry_act  = actionv "ac_running_entry";
214
      during_act = action "disp=(cent,sec,min)";
215
      exit_act   = actionv "ac_running_exit";
216
    };
217
    outer_trans = [trunning_start; trunning_lap];
218
    inner_trans = [];
219
    internal_composition = Or ([], [])
220
  }
221
  in
222

    
223
  let def_lap = {
224
    state_actions = {
225
      entry_act  = actionv "ac_lap_entry";
226
      during_act = actionv "ac_lap_during";
227
      exit_act   = actionv "ac_lap_exit";
228
    };
229
    outer_trans = [tlap_start; tlap_lap];
230
    inner_trans = [];
231
    internal_composition = Or ([], [])
232
  }
233
  in
234

    
235
  let src = [
236
    State([smain;srun;srunning], def_running);
237
    State([smain;srun;slap], def_lap);
238
    State([smain;srun], def_run);
239
    State([smain;sstop;sreset], def_reset);
240
    State([smain;sstop;slapstop], def_lapstop);
241
    State([smain;sstop], def_stop);
242
    State([smain], def_main);
243
    Junction("jreset", []);
244
    Junction("j1", [tj1j2;tj1j3]);
245
    Junction("j2", [tj2j3droite; tj2j3gauche]);
246
    Junction("j3", []);
247
  ]
248
  in
249
  let globals =
250
    let int_typ = Corelang.mktyp Location.dummy_loc Lustre_types.Tydec_int in
251
    List.map (fun k ->
252
      Corelang.mkvar_decl
253
	Location.dummy_loc
254
	(k, (* name *)
255
	 int_typ, (* type *)
256
	 Corelang.dummy_clock_dec, (* clock *)
257
	 false, (* not a constant *)
258
	 None, (* no default value *)
259
	 None (* no parent known *)
260
	),
261
      (* Default value is zero *)
262
      Corelang.mkexpr Location.dummy_loc (Lustre_types.Expr_const (Lustre_types.Const_int 0))
263
      
264
    )
265
      ["cent";
266
       "sec";
267
       "min";
268
       "cont"
269
      ]
270
  in
271
  Program (smain, src, globals)
272

    
273
let traces : trace_t list =
274
  [
275
    [None; Some "TIC"; Some "START"; Some "TIC"; Some "TIC"];
276
    [None; Some "START"; Some "START"; Some "START"];
277
    [None; Some "START"; Some "TIC"; Some "START"; Some "TIC"]
278
  ]