S
Steven Sharp
Guest
Eric Peterson <Eric.R.Peterson@verizon.net> wrote in message news:<pan.2003.07.21.16.48.38.1973@verizon.net>...
a separate instance of the task in each instance of the module that
declares it (just as there is a separate instance of a reg in each
instance of the module that declares it). But there is not a separate
instance of the task for each place that calls it within a module.
That means that multiple processes in the same module that call the same
task at overlapping times will be sharing the same variables.
copy of each variable whenever execution enters its scope, and deallocate
it when execution exits the scope. These variables are initialized to the
default initialization value (X for most variables) when allocated. Since
there is not guaranteed to be one instance of each variable, these variables
cannot be referenced by hierarchical names, unlike normal task variables.
There are also some other restrictions on what can be done with them.
Re-entrant tasks and functions are declared by putting the word "automatic"
after the keyword "task" or "function" in the declaration. Whether you
can make use of this depends on whether your tools support this particular
Verilog-2001 feature. NC-Verilog and BuildGates support it, and I believe
that VCS supports it by now also.
The "vector of tasks" approach could have been done by using a different
Verilog-2001 feature: the generate-for. However, the standard specifically
made it illegal to put tasks and functions inside generate-for loops, for
no good reason. At any rate, a tool that supports generates is likely to
support re-entrant tasks and functions already.
The most obvious approach to this using Verilog-1995 would be to put the
tasks into a module, and instantiate the module as many times as you
need instances of the task. An array of instances could be used to do
this in one instantiation, like your vector of tasks. Then call the task
using a hierarchical name for the appropriate instance. This is less
convenient than a re-entrant task, especially if the task needs to access
variables in the instantiating module, but even that can be done by using
hierarchical names in the task (probably of the form of
parent_module_name.variable_name, rather than the more usual
parent_instance_name.variable_name, so that it doesn't care about the
instance name of the module using it).
Actually, there is a concept of multiple instances of a task: there isI'm trying to use Verilog tasks to make my code more structured, but
am running into a potential limitation - there seems to be no concept
of multiple 'instances' of a task.
a separate instance of the task in each instance of the module that
declares it (just as there is a separate instance of a reg in each
instance of the module that declares it). But there is not a separate
instance of the task for each place that calls it within a module.
That means that multiple processes in the same module that call the same
task at overlapping times will be sharing the same variables.
Understood.If this seems confusing, what I'm
running up against is the way Verilog has only a single copy of all
task-scoped variables - each caller shares those same variables. I'm
looking to have separate ('per-instance') copies of those variables.
Verilog-2001 adds re-entrant tasks and functions, which allocate a newSo my question is, is there a way to have multiple instances of a
task, each with their own independent task variables? Can one have a
vector of tasks? If not, then is there a conventional way to do this,
say keeping external task 'state' in an array (per instance) and pass
that state as an inout variable?
copy of each variable whenever execution enters its scope, and deallocate
it when execution exits the scope. These variables are initialized to the
default initialization value (X for most variables) when allocated. Since
there is not guaranteed to be one instance of each variable, these variables
cannot be referenced by hierarchical names, unlike normal task variables.
There are also some other restrictions on what can be done with them.
Re-entrant tasks and functions are declared by putting the word "automatic"
after the keyword "task" or "function" in the declaration. Whether you
can make use of this depends on whether your tools support this particular
Verilog-2001 feature. NC-Verilog and BuildGates support it, and I believe
that VCS supports it by now also.
The "vector of tasks" approach could have been done by using a different
Verilog-2001 feature: the generate-for. However, the standard specifically
made it illegal to put tasks and functions inside generate-for loops, for
no good reason. At any rate, a tool that supports generates is likely to
support re-entrant tasks and functions already.
The most obvious approach to this using Verilog-1995 would be to put the
tasks into a module, and instantiate the module as many times as you
need instances of the task. An array of instances could be used to do
this in one instantiation, like your vector of tasks. Then call the task
using a hierarchical name for the appropriate instance. This is less
convenient than a re-entrant task, especially if the task needs to access
variables in the instantiating module, but even that can be done by using
hierarchical names in the task (probably of the form of
parent_module_name.variable_name, rather than the more usual
parent_instance_name.variable_name, so that it doesn't care about the
instance name of the module using it).