SLIDE 2 EDA222/DIT160 – Real-Time Systems, Chalmers/GU, 2008/2009 Lecture #4
Updated 2009-01-25
2
Calendar time in Ada 95 Calendar time in Ada 95
Ada.Calendar Ada.Calendar defines a data type
defines a data type Time
Time that represents
that represents calendar time (date + seconds since midnight) with a calendar time (date + seconds since midnight) with a resolution of at least resolution of at least 20 ms 20 ms. Values of this type can be . Values of this type can be converted to year, month, day and seconds. converted to year, month, day and seconds. Calendar time is normally monotonic (non Calendar time is normally monotonic (non-
decreasing), but can be adjusted (forwards/backwards) as a consequence can be adjusted (forwards/backwards) as a consequence
- f e.g. daylight savings time or other time adjustments.
- f e.g. daylight savings time or other time adjustments.
The current value of the calendar time can be read by calling The current value of the calendar time can be read by calling the function the function Ada.Calendar.Clock
Ada.Calendar.Clock.
. A (calendar) time interval (i.e. the difference between two A (calendar) time interval (i.e. the difference between two time instants) is represented by the data type time instants) is represented by the data type Duration
Duration.
.
Real time in Ada 95 Real time in Ada 95
Ada.Real_Time Ada.Real_Time defines a data type
defines a data type Time
Time that represents real
that represents real time (physical time) with a resolution of at least time (physical time) with a resolution of at least 1 ms 1 ms. . Values of this type Values of this type cannot cannot be converted to be converted to calender calender data. data. Real time is strictly monotonic (cannot be adjusted backwards) Real time is strictly monotonic (cannot be adjusted backwards) and measured in elapsed and measured in elapsed time units time units since an since an epoch
. Time unit and epoch are both implementation dependent. unit and epoch are both implementation dependent. The current value of the real time can be read by calling the The current value of the real time can be read by calling the function function Ada.Real_Time.Clock
Ada.Real_Time.Clock.
.
A (real) time interval (i.e. the difference between two time A (real) time interval (i.e. the difference between two time instants) is represented by the data type instants) is represented by the data type Time_Span
Time_Span.
.
Although same names are used for types & functions, Although same names are used for types & functions, Ada.Calendar Ada.Calendar
and and Ada.Real_Time
Ada.Real_Time can coexist in the same program. can coexist in the same program.
Example: control of execution time Example: control of execution time
(with (with Ada.Calendar Ada.Calendar) )
with Ada.Calendar; use Ada.Calendar; package body Controller is task body Temp_Controller is ...
- - declaration of variables
Start, Finish : Time; Interval : Duration := 1.7; Overrun_Error : exception; begin loop Start := Clock; ...
- - statements in Temp_Controller;
Finish := Clock; if Finish - Start > Interval then raise Overrun_Error; end if; end loop; exception when Overrun_Error =>
- - program code for error handling
end Temp_Controller; end Controller;
Example: control of execution time Example: control of execution time
(with (with Ada.Real_Time Ada.Real_Time) )
with Ada.Real_Time; use Ada.Real_Time; package body Controller is task body Temp_Controller is ...
- - declaration of variables
Start, Finish : Time; Interval : Time_Span := To_Time_Span(1.7); Overrun_Error : exception; begin loop Start := Clock; ...
- - statements in Temp_Controller;
Finish := Clock; if Finish - Start > Interval then raise Overrun_Error; end if; end loop; exception when Overrun_Error =>
- - program code for error handling
end Temp_Controller; end Controller; Time constants have type Duration as default. Conversion of time intervals is found in Ada.Real_Time.