A task is a program that is encapsulated between "Task-endtask". The task is performed by the tune, and only
is executed at the time of invocation, if the task is defined, but it is not invoked throughout the process, the task is not
Implementation of the. Calling a task may require it to process some data and return the result of the operation, so the task should have received
Output from the input and return data. In addition, tasks can be called each other, and functions can also be called within a task.
1. Task definition
The task definition is in the following form:
Task task_id;
[Declaration]
Procedural_statement
Endtask
Where the keyword task and endtask the content between them as a task definition, the task marks a
The start of the task definition structure; task_id is the task name; optional declaration is the port declaration statement and the variable declarator
, the task receives the input value and the return output value is through the port declared here; procedural_statement
is a process statement used to accomplish this task, and if there are more than one procedure statement, it should be placed inside the statement block;
Endtask defines a struct end flag for a task. An instance of a task definition is given below.
: Defines a task.
Task task_demo; //Task definition structure at the beginning, named task_demo
input [7:0] x,y; //Input port description
output [7:0] tmp; //Output port description
if (x>y) //Give a description of the task definition statement
tmp = x;
else
tmp = y;
Endtask
The code above defines a task named "Task_demo", which takes the maximum value of two numbers. When you define a task,
The following six points need to be noted:
(1) The port name cannot be listed in the first line of the "task" statement;
(2) The input, output and bidirectional ports of the task are unlimited, even without input, output and
Bidirectional Port.
(3) In the description statement of a task definition, you can use a statement that is not integrated (most frequently used
is the delay control statement), but this causes the task to be non-consolidated.
(4) You can call other tasks or functions in a task, or you can call yourself.
(5) Initial and always process blocks cannot appear within a task definition structure.
(6) A "Disable Abort statement" can appear in the task definition, which interrupts the task being performed, but it is not
can be integrated. When the task is interrupted, the program flow returns to the place where the task was called to continue execution.
2. Task invocation
Although the initial statement and the ALWAYS statement statement cannot appear in the task, the task invocation statement can be used in the initial statement
And always statements, with the following syntax:
task_id[(port 1, Port 2, ..., Port N)];
Where task_id is the task name to invoke, Port 1, Port 2, ... is a list of parameters. The parameter list gives the input to any
Data (input to the task) and the variable that receives the result (the returned result is received from the output of the task).
In a task invocation statement, the order of the parameter list must be the same as the Port declaration order in the task definition. The task invocation statement is
Procedural statements, so the variables that receive the returned data in a task call must be of the register type. The following gives a task to tune
Use instances.
Example: Implement a 4-bit full-additive by Verilog HDL task call.
Module EXAMPLE (A, B, CIN, S, COUT);
input [3:0] A, B;
Input CIN;
Output [3:0] S;
Output COUT;
reg [3:0] S;
Reg COUT;
reg [1:0] S0, S1, S2, S3;
Task ADD;
Input A, B, CIN;
Output [1:0] C;
reg [1:0] C;
Reg S, COUT;
Begin
S = A ^ B ^ CIN;
COUT = (a&b) | (a&cin) | (b&cin);
C = {COUT, S};
End
Endtask
Always @ (A or B or CIN) begin
ADD (A[0], b[0], CIN, S0);
ADD (A[1], b[1], s0[1], S1);
ADD (A[2], b[2], s1[1], S2);
ADD (A[3], b[3], s2[1], S3);
S = {S3[0], s2[0], s1[0], s0[0]};
COUT = s3[1];
End
Endmodule
Here are some things to keep in mind when invoking a task:
(1) The task invocation statement can only appear within the process block;
(2) The processing method of the task invocation statement and a common behavior description statement is consistent;
(3) When an input, output, or bidirectional port is called, the task invocation statement must contain a list of port names, and the signal
The port order and type must match the order and type in the task definition structure. It is necessary to note that the output port of the task
must correspond to data variables of the register type.
(4) The integrated task can only implement the combinatorial logic, which means that the time to call the synthetic task is "0". And in the face
The task for simulation can have timing control, such as latency, so the call time for the simulation-oriented task is not "0".
The use of task