Académique Documents
Professionnel Documents
Culture Documents
Séance 2
Modèles des systèmes
embarqués
3
Objectifs
Le modèle super-loop
Le modèle orienté évènements et interruptions
Le modèle basé sur les processus
4
Système embarqué
5
Modèle super-loop
Super-loop (1)
1 main ()
2 {
3 init ialisation () ; // ini tialisat ion du système
4
5 while (1) {
6 check_device () ; // examination de l ’ état du périphérique
7
8 process_data () ; // traitement des données
9
10 o utput_response () ; // production d ’ une sortie
11 }
12 }
7
Super-loop (2)
8
Programmation Arduino
9
Contrôle port UART
10
Désavantage
11
Modèle orienté évènements
Évènement
13
Super-loop vs évènement
14
Modèle orienté interruptions
15
Affichage de l’heure (1)
1 void IRQ_handler ()
2 {
3 // ...
4 if ( vicstatus & (1 < <4) )
5 timer_handler () ;
6 }
7
8 int main ()
9 {
10 // ... initialisation ...
11 while (1) {
12 asm ( " MOV r0 , #0; MCR p15 ,0 , R0 , c7 , c0 ,4 " ) ; // mettre CPU en état WFI
13 }
14 }
16
Affichage de l’heure (2)
1 void timer_handler ()
2 {
3 TIMER * t = & timer ;
4 t - > tick ++;
5 if (t - > tick == 60) {
6 // ... mettre à jour le temps ...
7 }
8
9 if (t - > tick == 0) {
10 // ... afficher l ’ heure ...
11 }
12
13 if (( t - > ss % 5) == 0) {
14 // ... afficher texte particulier ...
15 }
16
17 t i m e r _ c l e a r I n t e r r u p t () ;
18 }
17
Wait-For-Interrupt (WFI)
18
Interruption imbriquée
19
Affichage de l’heure (3)
20
Affichage de l’heure (4)
22
Contrôle port UART et clavier (2)
1 int main ()
2 {
3 // ... initialisation ...
4 while (1) {
5 if ( uline ) {
6 ugets ( line ) ;
7 uprintf ( " UART : line =% s \ n " , line ) ;
8 lock () ; uline = 0; unlock () ;
9 }
10 if ( kline ) {
11 gets ( line ) ;
12 color = GREEN ;
13 printf ( " KBD : line =% s \ n " , line ) ;
14 lock () ; kline = 0; unlock () ;
15 }
16 asm ( " MOV r0 , #0; MCR p15 ,0 , R0 , c7 , c0 ,4 " ) ; // mettre CPU en état WFI
17 }
18 }
23
Condition de course
24
Priorité
25
Modèle processus
Processus
Nombre de processeurs
Espace d’adresses
Création statique ou dynamique de processus
Préemptions des processus
27
Processeur
28
Espace d’adresses
29
Création de processus
30
Préemption
31
Type de modèles (1)
32
Type de modèles (2)
33
Type de modèles (3)
34
Méthode de design
Méthode de design
36
Langage de haut niveau
37
Machine à états finis (1)
F = hS, X , O, f i
où
S est un ensemble fini d’états
X est un ensemble fini d’entrées
O est un ensemble fini de sorties
f est une fonction de transition d’états
f : S ×I → S ×O
(s, x ) 7→ (s 0 , o)
38
Machine à états finis (2)
39
FSM pour système embarqué
40
Étape 1 : Construction tableau d’états (1)
x1 est un slash /
x2 est un retour à la ligne \n
x3 est tout sauf /, \n ou EOF
x4 est EOF (end-of-file)
41
Étape 1 : Construction tableau d’états (2)
État x1 x2 x3 x4
S0 S2 /– S1 /"x2 " S1 /"x3 " S4 /–
S1 S2 /– S1 /"x2 " S1 /"x3 " S4 /–
S2 S3 /– S1 /"/x2 " S1 /"/x3 " S4 /–
S3 S3 /– S1 /"x2 " S3 /– S4 /–
S4 S4 /– S4 /– S4 /– S4 /–
42
Étape 2 : Minimisation tableau d’états (1)
Réflexive ∀x ∈ R : xRx
Symétrique ∀x , y ∈ R : xRy =⇒ yRx
Transitive ∀x , y , z ∈ R : xRy ∧ yRz =⇒ xRz
43
Étape 2 : Minimisation tableau d’états (2)
44
Étape 2 : Minimisation tableau d’états (3)
45
Étape 3 : Traduction tableau d’états en code
1 int main ()
2 {
3 int c ;
4 int state = 1;
5 FILE * fp = fopen ( " cprogram . c " , " r " ) ;
6
7 while (( c = fgetc ( fp ) ) != EOF ) {
8 switch ( state ) {
9 case 1:
10 switch ( c ) {
11 case ’/ ’ : state = 2; break ;
12 case ’\ n ’: state = 1; printf ( " % c " , c ) ; break ;
13 default : state = 1; printf ( " % c " , c ) ; break ;
14 }
15 break ;
16 // ... autre cas ...
17 }
18 }
19 }
46
StateCharts
47
Crédits
https://www.flickr.com/photos/uwehermann/2995807588
https://www.flickr.com/photos/drownedman/4205166796
https://www.flickr.com/photos/thomashawk/9779035382
https://www.flickr.com/photos/junaidrao/34773734383
48