© S. Ramesh / Kavi Arya / Krithi Ramamritham 1 IT-606 Embedded Systems (Software ) S. Ramesh Kavi...
-
Upload
octavia-james -
Category
Documents
-
view
229 -
download
1
Transcript of © S. Ramesh / Kavi Arya / Krithi Ramamritham 1 IT-606 Embedded Systems (Software ) S. Ramesh Kavi...
1© S. Ramesh / Kavi Arya / Krithi Ramamritham
IT-606Embedded Systems
(Software)S. RameshKavi Arya
Krithi Ramamritham
KReSIT/ IIT Bombay
3© S. Ramesh / Kavi Arya / Krithi Ramamritham
Esterel Tools• Compiler
– C-code for simulation – C-code for target implementation in SW – bliff code for implementation in HW and
verification• Simulator - Xes• Verifer
– Xeve – fctools – atg
4© S. Ramesh / Kavi Arya / Krithi Ramamritham
Make file - An example
all: blif genc obj es blif: esterel –Lblif :-soft -causal -main simple
auto.strl genc: esterel -simul -main simple auto.strl obj: gcc -w -c auto.c es: xes auto.o
6© S. Ramesh / Kavi Arya / Krithi Ramamritham
Verification Tools• Xeve
– converts bliff code into fc2 format – hiding of signals
• FcTools – Automata minimization – Automata abstractions
• Atg – display of automaton – Manual inspection
7© S. Ramesh / Kavi Arya / Krithi Ramamritham
Code generator • Compiler (without special options) produces
– reactive engine that implements the automaton – one function for each input signal
• the reactive engine is just a procedure • user has to write a main program that calls the
engine • user has to write a function for each output
signal and sensor• when to call the engine, which input signals
are simultaneous decided by the user • the engine calls the output functions
8© S. Ramesh / Kavi Arya / Krithi Ramamritham
ExampleMain:: every milli second for every input that has occurred call f_input(par); call f_kernel; end
• Assume interface functions run concurrently with the main program
• Input parameter gets the value from specific registers or memory
• f_kernel calls output functions corresponding to emitted outputs
9© S. Ramesh / Kavi Arya / Krithi Ramamritham
A Simple Example
An Auto Controller:• initially waits for the engine to be on• when car is running,
acceleration/deceleration controls the throttle valve
• car stops when the ignition is off
10© S. Ramesh / Kavi Arya / Krithi Ramamritham
The codemodule simple:input ignition_on,ignition_off,accel;output control_throttle;loop abort await ignition_on; every accel do emit control_throttle end every when ignition_off endend module
11© S. Ramesh / Kavi Arya / Krithi Ramamritham
Use of Esterel Tools• compile the program to simulate (-simul
option)• compile the program to generate bliff code• use xeve to generate automaton• use atg for visual display
13© S. Ramesh / Kavi Arya / Krithi Ramamritham
A Complex Controller
Additional safety feature:• monitors status of the door (closed or
open) while in motion• sends out alarm when door opens• ensures that doors are closed while starting
14© S. Ramesh / Kavi Arya / Krithi Ramamritham
The codemodule complex:input ignition_on,ignition_off,accel;input door_opened, door_locked;output alarm,control_throttle,door_lock; loop abort await ignition_on; emit door_lock; loop await door_locked; abort every accel do emit control_throttle end every when door_opened; emit alarm; emit door_lock; end; when ignition_off end end module
17© S. Ramesh / Kavi Arya / Krithi Ramamritham
Mindstorms robots• Smart toys assembled using certain Lego
bricks called, Robotics Invention System– RCX brick (microcomputer), inspired by MIT
media lab. Programmable Brick– touch sensors– light sensor– Motors– IR Transceiver– Serial cable
18© S. Ramesh / Kavi Arya / Krithi Ramamritham
RCX • Lego Micro computer
– 8 bit 16 MHz Hitachi controller– 8K ROM, 19K RAM– Supports three touch sensors, three motors and
one light sensor– Programmed using PC – Loaded using IR transmitter connected through
serial cable• Programmed using RCS programming language• Program receives sensor inputs and controls motor
movements
19© S. Ramesh / Kavi Arya / Krithi Ramamritham
Synchronous Programming • Mindstorms can be programmed using
synchronous languages, like Esterel.• Thanks to an effort by some french groups
– http://www.emn.fr/x-info/lego//
• Makes use of LegOS, its tools and APIs
20© S. Ramesh / Kavi Arya / Krithi Ramamritham
LegOS• An open source OS for lego Mindstorms
initiated by Markus L. Noga – Web page: http://www.noga.de/legOS/
• Supports (version 0.2.0)– Dynamic loading of programs and modules – Full IR packet networking – Preemptive multitasking – Dynamic memory management – Drivers for all RCX subsystems
21© S. Ramesh / Kavi Arya / Krithi Ramamritham
Cross Compilation• The OS cross - compiled on a PC and
downloaded onto the RCX via IR transceiver• Runs in both Linux and windows• Provides many APIs for application
programs– Inputting from Sensors– Actuating motors
• Application programs (in C) use these APIs to control
• cross-compiled and loaded onto the RCX
22© S. Ramesh / Kavi Arya / Krithi Ramamritham
Esterel Programming• Applications can be written in Esterel• An extension of Esterel compiler is
available• Need to use specific names for inputs and
outputs– touch_1, touch_3, motor_a_speed,
motor_b_speed, cputs etc.• Here is an example
23© S. Ramesh / Kavi Arya / Krithi Ramamritham
A simple program module lego1 :
input TOUCH_1, TOUCH_3; output MOTOR_A_SPEED(integer),
MOTOR_C_SPEED(integer), MOTOR_A_DIR(integer),
MOTOR_C_DIR(integer), CPUTS(string); relation TOUCH_1 # TOUCH_3;
constant MOTOR_FWD, MOTOR_REV, MAX_SPEED : integer;
24© S. Ramesh / Kavi Arya / Krithi Ramamritham
var t : integer in emit MOTOR_A_SPEED(MAX_SPEED/2); emit MOTOR_C_SPEED(MAX_SPEED/2);
loop emit MOTOR_A_DIR(MOTOR_FWD); emit MOTOR_C_DIR(MOTOR_FWD); emit CPUTS("fwd"); await [TOUCH_1 or TOUCH_3]; present TOUCH_1 then t:=1; else t:=3; end present;
25© S. Ramesh / Kavi Arya / Krithi Ramamritham
emit MOTOR_A_DIR(MOTOR_REV); emit MOTOR_C_DIR(MOTOR_REV); emit CPUTS("rev"); await 100 tick; % 1 tick = 1 ms if t=1 then emit MOTOR_A_DIR(MOTOR_FWD); emit CPUTS("right"); else emit MOTOR_C_DIR(MOTOR_FWD); emit CPUTS("left"); end if; await 100 tick; % 1 tick = 1 ms end loop
end var.
26© S. Ramesh / Kavi Arya / Krithi Ramamritham
Compiling
• This program can be simulated• Compiled using the extended compiler to
generate C code• Use legOS cross compiler to generate
code and download onto the RCX• Look at the web-site for more examples
27© S. Ramesh / Kavi Arya / Krithi Ramamritham
A Simple Case-studyPlastic Injection Controller• a simple controller• controls a plastic injection unit.• The unit injects plastic material from a tank
into a molding chamber • When chamber is empty, a motor started in
the forward direction • motor moves a piston until it reaches
position B
28© S. Ramesh / Kavi Arya / Krithi Ramamritham
Illustration (contd.)• motion is reversed until position A reached
in the opposite direction• plastic material in the tank heated by a coil• temperature of the tank controlled between
Tmin and Tmax
29© S. Ramesh / Kavi Arya / Krithi Ramamritham
Time Constraints• motor must stop within in time units after
signals A and B are emitted as otherwise, the piston might get stuck
• contact switch made on/off within temp after temperature limits Tmin and Tmax reached to avoid boiling and keep it flowing
30© S. Ramesh / Kavi Arya / Krithi Ramamritham
The code:module simple:
constant T_min=30:integer, T_max=100:integer;input A,B,form_empty;sensor Temp: integer;output motor_on(boolean), motor_off;output contact_on,contact_off;relation A#B;
31© S. Ramesh / Kavi Arya / Krithi Ramamritham
[ loop if ?Temp<T_min then emit contact_on end; if ?Temp>T_max then emit contact_off end; await tick; end
||
loop await form_empty; emit motor_on(true); await B; emit motor_on(false); await A; emit motor_off; end]end module
33© S. Ramesh / Kavi Arya / Krithi Ramamritham
A Cruise Controller
A more complex auto controller:• includes the feature of cruise mode of
driving• illustrates the features like modules, valued
signals and procedure calls
34© S. Ramesh / Kavi Arya / Krithi Ramamritham
module cruise:input cruise;input accel,brake_pressed;input engine_off;input accel_released,ignition_on;input belt_fastened,belt_unfastened;output chk_belts,start_engine;output control_throttle:double;output alarm;input current_speed:integer;output cruising;procedure increase_speed(double)(integer);procedure compute_throttle(double) (integer,integer);
35© S. Ramesh / Kavi Arya / Krithi Ramamritham
loop await ignition_on; emit chk_belts; await belt_fastened; emit start_engine;
36© S. Ramesh / Kavi Arya / Krithi Ramamritham
abort [ loop abort run manual_mode; when cruise; abort run cruise_mode; when
brake_pressed; end loop when engine_off end loop end module
|| every belt_unfastened do emit alarm end
]
37© S. Ramesh / Kavi Arya / Krithi Ramamritham
module manual_mode:input accel_released,accel;output control_throttle:double;var th$_value:=5.0:double,val:=0:integer in loop abort every accel do emit control_throttle(th_value + 2.0); end every when accel_released; endend var end module
38© S. Ramesh / Kavi Arya / Krithi Ramamritham
module cruise_mode:input current_speed:integer;output control_throttle:double, cruising;procedure compute_throttle(double) (integer,integer); var cruise_speed:=?current_speed:integer, th_value:double in cruise_speed:=?current_speed; every tick do call compute_throttle(th_value) (?current_speed,cruise_speed); emit control_throttle(th_value); emit cruising endend varend module
39© S. Ramesh / Kavi Arya / Krithi Ramamritham
A Train Controller• controls the movement of an automatic
train• train moves back and forth between a set
of stations• no request means the train is idle at one of
the stations• request are serviced eventually• door is closed when the train is in motion• buttons are provided inside the train and in
the stations
40© S. Ramesh / Kavi Arya / Krithi Ramamritham
module Train:input d_closed, d_opened, stn_arrived(integer);input request(integer);output d_close,d_open, t_run, t_stop;loop var X: integer inemit d_open;await d_opened;await request; X:=?request;emit d_close;await d_closed; trap Stop in
41© S. Ramesh / Kavi Arya / Krithi Ramamritham
loop abort sustain t_run when stn_arrived; if X=?stn_arrived then emit t_stop; exit Stop; endend %loopend %trapend %varend %outer loopend module
42© S. Ramesh / Kavi Arya / Krithi Ramamritham
A mine pump controller• controls a pump that drains excess water in the
mines• pump should start draining when water level is high• pump has to stop when water is too low• mine has methane which is combustible when the
pump is on• high dose of CO is lethal• warnings are to be issued• auto and manual mode for pump• pump is started and stopped under operator control• default is auto
43© S. Ramesh / Kavi Arya / Krithi Ramamritham
module pump_controller:input start,stop,methane,co,hw_level;input lw_level,manual;input auto;output p_run,p_stop,m_alarm,c_alarm;[ loop abort loop await hw_level; await immediate [ not methane ]; abort sustain p_run
44© S. Ramesh / Kavi Arya / Krithi Ramamritham
when [ methane or lw_level ]; emit p_stop end when manual; abortloopawait start;await immediate [ not methane ];abortsustain p_runwhen [methane or stop];emit p_stop;end