1 / 60

Subprograms

Subprograms. Subprograms. Similar to subprograms found in other languages Allow repeatedly used code to be referenced multiple times without rewriting Break down large blocks of code into small, more manageable parts VHDL provides functions and procedures. Subprograms (cont’d).

Download Presentation

Subprograms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Subprograms

  2. Subprograms • Similar to subprograms found in other languages • Allow repeatedly used code to be referenced multiple times without rewriting • Break down large blocks of code into small, more manageable parts • VHDL provides functions and procedures

  3. Subprograms (cont’d) • Contain sequential statements similar to processes • May declare local variables, constants • Executed when called from a sequential statement. • Local Variables are re-initialized every time a subprogram is called. • Parameters of calling routine are known as actuals, while the parameters of the declared subprogram are known as formals. • Up level referencing to higher level variables and signals is allowed. • Recursive calls by functions and procedures are allowed • Attributes of signals cannot be accessed within subprograms

  4. Functions • Produce a single return value • Called by expressions • Cannot modify the parameters passed to them • Require a RETURN statement FUNCTION add_bits (a, b : IN BIT) RETURN BIT IS BEGIN -- functions cannot return multiple values RETURN (a XOR b); END add_bits; FUNCTION add_bits2 (a, b : IN BIT) RETURN BIT IS VARIABLE result : BIT; -- variable is local to function BEGIN result := (a XOR b); RETURN result; -- the two functions are equivalent END add_bits2;

  5. Functions x

  6. Functions

  7. Functions

  8. Functions

  9. Functions

  10. Example of a Function

  11. Example of a Function (cont)

  12. Functions • Functions must be called by other statements • Parameters use positional association ARCHITECTURE behavior OF adder IS BEGIN PROCESS (enable, x, y) BEGIN IF (enable = '1') THEN result <= add_bits(x, y); carry <= x AND y; ELSE carry, result <= '0'; END PROCESS; END behavior; FUNCTION add_bits (a, b : IN BIT)

  13. Procedures

  14. Procedures (cont)

  15. Procedures (cont)

  16. Example of a Procedure

  17. Another Example of a Procedure

  18. Summary on Sequential Statements

  19. Procedures • May produce multiple output values • Are invoked by statements • May modify the parameters PROCEDURE add_bits3 (SIGNAL a, b, en : IN BIT; SIGNAL temp_result, temp_carry : OUT BIT) IS BEGIN -- procedures can return multiple values temp_result <= (a XOR b) AND en; temp_carry <= a AND b AND en; END add_bits3; • Do not require a RETURN statement

  20. Procedures (Cont.) • With parameter passing, it is possible to further simplify the architecture ARCHITECTURE behavior OF adder IS BEGIN PROCESS (enable, x, y) BEGIN add_bits3(x, y, enable, result, carry); END PROCESS; END behavior; • The parameters must be compatible in terms of data flow and data type PROCEDURE add_bits3 (SIGNAL a, b, en : IN BIT; SIGNAL temp_result, temp_carry : OUT BIT)

  21. Signal Resolution and Buses Execution phase Signal update phase Transaction queue OR Resolved signal Bus Resolution Function AND

  22. Bus ResolutionSmoke Generator • VHDL does not allow multiple concurrent signal assignments to the same signal • Multiple sequential signal assignments are allowed LIBRARY attlib; USE attlib.att_mvl.ALL; -- this code will generate an error ENTITY bus IS PORT (a, b, c : IN MVL; z : OUT MVL); END bus; ARCHITECTURE smoke_generator OF bus IS SIGNAL circuit_node : MVL; BEGIN circuit_node <= a; circuit_node <= b; circuit_node <= c; z <= circuit_node; END smoke_generator;

  23. Bus Resolution Functions • Are used to determine the assigned value when there are multiple signal drivers to the same signal FUNCTION wired_and (drivers : MVL_VECTOR) RETURN MVL IS VARIABLE accumulate : MVL := '1'; BEGIN FOR i IN drivers'RANGE LOOP accumulate := accumulate AND drivers(i); END LOOP; RETURN accumulate; END wired_and; • Bus resolution functions may be user defined or called from a package

  24. Bus ResolutionSmoke Generator Fixed • A signal which has a bus resolution function associated with it may have multiple drivers LIBRARY attlib; USE attlib.att_mvl.ALL; USE WORK.bus_resolution.ALL; ENTITY bus IS PORT (a, b, c : IN MVL; z : OUT MVL); END bus; ARCHITECTURE fixed OF bus IS SIGNAL circuit_node : wired_and MVL; BEGIN circuit_node <= a; circuit_node <= b; circuit_node <= c; z <= circuit_node; END fixed;

  25. Null Transactions • How can a driver be disconnected (i.e. not influence the output at all)? • Use the null waveform element • Example bus_out <= NULL AFTER 17 ns; • What happens if all drivers of a resolved signal are disconnected? • Use register kind in signal declaration to keep most recently determined value • Use bus kind in signal declaration if resolution function will determine the value • Example signal t : wired_bus BUS; signal u : BIT REGISTER;

  26. Concurrent Statement • Exists outside of a process but in an architecture • The process is itself a concurrent statement all processes scheduled to run concurrently • Concurrent signal assignment is a short hand form for a single statement process -- equivalent to process containing one statement, sensitive to changes on the right hand side. • Used frequently in DATAFLOW style descriptions

  27. The Process

  28. Concurrent Signal Assignment

  29. Concurrent Assignment Statements

  30. Concurrent Signal Sensitivity • Concurrent Statements are sensitive to all signals on the input side • If a signal appears on both sides, the statement is sensitive to changes in its own output. • A <= A+B; will be evaluated when B changes. This will change A and the statement will be evaluated again. • Time will not be able to advance because the statement keeps executing.

  31. Conditional Signal Statement

  32. Example of Conditional Signal Statement

  33. Selected Signal Statement

  34. Example of Selected Signal Assignment

  35. Concurrent Procedure Call • IN, OUT and INOUT parameter modes • Allows return of more than 1 value (unlike function call) • Considered a statement • Equivalent to a process containing the single procedure call followed by a wait on parameters of mode in or inout

  36. Example of Concurrent Procedure Call

  37. Sequential vs. ConcurrentStatement in Simulation Cycle • VHDL is inherently a concurrent language • All VHDL processes execute concurrently • Concurrent signal assignment statements are actually oneline processes • VHDL statements execute sequentially within a process • Concurrent processes with sequential execution within a process offers maximum flexibility • Supports various levels of abstraction • Supports modeling of concurrent and sequential events as observed in real systems

  38. Blocks

  39. Blocks • Blocks are concurrent statements and provide a mechanism to partition an architecture description • Items declared in declarative region of block are visible only inside the block, e.g. : • signals, subprograms • Blocks may be nested to define a hierarchical partitioning of the architectural description • Blocks may contain Guards for disabling drives.

  40. Blocks

  41. Nested Blocks

  42. End of this file

  43. Modeling Styles • Behavioral Modeling • Explicit definition of mathematical relationship between the input and output • No implementation information • Structural Modeling • Implicit definition of I/O relationship through particular structure • Interconnection of components

  44. Behavioral Modeling • All VHDL processes execute concurrently • Non-procedural • Data-flow • Concurrent execution • Procedural • Algorithmic • Sequential execution of statements • Equivalent to a single concurrent statement

  45. Data Flow Model • Concurrent Statements • Execute in arbitrary order • Execute only when any of input variables changes Local_Sig_1 <= In_1 AND In_2 ; Local_Sig_2 <= In_1 OR Local_Sig_1;

  46. Signal Assignment Statements • Two Types • Conditional concurrent signal assignment statement • Selected concurrent signal assignment statement • Each of These Has a Sequential Process Equivalent • Either Form Can Be Used and Are Equivalent

  47. BIT or BOOLEAN? • Logical Types Are Not Equal • BIT for signals • ‘0’ or ‘1’ • Character type • BOOLEANfor conditions • TRUE or FALSE

  48. Conditional Concurrent Syntax signal_identifier<=options conditional_waveforms; options<= [guarded][delay_mechanisms] conditional_waveforms<= {waveformwhenconditionelse} waveform[whencondition]

  49. Waveform Syntax waveform<= (value_expression[aftertime_expression]) { , ... }

  50. Operator Precedence • Highest to Lowest • Unary operator: NOT • Relational operators: =, /=, <, <=, >, >= • Boolean (bitwise): AND, OR, NAND, NOR, XOR, XNOR • Parentheses Can Be Used to • Force particular order of evaluation • Improve readability of expressions

More Related