Jump to content
Wikipedia The Free Encyclopedia

Event-driven finite-state machine

From Wikipedia, the free encyclopedia
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations . Please help improve this article by introducing more precise citations. (November 2024) (Learn how and when to remove this message)
This article's "Same example in Ginr" section contains promotional content . Please help improve it by removing promotional language and inappropriate external links, and by adding encyclopedic text written from a neutral point of view. (October 2025) (Learn how and when to remove this message)
P ≟ NP 

This theoretical computer science–related article is a stub. You can help Wikipedia by expanding it.

In computation, a finite-state machine (FSM) is event driven if the transition from one state to another is triggered by an event or a message. This is in contrast to the parsing-theory origins of the term finite-state machine where the machine is described as consuming characters or tokens.

Often these machines are implemented as threads or processes communicating with one another as part of a larger application. For example, a telecommunication protocol is most of the time implemented as an event-driven finite-state machine.

Example in C

[edit ]

This code describes the state machine for a very basic car radio system. It is basically an infinite loop that reads incoming events. The state machine is only 2 states: radio mode, or CD mode. The event is either a mode change from radio to cd back and forth, or a go to next (next preset for radio or next track for CD).

/********************************************************************/
#include<stdio.h>
/********************************************************************/
typedefenum{
ST_RADIO,
ST_CD
}STATES;
typedefenum{
EVT_MODE,
EVT_NEXT
}EVENTS;
EVENTSreadEventFromMessageQueue(void);
/********************************************************************/
intmain(void)
{
/* Default state is radio */
STATESstate=ST_RADIO;
intstationNumber=0;
inttrackNumber=0;
/* Infinite loop */
while(1)
{
/* Read the next incoming event. Usually this is a blocking function. */
EVENTSevent=readEventFromMessageQueue();
/* Switch the state and the event to execute the right transition. */
switch(state)
{
caseST_RADIO:
switch(event)
{
caseEVT_MODE:
/* Change the state */
state=ST_CD;
break;
caseEVT_NEXT:
/* Increase the station number */
stationNumber++;
break;
}
break;
caseST_CD:
switch(event)
{
caseEVT_MODE:
/* Change the state */
state=ST_RADIO;
break;
caseEVT_NEXT:
/* Go to the next track */
trackNumber++;
break;
}
break;
}
}
}

Same example in Ginr

[edit ]
This section contains promotional content . Please help improve it by removing promotional language and inappropriate external links, and by adding encyclopedic text written from a neutral point of view. (October 2025) (Learn how and when to remove this message)

Ginr is an industrial-strength compiler producing multitape finite state automata from rational patterns, functions and relations expressed in semiring algebraic terms. The example below shows a binary rational function equivalent to the above example, with an additional transition (nil, radio) to set the system into its initial state. Here the input symbols nil, mode, next denote events that drive a transducer with output effectors cd, nextTrack, radio, nextStation. Expressions like this are generally much easier to express and maintain than explicit listings of transitions.

StateMachine = (
 (nil, radio)
 (
 (mode, cd) (next, nextTrack)*
 (mode, radio) (next, nextStation)*
 )*
 (
 (mode, cd) (next, nextTrack)*
 )?
);

Compilation produces a subsequential (single-valued) binary transducer mapping sequences of events to sequences of effectors that actuate features of the CD/radio device.

StateMachine:prsseq;
(START) nil [ radio ] 1
1 mode [ cd ] 2
2 mode [ radio ] 3
2 next [ nextTrack ] 2
3 mode [ cd ] 2
3 next [ nextStation ] 3

Modelling discrete systems in this manner obtains a clean separation of syntax (acceptable ordering of events) and semantics (effector implementation). The syntactic order of events and their extension into the semantic domain is expressed in a symbolic (semiring) domain where they can be manipulated algebraically while semantics are expressed in a procedural programming language as simple effector functions, free from syntactic concerns. The rational expressions provide concise holistic maps of the protocols that effect system governance. The compiled automata are post-processed to obtain efficient controllers for run-time deployment.

See also

[edit ]
[edit ]
  • Ginr (ginr whitepaper and user's guide)
  • Ribose (demonstrates using ginr to transduce sequential media)

Further reading

[edit ]
  • Peatman, John B. (1977). Microcomputer-based Design. New York: McGraw-Hill, Inc. ISBN 0-07-049138-0.
  • Brookshear, J. Glenn (1989). Theory of Computation: Formal Languages, Automata, and Complexity. Redwood City, California: Benjamin/Cummings Publish Company, Inc. ISBN 0-8053-0143-7.

AltStyle によって変換されたページ (->オリジナル) /