![]() |
![]() |
![]() |
![]() |
![]() |
Implementation
In this section the implementation details are discussed. These details are meaningful for understanding how a generated Cmicro application does work.
Time
For host simulation, with the predefined integration settings, a time unit represents one second. In target applications, time is to be implemented by the user (see subsection Defining the SDL System Time Functions in mk_stim.c).
Real Time
If real time is used, then there will be a connection between the clock in the executing program and the wall clock. For applications the user must provide the connection with the wall clock, normally the hardware timer.
The C standard function time used as the real time clock returns the time in seconds. The implementation of the clock can be changed by re-implementing the function xmk_NOW in mk_stim.c.
Scheduling
The Cmicro Kernel does not use a process ready queue. It processes the signals in the order of their appearance. To do this, there is a signal queue which stores the signals sent to any process (either internally or externally). There are different ways to influence the scheduling when using the Cmicro SDL to C Compiler:
- assigning priorities to processes
- assigning priorities to signals
- any combination of process and signal priorities
Assigning Priorities to Processes - Preemptive Scheduling
It is possible to assign priorities to process types (using SDL'88 terminology). The processes' priorities are assigned when designing the SDL system. They are assigned using the #PRIO directive.
There are some things to be kept in mind when using process priorities:
- Priorities have to begin with zero.
- Priorities have to be consecutive.
- All instances of a type have the same priority (SDL'88 terminology).
- Priority decreases with increasing numbers (zero is the highest priority level).
- The default priority is to be in the range of zero to the lowest priority number.
The Cmicro Kernel handles process priorities by collecting all signals sent to processes of the same priority in a separate queue. Thus, there is a queue for each priority level.
While the SDL system is running the kernel checks for signals in the queues with decreasing priority. This check takes place whenever an SDL output appears or a process performs an SDL nextstate operation. Because of the kernel checking for signals whenever an output takes place, it is possible to have preemptive scheduling.
Assume, there are two process types lowprio and highprio. Let process type lowprio have the priority one and process type highprio have the priority zero.
If an instance of process type lowprio performs an output to process type highprio, there appears a signal in a queue of a higher priority level (zero is the highest priority level available, process lowprio has priority one) which leads to the kernel immediately working on the signal sent to the process highprio. The transition of process lowprio will not end until process highprio has finished its transition invoked by the signal.
This way of scheduling is implemented using recursion.
Process priorities are available only when using a compiler which can handle recursion.
There is basically no restriction on the number of priority levels, but the target and compiler used will of course limit the depth of recursion.
As a general recommendation process priorities should not be assigned one per process type, but the process types should be grouped according to their purposes and these groups should then be assigned a priority level.
Assigning Priorities to Signals
The signals in the queue(s) are normally ordered according to their appearance (FIFO-strategy). By assigning priorities to signals this ordering is user definable. The directive #PRIO is used to assign a priority to signals.
Priority increases with decreasing numbers, but there is no restriction to use consecutive numbering.
Whenever a signal is sent, it is inserted into the signal queue(s) according to its priority.
Assume, there is a process performing two signal outputs, first_sig and second_sig. Using the standard FIFO-strategy signal first_sig would be worked on before signal second_sig. But with signal priorities and signal first_sig assigned priority fifty and signal second_sig assigned priority twenty, signal second_sig would be in front of signal first_sig in the queue and thus would be worked on before signal first_sig.
For more details please refer to Assigning Priorities - Directive #PRIO.
Combinations of Signal/Process Priority
Every combination of signal and process priorities may be used. In this way it is possible to adapt the scheduling to the users' needs.
Without process priorities a transition once started will have to be finished before the next transition can be dealt with. This is valid regardless of the time it will need to finish a transition.
Synonyms
External Synonyms
External synonyms can be used to parameterize an SDL system and thereby also a generated program. The values that should be used for the external synonyms must be included as macro definitions into the generated code, for instance by including another header file.
Using a Macro Definition
To use a macro definition in C to specify the value of an external synonym, the user should perform the following steps:
Example 575 : Macro Definition
#define synonym1 value1#define synonym2 value2
- The synonym names are the SDL names (without any prefixes).
- Introduce the following #CODE directive at the system level among the SDL definitions of synonyms, sorts, and signals, for example, but before any use of the synonyms.
/*#CODE#TYPE#include "filename"*/
If this structure is used, the value of an external synonym can be changed merely by changing the corresponding macro definition and re-compiling the system.
Procedure Calls and Operator Calls
In SDL-92, value returning procedures and operator calls are introduced. This means, that an SDL procedure can be called within an expression. As the Cmicro SDL to C Compiler cannot handle procedures with states, it is not necessary to map such calls to a different scheme.
TASK i := (call p(1)) + (call Q(i,k));
- is translated to something like:
i = p(1) + Q(i,k);
The value returning procedure calls are transformed to C functions which return values.
Operators which are defined using operator diagrams, are as in the models in the SDL recommendation, treated exactly as value returning procedures.
Generation of PAD function
The code generation for the PAD function is different compared with Cadvanced, in the way that code that is common in process types is copied into the PAD function for instantiated processes. This is implemented in contrast to Cadvanced, where for each process type definition there is a C function generated once, that is called by the instantiated PAD function, for common code. This makes a difference when system partitioning and/or file separation is used.
Any
`Any' should not be used in applications using the Cmicro SDL to C Compiler, as it leads to an error message.
Calculation of Receiver in Outputs
The Cmicro SDL to C Compiler is a code generator using the semantics of SDL-92 with some restrictions. The behavior for output is according to the rules described in the following:
- For an output without TO and without VIA in SDL, the Cmicro SDL to C Compiler calculates the receiver of the signal during code generation. If there is more than one possible receiving process type, then an error message will be printed out.
- For an output without TO and without VIA in SDL, it is also possible to have one process type, but more than one receiving instance of the signal. The response is that any of the living possible receivers may be selected during execution time. If no receiver is found, the C function ErrorHandler will be called.
- For an output with the VIA clause, the behavior of the Cmicro SDL to C Compiler is in principle the same as for an output without TO It computes the possible receivers in an output with the VIA clause and if there are several possible receivers, an error message is produced. The only difference between output with VIA and output without TO is that VIA can restrict the amount of possible processes.
- If output with TO is used in the above cases, no ambiguity can occur. The addressing of the process is then performed by a run-time variable.
- The possibility of specifying the name of a process when using OUTPUT TO is implemented. This is an SDL-92 feature. The Cmicro SDL to C Compiler behaves in the same way as when using implicit addressing (output without to).
- The broadcast feature of SDL-92 (VIA ALL) is not implemented, because it is not a real broadcast and not very useful for Cmicro Applications.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |