English subtitles

← TCM Example cs348 unit3new

Get Embed Code
1 Language

Showing Revision 1 created 04/12/2013 by Cogi-Admin.

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