450 likes | 637 Views
IT-606 Embedded Systems (Software ). S. Ramesh Kavi Arya Krithi Ramamritham KReSIT/ IIT Bombay. Esterel Tools & Illustrative Examples S. Ramesh. Esterel Tools. Compiler C-code for simulation C-code for target implementation in SW bliff code for implementation in HW and verification
E N D
IT-606Embedded Systems(Software) S. Ramesh Kavi Arya Krithi Ramamritham KReSIT/ IIT Bombay
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
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
Verification Tools • Xeve • converts bliff code into fc2 format • hiding of signals • FcTools • Automata minimization • Automata abstractions • Atg • display of automaton • Manual inspection
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
Example Main:: 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
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
The code module 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 end end module
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
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
The code module 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
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
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
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
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
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
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
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;
var t : integer inemit 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;
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.
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
A Simple Case-study Plastic 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
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
Time Constraints • motor must stop within tin time units after signals A and B are emitted as otherwise, the piston might get stuck • contact switch made on/off within ttemp after temperature limits Tmin and Tmax reached to avoid boiling and keep it flowing
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;
[ loop if ?Temp<T_min then emit contact_on end; if ?Temp>T_max then emit contact_off end; await tick;end||loopawait form_empty; emit motor_on(true);await B;emit motor_on(false);await A;emit motor_off;end]end module
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
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);
loop await ignition_on; emit chk_belts; await belt_fastened; emit start_engine;
|| every belt_unfastened do emit alarm end ] abort [ loop abort run manual_mode; when cruise; abort run cruise_mode; when brake_pressed; end loop when engine_off end loop end module
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; end end var end module
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 end end var end module
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
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 in emit d_open; await d_opened; await request; X:=?request; emit d_close; await d_closed; trap Stop in
loop abort sustain t_run when stn_arrived; if X=?stn_arrived then emit t_stop; exit Stop; end end %loop end %trap end %var end %outer loop end module
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
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
when [ methane or lw_level ]; emit p_stop end when manual; abort loop await start; await immediate [ not methane ]; abort sustain p_run when [methane or stop]; emit p_stop; end
when auto; end loop || every methane do emit m_alarm; end every || every co do emit c_alarm end every ] end module