25 aprile
-定义: A realtime application is an application where the correctness of the application depends on the timelines and predictability of the application as well as the results of computations.
- Temps reel peu contraint( SOFT)
- Temps reel tres contraint( HARD)
- STR rigide(dur): garantit que les taches critiques finissent a temps
- Tous les delais du systeme doivent etre limites Dicte les fonctions disponibles:-moimoire auxiliaire limitee ou manquante, donnees stockees dans la memoire a court emrme ou dans la ROM
- Majourite des caracteristeques evoluees absente(eg. memoire virtuelle)
- STR souple(lache):moins restrictif,
une tache critique est prioritaire sur les aurtre en conserve cette priorite jusqu'a ce qu'elle se temine
-Systeme embarque: dispositif informatique integere au dispositif pysique dont il assure le controle et ou la commande et dont il partage les contraintes d'environnment....
Forte interaction entre le materiel informatique et son instrumentation.
Fiabilite et perfomance de l'instrumentation doivent etre pris en consideration lors de la conception globale du system.
-Systeme deterministe: a partir de l'etat present du systeme, sa reaction a un stimulus donne est predictible.可预见
-Systeme non deterministe: a partir de l'etat courant, on ne peut pas garandir l'action que le system va executer.不确定性.
-Aeronautique: non deterministe.
Fonctionnement general: boucle infinie
Tant que TOUJOUR faire
Acquisition des entree(donnees capteurs,mesures...)
Calcule des ordres a envoyer au procede
Emission des ordres
Fin tant que
fonctionnment 2 modes :cyclique;evenement. 时钟驱动,事件驱动(特别是中断)
Tache:
- module logiciel dont l'execution realise une ou plusieurs actions elementatires en respectant les contrintes,performances et relations associees a ces actions.
- les actions devant evoluer en parallele doivent etre separeres dans des taches differents.
- definition des attributs.
tache,互相协作,或者互相竞争.
- Concurrence: 共享的资源
- Cooperation: 通信,同步 commnication , synchronisation.
synchronisation:
The VxWorks OS
Modern RTSs are based on complementary concepts of
multitasking
and
intertask communications. Multitasking allows a real-time application
to be constructed as a set of independent tasks, each with its own thread
of execution and set of system resources. The intertask communication facilities
allow these tasks to synchronize an communicate in order to coordinate
their activity.
Another Key facility in RTSs is hardware interrupt handling, because
interrupts are the usual mechanism to inform a system of external events.
ISRs
in VxWorks run in a special context of their own, outside of any task's
context.
Tasks
A task is a program in a state of execution. In VxWorks, tasks
have immediate, shared access to most system resources, while also maintaining
enough separate context to maintain individual threads of control.
-
Multitasking
Multitasking provides the fundamental mechanism for an application
to control and react to multiple, discrete real-world events.
The VxWorks real-time kernel, wind, provides the basic multitasking
environment.
Multitasking creates the appearance of many threads of execution running
concurrently when, in fact, the kernel interleaves their execution on the
basis of a scheduling algorithm.
Each apparently independent program is called a task.
The task control block (TCB)
Context:
-
A thread of execution, that is, the task's program counter
-
The CPU registers and (optionally) floating-point registers
-
A stack for dynamic variables and function calls
-
I/O assignments for standard input, output, and error
-
A delay timer
-
A timeslice timer
-
Kernel control structures
-
Signal handlers
-
Debugging and performance monitoring values
In VxWorks, one important resource that is not part of a task's context
is
memory address space: all code executes in a single common address
space. Giving each task its own memory space requires virtual-to-physical
memory mapping (Virtual Memory)
-
State Transitions
Four states: pended, ready, suspended, delayed
-
READY: The state of a task that is not waiting for any resource
other than the CPU.
-
PEND: The state of a task that is blocked due to the unavailability
of some resource.
-
DELAY: The state of a task that is asleep for some duration.
SUSPEND: The state of a task that is unavailable for execution.
This state is used primarily for
debugging. Suspension does not inhibit state transition, only task
execution. Thus pended-suspended tasks can still unblock and delayed-suspended
tasks
can still awaken.
-
Scheduling
Two types of scheduling:
-
Preemptive Priority Scheduling: 256 levels of priority. 0 is highest
255 is lowest
-
Round-Robin Scheduling: Tasks at the same priority level are scheduling
using RR with time-slicing.
The wind scheduler can be explicitly disabled and enabled on a per-task
basis using Preemption locks. A task disables the scheduler by calling
the taskLock(): No priority-based preemption
can occur while the task is running.
However, if the task explicitly blocks or suspends, the scheduler selects
the next highest-priority eligible task to execute. When the preemption-locked
task unblocks and begins running again, preemption is again disabled. They
do not block interrupt handling though.
Preemption locks can be used for mutual exclusion
-
Tasking Control
-
Task Creation and Activation
Routines to create tasks:
| Call
| Description
|
| taskSpawn()
| Spawn (create and activate) a new task.
|
| taskInit()
| Initialize a new task.
|
| taskActivate()
| Activate an initialized task.
|
tid = taskSpawn ( name, priority, options, stacksize, main, arg1,
..., arg10 );
-
Each task has a task name and a task id.
-
Tasks can be dynamically deleted from the system.
-
taskDelete(). You must make sure a task which is in its critical
section is not deleted.
-
taskSafe() and taskUnsafe() routines help with unexpected
deletion of tasks:
taskSafe ();
semTake (semId, WAIT_FOREVER); /* Block until semaphore available
*/
.
. critical region
.
semGive (semId); /* Release semaphore */
taskUnsafe ();
-
Task Control routines:
-
taskSuspend(): Suspend a task.
-
taskResume() : Resume a task.
-
taskRestart() : Restart a task.
-
taskDelay() : Delay a task; delay units are ticks.
-
nanosleep() : Delay a task; delay units are nanoseconds. (sysClkRateGet())
Intertask Communications
VxWorks supplies a rich set of intertask communication mechanisms,
including:
-
Shared memory, for simple sharing of data.
-
Semaphores, for basic mutual exclusion and synchronization.
-
Message queues and pipes, for intertask message passing within a
CPU.
-
Sockets and remote procedure calls, for network-transparent intertask
communication.
-
Signals, for exception handling.