7

Application justifying the two resource configurations: • split the single 8-bit GPIO latch in two 4-bit subsets. • autoroute. • constraint file after re-naming gpio rtl to ...
2MB taille 11 téléchargements 467 vues
Embedded systems 6/7 J.-M Friedt

Embedded systems 6/7 G. Goavec-M´erou, J.-M Friedt FEMTO-ST/time & frequency department [email protected] slides at jmfriedt.free.fr

November 11, 2018

1/9

Embedded systems 6/7

Device

J.-M Friedt

A device only defines the resources needed by a peripheral but will not create the communication entries (taken care of by the driver) static

struct resource jmf resources1 [ ] = { {. s t a r t = 0 x41200000 , . end = 0 x412000ff , . f l a g s = IORESOURCE MEM , // PAS IORESOURCE MEM . name = " io - led1 " }, {. s t a r t = 0 x41210000 , . end = 0 x412100ff , . f l a g s = IORESOURCE MEM , // PAS IORESOURCE MEM . name = " io - led2 " },

}; static

s t r u c t p l a t f o r m d e v i c e ∗pdev1 ,∗ p de v2 ;

static int i n i t g p i o s i m p l e i n i t ( void ) {p de v1=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 de v2=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 ) ) ; return 0; } s t a t i c void e x i t gpio simple exit ( void ) { p l a t f o r m d e v i c e u n r e g i s t e r ( pd e v1 ) ; p l a t f o r m d e v i c e u n r e g i s t e r ( pd e v2 ) ; } module init ( gpio simple init ) module exit ( gpio simple exit ) 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 driver_override

modalias power

/sys/bus/platform/devices/jmf.1: driver modalias driver_override power

subsystem uevent

valuer valuew

subsystem uevent

valuer valuew 2/9

Embedded systems 6/7

Driver

J.-M Friedt

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 ,→ c h a r ∗buf , 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 ) ; long i n t res ; i f ( ! k s t r t o l ( buf , 1 0 , & r e s ) ) p r i n t k ( " % s = % d " , buf , r e s ) ; r e t u r n ( count ) ; }

d e v i c e a t t r i b u t e ∗a t t r , c o n s 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 ∗pdev ) { 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 ∗pdev ) { 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 hello % 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+0x04 ) ; // 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 return 0; } static

struct platform driver gpio simple driver = { . probe = gpio simple probe , . remove = gpio simple remove , . d r i v e r = {. name = " jmf " ,} ,

}; module platform driver ( gpio simple driver ) ; MODULE LICENSE ( " GPL " ) ;

3/9

Embedded systems 6/7 J.-M Friedt

FPGA Xilinx Vivado to configure the FPGA (WebPack: 37 GB, including SDK)

PS (Zynq)+bus AXI+GPIO for accessing EMIO (25 min sythesis first time, 5 min afterwards) Vivado provides mandatory address ranges for each peripheral on the AXI bus

4/9

Embedded systems 6/7 J.-M Friedt

FPGA: EMIO EMIO: GPIO connected to the PL (6= MIO connected to the PS) Functions of the registers provided by the GPIO block:

1

:

1 https://www.xilinx.com/support/documentation/ip_documentation/axi_ gpio/v2_0/pg144-axi-gpio.pdf 5/9

Embedded systems 6/7

Configuring the FPGA from GNU/Linux: fpga manager

J.-M Friedt

Unified, vendor independent access to the PL par of the SoC: • convert the .bit synthesized by Vivado to a bit.bin: provide a configuration file .bif all: {bitstream_name.bit}

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

• configure the FPGA using fpga manager

(mkdir /lib/firmware if needed)

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

• Use the functionalities provided by the new FPGA bitstream devmem 0x41200004 w 0x0 devmem 0x41200000 w 0xf

• WARNING: accessing the FPGA while not configured by a bitstream will yield a crash of Linux (AXI transaction not acknowledged) 6/9

Embedded systems 6/7

fpga manager

J.-M Friedt

Demonstration of a driver for controlling the 8 LEDs from the probe method #i n c l u d e #i n c l u d e #i n c l u d e // i o r e m a p static

struct platform driver gpio simple driver = { . probe = gpio simple probe , . remove = gpio simple remove , . 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 ∗pdev ) { 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 ∗pdev ) { s t r u c t r e s o u r c e ∗r ; s t a t i c void iomem ∗ 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 hello % 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 x04 ) ; w r i t e l ( 0 x0 , j m f g p i o +0x04 ) ; // 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 return 0; } module platform driver ( gpio simple driver ) ; MODULE LICENSE ( " GPL " ) ;

7/9

Embedded systems 6/7 J.-M Friedt

Controlling the LEDs from a writable file Private structure dupplicating the resources used by the driver

2

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 ∗buf , 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 ) ; // LOCAL c o p y long i n t res ; i f ( ! k s t r t o l ( buf , 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 = % ld " , buf , r e s ) ; r e t u r n ( count ) ; } 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 ∗pdev ) { 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 ( pdev ) ; kfree ( ma struct ) ; 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 ∗pdev ) { 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 ) ; return 0; }

2 DO NOT create a global variable which would be overwritten by the latest copy of the driver being loaded.

8/9

Embedded systems 6/7 J.-M Friedt

Demonstration using multiple copies of the driver Application justifying the two resource configurations: • split the single 8-bit GPIO latch in two 4-bit subsets • autoroute • constraint file after re-naming gpio rtl to ledo 2 Separating the GPIO bus into two 4 bit latches

Address space provided by Vivado EMIO pins conType and wiring of the pins nected to LEDs Exercise: update the driver to fetch the two possible configurations, depending whether led0 or led1 is being controlled

Demonstrate passing parameters (pattern on the LEDs) through /sys

9/9