-
Notifications
You must be signed in to change notification settings - Fork 0
/
prod_cons_nb.xml
2843 lines (2734 loc) · 93.8 KB
/
prod_cons_nb.xml
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
<nta>
<declaration>typedef int short;
typedef int unsigned_short;
typedef int uint64;
typedef int tlm_sync_enum;
const tlm_sync_enum END_RESP = 2;
const tlm_sync_enum TLM_UPDATED = 2;
const tlm_sync_enum BEGIN_RESP = 1;
const tlm_sync_enum TLM_ACCEPTED = 1;
const tlm_sync_enum TLM_GENERIC_ERROR_RESPONSE = 64;
const tlm_sync_enum TLM_INCOMPLETE_RESPONSE = 16;
const tlm_sync_enum END_REQ = 8;
const tlm_sync_enum TLM_OK_RESPONSE = 32;
const tlm_sync_enum TLM_COMPLETED = 4;
const tlm_sync_enum BEGIN_REQ = 4;
const tlm_sync_enum TLM_WRITE_COMMAND = 16;
const tlm_sync_enum TLM_IGNORE_COMMAND = 32;
const tlm_sync_enum TLM_READ_COMMAND = 8;
const tlm_sync_enum TLM_BURST_ERROR_RESPONSE = 32;
typedef int tlm_dmi;
typedef int sc_uint;
typedef int unsigned_int;
clock global;
///////////////////////////
// MEMORY ALLOCATION STATES
///////////////////////////
const int MEM_FREE = 0;
const int MEM_STATIC_OBJ = 1;
const int MEM_STATIC_ARR_HEAD = 2;
const int MEM_STATIC_ARR_TAIL = 3;
const int MEM_DYN_OBJ = 4;
const int MEM_DYN_ARR_HEAD = 5;
const int MEM_DYN_ARR_TAIL = 6;
const int NULL = -1;
////////////////////////
// MEMORY RELATED ERRORS
////////////////////////
bool MEM_ERR_DOUBLE_FREE = false;
bool MEM_ERR_INVALID_ARR_DELETE = false;
bool MEM_ERR_INVALID_OBJ_DELETE = false;
bool MEM_ERR_DELETE_ON_STATIC_VAR = false;
bool MEM_ERR_NOT_ENOUGH_MEM = false;
bool MEM_ERR_CORRUPTED_MEM = false;
bool MEM_ERR_FRAGMENTED_MEM = false;
///////////////////
// BOOL - globals
///////////////////
const bool DEFAULT_BOOL_VALUE = false;
const int BOOL_MEMSIZE = 0;
int BOOL_FREE_MEM = BOOL_MEMSIZE;
typedef int[NULL, BOOL_MEMSIZE-1] bool_addr_ptr;
///////////////////
// INT - globals
///////////////////
const int DEFAULT_INT_VALUE = 0;
const int INT_MEMSIZE = 14;
int INT_FREE_MEM = INT_MEMSIZE;
typedef int[NULL, INT_MEMSIZE-1] int_addr_ptr;
int[0, 6] intMemState[INT_MEMSIZE];
int intMem[INT_MEMSIZE];
bool MEM_ERR_FRAGMENTED_MEM_INT = false;
bool MEM_ERR_NOT_ENOUGH_MEM_INT = false;
///////////////////
// TLM_DMI - globals
///////////////////
const tlm_dmi DEFAULT_TLM_DMI_VALUE = 0;
const int TLM_DMI_MEMSIZE = 0;
int TLM_DMI_FREE_MEM = TLM_DMI_MEMSIZE;
typedef int[NULL, TLM_DMI_MEMSIZE-1] tlm_dmi_addr_ptr;
///////////////////
// TLM_SYNC_ENUM - globals
///////////////////
const tlm_sync_enum DEFAULT_TLM_SYNC_ENUM_VALUE = 0;
const int TLM_SYNC_ENUM_MEMSIZE = 0;
int TLM_SYNC_ENUM_FREE_MEM = TLM_SYNC_ENUM_MEMSIZE;
typedef int[NULL, TLM_SYNC_ENUM_MEMSIZE-1] tlm_sync_enum_addr_ptr;
///////////////////
// UINT64 - globals
///////////////////
const uint64 DEFAULT_UINT64_VALUE = 0;
const int UINT64_MEMSIZE = 0;
int UINT64_FREE_MEM = UINT64_MEMSIZE;
typedef int[NULL, UINT64_MEMSIZE-1] uint64_addr_ptr;
///////////////////
// DATA - globals
///////////////////
typedef struct {int val;} data;
const data DEFAULT_DATA_VALUE = {0};
const int DATA_MEMSIZE = 9;
int DATA_FREE_MEM = DATA_MEMSIZE;
typedef int[NULL, DATA_MEMSIZE-1] data_addr_ptr;
int[0, 6] dataMemState[DATA_MEMSIZE];
data dataMem[DATA_MEMSIZE];
bool MEM_ERR_FRAGMENTED_MEM_DATA = false;
bool MEM_ERR_NOT_ENOUGH_MEM_DATA = false;
///////////////////
// Global Variable Definition
///////////////////
bool PEQ_ERR_OUT_OF_ELEMENTS = false;
data_addr_ptr prod_d = NULL;
chan activate;
chan deactivate;
chan updatestart;
chan updateend;
broadcast chan initdone;
broadcast chan deltadelay;
broadcast chan advancetime;
int deltacount = 0;
int readyprocs = 1;
int updaterequests = 0;
chan scmodules_initialized;
broadcast chan dummybchannel;
chan dummychannel;
int dummyinteger;
broadcast chan prod_thread0_sensitivechan;
broadcast chan prod_thread0_timeoutevent_wait;
chan prod_thread0_timeoutevent_notify;
chan prod_thread0_timeoutevent_notify_imm;
int prod_thread0_timeoutevent_notify_t;
chan prod_thread0_Producer_initiator_main_ctrl;
chan cons_Consumer_nb_transport_fw_ctrl;
data_addr_ptr cons_Consumer_nb_transport_fw_param_tran = NULL;
int_addr_ptr cons_Consumer_nb_transport_fw_param_phase = NULL;
int_addr_ptr cons_Consumer_nb_transport_fw_param_t = NULL;
tlm_sync_enum cons_Consumer_nb_transport_fw_return;
chan cons_cons_peq_notify_peq_notify_ctrl;
chan cons_cons_peq_notify_peq_element_ctrl[4];
bool cons_cons_peq_notify_peqInUse[4];
data_addr_ptr cons_cons_peq_fetch_peq_cb_param_tran = NULL;
chan cons_cons_peq_fetch_peq_fetch_ctrl;
int_addr_ptr cons_cons_peq_fetch_peq_cb_param_phase = NULL;
int cons_cons_peq_peq_element_param_delay;
data_addr_ptr cons_cons_peq_peq_element_param_trans = NULL;
int_addr_ptr cons_cons_peq_peq_element_param_phase = NULL;
chan cons_Consumer_cons_peq_cb_ctrl;
data_addr_ptr cons_Consumer_cons_peq_cb_param_tran = NULL;
int_addr_ptr cons_Consumer_cons_peq_cb_param_phase = NULL;
chan prod_Producer_nb_transport_bw_ctrl;
data_addr_ptr prod_Producer_nb_transport_bw_param_tran = NULL;
int_addr_ptr prod_Producer_nb_transport_bw_param_phase = NULL;
int_addr_ptr prod_Producer_nb_transport_bw_param_t = NULL;
tlm_sync_enum prod_Producer_nb_transport_bw_return;
chan prod_prod_peq_notify_peq_notify_ctrl;
chan prod_prod_peq_notify_peq_element_ctrl[4];
bool prod_prod_peq_notify_peqInUse[4];
data_addr_ptr prod_prod_peq_fetch_peq_cb_param_tran = NULL;
chan prod_prod_peq_fetch_peq_fetch_ctrl;
int_addr_ptr prod_prod_peq_fetch_peq_cb_param_phase = NULL;
int prod_prod_peq_peq_element_param_delay;
data_addr_ptr prod_prod_peq_peq_element_param_trans = NULL;
int_addr_ptr prod_prod_peq_peq_element_param_phase = NULL;
chan prod_Producer_prod_peq_cb_ctrl;
data_addr_ptr prod_Producer_prod_peq_cb_param_tran = NULL;
int_addr_ptr prod_Producer_prod_peq_cb_param_phase = NULL;
///////////////////
// INT - helper functions
///////////////////
bool is_free_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_FREE;
}
bool is_obj_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_STATIC_OBJ || intMemState[pos] == MEM_DYN_OBJ;
}
bool is_static_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_STATIC_OBJ || intMemState[pos] == MEM_STATIC_ARR_HEAD || intMemState[pos] == MEM_STATIC_ARR_TAIL;
}
bool is_dynamic_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_DYN_OBJ || intMemState[pos] == MEM_DYN_ARR_HEAD || intMemState[pos] == MEM_DYN_ARR_TAIL;
}
bool is_arr_head_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_STATIC_ARR_HEAD || intMemState[pos] == MEM_DYN_ARR_HEAD;
}
bool is_arr_tail_elem_int(int_addr_ptr pos) {
return intMemState[pos] == MEM_STATIC_ARR_TAIL || intMemState[pos] == MEM_DYN_ARR_TAIL;
}
void check_mem_errors_for_delete_int(int_addr_ptr pos, bool isStatic, bool shouldBeAnArray) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else if (is_free_elem_int(pos)) {
MEM_ERR_DOUBLE_FREE = true;
} else if (not is_obj_elem_int(pos) && not is_arr_head_elem_int(pos)) {
// something went completely wrong :(
// ex: delete somewhere in the middle of an array
MEM_ERR_CORRUPTED_MEM = true;
} else {
if (!isStatic && is_static_elem_int(pos)) {
MEM_ERR_DELETE_ON_STATIC_VAR = true;
}
if (shouldBeAnArray) {
if (not is_arr_head_elem_int(pos)) {
MEM_ERR_INVALID_ARR_DELETE = true; // shouldn't have called 'delete []' ?
}
} else { // delete normal obj
if (not is_obj_elem_int(pos)) {
MEM_ERR_INVALID_OBJ_DELETE = true;
}
}
}
}
bool addr_is_in_range_int(int pos) {
return pos >= 0 && pos < INT_MEMSIZE;
}
bool addr_is_valid_int(int_addr_ptr pos) {
return pos != NULL && intMemState[pos] != MEM_FREE;
}
bool is_arr_elem_int(int head, int index) {
int i;
if (!addr_is_in_range_int(head + index)) {
return false;
}
if (!is_arr_head_elem_int(head)) {
return false;
}
if (index < 0) { // assuming heap/stack arrays grow leftward
return false;
}
for (i = head + 1; i <= head + index; i++) {
if (!is_arr_tail_elem_int(i)) {
return false;
}
}
return true;
}
///////////////////
// INT - private
///////////////////
void allocate_and_init_int(int memState, int_addr_ptr pos, int value) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
intMemState[pos] = memState;
intMem[pos] = value;
if (memState == MEM_FREE) {
INT_FREE_MEM++;
} else {
INT_FREE_MEM--;
}
}
}
void allocate_int(int memState, int_addr_ptr pos) {
allocate_and_init_int(memState, pos, DEFAULT_INT_VALUE);
}
int_addr_ptr find_free_pos_int(int memState) {
int_addr_ptr pos = NULL;
if (memState == MEM_STATIC_OBJ) { // stack
for(pos = 0; pos <= INT_MEMSIZE - 1; pos++) {
if (intMemState[pos] == MEM_FREE) {
return pos;
}
}
} else if (memState == MEM_DYN_OBJ) { // heap
for(pos = INT_MEMSIZE - 1; pos >= 0; pos--) {
if (intMemState[pos] == MEM_FREE) {
return pos;
}
}
}
return NULL;
}
int_addr_ptr find_free_pos_and_allocate_and_init_int(int memState, int value) {
int_addr_ptr pos;
if (INT_FREE_MEM == 0) {
MEM_ERR_NOT_ENOUGH_MEM = true;
MEM_ERR_NOT_ENOUGH_MEM_INT = true;
return NULL;
}
pos = find_free_pos_int(memState);
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
allocate_and_init_int(memState, pos, value);
}
return pos;
}
int_addr_ptr find_free_pos_and_allocate_int(int memState) {
return find_free_pos_and_allocate_and_init_int(memState, DEFAULT_INT_VALUE);
}
void delete_int(int_addr_ptr pos, bool isStatic) {
check_mem_errors_for_delete_int(pos, isStatic, false);
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
}
//////////////////
// INT - public
//////////////////
int_addr_ptr allocate_static_int() {
return find_free_pos_and_allocate_and_init_int(MEM_STATIC_OBJ, DEFAULT_INT_VALUE);
}
int_addr_ptr allocate_dynamic_int() {
return find_free_pos_and_allocate_and_init_int(MEM_DYN_OBJ, DEFAULT_INT_VALUE);
}
int_addr_ptr allocate_static_and_init_int(int value) {
return find_free_pos_and_allocate_and_init_int(MEM_STATIC_OBJ, value);
}
int_addr_ptr allocate_dynamic_and_init_int(int value) {
return find_free_pos_and_allocate_and_init_int(MEM_DYN_OBJ, value);
}
void delete_static_int(int_addr_ptr pos) {
delete_int(pos, true);
}
void delete_dynamic_int(int_addr_ptr pos) {
delete_int(pos, false);
}
void empty_stack_int(int_addr_ptr pos) {
if (pos != NULL) {
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
}
}
/////////////////////////
// INT ARRAY - private
/////////////////////////
int_addr_ptr find_free_pos_arr_int(int memState, int length) {
int count = 0;
int_addr_ptr pos = -1;
int i = 0;
if (memState == MEM_STATIC_ARR_HEAD) {
for (i = 0; i <= INT_MEMSIZE - 1; i++) {
if (intMemState[i] == MEM_FREE) {
if (count == 0) {
pos = i;
}
count++;
if (count == length) {
return pos;
}
} else if (is_static_elem_int(i)) {
count = 0;
pos = NULL;
} else {
return NULL;
}
}
} else if (memState == MEM_DYN_ARR_HEAD) {
for(i = INT_MEMSIZE - 1; i >= 0; i--) {
if (intMemState[i] == MEM_FREE) {
if (count == 0) {
pos = i;
}
count++;
if (count == length) {
return pos - length + 1; // return the 'lower' index w.r.t. the memArray; + 1 because count starts at 0
}
} else if (is_static_elem_int(i)) {
count = 0;
pos = NULL;
} else {
return NULL;
}
}
}
return NULL;
}
int_addr_ptr allocate_arr_int(int memState, int length) {
int i;
int_addr_ptr pos;
int tailElemStateType;
if (INT_FREE_MEM < length) {
MEM_ERR_NOT_ENOUGH_MEM = true;
MEM_ERR_NOT_ENOUGH_MEM_INT = true;
return NULL;
}
pos = find_free_pos_arr_int(memState, length);
if (pos == NULL) {
MEM_ERR_FRAGMENTED_MEM = true;
MEM_ERR_FRAGMENTED_MEM_INT = true;
return NULL;
}
if (memState == MEM_STATIC_ARR_HEAD) {
tailElemStateType = MEM_STATIC_ARR_TAIL;
} else {
tailElemStateType = MEM_DYN_ARR_TAIL;
}
allocate_int(memState, pos); // allocate head
for(i = pos + 1; i < (pos + length); i++) {
allocate_int(tailElemStateType, i);
}
return pos;
}
void delete_arr_int(int_addr_ptr pos, bool isStatic) {
int i = pos + 1;
check_mem_errors_for_delete_int(pos, isStatic, true);
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
while(i < INT_MEMSIZE && is_arr_tail_elem_int(i)) {
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
i=i+1;
}
}
////////////////////////
// INT ARRAY - public
////////////////////////
int_addr_ptr allocate_static_arr_int(int length) {
return allocate_arr_int(MEM_STATIC_ARR_HEAD, length);
}
int_addr_ptr allocate_dynamic_arr_int(int length) {
return allocate_arr_int(MEM_DYN_ARR_HEAD, length);
}
void delete_arr_static_int(int_addr_ptr pos) {
delete_arr_int(pos, true);
}
void delete_arr_dynamic_int(int_addr_ptr pos) {
delete_arr_int(pos, false);
}
void empty_stack_arr_int(int_addr_ptr pos) {
int i = pos + 1;
if (pos != NULL) {
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
while(i < INT_MEMSIZE && is_arr_tail_elem_int(i)) {
allocate_and_init_int(MEM_FREE, pos, DEFAULT_INT_VALUE);
i++;
}
}
}
void init_arr_elem_int(int_addr_ptr pos, int value) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
intMem[pos] = value;
}
}
///////////////////
// DATA - helper functions
///////////////////
bool is_free_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_FREE;
}
bool is_obj_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_STATIC_OBJ || dataMemState[pos] == MEM_DYN_OBJ;
}
bool is_static_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_STATIC_OBJ || dataMemState[pos] == MEM_STATIC_ARR_HEAD || dataMemState[pos] == MEM_STATIC_ARR_TAIL;
}
bool is_dynamic_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_DYN_OBJ || dataMemState[pos] == MEM_DYN_ARR_HEAD || dataMemState[pos] == MEM_DYN_ARR_TAIL;
}
bool is_arr_head_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_STATIC_ARR_HEAD || dataMemState[pos] == MEM_DYN_ARR_HEAD;
}
bool is_arr_tail_elem_data(data_addr_ptr pos) {
return dataMemState[pos] == MEM_STATIC_ARR_TAIL || dataMemState[pos] == MEM_DYN_ARR_TAIL;
}
void check_mem_errors_for_delete_data(data_addr_ptr pos, bool isStatic, bool shouldBeAnArray) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else if (is_free_elem_data(pos)) {
MEM_ERR_DOUBLE_FREE = true;
} else if (not is_obj_elem_data(pos) && not is_arr_head_elem_data(pos)) {
// something went completely wrong :(
// ex: delete somewhere in the middle of an array
MEM_ERR_CORRUPTED_MEM = true;
} else {
if (!isStatic && is_static_elem_data(pos)) {
MEM_ERR_DELETE_ON_STATIC_VAR = true;
}
if (shouldBeAnArray) {
if (not is_arr_head_elem_data(pos)) {
MEM_ERR_INVALID_ARR_DELETE = true; // shouldn't have called 'delete []' ?
}
} else { // delete normal obj
if (not is_obj_elem_data(pos)) {
MEM_ERR_INVALID_OBJ_DELETE = true;
}
}
}
}
bool addr_is_in_range_data(int pos) {
return pos >= 0 && pos < DATA_MEMSIZE;
}
bool addr_is_valid_data(data_addr_ptr pos) {
return pos != NULL && dataMemState[pos] != MEM_FREE;
}
bool is_arr_elem_data(int head, int index) {
int i;
if (!addr_is_in_range_data(head + index)) {
return false;
}
if (!is_arr_head_elem_data(head)) {
return false;
}
if (index < 0) { // assuming heap/stack arrays grow leftward
return false;
}
for (i = head + 1; i <= head + index; i++) {
if (!is_arr_tail_elem_data(i)) {
return false;
}
}
return true;
}
///////////////////
// DATA - private
///////////////////
void allocate_and_init_data(int memState, data_addr_ptr pos, data value) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
dataMemState[pos] = memState;
dataMem[pos] = value;
if (memState == MEM_FREE) {
DATA_FREE_MEM++;
} else {
DATA_FREE_MEM--;
}
}
}
void allocate_data(int memState, data_addr_ptr pos) {
allocate_and_init_data(memState, pos, DEFAULT_DATA_VALUE);
}
data_addr_ptr find_free_pos_data(int memState) {
data_addr_ptr pos = NULL;
if (memState == MEM_STATIC_OBJ) { // stack
for(pos = 0; pos <= DATA_MEMSIZE - 1; pos++) {
if (dataMemState[pos] == MEM_FREE) {
return pos;
}
}
} else if (memState == MEM_DYN_OBJ) { // heap
for(pos = DATA_MEMSIZE - 1; pos >= 0; pos--) {
if (dataMemState[pos] == MEM_FREE) {
return pos;
}
}
}
return NULL;
}
data_addr_ptr find_free_pos_and_allocate_and_init_data(int memState, data value) {
data_addr_ptr pos;
if (DATA_FREE_MEM == 0) {
MEM_ERR_NOT_ENOUGH_MEM = true;
MEM_ERR_NOT_ENOUGH_MEM_DATA = true;
return NULL;
}
pos = find_free_pos_data(memState);
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
allocate_and_init_data(memState, pos, value);
}
return pos;
}
data_addr_ptr find_free_pos_and_allocate_data(int memState) {
return find_free_pos_and_allocate_and_init_data(memState, DEFAULT_DATA_VALUE);
}
void delete_data(data_addr_ptr pos, bool isStatic) {
check_mem_errors_for_delete_data(pos, isStatic, false);
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
}
//////////////////
// DATA - public
//////////////////
data_addr_ptr allocate_static_data() {
return find_free_pos_and_allocate_and_init_data(MEM_STATIC_OBJ, DEFAULT_DATA_VALUE);
}
data_addr_ptr allocate_dynamic_data() {
return find_free_pos_and_allocate_and_init_data(MEM_DYN_OBJ, DEFAULT_DATA_VALUE);
}
data_addr_ptr allocate_static_and_init_data(data value) {
return find_free_pos_and_allocate_and_init_data(MEM_STATIC_OBJ, value);
}
data_addr_ptr allocate_dynamic_and_init_data(data value) {
return find_free_pos_and_allocate_and_init_data(MEM_DYN_OBJ, value);
}
void delete_static_data(data_addr_ptr pos) {
delete_data(pos, true);
}
void delete_dynamic_data(data_addr_ptr pos) {
delete_data(pos, false);
}
void empty_stack_data(data_addr_ptr pos) {
if (pos != NULL) {
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
}
}
/////////////////////////
// DATA ARRAY - private
/////////////////////////
data_addr_ptr find_free_pos_arr_data(int memState, int length) {
int count = 0;
data_addr_ptr pos = -1;
int i = 0;
if (memState == MEM_STATIC_ARR_HEAD) {
for (i = 0; i <= DATA_MEMSIZE - 1; i++) {
if (dataMemState[i] == MEM_FREE) {
if (count == 0) {
pos = i;
}
count++;
if (count == length) {
return pos;
}
} else if (is_static_elem_data(i)) {
count = 0;
pos = NULL;
} else {
return NULL;
}
}
} else if (memState == MEM_DYN_ARR_HEAD) {
for(i = DATA_MEMSIZE - 1; i >= 0; i--) {
if (dataMemState[i] == MEM_FREE) {
if (count == 0) {
pos = i;
}
count++;
if (count == length) {
return pos - length + 1; // return the 'lower' index w.r.t. the memArray; + 1 because count starts at 0
}
} else if (is_static_elem_data(i)) {
count = 0;
pos = NULL;
} else {
return NULL;
}
}
}
return NULL;
}
data_addr_ptr allocate_arr_data(int memState, int length) {
int i;
data_addr_ptr pos;
int tailElemStateType;
if (DATA_FREE_MEM < length) {
MEM_ERR_NOT_ENOUGH_MEM = true;
MEM_ERR_NOT_ENOUGH_MEM_DATA = true;
return NULL;
}
pos = find_free_pos_arr_data(memState, length);
if (pos == NULL) {
MEM_ERR_FRAGMENTED_MEM = true;
MEM_ERR_FRAGMENTED_MEM_DATA = true;
return NULL;
}
if (memState == MEM_STATIC_ARR_HEAD) {
tailElemStateType = MEM_STATIC_ARR_TAIL;
} else {
tailElemStateType = MEM_DYN_ARR_TAIL;
}
allocate_data(memState, pos); // allocate head
for(i = pos + 1; i < (pos + length); i++) {
allocate_data(tailElemStateType, i);
}
return pos;
}
void delete_arr_data(data_addr_ptr pos, bool isStatic) {
int i = pos + 1;
check_mem_errors_for_delete_data(pos, isStatic, true);
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
while(i < DATA_MEMSIZE && is_arr_tail_elem_data(i)) {
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
i++;
}
}
////////////////////////
// DATA ARRAY - public
////////////////////////
data_addr_ptr allocate_static_arr_data(int length) {
return allocate_arr_data(MEM_STATIC_ARR_HEAD, length);
}
data_addr_ptr allocate_dynamic_arr_data(int length) {
return allocate_arr_data(MEM_DYN_ARR_HEAD, length);
}
void delete_arr_static_data(data_addr_ptr pos) {
delete_arr_data(pos, true);
}
void delete_arr_dynamic_data(data_addr_ptr pos) {
delete_arr_data(pos, false);
}
void empty_stack_arr_data(data_addr_ptr pos) {
int i = pos + 1;
if (pos != NULL) {
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
while(i < DATA_MEMSIZE && is_arr_tail_elem_data(i)) {
allocate_and_init_data(MEM_FREE, pos, DEFAULT_DATA_VALUE);
i++;
}
}
}
void init_arr_elem_data(data_addr_ptr pos, data value) {
if (pos == NULL) {
MEM_ERR_CORRUPTED_MEM = true;
} else {
dataMem[pos] = value;
}
}
void prod_ctor(data_addr_ptr &d){
}
void cons_ctor(){
}
void sc_main(){
prod_ctor(prod_d);
cons_ctor();
}</declaration>
<template>
<name>Consumer_cons_peq_cb</name>
<parameter>int_addr_ptr &cons_socket_nb_transport_bw_param_phase, chan &cons_peq_cb_ctrl, int_addr_ptr &cons_peq_cb_param_phase, data_addr_ptr &cons_socket_nb_transport_bw_param_tran, int &cons_peq_peq_element_param_delay, chan &cons_socket_nb_transport_bw_ctrl, data_addr_ptr &cons_peq_peq_element_param_trans, int_addr_ptr &cons_socket_nb_transport_bw_param_t, chan &cons_peq_notify_ctrl, data_addr_ptr &cons_peq_cb_param_tran, int_addr_ptr &cons_peq_peq_element_param_phase</parameter>
<declaration>data_addr_ptr tran = NULL;
int_addr_ptr phase = NULL;
int_addr_ptr phase1 = NULL;
int_addr_ptr delay = NULL;</declaration>
<location id="id0" x="302" y="51">
<name x="246" y="17">init_location_cons</name>
</location>
<location id="id1" x="472" y="178">
<name x="462" y="144">cons_peq1</name>
<urgent/>
</location>
<location id="id2" x="1548" y="1211">
<name x="1572" y="1203">chkptr_3</name>
<urgent/>
</location>
<location id="id3" x="277" y="1164">
<name x="289" y="1139">chkptr_4</name>
<urgent/>
</location>
<location id="id4" x="268" y="1071">
<name x="280" y="1062">cons_peq7</name>
<urgent/>
</location>
<location id="id5" x="260" y="867">
<name x="272" y="867">cons_peq9</name>
</location>
<location id="id6" x="251" y="603">
<name x="241" y="569">cons_peq11</name>
<urgent/>
</location>
<location id="id7" x="523" y="671">
<name x="513" y="637">cons_peq5</name>
<urgent/>
</location>
<location id="id8" x="1215" y="240">
<name x="1205" y="206">cons_peq2</name>
<urgent/>
</location>
<location id="id9" x="1051" y="304">
<name x="1003" y="314">chkptr_5</name>
<urgent/>
</location>
<location id="id10" x="619" y="368">
<name x="643" y="360">chkptr_6</name>
<urgent/>
</location>
<location id="id11" x="619" y="432">
<urgent/>
</location>
<location id="id12" x="619" y="577">
<name x="637" y="561">cons_peq4</name>
</location>
<location id="id13" x="816" y="1147">
<name x="806" y="1113">cons_peq6</name>
<urgent/>
</location>
<location id="id14" x="260" y="221">
<name x="250" y="187">cons_peq12</name>
<urgent/>
</location>
<location id="id15" x="268" y="969">
<name x="280" y="952">cons_peq8</name>
<urgent/>
</location>
<location id="id16" x="234" y="705">
<name x="136" y="688">cons_peq10</name>
<urgent/>
</location>
<location id="id17" x="619" y="513">
<name x="527" y="493">cons_peq3</name>
<urgent/>
</location>
<init ref="id0"/>
<transition>
<source ref="id1"/>
<target ref="id2"/>
<label kind="guard" x="1556" y="677">intMem[phase] == 0</label>
<label kind="comments" x="1156" y="17">Guard:
nodeID: 2131, file: prodcons.cpp, line: 164</label>
<nail x="1548" y="192"/>
<nail x="1548" y="1195"/>
</transition>
<transition>
<source ref="id2"/>
<target ref="id3"/>
<label kind="guard" x="319" y="1241">addr_is_valid_int(delay)</label>
<label kind="assignment" x="319" y="1253">intMem[delay] = 2</label>
<label kind="comments" x="1249" y="739">Guard:
nodeID: -1, file: , line: -1Update:
nodeID: 2151, file: prodcons.cpp, line: 165</label>
</transition>
<transition>
<source ref="id3"/>
<target ref="id4"/>
<label kind="guard" x="-21" y="1067">addr_is_valid_int(phase1)</label>
<label kind="assignment" x="-21" y="1080">intMem[phase1] = 1</label>
<label kind="comments" x="1249" y="816">Guard:
nodeID: -1, file: , line: -1Update:
nodeID: 2185, file: prodcons.cpp, line: 166</label>
</transition>
<transition>
<source ref="id6"/>
<target ref="id7"/>
<label kind="synchronisation" x="268" y="687">cons_peq_notify_ctrl?</label>
<nail x="260" y="687"/>
</transition>
<transition>
<source ref="id1"/>
<target ref="id8"/>
<label kind="guard" x="1342" y="204">!(intMem[phase] == 0)</label>
<label kind="comments" x="-105" y="454">Guard:
nodeID: 2131, file: prodcons.cpp, line: 164</label>
<nail x="1334" y="204"/>
<nail x="1334" y="236"/>
</transition>
<transition>
<source ref="id8"/>
<target ref="id9"/>
<label kind="guard" x="1059" y="256">intMem[phase] == 2</label>
<label kind="comments" x="-59" y="493">Guard:
nodeID: 2372, file: prodcons.cpp, line: 174</label>
<nail x="1051" y="256"/>
<nail x="1051" y="288"/>
</transition>
<transition>
<source ref="id9"/>
<target ref="id10"/>
<label kind="guard" x="627" y="320">addr_is_valid_int(delay)</label>
<label kind="assignment" x="627" y="333">intMem[delay] = 2</label>
<label kind="comments" x="-59" y="374">Guard:
nodeID: -1, file: , line: -1Update:
nodeID: 2392, file: prodcons.cpp, line: 175</label>
<nail x="619" y="320"/>
<nail x="619" y="352"/>
</transition>
<transition>
<source ref="id10"/>
<target ref="id11"/>
<label kind="guard" x="627" y="384">addr_is_valid_int(phase1)</label>
<label kind="assignment" x="627" y="397">intMem[phase1] = 2</label>
<label kind="comments" x="1156" y="119">Guard:
nodeID: -1, file: , line: -1Update:
nodeID: 2426, file: prodcons.cpp, line: 176</label>
<nail x="619" y="384"/>
<nail x="619" y="416"/>
</transition>
<transition>
<source ref="id8"/>
<target ref="id13"/>
<label kind="guard" x="1212" y="677">!(intMem[phase] == 2)</label>
<label kind="comments" x="1156" y="68">Guard:
nodeID: 2372, file: prodcons.cpp, line: 174</label>
<nail x="1204" y="256"/>
<nail x="1204" y="1131"/>
</transition>
<transition>
<source ref="id13"/>
<target ref="id7"/>
<label kind="guard" x="436" y="893">intMem[phase] == 3</label>
<label kind="comments" x="1266" y="484">Guard:
nodeID: 2527, file: prodcons.cpp, line: 181</label>
<nail x="428" y="1131"/>
<nail x="428" y="687"/>
</transition>
<transition>
<source ref="id13"/>
<target ref="id7"/>
<label kind="guard" x="589" y="893">!(intMem[phase] == 3)</label>
<label kind="comments" x="1266" y="535">Guard:
nodeID: 2527, file: prodcons.cpp, line: 181</label>
<nail x="581" y="1131"/>
<nail x="581" y="687"/>
</transition>
<transition>
<source ref="id14"/>
<target ref="id0"/>
<label kind="synchronisation" x="132" y="68">cons_peq_cb_ctrl!</label>
<nail x="260" y="51"/>
</transition>
<transition>
<source ref="id0"/>
<target ref="id1"/>
<label kind="synchronisation" x="387" y="9">cons_peq_cb_ctrl?</label>
<label kind="assignment" x="379" y="26">tran = cons_peq_cb_param_tran,
phase = cons_peq_cb_param_phase,
delay = allocate_static_int(),
phase1 = allocate_static_int()</label>
<label kind="comments" x="-42" y="102">Update:
nodeID: -1, file: , line: -1,
nodeID: -1, file: , line: -1,
nodeID: -1, file: , line: -1,
nodeID: -1, file: , line: -1</label>
<nail x="302" y="178"/>
</transition>
<transition>
<source ref="id4"/>
<target ref="id15"/>
<label kind="assignment" x="-73" y="983">cons_socket_nb_transport_bw_param_tran = tran,