-
Title:
TCM Example cs348 unit3new
-
Description:
-
The syntax of a TCM is very similar to a method. You have a name, a parameter
-
list, and a block of code. The noticeable difference is the at followed by an
-
event name. This is called the default sampling event of the TCM. And it's the
-
main synchronization event for the execution. Inside the TCM you can execute
-
procedural action, actions and synchronization statements. So back in our
-
packet driver, we have our clock event. And here is our first example TCM. One
-
parameter called duration. And the default event is clock_f. But when you start
-
a thread or when you start a TCM, before anything gets executed, you need one
-
occurrence of the default event. So before we get into executing any of this,
-
this event needs to happen. We have two print statements, and then we have our
-
first synchronization action. We want to suspend the TCM execution by a number
-
of cycles, so we do wait duration times cycle. Cycle refers to the default
-
event, and duration is our input parameter. So here we can control how long
-
this TCM will suspend here. Once this temporal expression is finished. We fall,
-
fall down here, and execute further actions. So we have another print
-
statement, and then stop run to stop the simulation. In order to span off a
-
thread, you use the start action. So in the run phase at time 0, or just before
-
the simulation starts. We spawn off our thread, our TCM. And pass in 5 as a
-
parameter. You cannot call a TCM from a method because TCMs consume time. From
-
within a TCM, you could call another TCM. And this is like a suspend. So
-
calling another TCM will start that TCM. And when it's finished, they will,
-
control returns back to the calling TCM, and it will execute further. Let's
-
have a look at the log file. So here we can see, when we start running, we
-
don't get the print statements. We only get them after we had the first clock.
-
So at time 100 we get our clock, and then we get indication that our TCM has
-
started. It then waits for 5 cycles and prints that the TCM is now going to
-
end. And we call stop run to stop the simulation. So this is how you can
-
execute a method over time, and it's called a time consuming method.