Download presentation
Presentation is loading. Please wait.
1
Programming Languages for Embedded Systems
2
Embedded Systems Communication Terminals Communication Infra Structure Control Systems Surveillance Systems Alarm Systems
3
Embedded Systems Embedded into real physical world. Often dependable (high risk). Concurrency natural. Real time demands. Performance demands.
4
Real Time Programming Languages RT-PASCAL Conc. PASCAL Ada Modula (2) OCCAM C / C++ Erlang RT -JAVA
5
Language Support Low level programming High level programming Concurrency Synchronization (IPC) Exception handling Real time features
6
Low level issues Physical memory directly adressable Registers accessible (Direct) interrupt control
7
Low Level Programming Memory Access C: linker directives and register variables (not really C) char xdata RAM[SIZE]; Ada: for var’Adress use System.Storage_Elements.ToAdress(offset) RT-JAVA: RawMemory Access( long base, long size) setByte(long offset), getByte(long offset)
8
Low Level Programming Interrupt Control C: void interrupt[nr] Handler(void){..} Ada: pragma Attach_Handler(Handler,intr_nr); RT-JAVA: publ. Class AsyncEvent{}, addHandler(AsyncEventhandler, Handler), bindTo(java.lang.String happening)
9
High level issues High level data structures (rec., list, queues, trees) High level program structures (conditionals, iterations, abstraction) Modularity (modules, components)
10
Concurrency Models Uniprocessor multiplexing Multiprocessor multiplexing (shared memory) Distributed systems (networks)
11
Concurrency Models Co-routines Cobegin -end Fork and join Threads Explicit processes
12
Co-routines (domestic non preemptive kernels) Op. Sys ABC
13
Co-routines (Modula 2) AB C
14
Cobegin/coend (par) (OCCAM) cobegin st1; st2; st3;. stN; coend PAR st1;. stN; SEQ st1;. stN; PAR i=1 FOR N proc(i);
15
Threads (JAVA, POSIX) Light weigth processes sharing data memory. Handled by language run time system. (JAVA:) java.lang.Thread (implements java.lang.Runnable - has run method) class MyThread extends Thread { //constructor public MyThread ( ) { //initialization} public void run ( ) //executed upon calling inherited start-method {// Thread statements}
16
Threads (JAVA:) public class ThreadExample { public static void main ( ) { MyThread thread1,thread2; thread1 = new MyThread( ); thread2 = new MyThread ( ); thread1.start( ); thread2.start( ); }
17
Fork and Join (POSIX,Erlang,Mesa ) (Erlang: in Pid1) Pid2 = spawn(Module, Function, Arguments) (Mesa: ) function F return …; procedure P; … C:= fork F; (concur. Exec.) … J:= join C; (synchronization) end P; (POSIX:) child_id = fork(proces_id);. C = wait(child_id);
18
Explicit process Declaration (Ada: ) procedure OurProc is task A; task B; -- declare A -- declare B -- startup point for A and B -- statements for OurProc -- declare A task body A is - - declarations for A begin - - statements for A end -- declare B task body B is - - declarations for B begin - - statements for B end
19
Synchronization Models Shared variables Message based communication Remote Procedure Calls Asynchonous Control Transfer
20
Shared Memory Need for mutual exclusion. Either busy waiting or atomic primitives with suspension (wait). Semaphores, conditional regions, monitors or protected objects
21
Shared Memory Conditional Critical Regions ( Edison:) st; --- region do st1; -- stN; end region st; --- guard is logical expression, i.e. N>3 Suspended process must be awakened to evaluate guard whenever CCR is left. Evaluation order. Can be spread all over the code.
22
Shared Memory Monitors (Modula 1: ) INTERFACE MODULE MyMon; var Con: SIGNAL; procedure A( ) begin wait (Con); --- end procedure B( ) begin --- send (Con); end Procedures execute mutually exclusive
23
Shared Memory Protected objects (Ada: ) protected body ProObj is entry Out (OutVar: out Integer) when is begin --- end Out entry In (InVar: in Integer) when is begin --- end In Concurrent reads (in) - mutually exclusive writes (out) process suspended until condition evaluates true
24
Shared Memory Protected objects (java: ) public synchronized void A ( ) { while (! condA) { try{ wait( );} catch (...) {...} - - - notify ( ); // or notifyAll( ); } public synchronized void B ( ) { while (! condB) { try{ wait( );} catch (...) {...} - - - notify ( ); // or notifyAll( ); } Mutual exclusive execution of object methods notify and notifyAll moves waiting process(es) to ready queue !
25
Message based Communication Asynchronous: No blocking while waiting for reply (queueing) - not language supported because of program complexity but - can be implemented using synchronous message passing. Synchronous: Blocking while waiting for reply
26
Message based Communication (OCCAM2: ) CHAN OF INT ch; ch ! X ch ? X ERLANG: Pid2 = spawn(echo, loop, []), Pid2 ! {self(), hello}, (in Pid2) receive {From, Msg} -> //some action, end.
27
Message based Communication Remote Invocation (Ada (Rendezvous): ) task MyTask ( ) is -- entry Echo (Inp: in Integer; Outp: out Integer) -- end MyTask task body MyTask is -- begin accept Echo (Inp: in Integer; Outp: out Integer) do -- Outp=Inp; end Call (in calling task:) MyTask.Call (2,X);
28
Exception handling taxonomy of exceptions Synchronous: Exception timely linked to point in control flow. (Divide by zero) Asynchronous: Exception related to other than current point in control flow. (Interrupt) Internal: Unexpected result of computations (SW error). External: Unexpected behaviour of environment. (Broken network)
29
Exception handling issues in exception handling Intermingled (older) : “ if (! Myfunction ( ) ) exit (0) “ Structured (modern) : control flow implicitely defined Domain: Region of program handled by exceptionhandler. Propagation: Passing on exceptions on to callee.
30
Exception handling domain: (Ada: ) (blockstructured) declare -- begin -- exception end (C++,JAVA: ) try { //statements within scope } catch { //exception spec.} (CHILL: ) exceptions associated to all statements
31
Exception handling Propagation: Resumption: Execption handler allows procedure to resume action when exception has been handled. Termination: Exeception handler only handles what is needed when procedure cannot execute. Hybrid: Procedure is retried when exception has been handled.
32
Real Time Issues Access to a physical (independent) clock Clock granularity Delay Timeout Scheduling: Periods, Comp. Times, Deadlines e.t.c.
33
Real Time Issues Access to a physical (independent) clock (OCCAM2: ) TIMER clock; INT Time; clock ? Time; //Relative time is read into “Time” (Ada: ) with Ada.Real_Time; time : Time; begin time := Clock; end
34
Real Time Issues Access to a physical (independent) clock (JAVA:) import java.util.Date; Date d; d= new Date; d.toString ( ); //returns time in 64 bits mSec. (RT-JAVA:) import java.util.Date; public class {AbsoluteTime | RelativeTime | RationalTime} extendsHighResolutionTime AbsoluteTime time; --- time.getMilliseconds( ); //64 bits time.getNanoseconds( ); //32 bits
35
Real Time Issues Delay: (Ada: ) delay 10.0; //sleeps 10 sec from now (relative) delay until 100.0; // sleeps until absolute time reaches 100 sec. (absolute) Only lower bound guarantteed (OCCAM2: ) TIMER clock; SEQ clock ? time; clock ? AFTER time PLUS (<offset<)
36
Real Time Issues Delay: (JAVA: ) int time; //inside thread try { sleep (time) } catch ( ) { //handling action} Relative delay (RT-JAVA: ) HighResolutionTime time; //inside realtime thread try { sleep (time) } catch ( ) { //handling action} Relative or absolute delay in nanosecs. granularity
37
Real Time Issues Timeout (wait for messages): (Ada: ) select accept Call(.. ) do -- action end Call or delay(until) end select (OCCAM2: ) SEQ ALT call ? Param -- action for call clock ? AFTER ( ) -- action for timeout
38
Real Time Issues Timeout (wait for completion): (Ada: ) select delay(until) ; then abort -- action ( RT-JAVA:) public abstract class Timer (HighRes.Time t, Clock c, AsyncEventHandler Handler); AsyncEventHandler is a runnable object //in Handler.run ( ) MyThread.stop ( ); el. MyThread.interrupt ( );
39
Real Time Issues Task Scheduling: (Ada: ) //Fixed priority assignment comes with Real-Time Systems Annex. task MyRTTask is entry.. pragma Priority( ) end MyRTTask (OCCAM2: ) //Fixed priority assignment included in language PRI PAR //order: P1,P2,(P3,P4),P5 P1 P2 PAR P3 P4 P5
40
Real Time Issues Task Scheduling: (Ada: ) //Immediate Ceiling Priority (ICPP) //Ceiling: C(S) = max {Prio(T) | T locks S} //When t locks S it executes under max {prio(t),C(S)} pragma Locking_Policy(Ceiling_Locking)
41
Real Time Issues Task Scheduling: (JAVA: ) // Some prioritized scheduling policy - semantics rather loose. class MyThread extends Thread.. public MyThread ( ) //10 distinct priority levels { setPriority ( ); --- }
42
Real Time Issues Task Scheduling: (RT - JAVA: ) //Supports at least 28 priorities in fixed prio. preemptive scheduling. class MyRTThread extends RealTimeThread.. SchedulingParameters Scheduling; ReleaseParameters Release; MyRTT = new MyRTThread (Scheduling, Release);
43
Real Time Issues Task Scheduling: (RT - JAVA: ) 1 - 28 Periodic Parameters Scheduling parameters Priority Parameters Importance Parameters If missed deadlines //start, cost, period,deadline Release Parameters Aperiodic Parameters //cost,deadline deadline,overrunHandler, missHandler Sporadic Parameters //minInterarrival
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.