• Aucun résultat trouvé

Syst`emes embarqu´es 6

N/A
N/A
Protected

Academic year: 2022

Partager "Syst`emes embarqu´es 6"

Copied!
10
0
0

Texte intégral

(1)

embarqu´es 6 J.-M Friedt

Syst` emes embarqu´ es 6

G. Goavec-M´ erou, J.-M Friedt FEMTO-ST/d´ epartement temps-fr´ equence

jmfriedt@femto-st.fr transparents ` a jmfriedt.free.fr

21 septembre 2017

1 / 10

(2)

embarqu´es 6

J.-M Friedt

Device

Le device ne fait qu’instancier le mat´ eriel mais n’est pas en charge de cr´ eer les fichiers de communication (une s´ erie de fichiers par driver)

s t a t i c s t r u c t r e s o u r c e j m f r e s o u r c e s 1 [ ] ={ {. s t a r t = 0 x 4 1 2 0 0 0 0 0 ,

. end = 0 x 4 1 2 0 0 0 f f ,

. f l a g s = IORESOURCE MEM , // PAS IORESOURCE MEM . name =" io - l e d 1 "

},

{. s t a r t = 0 x 4 1 2 1 0 0 0 0 , . end = 0 x 4 1 2 1 0 0 f f ,

. f l a g s = IORESOURCE MEM , // PAS IORESOURCE MEM . name =" io - l e d 2 "

}, };

s t a t i c s t r u c t p l a t f o r m d e v i c e ∗pdev1 ,∗p d e v 2 ; s t a t i c i n t i n i t g p i o s i m p l e i n i t (v o i d)

{p d e v 1= p l a t f o r m d e v i c e r e g i s t e r s i m p l e (" jmf ", 0 , j m f r e s o u r c e s 1 , ARRAY SIZE ( j m f r e s o u r c e s 1 ) ) ; p d e v 2= p l a t f o r m d e v i c e r e g i s t e r s i m p l e (" jmf ", 1 , j m f r e s o u r c e s 1 , ARRAY SIZE ( j m f r e s o u r c e s 1 ) ) ; r e t u r n 0 ;

}

s t a t i c v o i d e x i t g p i o s i m p l e e x i t (v o i d) {p l a t f o r m d e v i c e u n r e g i s t e r ( p d e v 1 ) ;

p l a t f o r m d e v i c e u n r e g i s t e r ( p d e v 2 ) ; }

m o d u l e i n i t ( g p i o s i m p l e i n i t ) m o d u l e e x i t ( g p i o s i m p l e e x i t ) MODULE LICENSE (" GPL ") ; redpitaya> insmod dr_comm.ko redpitaya> insmod pl_resource2.ko jmf hello 0

jmf hello 1

redpitaya> ls /sys/bus/platform/devices/jmf.*

/sys/bus/platform/devices/jmf.0:

driver modalias subsystem valuer

driver_override power uevent valuew

/sys/bus/platform/devices/jmf.1:

driver modalias subsystem valuer

driver_override power uevent valuew2 / 10

(3)

embarqu´es 6

J.-M Friedt

Driver

s t a t i c s s i z e t g p i o s i m p l e s t o r e (s t r u c t d e v i c e ∗dev , s t r u c t d e v i c e a t t r i b u t e ∗a t t r , c o n s t →

,→c h a r∗b u f , s i z e t c o u n t )

{s t r u c t j m f s t r u c t∗m a s t r u c t=d e v g e t d r v d a t a ( d e v ) ; l o n g i n t r e s ;

i f ( ! k s t r t o l ( b u f , 1 0 , & r e s ) ) p r i n t k (" % s = % d ", b u f , r e s ) ; r e t u r n( c o u n t ) ;

}

s t a t i c DEVICE ATTR ( v a l u e w , 0 2 2 0 , NULL , g p i o s i m p l e s t o r e ) ; s t a t i c i n t g p i o s i m p l e r e m o v e (s t r u c t p l a t f o r m d e v i c e∗p d e v ) {d e v i c e r e m o v e f i l e (& pdev−>dev , &d e v a t t r v a l u e w ) ;

p r i n t k ( KERN ALERT" jmf bye % d \ n ", pdev−>i d ) ;r e t u r n 0 ; }

s t a t i c i n t g p i o s i m p l e p r o b e (s t r u c t p l a t f o r m d e v i c e ∗p d e v ) {s t r u c t r e s o u r c e∗r ;

v o i d∗m;

d e v i c e c r e a t e f i l e (& pdev−>dev , &d e v a t t r v a l u e w ) ; r= p l a t f o r m g e t r e s o u r c e ( pdev , IORESOURCE MEM , pdev−>i d ) ;

p r i n t k ( KERN ALERT" jmf h e l l o % d :% x - -% x \ n ", pdev−>i d , (i n t) r−>s t a r t , (i n t) r−>end ) ; m=i o r e m a p ( r−>s t a r t , r e s o u r c e s i z e ( r ) ) ; // on r e c u p e r e end−s t a r t

w r i t e l ( 0 x0 ,m+0x 0 4 ) ; // a l l a s o u t p u t ( 0 = o u t p u t ! ) w r i t e l ( 0 x05 ,m) ; // a l l a s o u t p u t

r e t u r n 0 ; }

s t a t i c s t r u c t p l a t f o r m d r i v e r g p i o s i m p l e d r i v e r ={ . p r o b e = g p i o s i m p l e p r o b e , . r e m o v e = g p i o s i m p l e r e m o v e , . d r i v e r ={. name =" jmf ",}, };

m o d u l e p l a t f o r m d r i v e r ( g p i o s i m p l e d r i v e r ) ; MODULE LICENSE (" GPL ") ;

3 / 10

(4)

embarqu´es 6

J.-M Friedt

FPGA

Xilinx Vivado pour configurer le FPGA (28 GB, penser ` a installer SDK)

PS (Zynq)+bus AXI+GPIO donne acc` es aux EMIO

Vivado impose les adresses sur bus AXI des divers p´ eriph´ eriques

4 / 10

(5)

embarqu´es 6

J.-M Friedt

FPGA : EMIO

EMIO : GPIO connect´ es au PL (6= MIO connect´ es au PS)

Rˆ ole des registres du bloc GPIO : 1 :

1. https://www.xilinx.com/support/documentation/ip_documentation/axi_

gpio/v2_0/pg144-axi-gpio.pdf

5 / 10

(6)

embarqu´es 6

J.-M Friedt

Programmer le FPGA depuis

GNU/Linux (m´ ethode unifi´ ee) : fpga manager

• passer d’un .bit ` a un .bin : fournir un fichier de configuration .bif

all: {nom_du_bitstream.bit}

• bit → bit.bin

$VIVADO_SDK/bin/bootgen -image file.bif -arch zynq -process_bitstream bin

• flasher le FPGA avec fpga manager

cp system_wrapper.bit.bin /lib/firmware/system_wrapper.bit.bin

echo "system_wrapper.bit.bin" > /sys/class/fpga_manager/fpga0/firmware

• Profiter du nouveau bitstream dans le FPGA

devmem 0x41200004 w 0x0 devmem 0x41200000 w 0xf

• ATTENTION : acc´ eder au FPGA alors qu’aucun bitstream ne configure le FPGA se traduit par un crash de Linux

(transaction AXI non-acquit´ ee)

6 / 10

(7)

embarqu´es 6

J.-M Friedt

fpga manager

D´ emonstration avec un driver pour commander les 8 LEDs depuis la m´ ethode init

#i n c l u d e<l i n u x / m o d u l e . h>

#i n c l u d e<l i n u x / p l a t f o r m d e v i c e . h>

#i n c l u d e<l i n u x / i o . h> // i o r e m a p s t a t i c s t r u c t p l a t f o r m d r i v e r g p i o s i m p l e d r i v e r ={

. p r o b e = g p i o s i m p l e p r o b e , . r e m o v e = g p i o s i m p l e r e m o v e , . d r i v e r ={. name =" jmf ",}, };

s t a t i c i n t g p i o s i m p l e r e m o v e (s t r u c t p l a t f o r m d e v i c e∗p d e v ) {p r i n t k ( KERN ALERT" jmf bye % d \ n ", pdev−>i d ) ;r e t u r n 0;}

s t a t i c i n t g p i o s i m p l e p r o b e (s t r u c t p l a t f o r m d e v i c e ∗p d e v ) {s t r u c t r e s o u r c e∗r ;

s t a t i c v o i d i o m e m∗j m f g p i o ; // i n t j m f g p i o ;

r= p l a t f o r m g e t r e s o u r c e ( pdev , IORESOURCE MEM , pdev−>i d ) ; // MEM e t non IO p r i n t k ( KERN ALERT" jmf h e l l o % d :% x - -% x \ n ", pdev−>i d , (i n t) r−>s t a r t , (i n t) r−>end ) ; j m f g p i o =(v o i d ∗) i o r e m a p ( r−>s t a r t , 0 x 0 4 ) ;

w r i t e l ( 0 x0 , j m f g p i o +0x 0 4 ) ; // a l l a s o u t p u t w r i t e l ( 0 x05 , j m f g p i o ) ; // a l l a s o u t p u t r e t u r n 0 ;

}

m o d u l e p l a t f o r m d r i v e r ( g p i o s i m p l e d r i v e r ) ; MODULE LICENSE (" GPL ") ;

7 / 10

(8)

embarqu´es 6

J.-M Friedt

Comment commander les LEDs

depuis un fichier en ´ ecriture

Structure priv´ ee duppliquant les ressources occup´ ees par le pilote

s t r u c t j m f s t r u c t {v o i d∗mem base ;};

s t a t i c s s i z e t g p i o s i m p l e s t o r e (s t r u c t d e v i c e ∗dev , s t r u c t d e v i c e a t t r i b u t e ∗a t t r , c o n s t →

,→c h a r∗b u f , s i z e t c o u n t )

{s t r u c t j m f s t r u c t∗m a s t r u c t=d e v g e t d r v d a t a ( d e v ) ; l o n g i n t r e s ;

i f ( ! k s t r t o l ( b u f , 1 0 , & r e s ) ) w r i t e l ( r e s , m a s t r u c t−>mem base ) ; // a l l a s o u t p u t p r i n t k (" % s = % d ", b u f , r e s ) ;

r e t u r n( c o u n t ) ; }

s t a t i c DEVICE ATTR ( v a l u e w , 0 2 2 0 , NULL , g p i o s i m p l e s t o r e ) ; s t a t i c i n t g p i o s i m p l e r e m o v e (s t r u c t p l a t f o r m d e v i c e∗p d e v ) {s t r u c t j m f s t r u c t∗m a s t r u c t=p l a t f o r m g e t d r v d a t a ( p d e v ) ;

k f r e e ( m a s t r u c t ) ;

d e v i c e r e m o v e f i l e (& pdev−>dev , &d e v a t t r v a l u e w ) ; p r i n t k ( KERN ALERT" jmf bye % d \ n ", pdev−>i d ) ;r e t u r n 0 ; }

s t a t i c i n t g p i o s i m p l e p r o b e (s t r u c t p l a t f o r m d e v i c e ∗p d e v ) {s t r u c t r e s o u r c e∗r ;

s t r u c t j m f s t r u c t∗m a s t r u c t ;

m a s t r u c t =(s t r u c t j m f s t r u c t ∗) k z a l l o c (s i z e o f(s t r u c t j m f s t r u c t ) , GFP KERNEL ) ; // z=z e r o d e v i c e c r e a t e f i l e (& pdev−>dev , &d e v a t t r v a l u e w ) ;

r= p l a t f o r m g e t r e s o u r c e ( pdev , IORESOURCE MEM , pdev−>i d ) ;

m a s t r u c t−>mem base=i o r e m a p ( r−>s t a r t , r e s o u r c e s i z e ( r ) ) ; // on r e c u p e r e end−s t a r t p l a t f o r m s e t d r v d a t a ( pdev , m a s t r u c t ) ;

r e t u r n 0 ; }

8 / 10

(9)

embarqu´es 6

J.-M Friedt

D´ emonstration sur plusieurs

instances du pilote

Application pour justifier de deux configurations des ressources :

• diviser le latch GPIO en deux sous ensembles de 4 bits

• autorouter

• fichier de contrainte apr` es avoir renomm´ e gpio rtl en ledo 2

Nature et assignation des broches

S´ eparation du GPIO en 2 latchs de 4 bits

Plages d’adresses propos´ ees par Vivado

Exercice : re-´ ecrire le pilote pour s’approprier deux configurations possibles, selon que ce soit led0 ou led1

D´ emonstration du passage de param` etre (motif des LEDs) par /sys

9 / 10

(10)

embarqu´es 6

J.-M Friedt

Exercice pour le 1er Janvier 2018

1 ajouter le bloc XADC au design Vivado contenant le GPIO

2 synth´ etiser et flasher ce bitstream : quelles broches sont associ´ ees aux entr´ ees analogiques ? quelle gamme de tensions ?

3 trouver la documentation du bloc XADC et identifier les registres pertinents pour la mise en œuvre des convertisseurs

4 proposer un driver capable de lire une valeur d’un ADC (quelle est l’adresse de base des registres ?)

5 d´ emontrer un ´ echantillonnage p´ eriodique du XADC par un driver

10 / 10

Références

Documents relatifs

D´ emontrer la compilation et le chargement du pilote sur PC (il se pourrait qu’il faille d´ efinir une variable d’environnement de fa¸ con appropri´ ee, en fonction de la version

• Alternative au temps r´ eel : le mat´ eriel reconfigurable se charge des op´ erations rapides et d´ echarge le processeur de tˆ aches imm´ ediates (UART, FIFO, ADC du coldfire

• Partant de l’exemple de module avec timer en /dev, impl´ ementer une m´ ethode read qui se d´ ebloque ` a intervalles de temps r´ eguliers (utiliser un mutex). • Proposer

• depuis le CPU (Linux) : pilote noyau pour communiquer avec les p´ eriph´ eriques. • description de la configuration mat´ erielle par le m´ ecanisme des devicetree consult´ e par

Notion de syst` eme embarqu´ e Architecture des processeurs Mat´ eriel v.s logiciel Rappels de C Les microcontrˆ oleurs 8 bits G´ en´ eralit´ es sur les syst` emes num´ eriques

Si nous pouvons interrompre l’ex´ ecution, ou modifier l’initialisation de i, nous serons en mesure d’afficher le message re- cherch´ e (d´ ebloque)5. Supposons que le vendeur de

timers : expiration d’un timer ou un tick (p ´eriode) d’horloge syst `eme autres p ´eriph ´eriques : touche clavier, clic souris, paquet ethernet,.. Exceptions et Interruptions

– Il ne peut y avoir plus d’un processus dans sa section critique en mˆeme temps – Un processus en dehors de sa section critique ne peut bloquer un autre