Docsity

Data Type and Attributes: Lexical Elements - Slide Notes for Exam | ECE 4514, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
1
Martin 2003ECE 4514 1
Review
zConcurrent statements
zConditional and selected signal
assignments
• Cannot be placed inside a process
• Equivalent to some process
zAssert statement
• Debugging
9/22/2003 2
VHDL in Action
Chapter 3
Chapter 5, Section 5.1.4
Data Types and Attributes
Martin 2003ECE 4514 3
This week
zBasic Data types
zObject declarations
zData type attributes
Martin 2003ECE 4514 4
Lexical Elements
zElements that cannot be divided
by spaces, tabs, <CR>s
• Identifiers
• Comments
• Delimiters (<=)
• Literals
Martin 2003ECE 4514 5
Literals
zCharacter Literal
• '1' 'A'
zCharacter String Literal
• "This is a string."
zBit String Literal
• B"00110110"
• X"36"
• B"0011_0110"
Martin 2003ECE 4514 6
More Literals
zAbstract Literal
• Integer
•21
• 2134_5641
•2E10
• Real
•2.0
•3.2E4
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Data Type and Attributes: Lexical Elements - Slide Notes for Exam | ECE 4514 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

ECE 4514 Martin 2003 1

Review

z Concurrent statements

z Conditional and selected signal

assignments

• Cannot be placed inside a process

• Equivalent to some process

z Assert statement

• Debugging

9/22/2003 2

VHDL in Action

Chapter 3

Chapter 5, Section 5.1.

Data Types and Attributes

ECE 4514 Martin 2003 3

This week

z Basic Data types

z Object declarations

z Data type attributes

ECE 4514 Martin 2003 4

Lexical Elements

z Elements that cannot be divided

by spaces, tabs, s

• Identifiers

• Comments

• Delimiters (<=)

• Literals

Literals

z Character Literal

• '1' 'A'

z Character String Literal

• "This is a string."

z Bit String Literal

• B"00110110"

• X"36"

• B"0011_0110"

More Literals

z Abstract Literal

• Integer

• 2134_

• 2E

• Real

• 3.2E

ECE 4514 Martin 2003 7

Data Types

z Scalar

  • values have only one component
  • example: integers and naturals z Composite
  • types are complex objects
  • example: arrays or records z Access
  • types that provide access to other types z File
  • types that provide access to files

ECE 4514 Martin 2003 8

Scalar Types

z Enumeration (discrete)

z Integer (discrete, numeric)

z Physical (numeric)

z Floating point or real (numeric)

TYPES

ECE 4514 Martin 2003 9

Predefined

Enumeration Types

z type Bit is ('0', '1' ); z type Boolean is (FALSE, TRUE); z type Character is (NUL, …, 'A', 'B', …, 'a', 'b', …, DEL)

ECE 4514 Martin 2003 10

User Defined

Enumeration Types

type COLOR is (Red, Orange, Yellow, Green, Blue);

type STATE is ( S1, S2, S3);

type STD_ULOGIC is ('U', 'X', ' 0 ', ' 1 ', 'Z', 'W', 'L', 'H', '-');

type HORSE is ( Mare, Stallion, Gelding, Colt, Filly );

SCALAR TYPES

Enumeration Data Types

type COLOR is (Red , Orange , Yellow , Green , Blue) ;

Red Orange Yellow Green Blue 0 1 2 3 4 < Orange EXAMPLE: signal MARKER : Color ; -- in declaration signal CAR : Color := Yellow ;


MARKER <= Blue ; -- within the body of an architecture

SCALAR TYPES

Subtype

z Constrains the values of a type

to be in the subtype range.

z Does not define a new type

z All subtypes of a given type

have the same base type

ECE 4514 Martin 2003 19

Composite Types

z An object that holds more than one

value: ARRAYS

z Predefined unconstrained array

types:

type Bit_Vector is array (Natural range <>) of Bit; type String is array (Positive range <>) of Character; Using these predefined types: signal DATA_BUS: Bit_Vector(15 downto 0); signal INST_OP: Bit_Vector( 5 to 7);

ECE 4514 Martin 2003 20

User Defined

Composites

z Constrained composites

type BCD_BUS is array (3 downto 0) of Bit; type REGFILE is array (5 downto 0) of Bit_Vector (7 downto 0); type ARRAY2D is array (3 downto 0 , 8 downto 0) of Bit;

z Unconstrained composite

type ARRAY2DB is array (Natural range <>, Natural range <>) of Bit;

COMPOSITE TYPES

ECE 4514 Martin 2003 21

Composite Values

z Initializing and assigning

values to composites:

signal DATA_BUS: Bit_Vector(31 downto 0) := B"0111_0110_0101_0100_0011_0010_0001_0000"; signal ADDR_BUS: Bit_Vector(15 downto 0) := X" 7654 ";

ADDR_BUS <= DATA_BUS(20 downto 5);

What is the value of data_bus(3)?

COMPOSITE TYPES

ECE 4514 Martin 2003 22

More Composite Values

z Initializing and assigning

values to array composites:

type REGISTER is array(2 downto 0) of Bit_Vector(7 downto 0);

signal F: REGISTER := (X" 12 ", X"DF",X"9A");

F(2) <= B"1010_0101";

What is the value of F(0)?

COMPOSITE TYPES

Aggregates

z A structured collection of values used to initialize a signal or variable with composite type

Example: A two-dimensional array of characters A B C C

type CHAR2D is array (0 to 1,0 to 1) of Character; variable CM1:CHAR2D := (('A','B'),('C','C')); -- positional

variable CM2:CHAR2D := (1=>(0|1=>'C'), 0=>(1=>'B', 0=>'A')); -- associative

COMPOSITE TYPES

Composites with

Enumeration Indexes

type COLOR is (Red, Orange, Yellow, Green,

Blue);

type COLOR_COUNT is array (COLOR range

<>) of Natural;

signal SUBPRISM : COLOR_COUNT (Orange

to Green) := (15, 20, 30);

SUBPRISM(Orange) <= 32;

SUBPRISM(Yellow) <= 3;

COMPOSITE TYPES

ECE 4514 Martin 2003 25

Composites Examples

type COLOR is (Red, Orange, Yellow, Green, Blue);

type ARRAY_OF_COLORS is array (Natural range

<>) of COLOR;

signal RAINBOW : ARRAY_OF_COLORS( 3 to 5 );

RAINBOW(3) <= Green;

RAINBOW(4 to 5) <= (Red, Blue);

COMPOSITE TYPES

ECE 4514 Martin 2003 26

Unary Operator Table

type MVL4 is ('X', '0', '1', 'Z') ;

type MVL4_TAB1D is array (MVL4) of MVL4;

constant INV: MVL4_TAB1D := ('X', '1', '0', 'X');

variable A,B: MVL4;

A := INV(B);

ECE 4514 Martin 2003 27

Binary Operator Table

type MVL4 is ( 'X', '0', '1', 'Z' );

type MVL4D_TAB2D is array (MVL4, MVL4) of MVL4 ;

constant AND_MVL4:MVL4_TAB2D :=

(( ' X ', ' 0 ', ' X ', ' X ' ) , ( ' 0 ', ' 0 ', ' 0 ' , ' 0 ' ) ,

( ' X ', ' 0 ', ' 1 ', ' X ' ) , ( ' X ', ' 0 ', ' X ', ' X ' )) ;

signal X,Y,Z : MVL4 ;

Z <= AND_MVL4(X,Y) ;

ECE 4514 Martin 2003 28

Records

z Composites with heterogeneous

elements

z Similar to C/C++ structures

type MONTH_NAME is (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC); type DATE is record DAY: Positive range 1 to 31; MONTH: MONTH_NAME; YEAR: Natural range 0 to 9999; end record;

COMPOSITE TYPES

Records (cont’d)

z Using the Date record:

signal BIRTHDAY, HOLIDAY: DATE;

BIRTHDAY <= (16, AUG, 1943);

HOLIDAY <= (25, DEC, 2000);

BIRTHDAY.DAY <= 9;

BIRTHDAY.MONTH <= JUN;

BIRTHDAY.YEAR <= 2000;

COMPOSITE TYPES

Access Types

z Also known as pointer types

z Provide a means to access

dynamic objects (objects which

are created and destroyed

during simulation).

z Not used in this course

ECE 4514 Martin 2003 37

Data Type Attribute

z 'right

A := COLOR'right;

Type_name‘right Predefined constant that specifies

the right-most data value in a list of values_._

ECE 4514 Martin 2003 38

Data Type Attribute

z 'low

A := COLOR'low;

Type_name'low Predefined constant that specifies

the value associated with the lowest position number in a list of values_._

ECE 4514 Martin 2003 39

Data Type Attribute

z 'high

A := COLOR'high;

Type_name'high Predefined constant that specifies

the value associated with the highest position number in a range_._

ECE 4514 Martin 2003 40

Subtype Examples

type COLOR is (Red, Orange, Yellow, Green, Blue); subtype LONGWAVE is COLOR range COLOR'left to Yellow; subtype SW is COLOR range COLOR'right downto Orange;

A := SW'right; -- What is the value of A? B := SW'high; -- What is the value of B? C:= SW'val(2); -- What is the value of C? D := SW'pos(Green); -- What is the value of D?

More Attributes

z 'event

signal CLK : Bit := '0';

SIG_NAME ' event Function that returns a Boolean value

that is TRUE if there is an event on signal SIG_NAME during the current simulation cycle_._

SIGNAL ATTRIBUTES

Attribute Example

z Determining if a rising edge in CLK has

occurred in a process:

DFFAC: process ( CLK, RESET ) begin if RESET = ‘1’ then Q <= ‘0’; elsif CLK'event and CLK = '1' then -- if CLK just changed value, and is now '1', then Q <= D; end if; end process;

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 43

More Useful Attributes

z 'active

signal CLK : Bit := '0';

assert not CLK'active

report "note: CLK has just been assigned";

SIG_NAME'active Function that returns a Boolean value that

is TRUE if there is a transaction on signal SIG_NAME during the current simulation cycle.

Note: this assignment is a transaction but may not be an event.

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 44

More Useful Attributes

z 'stable(n)

SIG_NAME'stable(n) A signal of type Boolean that is TRUE only

if signal SIG_NAME has NOT changed value (has no events) for time n.

S

S'stable(3 ns)

1 0 T F

Time (ns)

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 45

Relationship Between

'stable and 'event

Time (ns)

S

1 0

S'stable

T F

S'event T F

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 46

D Flip-Flop Timing

Requirements

z SETUP TIME (SUT) - D input must be

stable for 10 ns prior to the rising

edge of clock.

z HOLD TIME (HT) - D input must be

stable for 2 ns after the rising edge

of clock

z MINIMUM PULSE WIDTH (MPW)- The

clock must be high for at least 8 ns.

D Flip Flop Timing

Requirements

SUT HT

MPW

CLK

D

Timing Assertion

Development

z Develop an expression that is

true when the error occurs.

z Logically negate the expression

to obtain the required assert

conditon

z DeMorgan's Theorem may be

useful.

ECE 4514 Martin 2003 55

Attributes for Signals of

Array Type

z 'right

signal DBUS : Bit_Vector ( 5 downto 0);

DBUS(DBUS'right) <= '0'; -- which value

-- is assigned?

SIG_NAME'right Returns the right most value of

the index range of SIG_NAME.

Attributes for Signals of

Array Type

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 56

z 'high

signal DBUS : Bit_Vector ( 5 downto 0);

DBUS(0) <= DBUS( DBUS'high );

SIG_NAME'high Returns the upper bound of

index range of SIG_NAME.

Attributes for Signals of

Array Type

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 57

z 'low

signal DBUS : Bit_Vector ( 5 downto 0);

for I in DBUS'high downto DBUS'low

loop

SIG_NAME'low Returns the lower bound of

the index range of SIG_NAME.

Attributes for Signals of

Array Type

SIGNAL ATTRIBUTES

ECE 4514 Martin 2003 58

z 'ascending

signal DBUS: Bit_vector ( 0 to 5);

if DBUS'ascending then for I in DBUS'left to DBUS'right loop


end loop;

end if;

SIG_NAME'ascending Returns a Boolean

TRUE if the declaration of SIG_NAME is an ascending range.

Attributes for Signals of

Array Type

SIGNAL ATTRIBUTES

z 'length

signal DBUS : Bit_vector ( 5 downto 3);

for i in DBUS'length-1 downto 0

loop

SIG_NAME'length Returns the number of

elements in array SIG_NAME.

Attributes for Signals of

Array Type

SIGNAL ATTRIBUTES

Signal Attributes

z 'last_event

signal CLK : Bit := '0';

if CLK'last_event < 100 ns then

end if;

SIGNAL ATTRIBUTES

SIG_NAME'last_event

Returns the TIME since the last event on SIG_NAME occurred.

ECE 4514 Martin 2003 61

Signal Attributes

z 'last_active

signal CLK : Bit := '0';

if CLK'last_active > CLK'last_event then assert false report " CLK assigned the same value at least twice";

SIGNAL ATTRIBUTES

SIG_NAME'last_active

Returns the TIME since the last transaction on SIG_NAME_._

ECE 4514 Martin 2003 62

Signal Attributes

z 'last_value

signal TRAFFIC : COLOR := red;

process begin

if TRAFFIC'last_value = red and TRAFFIC = green

then ;

SIGNAL ATTRIBUTES

SIG_NAME'last_value -- Returns the previous value

assigned to SIG_NAME_._

More More Attributes

z SIG'leftof / SIG'rightof

z SIG'succ / SIG'pred

z SIG'pos

z SIG'val

z SIG'range / SIG'reverse_range

• for i in SIG'range loop

SIGNAL ATTRIBUTES

Is that all?

z No. Plenty more attributes.

z Plus: user-defined attributes.

ATTRIBUTES