4 - Behavior
First of all a process has an implicit message queue to receive the messages listed in the channels.
A process description is based on an extended finite state machine. A process state determines which behavior the process will have when receiving a specific stimulation. A transition is the code between two states. The process can be hanging on its message queue or a semaphore or running e.g. executing code.
SDL-RT processes run concurrently; depending on the underlying RTOS and sometimes on the target hardware the behavior might be slightly different. But messages and semaphores are there to handle process synchronization so the final behavior should be independent of the RTOS and of the hardware. Since SDL-RT is open to any C code it is up to the designer to make sure this statement stays true !
Note that in a state diagram the previous statement is always connected to the symbol upper frame and the next statement is connected to the lower frame or on the side.
4.1 - Start
The start symbol represent the starting point for the execution of the process:
The transition between the Start symbol and the first state of the process is called the start transition. This transition is the first thing the process will do when started. During this initialization phase the process can not receive messages. All other symbols are allowed.
4.2 - State
The name of the process state is written in the state symbol:
The state symbol means the process is waiting for some input to go on, the allowed symbols to follow a state symbol are:
- message input
the message could be coming from an external channel, or it could be a timer message started by the process itself.
- continuous signal
when reaching a state with continuous signals, the expressions in the continuous signals are evaluated following the defined priorities. All continuous signal expressions are evaluated before the message input !
- save
the incoming message can not be treated in the current process state. It is saved until the process state changes. When the process state has changed the saved messages are treated first (before any other messages in the queue but after continuous signals).
Some transitions can be valid for several states, the different state names are then listed separated by a comma. A star ('*') means all states.
A process in a specific state can receive several types of messages or treat several continuous signals. To represent such a situation it is possible to have several message inputs connected to the state or to split the state in several symbols with the same name.
4.3 - Stop
A process can terminate itself with the stop symbol.
Note a process can not kill another process, it can only kill itself.
There is no syntax for that symbol.
4.4 - Message input
The message input symbol represent the type of message that is expected in an SDL-RT state. It always follows an SDL-RT state symbol and if received the symbols following the input are executed.
An input has a name and can come with parameters. To receive the parameters it is necessary to declare 2 variables that will be the parameter length and the pointer on the parameters.
The syntax in the message input symbol is the following:
<Message name> [(<length of data>, <pointer on data>)]
<data length> is a variable that needs to be declared.
<pointer on data> needs to be declared.
4.5 - Message output
A message output is used to exchange information. It puts data in the receiver's message queue in an asynchronous way.
The syntax in the message output symbol can be written in 2 ways depending if the queue Id of the receiver is known or not. A message can be sent to a queue Id or a process name. When communicating with the environment, a special syntax is provided.
4.5.1 Queue Id
<message name>[(<length of data>, <pointer on data>)] TO_ID <receiver queue id>
It can take the value given by the SDL-RT keywords:
PARENT The queue id of the parent process.
SELF The queue id of the current process.
OFFSPRING The queue id of the last created process if any or NULL if none.
SENDER The queue id of the sender of the last received message.
Examples:
4.5.2 Process name
<message name>[(<length of data>, <pointer on data>)] TO_NAME <receiver name>
<receiver name> is the name of a process if unique or it can be ENV when simulating and the message is sent out of the SDL system.
Examples:
If several instances have the same process name (several instances of the same process for example), the 'TO_NAME' will send the message to the first created process with the corresponding name. Therefore this method should no be used when the process name is not unique within the system.
4.5.3 Environment
<message name>[(<length of data>, <pointer on data>)] TO_ENV <C macro name>
<C macro name> is the name of the macro that will be called when this SDL output symbol is hit. If no macro is declared the message will be sent to the environment.
Example:
When sending data pointed by <pointer on data>, the corresponding memory should be allocated by the sender and should be freed by the receiving process. This is because this memory area is not copied to the receiver; only the pointer value is transmitted. So after being sent the sender should not use it any more.
4.6 - Message save
A process may have intermediate states that can not deal with new request until the on-going job is done. These new requests should not be lost but kept until the process reaches a stable state. Save concept has been made for that matter, it basically holds the message until it can be treated.
The Save symbol is followed by no symbol. When the process changes to a new state the saved messages will be the first to be treated (after continuous signals if any).
Even if the message has parameters.
Example:
4.7 - Continuous signal
A continuous signal is an expression that is evaluated right after a process reaches a new state. It is evaluated before any message input or saved messages.
The continuous signal expression to evaluate can contain any standard C expression that returns a C true/false expression. Since an SDL state can contain several continuous signal a priority level needs to be defined with the PRIO keyword. Lower values correspond to higher priorities. A continuous signal symbol can be followed by any other symbol except another continuous signal or a message input. The syntax is:
Example:
4.8 - Action
An action symbol contains a set of instructions in C code. The syntax is the one of C language.
Example:
4.9 - Decision
A decision symbol can be seen as a C switch / case.
Since it is graphical and therefore uses quite some space on the diagram it is recommended to use it when its result modifies the resulting process state. The decision symbol is a diamond with branches. Since a diamond is one of the worst shape to put text in it, it can be a "diamonded" rectangle. Each branch can be seen as a case of the switch.
The expression to evaluate in the symbol can contain:
- any standard C expression that returns a C true/false expression,
- an expression that will be evaluated against the values in the decision branches.
The values of the branches have keyword expressions such as:
The else branch contains the default branch if no other branch made it.
4.10 - Semaphore take
The Semaphore take symbol is used when the process attempts to take a semaphore.
To take a semaphore, the syntax in the 'semaphore take SDL-RT graphical symbol' is:
<semaphore name>(<timeout option>)
- FOREVER
Hangs on the semaphore forever if not available.
- NO_WAIT
Does not hang on the semaphore at all if not available.
- <number of ticks to wait for>
Hangs on the semaphore the specified number of ticks if not available.
4.11 - Semaphore give
To give a semaphore, the syntax in the 'semaphore give SDL-RT graphical symbol' is:
4.12 - Timer start
To start a timer the syntax in the 'start timer SDL-RT graphical symbol' is :
<timer name>(<time value in tick counts>)
<time value in tick counts> is usually an 'int' but is RTOS and target dependant.
4.13 - Timer stop
To cancel a timer the syntax in the 'cancel timer SDL-RT graphical symbol' is :
4.14 - Task creation
To create a process the syntax in the create process symbol is:
<process name>[:<process class>] [PRIO <priority>]
to create one instance of <process class> named <process name> with priority <priority>.
Examples:
4.15 - Procedure call
The procedure call symbol is used to call an SDL-RT procedure (Cf. "Procedure declaration" on page 29). Since it is possible to call any C function in an SDL-RT action symbol it is important to note SDL-RT procedures are different because they know the calling process context, e.g. SDL-RT keywords such as SENDER, OFFSPRING, PARENT are the ones of the calling process.
The syntax in the procedure call SDL graphical symbol is the standard C syntax:
[<return variable> =] <procedure name>({<parameters>}*);
Examples:
4.16 - Connectors
- split a transition into several pieces so that the diagram stays legible and printable,
- to gather different branches to a same point.
A connector-out symbol has a name that relates to a connector-in. The flow of execution goes from the connector out to the connector in symbol.
A connector contains a name that has to be unique in the process. The syntax is:
Examples:
4.17 - Transition option
Transition options are similar to C #ifdef.
The branches of the symbol have values true or false. The true branch is defined when the expression is defined so the equivalent C code is:
The branches can stay separated to the end of the transition or they can meet again and close the option as would do an #endif.
Examples:
4.18 - Comment
The comment symbol allows to write any type of informal text and connect it to the desired symbol. If needed the comment symbol can be left unconnected.
Example:
4.19 - Extension
The extension symbol is used to complete an expression in a symbol. The expression in the extension symbol is considered part of the expression in the connected symbol. Therefore the syntax is the one of the connected symbol.
Example:
4.20 - Procedure start
This symbol is specific to a procedure diagram. It indicates the procedure entry point.
There is no syntax associated with this symbol.
4.21 - Procedure return
This symbol is specific to a procedure diagram. It indicates the end of the procedure.
This symbol is specific to a procedure diagram. It indicates the end of the procedure. If the procedure has a return value it should be placed by the symbol.
4.22 - Text symbol
This symbol is used to declare C types variables.
The syntax is C language syntax.
4.23 - Additional heading symbol
This symbol is used to declare SDL-RT specific headings.
It has a specific syntax depending in which diagram it is used.
4.24 - Symbols ordering
The following table shows which symbols can be connected to a specific symbol.
The symbol in this column can be followed by the ticked symbols in its row.
The table above should be read row by row. The symbol in the left column can be followed by the ticked symbols on its row. For example the stop symbol can not be followed by any other symbol. The state symbol can be followed by input, save, or continuous signal symbols.
http://www.sdl-rt.org info@sdl-rt.org |