4' Programming Languages and Tools - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

4' Programming Languages and Tools

Description:

Data typing. purposes. guard against programming errors ... C, Ada: Test condition at beginning of loop. Java: Allows test at beginning or end of loop ... – PowerPoint PPT presentation

Number of Views:388
Avg rating:3.0/5.0
Slides: 35
Provided by: automatik
Category:

less

Transcript and Presenter's Notes

Title: 4' Programming Languages and Tools


1
REAL-TIME PROGRAMMINGLanguagues
Prof. Dr Sanja Vranes Institute Mihailo
Pupin Phone 2773149 E-mail Sanja.Vranes_at_institut
epupin.com
2
Characteristics of Real-Time Language
  • Additional demands of real-time applications
  • run-time requirements
  • effective interactions with i/o devices
  • Reliable software implementation
  • data typing
  • readability
  • for easier debugging
  • for maintenance of the program

3
Characteristics of Real-Time Language (cont.)
  • Improving portability
  • provide a discipline in production of compilers
  • avoid ambiguities in language specifications
  • limit the language complexity
  • Dealing with various I/O devices
  • use high level language instead of machine codes
  • need to be able to specify absolute addresses

4
Characteristics of Real-Time Language (cont.)
  • Made to realize predictability
  • no variable-sized arrays
  • no recursion
  • Ability to precisely specify delays
  • need an accurate clock
  • (Ada9X realtime annex, high precision, various
    granularity)
  • Improved comprehensibility and modularity
  • information hiding
  • ease of debugging and testing

5
Characteristics of Real-Time Language (cont.)
  • Data typing
  • purposes
  • guard against programming errors
  • specify the desired degree of numerical precision
  • strong typing
  • all variables are explicitly declared
  • no implicit type conversion allowed
  • explicit type conversions are possible

6
Data types
  • Allow programs to manipulate objects abstracted
    from implementation
  • Can increase robustness via compile-time
    consistency checking (type checking)
  • Solid type checking can be a particular asset for
    programming high-dependability systems!

7
Typing
  • Ada, Java
  • Strongly typed
  • Java allows implicit type conversions if no
    information is lost
  • C
  • Weakly typed
  • May, for example, assign int to short

8
Structured Data Types
  • Arrays
  • Offered by Ada, C, and Java
  • C, Java Index always starts with 0
  • Ada May start with any index
  • Records
  • C Initialization affects all fields
  • Ada
  • May initialize fields selectively
  • May initialize via names
  • Java can emulate records with classes

9
Loops
  • while loops
  • C, Ada Test condition at beginning of loop
  • Java Allows test at beginning or end of loop
  • Infinite loops
  • Ada loop ltStatementsgt end loop
  • C, Java while (1)

10
High-Quality C Code
  • C is like a sharp knife
  • Very versatilebut you have to know what you are
    doing
  • Cannot reduce risks arbitrarily without
    compromising utility
  • However, can lower risks significantly by
  • 1. Risk awareness
  • 2. Proper development process
  • 3. Conservative coding style
  • 4. Extensive static (compile-time) and dynamic
    (run-time) analyses
  • These precautions are all complementary, none
    replaces the others

11
An Overview of Ada
  • An Ada program consists of one or more program
    units
  • a subprogram (procedure or function) can be
    generic
  • a package (possibly generic) used for
    encapsulation and modularity
  • a task used for concurrency
  • a protected unit a data-oriented
    synchronisation mechanism
  • Library units package, subprogram
  • Subunits subprogram, package, task, protected
    unit

12
Blocks
  • Ada is a block-structured language
  • declare
  • -- definitions of types, objects,
  • -- subprograms etc.
  • begin
  • -- sequence of statements
  • exception
  • -- exception handlers
  • end
  • A block can be placed anywhere a statement can be
    placed

13
Block in C and Java
  • lt declarative part gt
  • lt sequence of statement gt

14
Points about Blocks
  • objects declared in a block may only be used in
    that block (scope)
  • any statement in the sequence of statement may
    itself be a block
  • exception handlers can be used to trap errors
    arising out of the execution of the sequence of
    statements (they may be omitted)

15
An Overview of Java
  • A class-based language
  • More type secure than C
  • As with Ada, Java can have exception handler at
    the end of a block
  • Functions can only be declared in the context of
    a class

16
Discrete Types
17
  • specifying range constraint
  • type ALTITUDE is new float range 0..100000
  • enumeration type
  • type day is (mon, tue, wed, thur, fri, sat, sun)
  • specifying the precision, accuracy
  • type prec1 is digits 8 range -1e20..1e20
  • type A1 is delta 0.001 range 0.000..0.999
  • record and tagged data type
  • type student is
  • record
  • NAME nametype
  • GPA gpatype
  • end record
  • type student1 is new student with
  • record
  • resident_reg_number integer
  • end record

18
  • Control structures
  • decision structures
  • if-then-else
  • for
  • do while
  • exit
  • loop
  • x x - k
  • if x lt 0 then exit
  • end if
  • end loop
  • case
  • case i is
  • when -5 gt y x
  • when others gt y 0
  • end case

19
  • Hierarchical decomposition
  • blocks, procedures, functions, packages
  • blocks
  • specification body
  • main purpose information hiding
  • disadvantage should be explicitly repeated
  • whenever needed
  • for i in 0..100 loop
  • block
  • var i integer
  • begin
  • for i in 1..5 loop
  • x x i
  • end loop
  • end
  • end loop

20
  • procedures and functions
  • written out once and called whenever needed
  • implement modularity effectively
  • packages
  • comparable to objects or abstract data type
  • consist of declaration body
  • declaration part
  • variable-type specifications a set of functions
  • body part (optional)
  • executable statements
  • nothing in the body is accessible to any outside
    code

21
  • exception handler attached to a modular unit
  • (block, procedure, function, or task
    body)
  • if no handling routine is not found within that
    unit at time of exception
  • ? the exception keeps propagating into a larger
    block until a handler is found

?
block C
exception is raised here
?
?
exception handler
procedure A procedure B
22
Programming in the large
  • Decomposition
  • Information hiding
  • Separate compilation
  • Reusability
  • Abstraction
  • Abstract data-types
  • Object oriented programming
  • Reusability

23
  • Multitasking
  • to handle concurrency and synchronization
  • constructs
  • task objects
  • exports only task entries
  • task entries
  • similar to procedures in Pascal, but not
    functions(? no return values by entries)
  • with in, out or in-out parameters
  • example
  • task Mailbox is
  • entry DEPOSIT(msg in message)
  • entry REMOVE(msg out message)
  • end Mailbox
  • calls from user program DEPOSIT(x) REMOVE(y)

24
  • constructs (contd)
  • task body
  • defines the implementation of its entries
  • specifies the order of execution for these
    entries
  • only one entry can be executed at a time inside a
    task body
  • accept statements
  • used to implement an entry
  • accept E(formal parameters) do body of E end E
  • select statements
  • allows for a choice between entries
  • select A1 B1 or A2 B2, or end select
  • qualified accept statements
  • when Boolexpr gt accept Entry() do end Entry

25
  • task rendezvous
  • a task encounter that arises when concurrent Ada
    tasks calls an entry or entries in the same task
  • entries inside a task must be executed at time ?
    without explicit synchronization mechanism,
    accesses to a task(or its entries) are
    synchronized rendezvous
  • the essential characteristic of a rendezvous is
    the fact that the calling task and the called
    task are coupled for the duration of the
    execution of an entry.
  • significance
  • no semaphores or P/V operations required for sync
  • accept/select statements and guards language
    constructs to express the order of execution of
    task entries

26
  • simple case of independent tasks
  • procedure ABC is
  • task X
  • task body X is
  • task body
  • end X
  • task Y
  • task body Y is
  • task body
  • end Y
  • ...
  • begin
  • procedure body
  • end ABC

27
  • case of communicating tasks
  • procedure CONCURRENT
  • task A
  • task body A is
  • declarations,
  • program up to point alpha
  • B.beta(X)
  • C.gamma(X)
  • program after point alpha
  • end A
  • task B is
  • entry beta (X float)
  • end B
  • task body B is
  • program up to point beta
  • accept beta(X float) do
  • program between beta and beta_2
  • end beta

alpha
gamma gamma_2
beta beta_2
A
C
B
28
  • case of exclusive control of resources
  • task RESOURCE_CONTROL is
  • entry CAPTURE
  • entry RELEASE
  • end RESOURCE_CONTROL
  • task body RESOURCE_CONTROL is
  • FREE Boolean TRUE
  • begin
  • loop
  • select
  • when FREE gt
  • accept CAPTURE do
  • FREE gt FALSE
  • end CAPTURE
  • or
  • accept RELEASE do
  • FREE gt TRUE
  • or

29
  • case of task priority
  • priority(A) gt priority(B) gtpriority(C)
  • pragma PRIORITY defines a static priority level
  • procedure ABC is
  • task A
  • task body A is
  • pragma PRIORITY(3)
  • begin
  • -- task body
  • end A
  • task B
  • task body B is
  • pragma PRIORITY(2)
  • begin
  • -- task body
  • end B
  • . . . . .
  • begin

30
  • an example
  • producer-consumer problem on mailbox
  • task type Mailbox is
  • entry DEPOSIT(msg in message)
  • entry REMOVE(msg out message)
  • end Mailbox
  • task body Mailbox is
  • length constant 24
  • subtype slotindex is INTEGER range
    0..(length1)
  • head, tail slotindex 0
  • mesnum INTEGER range 0..length 0
  • box array(slotindex)of message
  • (to be continued)

31
  • begin (contd)
  • loop
  • select
  • when mesnum lt length gt
  • accept DEPOSIT(msg in message) do
  • box(head) msg
  • head (head1) mod length
  • mesnum mesnum 1
  • end DEPOSIT
  • or
  • when mesnum gt 0 gt
  • accept REMOVE(msg out message) do
  • msg box(tail)
  • tail (tail 1) mod length
  • mesnum mesnum 1
  • end REMOVE
  • end select
  • end loop
  • end Mailbox

32
  • Low level programming
  • writing device drivers in Ada
  • example reading a temperature sensor
  • memory-mapped I/O
  • calling task initiates a temperature reading by
    READ_TEMP.START(TEMP), and then reads from TEMP
  • OFFON enumerated data type, (OFF, ON)
  • for OFFONSIZE use 1 --size of OFFON type to be
    1 bit
  • for OFFON use (OFFgt0, ONgt1) -- OFF0, ON1

vector addr. 10468
temperature controller
1568
addr. of int. service routine
control register
data register
113068
33
  • task TEMP_READER is
  • entry START(TEMP out INTEGER)
  • entry DONE --an interrupt whose vector address
    is
  • 81046(1046 octal)
  • for DONE use at 81046
  • end TEMP_READER
  • task body TEMPERATURE_READER is
  • B OFFON
  • TEMP_BUFFER INTEGER range 0..1024
  • for TEMP_BUFFER use at 811306 -- data reg.
  • for B use at 8156 range 0..0
  • -- zeroth bit of the contents of addr
    8156(control reg.)
  • begin
  • loop
  • accept START(TEMP out INTEGER)
  • B ON --starts measuring the temperature
  • accept DONE
  • TEMP TEMP_BUFFER

34
  • Task scheduling
  • real-time annex of Ada9X
  • task dispatching policy
  • active priority of a task max(base priority,
    any active priorities that are inherited)
  • ex) during a rendezvous, task A accepts an entry
    call from task B (A inherits the active priority
    of B)
  • active priority of A max(base priority of A,
    active priority of B)
  • compiler support for dispatching policies
  • pragma TASK_DISPATCHING_POLICY(policy_name
    ,compilation_unit_name)
  • entry queueing policy
  • specifies the order in which entry calls are
    served
  • allows priority queueing with multiple queues
  • ceiling priority policy
  • for priority inheritance for protected data types
Write a Comment
User Comments (0)
About PowerShow.com