(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
Programming models for event controlled programs
1. PROGRAMMING MODELS FOR
EVENT CONTROLLED PROGRAMS
PRESENTED BY:
PRIYA KAUSHAL
ROLL NO. 152615
ECE (ME) REGULAR
PRESENTED TO:
Dr. KANIKA SHARMA
2. State machine model
State machine is a model in which it is assumed that there are states and state transition
functions, which produce the states.
A state transition function is a function, which changes a state to its next state.
PROCESS:- When there are inputs to a process that change the state of the process to a
new state, and generate outputs which may also be the inputs for the next state.
3. Example of Door
• opened
• closed
states
• close door
• Open door
State
transition
function
4. Examples of States
Washing Rinsing Drying
Process of washing machine: Idle
Receiving A Ring
Dialling
Connected
Exchanging Messages
A telephone process
5. Programming Model for an
Event Controlled or Response
Controlled Programs
A programming model is to assume that the running process (program flow) can be considered as
running of a machine in a particular state, which will lead to other states on an event(s) resulting into
state transition.
A program flow in system can be modelled simply by an inter-state transition (from one state to
another).
6. Steps in Modelling as State machine
Transition to a new state occurs from the previous state on an event (input). The event may be setting a value of certain
parameter or the result of the execution of certain codes. A transition may be also be interrupt flag driven.
A state is identified by a flag condition or set of codes being executed or set of values of certain parameters.
A state can receive multiple tokens (inputs, messages, flags interrupts) from another state (s). A token (event) means either
an input or event-input.
A state can generate multiple tokens (outputs, messages, flags interrupts).
Steps that model or represent the states and inter-state transitions :
1
2
3
4
7. Finite State Machine (FSM)
Model
In a finite states machine model, a process or function can be described by means of finite states.
There is only one directed incoming arc and one outgoing arc at a state.
A state from a process flow in FSM can lead to any one of the several possible subsequent states. This
will depend on the output function and state transition function at the state.
9. Modelling a process as Finite
State Machine (FSM)
• Finite set of inputs (tokens or event-flags or status flags) with their
values for reaching the state.
• Finite actions (for example computations) at the state.
• Finite set of outputs with their possible values and an output function
for the state that give the outputs.
• State transition function for each state to take it to the next state.
Followings
specified
for each
sate:
10. Timer Idle Timer
Start
Timer
Running
Load Input
Num-Ticks
Decrement Input
Event
Output
Count=Num-Ticks
Output
Count=Count-1
Output
Count=0
Timeout Flag=Set
Decrement
Input Event when Count=1
TimerIdle
Use of FSM Model
States of a timer using FSM
Example…..
11. Use of FSM Model
Idle
Start
Running
Finished
‘Idle’ State: it starts state transition on loading
an input, Num-Ticks (number of ticks after
which the timer finishes) and transition to ‘Start’
state occurs.
‘Running’ State: on each clock input for
decrement, the Count value decrements.
‘Finished’ State: program flows to finished state
when Count reaches to zero.
A timer has four finite states:
12. Use of FSM Model
Function Idle Function Call Function
Executing
Call Save Over
Output
Saves current status and values on
stack
End
Return
Instruction
Function Return
Output
Restores saved status and values from
stack
Example….
States of a call function using FSM
13. Use of FSM Model
Idle
Call
Executing
Return
An ‘idle’ state to ‘call’ state transition takes place when a
function-call occurs in the program. Output from this state is
saved on to a stack.
Instructions are executed in the ‘executing’ state and program
counter changes with the program flow.
The transition to ‘return’ state happens when the instruction
reaches the return instruction.
The transition to ‘idle’ state occurs after retrieving the saved
status and values from the stack.
A call function has four finite states:
14. FSM State Table
• When the FSM model is represented graphically with circles and directed arcs,
It becomes complex in the case of a complex process with a large number of states.
• To design software using the model, a state table can then be designed for representation of every
state in its rows.
Use of State Table for Real Time Programming
15. FSM State Table
1
• Present state name or identification.
2
• Action(s) at state until some event(s).
3
• The events that cause the execution of state transition function.
4
• Output(s) from the state output function(s).
5
• Next state.
6
• Expected time interval for finishing the transitions to new state after event.
16. Coding using each row
While (present state) { action ( ); if (event =……..; token =…….)
{output =………; StateTransitionFunction ( ); }; }
Or
Switch (state)
Case present state: action ( ); if (event=…….; token =……)
{output =……..; StateTransitionFunction ( ); }; }