VHDL: Programming By Example, Fourth Edition

Chapter 5: Subprograms and Packages

In this chapter, subprograms and packages are discussed. Subprograms consist of procedures and functions used to perform common operations. Packages are mechanisms that allow sharing data among entities. Subprograms, types, and component declarations are the tools to build designs with, and packages are the toolboxes.

Subprograms

Subprograms consist of procedures and functions. A procedure can return more than one argument; a function always returns just one. In a function, all parameters are input parameters; a procedure can have input parameters, output parameters, and inout parameters.

There are two versions of procedures and functions: a concurrent procedure and concurrent function, and a sequential procedure and sequential function. The concurrent procedure and function exist outside of a process statement or another subprogram; the sequential function and procedure exist only in a process statement or another subprogram statement.

All statements inside of a subprogram are sequential. The same statements that exist in a process statement can be used in a subprogram, including WAIT statements.

A procedure exists as a separate statement in an architecture or process; a function is usually used in an assignment statement or expression.

Function

The following example is a function that takes in an array of the std_logic type (described in Chapter 9, Synthesis and Appendix A, Standard Logic Package ) and returns an integer value. The integer value represents the numeric value of all of the bits treated as a binary number:

<b class="bold">USE LIBRARY IEEE;</b><b class="bold">USE IEEE.std_logic_1164.ALL;</b><b class="bold">PACKAGE num_types IS</b><b class="bold"> TYPE log8 IS ARRAY(0 TO...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: DC-DC Converter Chips
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.