Danh mục

Verilog Programming part 25

Số trang: 7      Loại file: pdf      Dung lượng: 46.56 KB      Lượt xem: 17      Lượt tải: 0    
10.10.2023

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

8.1 Differences between Tasks and Functions Tasks and functions serve different purposes in Verilog. We discuss tasks and functions in greater detail in the following sections. However, first it is important to understand differences between tasks and functions, as outlined in Table 8-1. Table 8-1. Tasks and Functions Functions A function can enable another function but not another task. Functions always execute in 0 simulation time. Functions must not contain any delay, event, or timing control statements. Functions must have at least one input argument. They can have more than one input. Functions always return a single value. They cannot...
Nội dung trích xuất từ tài liệu:
Verilog Programming part 258.1 Differences between Tasks and FunctionsTasks and functions serve different purposes in Verilog. We discuss tasks andfunctions in greater detail in the following sections. However, first it is importantto understand differences between tasks and functions, as outlined in Table 8-1. Table 8-1. Tasks and Functions Functions TasksA function can enable another A task can enable other tasks andfunction but not another task. functions.Functions always execute in 0 Tasks may execute in non-zero simulationsimulation time. time.Functions must not contain any Tasks may contain delay, event, or timingdelay, event, or timing control control statements.statements.Functions must have at least one Tasks may have zero or more argumentsinput argument. They can have more of type input, output, or inout.than one input.Functions always return a single Tasks do not return with a value, but canvalue. They cannot have output or pass multiple values through output andinout arguments. inout arguments.Both tasks and functions must be defined in a module and are local to the module.Tasks are used for common Verilog code that contains delays, timing, eventconstructs, or multiple output arguments. Functions are used when commonVerilog code is purely combinational, executes in zero simulation time, andprovides exactly one output. Functions are typically used for conversions andcommonly used calculations.Tasks can have input, output, and inout arguments; functions can have inputarguments. In addition, they can have local variables, registers, time variables,integers, real, or events. Tasks or functions cannot have wires. Tasks and functionscontain behavioral statements only. Tasks and functions do not contain always orinitial statements but are called from always blocks, initial blocks, or other tasksand functions.[ Team LiB ][ Team LiB ]8.2 TasksTasks are declared with the keywords task and endtask. Tasks must be used if anyone of the following conditions is true for the procedure: • There are delay, timing, or event control constructs in the procedure. • The procedure has zero or more than one output arguments. • The procedure has no input arguments.8.2.1 Task Declaration and InvocationTask declaration and task invocation syntax are as follows.Example 8-1 Syntax for Taskstask_declaration ::= task [ automatic ] task_identifier ; { task_item_declaration } statement endtask | task [ automatic ] task_identifier ( task_port_list ) ; { block_item_declaration } statement endtasktask_item_declaration ::= block_item_declaration | { attribute_instance } tf_input_declaration ; | { attribute_instance } tf_output_declaration ; | { attribute_instance } tf_inout_declaration ;task_port_list ::= task_port_item { , task_port_item }task_port_item ::= { attribute_instance } tf_input_declaration | { attribute_instance } tf_output_declaration | { attribute_instance } tf_inout_declarationtf_input_declaration ::= input [ reg ] [ signed ] [ range ] list_of_port_identifiers | input [ task_port_type ] list_of_port_identifierstf_output_declaration ::= output [ reg ] [ signed ] [ range ] list_of_port_identifiers | output [ task_port_type ] list_of_port_identifierstf_inout_declaration ::= inout [ reg ] [ signed ] [ range ] list_of_port_identifiers | inout [ task_port_type ] list_of_port_identifierstask_port_type ::= time | real | realtime | integerI/O declarations use keywords input, output, or inout, based on the type ofargument declared. Input and inout arguments are passed into the task. Inputarguments are processed in the task statements. Output and inout argument valuesare passed back to the variables in the task invocation statement when the task iscompleted. Tasks can invoke other tasks or functions.Although the keywords input, inout, and output used for I/O arguments in a taskare the same as the keywords used to declare ports in modules, there is adifference. Ports are used to connect external signals to the module. I/O argumentsin a task are used to pass values to and from the task.8.2.2 Task ExamplesWe discuss two examples of tasks. The first example illustrates the use of inputand output arguments in tasks. The second example models an asymmetricsequence generator that generates an asymmetric sequence on the clock signal.Use of input and output argumentsExample 8-2 illustrates the use of input and output arguments in tasks. Consider atask called bitwise_oper, which computes the bitwise and, bitwise or, and bitwiseex-or of two ...

Tài liệu được xem nhiều: