LNT_Generic_Process_For_Port_Connections.lnt 2.36 KB
Newer Older
hana's avatar
update:    
hana committed
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
module LNT_Generic_Process_For_Port_Connections (Types) is 
-- No Behavior Annex
--  data port --
   process Data_Port [
   Input: LNT_Channel_Port, 
   Output: LNT_Channel_Port] 
   is 
      var Data : LNT_Type_Data in
         Data := EMPTY;
         loop 
            select 
               Input (?Data)
               [] 
               Output (Data)
            end select 
         end loop
      end var
   end process
   
--  event port --
--  for no periodic threads --
   process Event_Port [
   Input: LNT_Channel_Port, 
   Output: LNT_Channel_Port, 
   Notify: LNT_Channel_Event](
   Queue_Size: Nat) 
   is 
      var 
         Data : LNT_Type_Data,
         FIFO : LNT_Type_Data_FIFO,
         Is_New : bool
      in 
         FIFO := {};
         Data := EMPTY;
         Is_New := false; 
         loop 
            select 
               Input (?Data); 
               Is_New := true;
               if length (FIFO) >= Queue_Size then
                  FIFO := tail (FIFO)
               end if;
               FIFO := append (Data, FIFO)
               []
               if (FIFO != {}) then 
                  Output (Head (FIFO));
                  FIFO := tail (FIFO)
               else
                  Output (EMPTY)
               end if
               []
               if (Is_New) then 
                  Notify (Incoming_Event); 
                  Is_New := false
               else 
                  Notify (No_Event)
               end if
            end select 
         end loop
      end var
   end process

-- for periodic threads
   process Event_Port_For_Periodic [
   Input: LNT_Channel_Port, 
   Output: LNT_Channel_Port](
   Queue_Size: Nat) 
   is 
      var 
         Data : LNT_Type_Data,
         FIFO : LNT_Type_Data_FIFO,
         Is_New : bool
      in 
         FIFO := {};
         Data := EMPTY;
         Is_New := false; 
         loop 
            select 
               Input (?Data); 
               Is_New := true;
               if length (FIFO) >= Queue_Size then
                  FIFO := tail (FIFO)
               end if;
               FIFO := append (Data, FIFO)
               []
               if (FIFO != {}) then 
                  Output (Head (FIFO));
                  FIFO := tail (FIFO)
               else
                  Output (EMPTY)
               end if
            end select 
         end loop
      end var
   end process
end module