real real time systems time systems ada 95 reference
play

Real Real- -Time Systems Time Systems Ada 95 Reference Manual - PowerPoint PPT Presentation

EDA222/DIT160 Real-Time Systems, Chalmers/GU, 2008/2009 Lecture #4 Updated 2009-01-25 Real Real- -Time Systems Time Systems Ada 95 Reference Manual (ARM) Ada 95 Reference Manual (ARM) Ada 95 consists of a core language Ada 95 consists


  1. EDA222/DIT160 – Real-Time Systems, Chalmers/GU, 2008/2009 Lecture #4 Updated 2009-01-25 Real Real- -Time Systems Time Systems Ada 95 Reference Manual (ARM) Ada 95 Reference Manual (ARM) Ada 95 consists of a core language Ada 95 consists of a core language and a set of and a set of annex annex containing extensions for special applications. containing extensions for special applications. Specification • Ada 95 An Ada 95 implementation must support the entire core An Ada 95 implementation must support the entire core • Clocks, time, delay • Task priorities language , but can choose to support an arbitrary language , but can choose to support an arbitrary combination of annex. combination of annex. Implementation An annex may define new packages An annex may define new packages, , attributes attributes and and pragma, pragma, but may not introduce new syntax or change but may not introduce new syntax or change semantics of the semantics of the core language core language . . Verification Ada 95 Reference Manual (ARM) Clocks and time in Ada 95 Ada 95 Reference Manual (ARM) Clocks and time in Ada 95 The following parts of ARM are dealt with in this course: The following parts of ARM are dealt with in this course: To construct a real- To construct a real -time system, the chosen programming time system, the chosen programming language must support a concept of time that can be language must support a concept of time that can be Section 9: Tasks and Synchronization used for modeling the system’ used for modeling the system ’s time constraints. s time constraints. Section 13: Representation Issues Annex C: Systems Programming In Ada 95, time is represented as system clocks, that can In Ada 95, time is represented as system clocks, that can be read in order to report current time. be read in order to report current time. Annex D: Real-Time Systems Ada 95 has two different time packages that each defines Ada 95 has two different time packages that each defines In addition, the following parts of ARM are interesting: In addition, the following parts of ARM are interesting: a system clock: a system clock: Annex E: Distributed Systems Ada.Calendar: Ada.Calendar : compulsory package (Section 9.6) with a clock compulsory package (Section 9.6) with a clock Annex F: Information Systems that represents calendar time with that represents calendar time with " "satisfactory" resolution. satisfactory" resolution. Annex G: Numerics Ada.Real_Time: : annex package (Annex D.8) with a clock that annex package (Annex D.8) with a clock that Ada.Real_Time represents physical (monotonic) time with high resolution. represents physical (monotonic) time with high resolution. Annex H: Safety and Security 1

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

  3. EDA222/DIT160 – Real-Time Systems, Chalmers/GU, 2008/2009 Lecture #4 Updated 2009-01-25 Time delays Time delays Periodic activities Periodic activities How can the execution of a task be delayed in Ada? How can the execution of a task be delayed in Ada? Example: Execute a task periodically every 5th second. Example: • Use the (relative) delay statement : package body Periodic_Action is task body T is delay 10.0; -- wait for 10 seconds Interval : constant Duration := 5.0; begin loop • While the task is delayed in the delay statement, other tasks (if Action; delay Interval; such exist) may execute. end loop ; end T; end Periodic_Action; • The delay statement guarantees that the delay will be at least the This solution gives rise to a systematic time skew This solution gives rise to a systematic time skew indicated number of seconds (which should be of type Duration ). The code for Action takes a certain time Δ action – • The actual delay could be longer because the delayed task may The code for administrating the loop construct takes a certain time Δ loop – ⇒ The minimum interval between two executions of Action is: have to wait for other tasks to complete their execution. 5 + Δ action + Δ loop seconds. Periodic activities Periodic activities Periodic activities Periodic activities package body Periodic_Action is How can systematic time skew be avoided in Ada? How can systematic time skew be avoided in Ada? task body T is • Use the (absolute) delay statement: Interval : constant Duration := 5.0; Next_Time : Time; begin delay until Later; -- wait until clock becomes Later Next_Time := Clock + Interval; loop Action; • The absolute delay statement guarantees that the continued delay until Next_Time; Next_Time := Next_Time + Interval; execution is delayed until the given time instant at the earliest. end loop ; end T; end Periodic_Action; • The given time instant can be of arbitrary time type This solution does not eliminate local time skew local time skew This solution does not eliminate (i.e. from Ada.Calendar as well as from Ada.Real_Time ). Other tasks with same or higher priority may interfere so that the task – cannot begin its execution at the desired time instant – Local time skew may cause the start time within the current time interval to vary between different executions of the same task. – Local time skew can be avoided by using suitable scheduling algorithms or be determined with the aid of special analysis methods. 3

Recommend


More recommend