**2.2. The network block**

4 Will-be-set-by-IN-TECH

The *task* is the main construction in the TrueTime environment, this object is used to simulate periodic and aperiodic activities, for example controller and I/O tasks can be periodic and communication and event-driven controller can be aperiodic tasks. A set of attributes and a code function define a task; attributes as name, release time, worst-case execution time, budget, relative and absolute deadlines, priority (if fixed priority scheduling is used), period (if the task is periodic). Release time and absolute deadline are attributes constantly updated bye the kernel during simulation, while period and priority are kept constant, although can be changed by callas to kernel primitives trough execution [1]. An example of the definition

ttInitKernel(1, 0, 'prioFP'); %Inputs,Outputs,FixedPriority

The kernel primitive ttInitKernel() initializes a sensor node. The kernel is initialized by specifying the number of A/D and D/A channels and scheduling policy. The built-in priority function prioFP specifies fixed-priority scheduling. Rate monotonic prioRM, earliest deadline first prioEDF, and deadline monotonic prioDM scheduling are additional

*Interrupts* can be generated in two ways: An external interrupt is associated with one of the external interrupt channels of the computer block; when the signal of the corresponding channel changes value the interrupt triggers. The usefulness of this type of interrupt lies to simulate distributed controllers that execute when measurements arrive on the network. Internal interrupts work to construct timers, when a timer expires the interrupt is triggered. A user-defined interrupt handler is scheduled when an external or internal interrupt occurs. An interrupt, as a task, handles works but it is scheduled on a higher priority level. An interrupt handler is defined by name, a priority and a code function [1]. An example of a definition of

ttCreateInterruptHandler('nw\_handler1', prio, 'msgRcvSensor'); ttInitNetwork(4, 'nw\_handler1'); % node #4 in the network

functions exist for most of the commonly used scheduling schemes.

Cervin *et al.* [1, 2] mentions that simulated execution occurs at three distinct *priority* levels: the interrupt (highest priority), kernel and task (lower priority) levels. The execution may be preemptive or non-preemptive. At interrupt level, interrupt handlers are *scheduled* according to fixed priorities. At task level, dynamic-priority scheduling may be used. At each scheduling point, the priority of task is given by user-defined priority function which is a function of the task attributes, this makes it easy to simulate different scheduling policies. Predefined priority

ttCreatePeriodicTask('sens\_task', offset, period, ...

of a task is shown below:

% Create sensor task offset = 0; prio = 1;

period = 0.010;

function sensor\_init(arg) % Initialize TrueTime kernel

prio, 'senscode', data);

predefined scheduling policies [6].

a interrupt handler is as follows:

%Initialize the network

The TrueTime network block simulates the physical layer and the medium-access layer of several local-area networks. CSMA/CD (Ethernet), CSMA/AMP (CAN), Round Robin

#### 6 Will-be-set-by-IN-TECH 54 Numerical Simulation – From Theory to Industry Issues on Communication Network Control System Based Upon Scheduling Strategy Using Numerical Simulations <sup>7</sup>

(Token Bus), FDMA, TDMA (TTP), Switched Ethernet, WLAN (802.11b), and ZigBee (802.15.4) are some types of network supported [2]. The network blocks are mainly configured using blocks dialogs. Some parameters common to all types of networks are bit rate, the minimum frame size, and the network interface delay. For each type of network there are some parameters that specifie the number of nodes, data rate (bits/s), preprocessing delay, minimum frame size, maximum frame size, frame overhead, etc. The network blocks may be used having one kernel block for each node in the network. The tasks into the kernels can send and receive arbitrary Matlab structure arrays over the network using ttSendMsg and ttGetMsg kernel primitives. This way is to quite flexible but requires to program some routines to configure the system. An useful network scheduler viewer shows the network activity for all nodes involved. An overview of all Truetime's primitives can be found on [12].

Frequency

Controler

The objective of controlling the frequency is to achieve coordination through the convergence of values. Each sensor *Si* knows its minimum and maximum frequencies based upon messages sent to controller and it could be estimated its own real transmission frequency. Let a NCS with a set Ω = {*S*1, *S*2, ..., *Sl*} nodes that performs a set of task *τ<sup>i</sup>* = {*ci*, *pi*} for

An approach that modifies the frequency transmission uses *fm*, *fr*, *fx* frequencies. RTDS dynamics, is modeled as a linear time-invariant system, whose state variables are frequencies transmission rates of the *n* nodes that compose the RTDS [4]. Frequency rates of a node are affected by some external input frequency rates, minimal frequencies of all nodes and particular ratios serve as coefficients of the linear system. So, it is possible to control the NCS using the input vector *u*, such that the output vector *y* contains the frequency rates of all nodes within a nonlinear region *L*, bounded by the maximum and minimum transmission frequency

**Figure 2.** Transmission frequencies bounded by a schedulability region

*i* = {1, 2, , *n*}, a subset of Ω is sensor nodes subset Ω*<sup>s</sup>* = {*S*1, *S*2, ..., *Sm*}.

rates. Let we assume that there is a relationship amongst real frequencies *f* <sup>1</sup>

*xk*<sup>+</sup><sup>1</sup> = *Axk* + *Buk*,

external input frequencies *u*1, *u*2, ..., *um* which serve as coefficients of the linear system:

*xk*<sup>+</sup><sup>1</sup> = *Axk* + *Buk*,

*A*, *B*, *C* are matrices with appropriate dimensions. *A* is the matrix of relationships between frequencies of sensor nodes, *B* is the scale frequencies matrix, *C* is the matrix with frequencies ordered, *xk*<sup>+</sup><sup>1</sup> is a real frequencies vector in time *t* = *k* + 1, *yk* is the vector of output frequencies. The input *uk* is a function of reference frequencies and real frequencies of the nodes in the distributed system, hence *u* = *K*(*fm* − *fr*) where *fm*, *fr* are vectors. Then, the

**3.3. Network scheduling based on frequency transmission**

state vector in equation (1) can be written as:

f 4

f 3 f 2

> f 1

> > Time

*<sup>r</sup>* , *f* <sup>2</sup>

*yk* <sup>=</sup> *Cxk*. (1)

*xk*<sup>+</sup><sup>1</sup> <sup>=</sup> *A frk* <sup>+</sup> *<sup>B</sup>* (*K*(*fmk* <sup>−</sup> *frk*)). (2)

*<sup>r</sup>* , ..., *f <sup>m</sup>*

*<sup>r</sup>* and

*L*

Issues on Communication Network Control System Based Upon Scheduling Strategy Using Numerical Simulations

55
