1 - cpre 583 (reconfigurable computing): reconfigurable computing hw, vhdl 2 iowa state university...

152
1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview ) Instructor: Dr. Phillip Jones ([email protected]) Reconfigurable Computing Laboratory Iowa State University Ames, Iowa, USA http:// class.ece.iastate.edu/ cpre583/

Upload: chrystal-allen

Post on 17-Jan-2016

270 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

CPRE 583Reconfigurable Computing

(VHDL Overview )

Instructor: Dr. Phillip Jones([email protected])

Reconfigurable Computing LaboratoryIowa State University

Ames, Iowa, USA

http://class.ece.iastate.edu/cpre583/

Page 2: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

2 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL basics

• VHDL: (V)HSIC (H)ardware (D)escription (L)anguage– VHSIC: (V)ery (H)igh (S)peed (I)ntegrated (C)ircuit

• It is NOT a programming language!!!

• It is a Hardware Description Language (HDL)

• Conceptually VERY different form C,C++

Page 3: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

3 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

• C is inherently sequential (serial), one statement executed at a time

• VHDL is inherently concurrent (parallel), many statements execute (simulate) at a time

Page 4: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

4 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Page 5: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

5 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Page 6: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

6 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 1

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Page 7: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

7 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

Page 8: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

8 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

“Simulates in parallel ever delta time step”

Show impactOf changing Order of statements

Page 9: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

9 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 1B = 1C = 1X = 1Y = 1Z = 1Ans = 1

“Simulates in parallel ever delta time step”

Snap shot after input change

Page 10: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

10 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 2

“Simulates in parallel ever delta time step”

Page 11: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

11 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 2

“Simulates in parallel ever delta time step”

Different

Page 12: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

12 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 2

“Simulates in parallel ever delta time step”

Snap shot after input change

Page 13: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

13 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 2

“Simulates in parallel ever delta time step”

Page 14: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

14 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Some Key Differences from C

C example VHDL example

A = B + CX = Y + ZAns = A + X

Initially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

Current Values:A = 2B = 1C = 1X = 2Y = 1Z = 1Ans = 4

“Simulates in parallel ever delta time step”

Page 15: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

15 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Corresponding circuit

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

“Simulates in parallel ever delta time step”

Page 16: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

16 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Corresponding circuit

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(1)

X(1)

Ans(1)

Page 17: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

17 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Corresponding circuit

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(2)

X(2)

Ans(2)

Page 18: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

18 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Corresponding circuit

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

A <= B + CX <= Y + ZAns <= A + X

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(2)

X(2)

Ans(4)

Page 19: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

19 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Corresponding circuit (More realistic)

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

A <= B + C after 2nsX <= Y + Z after 2nsAns <= A + X after 2ns

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(1)

X(1)

Ans(1)2ns

2ns

2ns

Page 20: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

20 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(2)

X(2)

Ans(2)

Corresponding circuit (More realistic)

2ns

2ns

2ns

A <= B + C after 2nsX <= Y + Z after 2nsAns <= A + X after 2ns

Page 21: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

21 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL exampleInitially: A,B,C,X,Y,Z,Ans =1

“Simulates in parallel ever delta time step”

+

+

B(1)

C(1)

Y(1)

Z(1)

+

A(2)

X(2)

Ans(4)

Corresponding circuit (More realistic)

2ns

2ns

2ns

A <= B + C after 2nsX <= Y + Z after 2nsAns <= A + X after 2ns

Page 22: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

22 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Typical Structure of a VHDL FileLIBRARY ieee;

ENTITY test_circuit IS PORT(B,C,Y,Z,Ans);END test_circuit;

ARCHITECTURE structure OF test_circuit IS signal A : std_logic_vector(7 downto 0); signal X : std_logic_vector(7 downto 0);

BEGIN

A <= B + C; X <= Y + Z; Ans <= A + X;

END

Include Libraries

Define component name andInput/output ports

Declare internalsignals, components

Implement components functionality

Page 23: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

23 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Process

• Process provide a level serialization in VHDL (e.g. variables, clocked processes)

• Help separate and add structure to VHDL design

Page 24: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

24 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Process ExampleBEGIN

My_process_1 : process (A,B,C,X,Y,Z) Begin A <= B + C; X <= Y + Z; Ans <= A + X; End My_process_1;

My_process_2 : process (B,X,Y,Ans1) Begin A <= B + 1; X <= B + Y; Ans2 <= Ans1 + X; End My_process_2;

END;

Sensitivity list: specify inputs to theprocess. Process is updated when a specified input changes

Page 25: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

25 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Process Example (Multiple Drivers)BEGIN

My_process_1 : process (A,B,C,X,Y,Z) Begin A <= B + C; X <= Y + Z; Ans <= A + X; End My_process_1;

My_process_2 : process (B,X,Y,Ans1) Begin A <= B + 1; X <= B + Y; Ans2 <= Ans1 + X; End My_process_2;

END;

A signal can only be Driven (written) by one process. But can be readby many

Compile or simulator may give a “multiple driver” Erroror Warning message

Page 26: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

26 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Process Example (Multiple Drivers)BEGIN

My_process_1 : process (A,B,C,X,Y,Z) Begin A <= B + C; X <= Y + Z; Ans <= A + X; End My_process_1;

My_process_2 : process (B,X,Y,Ans1) Begin A1 <= B + 1; X1 <= B + Y; Ans2 <= Ans1 + X; End My_process_2;

END;

Maybe A,X were suppose to be A1,X1. Cutand paste error. Or may need to rethink Hardware structure to remove multiple driverissue.

Page 27: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

27 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Process Example (if-statement)BEGIN My_process_1 : process (A,B,C,X,Y,Z) Begin

if (B = 0) then C <= A + B; Z <= X + Y; Ans1 <= A + X; else C <= 1; Z <= 0; Ans1 <= 1; end if;

End My_process_1;END;

Add circuit

Page 28: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

28 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Clock Process ExampleBEGIN

My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN C <= A or B; Z <= X or Y; Ans <= C and Z; END IF; End My_process_1;

END;

or

or

A()

B()

X()

Y()

and

C()

Z()

Ans()

circuit not clocked

Page 29: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

29 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Clock Process ExampleBEGIN

My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN C <= A or B; Z <= X or Y; Ans <= C and Z; END IF; End My_process_1;

END;

or

or

A()

B()

X()

Y()

and

C()

Z()

Ans()

circuit with clock

clk

D Flip-FlopDFF

Register

Page 30: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

30 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Clock Process ExampleBEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN C <= A or B; Z <= X or Y; Ans <= C and Z; END IF; End My_process_1;END;

or

or

A()

B()

X()

Y()

and

C()

Z()

Ans()

circuit with clock

clk

Page 31: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

31 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Clock Process Example 2BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN C <= A xor B; Z <= X or Y; Ans <= C xor Z; END IF; End My_process_1;END;

xor

or

A()

B()

X()

Y()

xor

C()

Z()

Ans()

circuit with clock

clk

Page 32: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

32 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Clock Process Example 2 (Answer)BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN C <= A xor B; Z <= X or Y; Ans <= C xor Z; END IF; End My_process_1;END;

xor

or

A()

B()

X()

Y()

xor

C()

Z()

Ans()

circuit with clock

clk

Page 33: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

33 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL Constructs

• Entity• Process• Signal, Variable, Constants, Integers• Array, Record

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

Page 34: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

34 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Signals and Variables• Signals

– Updated at the end of a process– Have file scope

• Variables– Updated instantaneously– Have process scope

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

Page 35: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

35 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

std_logic, std_logic_vector

• Very common data types

• std_logic– Single bit value– Values: U, X, 0, 1, Z, W, H, L, -– Example: signal A : std_logic;

• A <= ‘1’;• Std_logic_vector: is an array of std_logic

– Example: signal A : std_logic_vector (4 downto 0);

• A <= x“00Z001”

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

Page 36: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

36 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Std_logic values

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 0

Page 37: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

37 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 0

1 U U U

Std_logic values

Page 38: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

38 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 1

0 1 U U

Std_logic values

Page 39: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

39 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 2

1 0 1 U

Std_logic values

Page 40: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

40 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 3

1 1 0 1

Std_logic values

Page 41: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

41 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 3

1 1 0 1

0 1

X

Std_logic values

Page 42: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

42 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 3

1 1 0 1

0 1

X

1

0

Std_logic values

Page 43: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

43 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 3

1 1 1 X

0 0

X

1

X

Std_logic values

Page 44: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

44 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 0

‘1’ Pull-up resistor

Std_logic values

Page 45: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

45 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 0

0 U H U

‘1’ Pull-up resistor

Std_logic values

Page 46: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

46 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 1

1 0 H 1

‘1’ Pull-up resistor

Std_logic values

Page 47: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

47 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Std_logic values– U : Uninitialized (signal has not been assigned a value yet)– X : Unknow (2 drivers one ‘0’ one ‘1’)– H : weak ‘1’ (example: model pull-up resister)

• I have never used this value– L : weak ‘0’

Time step 2

0 1 0 1

‘1’ Pull-up resistor

Resolution(H,0) = 0

Std_logic values

Page 48: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

48 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• mysignal’event (mysignal changed value)• mysignal’high (highest value of mysignal’s type)• mysignal’low• Many other attributes

– http://www.cs.umbc.edu/help/VHDL/summary.html

Pre-defined VHDL attributes

Page 49: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

49 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Signal: global to file• Variable: local to process

Singal vs Varible scope

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.cs.umbc.edu/help/VHDL/summary.htmlhttp://www.vhdl-online.de/tutorial/

My_process_1 : process (B,C,Y) Begin A <= B + C; Z <= Y + C; End My_process_1;

My_process_2 : process (B,X,Y,Ans1) Begin X <= Z + 1; Ans <= B + Y; End My_process_2;

Page 50: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

50 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Signal: global to file• Variable: local to process

Singal vs Varible scope

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.cs.umbc.edu/help/VHDL/summary.htmlhttp://www.vhdl-online.de/tutorial/

My_process_1 : process (B,C,Y) Begin A <= B + C; varZ <= Y + C; End My_process_1;

My_process_2 : process (B,X,Y,Ans1) Begin X <= varZ + 1; Ans <= B + Y; End My_process_2;

Each varZ are local to their process. Completely independent

Page 51: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

51 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Arrays and Records

• Arrays: Group signals of the same type together

• Records: Group signal of different types together

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

Page 52: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

52 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Array Example (Delay Shift Register)

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

flag_in flag_1 flag_2 flag_3 flag_out

BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN flag_1 <= flag_in; flag_2 <= flag_1; flag_3 <= flag_2; END IF; End My_process_1; flag_out <= flag_3END;

Page 53: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

53 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Array Example (Delay Shift Register)flag_in flag_1 flag_20 flag_out

BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN flag_reg(flag_reg'high downto 0) <= flag_reg(flag_reg'high-1 downto 0) & flag_in; END IF; End My_process_1; flag_out <= flag_reg(flag_reg'high);END;

type flag_reg_array is array (DELAY-1 downto 0) of std_logic;signal flag_reg : flag_reg_array;

Page 54: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

54 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Array Example (Delay Shift Register)

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

flag_in flag_1 flag_20 flag_out

BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN flag_1 <= flag_in; flag_2 <= flag_1;

flag_20 <= flag_19; END IF; End My_process_1; flag_out <= flag_20END;

Page 55: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

55 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Array Example (Delay Shift Register)

flag_reg(flag_reg'high downto 0)<= flag_reg(flag_reg'high-1 downto 0) & flag_in;

flag_in flag(0) flag(1) flag(2) flag_out

0 0 11

flag_in flag(0) flag(1) flag(2) flag_out

1 0 0

flag_in flag(0) flag(1) flag(2) flag_out

0 0 11

Page 56: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

56 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Array Example (Delay Shift Register)

VHDL on-line tutorials:http://www.seas.upenn.edu/~ese201/vhdl/vhdl_primer.htmlhttp://www.vhdl-online.de/tutorial/

flag_in flag_0 flag_1 flag_2 flag_out

BEGIN My_process_1 : process (clk) Begin IF (clk’event and clk = ‘1’) THEN flag_1 <= flag_in; flag_2 <= flag_1; flag_3 <= flag_2; END IF; End My_process_1; flag_out <= flag_3END;

Page 57: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

57 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Finite State Machine (FSM) Design

• Model of computation• High level application example (Networking)• Two major types

– Moore– Mealy

• Detailed view of application example

Page 58: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

58 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Finite State Machines

• What types of applications are they well suited– Streaming pattern recognition– Sequential event based control logic

• Allow hardware designer to reason about things in small pieces

Page 59: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

59 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

Page 60: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

60 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

IP src

Page 61: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

61 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

IP dest IP src

Page 62: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

62 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

src port IP dest IP src

Page 63: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

63 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

dest port src port IP dest IP src

Page 64: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

64 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

length dest port src port IP dest IP src

Page 65: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

65 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

Data 1 length dest port src port IP dest IP src

Page 66: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

66 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

Data 2 Data 1 length dest port src port IP dest IP src

Page 67: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

67 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM

Data 3 Data 2 Data 1 length dest port src port IP dest

Page 68: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

68 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM Send Alert

Data 3 Data 2 Data 1 length dest port src port IP dest

Page 69: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

69 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM Send Alert

r o C length dest port src port IP dest

Page 70: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

70 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM Send Alert

n r o C length dest port src port

Page 71: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

71 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Alert!!

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM Send Alert

! n r o C length dest port

Page 72: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

72 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)

• Process UDP packet headers (event driven)• Detect patterns in payload (e.g. “Corn”)• Modify payload based on header information

FSM Send Alert

Modify Packet

! n r o C length dest port

Page 73: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

73 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore and Mealy FSMs

• Moore: Output is only a function of the current state

• Mealy: Output is a function of the current state and input (“Mealy is more”)

Page 74: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

74 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

State Name

FSM output

Page 75: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

75 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Where to go on a given input

Page 76: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

76 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 1

Output: 0

Page 77: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

77 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 11011

1 0 1

0

100

1

Output: 00010

Page 78: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

78 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1010”

Start(0)

0(0)

0

1 10(0)

1

010(0)

0

1010(1)

1

1

01

10

0

Page 79: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

79 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Mealy FSM

• Moore: Output a function of the current state, and input

• Example detect every occurrence of “1011”

1 11 011 1011

State Name

Page 80: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

80 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Mealy FSM

1/0

0/0 1 11 011 1011

Inputoutput

• Moore: Output a function of the current state, and input

• Example detect every occurrence of “1011”

Start

Page 81: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

81 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Mealy FSM

1/0

0/0 1 11 011 1011

• Mealy: Output a function of the current state, and input

• Example detect every occurrence of “1011”

1/0 0/0

1/1

0/0

0/0Start1/0

Page 82: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

82 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Let:– X be inputs– Z be outputs– State(t) be the state of the FSM at the current time– State(t+1) be the next state of the FSM– δ be the transition between states

• State(t+1) = δ(State(t), X)• Output

– Moore: Z(State(t))– Mealy: Z(State(t), X)

FSM: General Circuit Architecture

x=1/z=0

0/1 S1 S2

1/0

0/0

z=0

Page 83: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

83 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

FSM: General Circuit Architecture

Combinational Logic

Inputs: XZ(State(t))Z(State(t),X)

Outputs

Moore

Mealy

State Storage

DFF

DFF

State(t) State(t+1) =δ(State(t), X)

Next State

Page 84: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

84 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL: IF and CASE constructs

• IF THEN ELSE can be mapped to a 2:1 Multiplexer (Mux)

2:1Mux

sel = b“0”

4

44

x”C”

x”D”

in_0

in_1x”C”

IF (sel = ‘0’) THEN out_1 <= in_0;ELSE out_1 <= in_1END IF;

out_1

Page 85: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

85 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

VHDL: IF and CASE constructs

4:1Mux

sel = b“10”

4

4

4

4

2

4

x”C”

x”D”

x”2”

x”7”

in_0

in_1

in_2

in_3

x”7”

• Mapping a CASE statement to a 4:1 Mux

out_1

CASE sel is WHEN “00” => out_1 <= in_0;WHEN “01” => out_1 <= in_1;WHEN “10” => out_1 <= in_2;WHEN “11” => out_1 <= in_3WHEN OTHERS => out_1 <= in_0;END CASE; Why do we need others here?

Page 86: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

86 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

CASE state is WHEN state_1 => IF (sel = ‘0’) THEN mux_out <= ‘1’; ELSE mux_out <= ‘0’; END IF;WHEN state_11 => -- similar codeWHEN state_011 => IF (sel = ‘0’) THEN mux_out <= ‘0’; ELSE mux_out <= ‘1’;WHEN state_1011 => --similar codeEND CASE;

VHDL: IF and CASE constructs

State = {state_1, state_11, state_011, state_1011} = {“00”, ”01”, ”10”, ”11”}

Enumerated Type

• Mapping a CASE statement to a 1:4 Decoder

1:4Decoder

2

out_0

out_1

out_2

out_3

state“10”

on2:1Mux

off2:1Mux

off2:1Mux

off2:1Mux

Page 87: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

87 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

CASE state is WHEN state_1 => IF (sel = ‘0’) THEN mux_out <= ‘1’; ELSE mux_out <= ‘0’; END IF;WHEN state_11 => -- similar codeWHEN state_011 => IF (sel = ‘0’) THEN mux_out <= ‘0’; ELSE mux_out <= ‘1’;WHEN state_1011 => --similar codeEND CASE;

VHDL: IF and CASE constructs

State = {state_1, state_11, state_011, state_1011} = {“00”, ”01”, ”10”, ”11”}

Enumerated Type

• Mapping a CASE statement to a 1:4 Decoder

1:4Decoder

2

out_0

out_1

out_2

out_3

state“00”

on2:1Mux

off2:1Mux

off2:1Mux

off2:1Mux

Page 88: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

88 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

FSM: General Circuit Architecture

Combinational Logic

Inputs: XZ(State(t))Z(State(t),X)

Outputs

Moore

Mealy

State Storage

DFF

DFF

State(t) State(t+1) =δ(State(t), X)

Next State

Page 89: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

89 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

-- Store the “state”Update_State: process(clk)begin if(clk’event and clk=‘1’) then state <= next_state; end if;end process Update_State;

VHDL for Mealy (“1011”) Example

DFF

next_statestate

Page 90: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

90 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

-- Compute combinational logicCombinational: process(x, state)begin case state is when state_1 => if(x = ‘0’) then z <= ‘0‘; next_state <= state_1; else z <= ‘0‘; next_state <= state_11; end if; when state_11 => if(x = ‘0’) then z <= ‘0’; next_state <= state_1; else z <= ‘0‘; next_state <= state_011 ; end if;

VHDL for Mealy (“1011”) Example

1/0

0/0 1 11 011 1011

1/0 0/0

1/1

0/0

0/0Start1/0

Compute output

Compute next_state

Page 91: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

91 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

when state_011 => if(x = ‘0’) then z <= ‘0‘; next_state <= state_1011; else z <= ‘0‘; next_state <= state_011; end if; when state_1011 => if(x = ‘0’) then z <= ‘0’; next_state <= state_1; else z <= ‘1‘; next_state <= state_11; end if; end case;end process Combinational;

VHDL for Mealy (“1011”) Example

1/0

1 11 011 1011

1/0 0/0

1/1

0/0

0/0 1/0

Page 92: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

92 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Network Processing Example: UDP

• UDP – User Datagram Protocol– Popular protocol for sending data over the internet

(TCP is popular another protocol)– Typical encapsulated within IP (Internet Protocol)

• UDP/IP– Gives no guarantee of delivery

• Relies on application layer to implement reliability• Unlike TCP which has reliably delivery build in.

• Reference for more info on IP and UDP details– http://www.freesoft.org/CIE/

• RCFs• Course

Page 93: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

93 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

UDP/IP Packet Format

Ver IHL TOS Total Length

Identification flagsfragment offset

TTL Protocol Header Checksum

Source IP Address

Destination IP Address

PaddingOptions

Note: flags 3 bits

32-bits

IP Header

Source Port Destination Port

Length Checksum

UDP Header

Byte1

UDP length (bytes) =UDP header+payload

0 31

Byte2 Byte3 Byte4

UDP Protocol = 17

Payload

Page 94: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

94 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Raise an alert signal when the pattern “corn!” is detected

• Return the number of times “corn!” is detected– Place count value as the last byte of the payload

Example: Network Processing Tasks

Page 95: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

95 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Streaming Network application (MP1)• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

FSM Send Alert

Modify Packet

! n r o C length dest port

Page 96: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

96 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Length

Draw out logic, and data flow!!!

Page 97: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

97 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Length

Page 98: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

98 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Alert signal when the pattern “corn!” is detected– Z = {Alert}

Alert FSM Design

“c”/0

c o r n

“o”/0 “r”/0

Start

!

“n”/0

“!”/1

others/0

others/0

others/0

others/0

Page 99: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

99 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Alert signal when the pattern “corn!” is detected• Output Packet’s Length

– Z = {Alert,length_vld,pack_length}– X = {vld,input} : Note “?” is don’t care

Alert FSM Design

“c”/0

c o r n

“o”/0 “r”/0

Start

!

“n”/0

“!”/1

others/0

others/0

others/0

others/0

Page 100: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

100 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Alert signal when the pattern “corn!” is detected• Output Packet’s Length

– Z = {Alert,length_vld,pack_length}– X = {vld,input} : Note “?” is don’t care

Alert FSM Design

1,“c”/0,0,0

c o r n

1,“o”/0,0,0 1,“r”/0,0,0

Start

!

1,“n”/0,0,0

1,“!”/1,0,0

1,others/0,0,0

1,others/0,0,0

1,others/0,0,0

1,others/0,0,0

StartIP

IPH_2

1,”?”/0,0,0

IPH_5

1,”?”/0,0,0UDPports

UDPlength

1,”?”/0,0,0

1,”?”/0,1,length

Page 101: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

101 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Length

Page 102: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

102 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

• Register & Counter Components• Design of Manager

Register & Counter Manager

Page 103: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

103 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Register and Counter Components

4:1Mux

DFF8 count

+ 8 8

Counter

inc_val

0set_value

sel(reset,load,inc)

resetloadinc

3:1Mux DFF

8 reg_val8

Register

0set_value

sel(reset,load)

resetload

Page 104: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

104 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Practice: Write VHDL(process for each)

4:1Mux

DFF8 count

+ 8 8

Counter

inc_val

0set_value

sel(reset,load,inc)

resetloadinc

3:1Mux DFF

8 reg_val8

Register

0set_value

sel(reset,load)

resetload

CASE sel is WHEN “00” | “11”=> out_1 <= in_0;WHEN “01” => out_1 <= in_1;

WHEN OTHERS => out_1 <= in_0;END CASE;

Name : process(clk)begin if(clk’event and clk=‘1’) then logic here end if;end process Name

Page 105: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

105 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Register VHDL

3:1Mux DFF

8 reg_val8

Register

0set_value

sel(reset,load)

reset

load

Name : process(clk)begin if(clk’event and clk=‘1’) then CASE reset&load is WHEN “10” | “11” => reg_val <= 0; WHEN “01” => reg_val <= set_value; WHEN OTHERS => reg_val <= reg_val; END CASE; end if;end process Name

Page 106: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

106 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Register VHDL

3:1Mux DFF

8 reg_val8

Register

0set_value

sel(reset,load)

reset

load

Name : process(clk)begin if(clk’event and clk=‘1’) then CASE sel is WHEN “10” | “11” => reg_val <= 0; WHEN “01” => reg_val <= set_value; WHEN OTHERS => reg_val <= reg_val; END CASE; end if;end process Name

sel <= reset&load;

Page 107: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

107 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Counter VHDLName : process(clk)begin if(clk’event and clk=‘1’) then CASE reset&load&inc is WHEN “100” | “101” | “110”| “111” => count <= 0; WHEN “010” | “011” => count <= set_value; WHEN “001” => count <= count + inc_val; WHEN OTHERS => count <= count; END CASE; end if;end process Name

4:1Mux

DFF8 count

+ 8 8

Counter

inc_val

0set_value

sel(reset,load,inc)

resetloadinc

Page 108: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

108 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Counter VHDLName : process(clk)begin if(clk’event and clk=‘1’) then CASE sel is WHEN “100” | “101” | “110”| “111” => count <= 0; WHEN “010” | “011” => count <= set_value; WHEN “001” => count <= count + inc_val; WHEN OTHERS => count <= count; END CASE; end if;end process Namesel <= reset&load&inc;

4:1Mux

DFF8 count

+ 8 8

Counter

inc_val

0set_value

sel(reset,load,inc)

resetloadinc

Page 109: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

109 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Length

Page 110: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

110 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Register and Counter Manger

Alert

Packet_Length

length_vld

corn_cnt

Packet_Length_reg

Counter

reset

inc

resetload

Register

0set_value0

set_value

load reset

inc_val1

Counter

inc

resetload0

set_value0

inc_val1position

Valid_data

Page 111: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

111 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Lengthlength_vld

reset

data_vlddata

reset

Packet_length

Page 112: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

112 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Lengthlength_vld

reset

data_vlddata

reset

Packet_length

Page 113: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

113 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Output sel

2:1MuxData_from_input

corn_cnt1

0

Data_to_output

sel

Comparator

Packet_length

Position

Comparator outputs 1 if inputs match

Page 114: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

114 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Output sel: VHDL

2:1MuxData_from_input

corn_cnt1

0

Data_to_output

sel

Comparator

Packet_length

Position

Comparator outputs 1 if inputs match

NOT in a process!Data_to_output <= corn_cnt when (Packet_length = Position) else Data_from_input

Page 115: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

115 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Architecture

Alert FSM

Alert

Register & CounterManagement

Packet InputProcess

Packet OutputProcess

2:1Mux

corn_cnt

outputsel

• Detect patterns in payload (e.g. “Corn!”)• Place the number of detections in last byte

of payload

position

Packet Lengthlength_vld

reset

data_vlddata

reset

Packet_length

Page 116: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

116 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Multiple Characters per Clock

• Network input stream typically 32-bit words– 4 8-bit characters per word.

• corn! Example

c o r n

! ? ? ?

Word 1

Word 2

cornStart

!???

corn/0

others/0

!???/1

Corn! on a word boundary

Page 117: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

117 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Multiple Characters per Clock

• Network input stream typically 32-bit words– 4 8-bit characters per word.

• corn! Example

? c o r

n ! ? ?

Word 1

Word 2

?corStart

n!??

?cor/0

others/0

n!??/1

Corn! offset by 1 byte

Page 118: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

118 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Multiple Characters per Clock

• Network input stream typically 32-bit words– 4 8-bit characters per word.

• corn! Example

? ? c o

r n ! ?

Word 1

Word 2

??coStart

rn!?

??co/0

others/0

rn!/1

Corn! offset by 2 bytes

Page 119: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

119 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Multiple Characters per Clock

• Network input stream typically 32-bit words– 4 8-bit characters per word.

• corn! Example

? ? ? c

o r n !

Word 1

Word 2

???cStart

orn!

???c/0

others/0

orn!/1

Corn! offset by 3 bytes

Page 120: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

120 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Multiple Characters per Clock

• Network input stream typically 32-bit words– 4 8-bit characters per word.

• corn! Example

c o r n

! ? ? ?

Word 2

Word 3

cornStart

!???

corn/0

others/0

!???/1

Corn! offset by 4 bytes

Page 121: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

121 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

Start

Page 122: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

122 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1

??co rn!?

??co/0

others/0

rn!/1

???c orn!

???c/0

others/0

orn!/1

Start

Page 123: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

123 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1

??co rn!?

??co/0

others/0

rn!/1

???c orn!

???c/0

others/0

orn!/1

Start

Page 124: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

124 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

Page 125: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

125 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 126: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

126 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 127: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

127 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 128: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

128 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 129: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

129 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 130: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

130 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 131: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

131 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 132: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

132 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 133: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

133 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 134: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

134 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify Alert FSM for Multiple characters

corn !???

corn/0

others/0

!???/1

?cor n!??

?cor/0

others/0

n!??/1??co rn!?

??co/0

others/0

rn!?/1

???c orn!

???c/0

others/0

orn!/1

Start

Start

StartStart

c b c o

r n ! c

o r n !

z c o r

Page 135: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

135 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify corn! counter for Multiple characters

Alert

corn_cntCounter

reset

inc

reset

load0

set_value0

inc_val1

Page 136: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

136 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify corn! counter for Multiple characters

Alt_0

corn_cntCounter

reset

inc

reset

load0

set_value0

inc_val1

Alt_1

Alt_2

Alt_3

Page 137: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

137 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify corn! counter for Multiple characters

Alt_0

corn_cntCounter

reset

inc

reset

load0

set_value0

inc_val1

Alt_1

Alt_2

Alt_3

OR

Page 138: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

138 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify corn! counter for Multiple charactersAlt_0

corn_cntCounter

reset

inc

reset

load0

set_value0

inc_val

Alt_1

Alt_2

Alt_3

OR

4:1Mux

sel(Alt0,Alt1, Alt2,Alt3)

4321

NOT in a process!Alt_merge <= Alt0 & Alt1 & Alt2 & Alt3;inc_val <= 4 when (Alt_merge = “1111”) 3 when (Alt_merge = “0111” or Alt_merge = “1011” ...) 2 when (Alt_merge = “0011” or Alt_merge = “0110” ...)

else 0

Page 139: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

139 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Modify corn! counter for Multiple characters

Alt_0

corn_cntCounter

reset

inc

reset

load0

set_value0

inc_val1

Alt_1

Alt_2

Alt_3

OR

Page 140: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

140 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

In progress Slides

Page 141: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

141 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

State Name

FSM output

Page 142: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

142 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Where to go on a given input

Page 143: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

143 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 1

Page 144: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

144 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

1

Input: 11

0

Page 145: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

145 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

1 0

Input: 011

01

0

Page 146: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

146 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 1011

1 0 1

00

1

Page 147: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

147 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 01011

1 0 1

0

00

1

Page 148: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

148 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example detect every occurrence of “1011”

Start(0)

1(0)

11(0)

011(0)

1011(1)

1

0

Input: 11011

1 0 1

0

100

1

Page 149: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

149 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example: vending machine– Events (assume all items cost 1 coin):

• Insert Coin• Make selection

Start(0)

Coin(0)

Insert Coin

Snack(1)

Makeselection

Insert Coin

Makeselection

Return(0)

Insert Coin

Makeselection

Page 150: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

150 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example: vending machine– Events (assume all items cost 1 coin):

• Insert Coin• Make selection• Return Coin

Start(0)

Coin(0)

Insert Coin

Snack(1)

Makeselection

Insert Coin

Makeselection

Return(0)

ReturnCoin

Page 151: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

151 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example: vending machine– Events (assume all items cost 1 coin):

• Insert Coin• Make selection• Return Coin

Start(0)

Coin(0)

Insert Coin

Snack(1)

Makeselection

Insert Coin

Makeselection

Return(0)

ReturnCoin

MakeselectionReturn

coin

Insert Coin

ReturnCoin

Page 152: 1 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames) CPRE 583 Reconfigurable Computing (VHDL Overview

152 - CPRE 583 (Reconfigurable Computing): Reconfigurable Computing HW, VHDL 2 Iowa State University (Ames)

Moore FSM

• Moore: Output is only a function of the current state

• Example: vending machine– Events (assume all items cost 1 coin):

• Insert Coin• Make selection

Start(0)

Coin(0)

Insert Coin

Snack(1)

Makeselection

Insert Coin

Makeselection

Return(0)

Insert Coin

Makeselection

Make Coin a snack option