L w I P t u t o r i a l F e r n a n d o R i n - - PowerPoint PPT Presentation

l w i p t u t o r i a l
SMART_READER_LITE
LIVE PREVIEW

L w I P t u t o r i a l F e r n a n d o R i n - - PowerPoint PPT Presentation

A d v a n c e d Wo r k s h o p o n mo d e r n F P G A - b a s e d t e c h n o l o g y f o r S c i e n t i f i c C o mp u t i n g L w I P t u t o r i a l F e r n a n d


slide-1
SLIDE 1

A d v a n c e d Wo r k s h

  • p
  • n

mo d e r n F P G A

  • b

a s e d t e c h n

  • l
  • g

y f

  • r

S c i e n t i f i c C

  • mp

u t i n g

S m r 3 2 8 9 – I C T P ( M a y 2 1 9 )

L w I P t u t

  • r

i a l

F e r n a n d

  • R

i n c ó n

f e r n a n d

  • .

r i n c

  • n

@u c l m . e s

slide-2
SLIDE 2

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 2

C

  • n

t e n t s

  • T

h e g u i d e n

  • t

t

  • g

e t l

  • s

t i n t h e h e l l

  • w
  • r

l d e c h

  • s

e r v e r e x a m p l e

  • T

h e e x e r c i s e :

– C

r e a t e a V i v a d

  • p

r

  • j

e c t w i t h a G P I O I P c

  • r

e c

  • n

n e c t e d t

  • t

h e b

  • a

r d l e d s a n d s w i t c h e s

– M

  • d

i f y a n U D P e c h

  • s

e r v e r t

  • s

e n d / r e c e i v e d a t a t

  • /

f r

  • m

a r e m

  • t

e c l i e n t

  • T

h e c l i e n t w i l l s e n d a n u m b e r t h a t w i l l b e d i s p l a y e d i n t h e l e d s

  • I

n r e t u r n , t h e e c h

  • s

e r v e r w i l l a n s w e r w i t h t h e c u r r e n t c

  • m

b i n a t i

  • n
  • f

t h e s w i t c h e s

– T

e s t t h e s e r v e r w i t h n e t c a t

– M

  • d

i f y t h e s e r v e r t

  • u

s e T C P

  • I

n t e r e s t i n g r e f e r e n c e :

– h

t t p s : / / w w w . x i l i n x . c

  • m

/ v i d e

  • /

s

  • c

/ n e t w

  • r

k i n g

  • w

i t h

  • l

w i p

  • f
  • c

u s e d

  • f

r e e

  • r

t

  • s

. h t m l

slide-3
SLIDE 3

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 3

F r e e R T O S n e t w

  • r

k a p p l i c a t i

  • n

H e r e t h e n e t w

  • r

k i n t e r f a c e a n d I p s a r e c

  • n

fi g u r e d b u t s t i l l t w

  • m
  • r

e t h r e a d s w i l l b e c r e a t e d :

  • x

e m a c i f _ i n p u t _ t h r e a d

  • e

c h

  • _

a p p l i c a t i

  • n

_ t h r e a d T h e y a r e t h e

  • n

l y t w

  • t

h a t w i l l r e m a i n

slide-4
SLIDE 4

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 4

D e e p e r l

  • k

i n t

  • t

h e n e t w

  • r

k _ t h r e a d

M A C a d d r e s s S t a t i c I P a d d r e s s N e t w

  • r

k i n t e r f a c e c

  • n

fi g u r a t i

  • n

L w I P b a c k g r

  • u

n d t a s k T h e e c h

  • s

e r v e r t a s k

slide-5
SLIDE 5

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 5

T h e U D P e c h

  • s

e r v e r

We n e e d t

  • k

e e p t r a c k

  • f

t h e c l i e n t s e n d i n g d a t a , s i n c e n

  • c
  • n

n e c

  • t

i

  • n

i s e s t a b l i s h e d a n d w e n e e d i t f

  • r

t h e r e p l y We s e n d t h e r e p l y t

  • t

h e c l i e n t p r e v i

  • u

s l y s a v e d

slide-6
SLIDE 6

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 6

T h e e x e r c i s e : S t e p 1 – V i v a d

  • p

r

  • j

e c t

  • F

i r s t c r e a t e a v i v a d

  • p

r

  • j

e c t w i t h a G P I O c

  • r

e c

  • n

n e c t e d t

  • b

u t t

  • n

s a n d l e d s ( c

  • u

l d a l s

  • b

e t w

  • d

i ff e r e n t G P I O s )

slide-7
SLIDE 7

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 7

S t e p 2 – U D P e c h

  • s

e r v e r

  • E

x p

  • r

t t h e v i v a d

  • d

e s i g n t

  • t

h e S D K

  • C

r e a t e a N e w → A p p l i c a t i

  • n

P r

  • j

e c t :

– S

e l e c t f r e e r t

  • s

1 _ x i l i n x a s t h e O S P l a t f

  • r

m

– T

h e s e l e c t i

  • n

i n v

  • l

v e s t h e g e n e r a t i

  • n
  • f

t h e F r e e R T O S b s p

– T

h e n c l i c k

  • n

N e x t

– I

n t h e n e x t d i a l

  • g

b

  • x

s e l e c t :

  • F

r e e R T O S l w I P e c h

  • s

e r v e r

– T

h e n c l i c k F i n i s h

  • N
  • w

w e ’ l l d

  • a

l i t t l e t u n i n g

  • f

t h e g e n e r a t e d c

  • d

e

slide-8
SLIDE 8

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 8

S t e p 2 – U D P e c h

  • s

e r v e r

  • T

h e g e n e r a t e d c

  • d

e i s u s i n g T C P f

  • r

t h e e c h

  • i

m p l e m e n t a t i

  • n

. We w i l l r e p l a c e w i t h a s i m p l i fi e d U D P v e r s i

  • n
  • T
  • d
  • s
  • ,

r e p l a c e t h e c

  • n

t e n t s

  • f

t h e m a i n . c a n d e c h

  • .

c fi l e s w i t h t h e

  • n

e p r

  • v

i d e d i n t h e s h a r e d f

  • l

d e r .

  • T

h e n c

  • n

n e c t t h e b

  • a

r d a r u n t h e c

  • d

e

slide-9
SLIDE 9

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 9

S t e p 3 – T e s t t h e U D P e c h

  • s

e r v e r

  • P

l u g t h e E t h e r n e t c a b l e t

  • t

h e P C

  • O

p e n a t e r m i n a l w i n d

  • w

i n t h e P C ( Wi n d

  • w

s K e y + w r i t e “ c m d ” )

  • C

d t

  • t

h e l

  • c

a t i

  • n
  • f

t h e n e t c a t d i r e c t

  • r

y

  • R

u n a n e t c a t U D P c l i e n t

– t

h e t a r g e t I P i s s t a t i c : 1 9 2 . 1 6 8 . 1 . 1

– T

h e s e r v e r i s l i s t e n i n g a t p

  • r

t 7 nc -u 192.168.1.10 7

  • I

f e v e r y t h i n g i s O K t h e l i n e s y

  • u

t y p e i n t h e t e r m i n a l w i n d

  • w

w i l l b e c

  • p

i e d b a c k

slide-10
SLIDE 10

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 10

S t e p 4 – s e r v e r m

  • d

i fi c a t i

  • n
  • N
  • w

w e w i l l m

  • d

i f y t h e s e r v e r t

  • i

m p l e m e n t t h e d e s i r e d f u n c t i

  • n

a l i t y t h i s w a y :

– We

w i l l u s e a q u e u e t

  • p

u s h t h e d a t a r e c e i v e d b y t h e e c h

  • t

h r e a d

– I

m m e d i a t e l y a f t e r r e c e i v i n g d a t a f r

  • m

a c l i e n t , t h e e c h

  • t

h r e a d w i l l r e p l y t

  • t

h a t s a m e c l i e n t w i t h t h e v a l u e r e a d f r

  • m

t h e s w i t c h e s G P I O

– A

s e c

  • n

d t a s k w i l l r e c e i v e d a t a f r

  • m

t h e q u e u e a n d w r i t e t h e v a l u e i n t

  • t

h e l e d s G P I O

  • I

n t h e ma i n . c a t t h e n e t w

  • r

k _ t h r e a d f u n c t i

  • n

C r e a t e a n e w “ l e d s _ t h r e a d ” R e m e m b e r t

  • i

n c l u d e t h e i n t e r f a c e d e fi n i t i

  • n

a t t h e t

  • p
  • f

t h e fi l e j u s t l i k e t h e e c h

  • a

p p l i c a t i

  • n

t h r e a d

slide-11
SLIDE 11

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 11

S t e p 4 – s e r v e r m

  • d

i fi c a t i

  • n
  • T

h e r e s t

  • f

m

  • d

i fi c a t i

  • n

s a r e p e r f

  • r

m e d i n t h e e c h

  • .

c fi l e

  • D

e c l a r e t h e q u e u e a s a g l

  • b

a l v a r i a b l e :

– QueueHandle_t xQueue;

  • A

n d a l s

  • t

h e t w

  • G

P I O i n s t a n c e s f

  • r

l e d s a n d s w i t c h e s

– XGpio gpio_leds, gpio_switches;

  • I

n t h e e c h

  • _

a p p l i c a t i

  • n

_ t h r e a d :

– C

r e a t e t h e q u e u e :

  • xQueue = xQueueCreate(

1, sizeof( unsigned int ) );

– T

h e n i n i t i a l i z e t h e G P I O S

  • XGpio_Initialize(&gpio_leds, XPAR_BOARD_LEDS_8B_DEVICE_ID);
  • XGpio_SetDataDirection(&gpio_leds, 1, 0x00);
  • .

. .

– I

n s i d e t h e i n fi n i t e w h i l e , a n d

  • n

c e d a t a h a s b e e n r e a d , p u s h i t i n t

  • t

h e q u e u e

  • int value = atoi(recv_buf)
  • xQueueSend(xQueue, &value, 0UL);

– F

i n a l l y r e a d t h e v a l u e f r

  • m

t h e s w i t c h e s ( X G p i

  • _

D i s c r e t e R e a d ( & g p i

  • _

s w i t c h e s , < c h a n n e l > ) ) , c

  • p

y i t i n t

  • a

b u ff e r a n d s e n d i t , i n s t e a d t h e c

  • p

y

  • f

t h e r e c e i v e d d a t a

Wh a t ’ s t h e m e a n i n g

  • f

t h i s ?

slide-12
SLIDE 12

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 12

S t e p 4 – s e r v e r m

  • d

i fi c a t i

  • n
  • F

i n a l l y c r e a t e t h e l e d s _ t h r e a d t h a t r e a d s f r

  • m

t h e q u e u e a n d c

  • p

i e s t h e v a l u e i n t

  • t

h e G P I O :

void leds_thread() { unsigned int value; for( ;; ) { xQueueReceive( xQueue, &value, portMAX_DELAY ); XGpio_DiscreteWrite(&gpio_leds, 1, value); } }

Wh a t ’ s t h e m e a n i n g

  • f

t h i s ?

slide-13
SLIDE 13

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 13

S t e p 5 – T e s t t h e s e r v e r

  • U

s e n e t c a t a g a i n t

  • t

e s t t h e s e r v e r . T h e s

  • c

k e t i s t h e s a m e

  • n

e t h a t w e u s e d p r e v i

  • u

s l y

slide-14
SLIDE 14

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 14

S t e p 6 – R e p l a c e U D P w i t h T C P

  • T

h i s w i l l

  • n

l y a ff e c t t h e e c h

  • .

c fi l e

  • I

n t h e e c h

  • _

a p p l i c a t i

  • n

_ t h r e a d :

– R

e p l a c e t h e p a r a m e t e r S O C K _ D G R A M w i t h S O C K _ S T R E A M w h e n c r e a t i n g t h e s

  • c

k e t

– A

f t e r t h e b i n d i n g p u t t h e s

  • c

k e t t

  • l

i s t e n

  • lwip_listen(sock, 0);

– A

n d g e t t h e c l i e n t _ l e n g t h t h a t i s r e q u i r e d f

  • r

t h e a c c e p t

  • client_length = sizeof(client_address);

– F

i n a l l y r e p l a c e t h e i n fi n i t e l

  • p

w i t h t h e f

  • l

l

  • w

i n g

  • n

e , b u t k e e p t h e p r e v i

  • u

s c

  • d

e t h a t w e ’ l l n e e d i n a n e x t r a t h r e a d :

w h i l e ( 1 ) { i f ( ( a c c e p t e d _ s

  • c

k = l w i p _ a c c e p t ( s

  • c

k , & c l i e n t _ a d d r e s s , ( s

  • c

k l e n _ t * ) & c l i e n t _ l e n g t h ) ) > ) { x T a s k C r e a t e ( p r

  • c

e s s _ e c h

  • _

r e q u e s t , " e c h

  • s

" , T H R E A D _ S T A C K S I Z E , ( v

  • i

d * ) a c c e p t e d _ s

  • c

k , D E F A U L T _ T H R E A D _ P R I O , & x E c h

  • T

a s k ) ; } }

slide-15
SLIDE 15

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 15

S t e p 6 – R e p l a c e U D P w i t h T C P

  • C

r e a t e t h e n e w t h r e a d t h a t w i l l h a n d l e t h e c

  • n

n e c t i

  • n

s a c c e p t e d ( p r

  • c

e s s _ e c h

  • _

r e q u e s t )

void process_echo_request(void *param) { int sock = (int) param; /* here the while (1) loop previously saved*/ …… /* close connection */ close(sock); vTaskDelete(NULL); }

slide-16
SLIDE 16

L w I P t u t

  • r

i a l S m r 3 2 8 9 – I C T P ( M a y 2 1 9 ) 16

S t e p 7 – N e t c a t t e s t

  • R

e p e a t t h e t e s t w i t h n e t c a t b u t r e m e m b e r t h a t n

  • w

w e a r e u s i n g T C P , t h e r e f

  • r

e :

– T

h e s e r v e r m u s t b e r u n n i n g b e f

  • r

e t h e c l i e n t t r i e s t

  • c
  • n

n e c t ( t h i s i s a c

  • n

n e c t i

  • n
  • r

i e n t e d p r

  • t
  • c
  • l

)

– T

h e c

  • m

m a n d l i n e d

  • e

s n ’ t i n c l u d e t h e

  • u

s w i t c h :

nc 192.168.1.10 7

– H

i t t i n g C t r l + C i n t h e t e r m i n a l w i n d

  • w

w i l l c l

  • s

e t h e c u r r e n t c

  • n

n e c t i

  • n