avrada_lib_2.1.0_fe38c6dc/src/avr-timer1-timing_events.ads

 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
------------------------------------------------------------------------------
--                                                                          --
--                                                                          --
--          A V R . R E A L _ T I M E . T I M I N G _ E V E N T S           --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
-- This specification is derived from the Ada Reference Manual for use with --
-- AVR-Ada.                                                                 --
--                                                                          --
--                                                                          --
------------------------------------------------------------------------------

with Interfaces;                   use Interfaces;

package AVR.Timer1.Timing_Events is

   --  Ticks correspond to Ada.Real_Time.Time_Span or Duration
   type Ticks is new Unsigned_16;

   type Timing_Event is limited private;

   type Timing_Event_Handler
     is access procedure (Event : in out Timing_Event);

   --  procedure Set_Handler
   --    (Event   : in out Timing_Event;
   --     At_Time : Time;
   --     Handler : Timing_Event_Handler);

   procedure Set_Handler
     (Event   : in out Timing_Event;
      In_Time : Ticks;
      Handler : Timing_Event_Handler);

   function Current_Handler
     (Event : Timing_Event) return Timing_Event_Handler;

   procedure Cancel_Handler
     (Event     : in out Timing_Event;
      Cancelled : out Boolean);

   function Ticks_Of_Event (Event : Timing_Event) return Ticks;


private

   type Timing_Event is record

      --  D.15 (22/2) requires atomicity with respect to the
      --  operations provided by the package and the timing events
      --  they manipulate. On real-time operating systems suitable for
      --  implementing this package, a different implementation
      --  strategy would be employed to meet that requirement.

      Timeout : Ticks := 0;
      --  The time at which the user's handler should be invoked when the
      --  event is "set" (i.e., when Handler is not null).

      Handler : Timing_Event_Handler;
      --  An access value designating the protected procedure to be invoked
      --  at the Timeout time in the future.  When this value is null the event
      --  is said to be "cleared" and no timeout is processed.

   end record;


   package Event_Queue is

      procedure Insert (This : access Timing_Event);
      --  Inserts This into the queue in ascending order by Timeout

      procedure Process_Events;
      --  Iterates over the list of events and calls the handlers for any of
      --  those that have timed out. Deletes those that have timed out.

      procedure Print_Events;

   end Event_Queue;


   pragma Inline (Cancel_Handler);
   pragma Inline (Current_Handler);

end AVR.Timer1.Timing_Events;