|
|
|
|
|
|
|
|
|
|
|
|
event methods
|
|
|
Events are variables that synchronize concurrent processes. When a sync is called, a process blocks until another process sends a trigger to unblock it. We have see this in data types chapter. |
|
|
|
|
|
To work with events, vera provides following methods. |
|
|
|
|
|
|
|
|
|
|
|
sync()
|
|
|
This method synchronizes statement execution to one or more triggers. Sync can be used as either a task or a function. |
|
|
|
|
|
task sync(ALL | ANY | ORDER | CHECK, event event_name1,
..., event event_nameN);
|
|
|
|
|
|
Where |
|
|
- event_name : Is the event variable name on which the sync is activated.
- ALL : The ALL sync type suspends the process until all of the specified
- events are triggered.
- ANY:The ANY sync type suspends the process until any of the
- specified events is triggered.
- ORDER:The ORDER sync type suspends the process untill all the events specified are triggered in given order
- CHECK:The CHECK sync type is called as a function. It does not suspend the thread. It returns a 1 if the trigger is ON and a 0 if it is not.
|
|
|
|
|
|
|
|
|
|
|
|
Example : event sync methods
|
|
|
|
|
|
1 #include "vera_defines.vrh"
2
3 program event_sync {
4 event try_event, try_event2;
5 // Simple event trigger and wait
6 fork {
7 delay(10);
8 printf("[%0d] Triggering try_event\n", get_time(LO) );
9 trigger(try_event);
10 } join none
11 sync(ALL, try_event);
12 printf("[%0d] Got try_event\n", get_time(LO) );
13 // ALL event trigger and wait
14 fork {
15 delay(10);
16 printf("[%0d] Triggering try_event2\n", get_time(LO) );
17 trigger(try_event2);
18 delay(10);
19 printf("[%0d] Triggering try_event\n", get_time(LO) );
20 trigger(try_event);
21 } join none
22 sync(ALL, try_event, try_event2);
23 printf("[%0d] Got try_event and try_event2\n", get_time(LO) );
24
25 // ANY event trigger and wait
26 fork {
27 delay(10);
28 printf("[%0d] Triggering try_event2\n", get_time(LO) );
29 trigger(try_event2);
30 } join none
31 sync(ANY, try_event, try_event2);
32 printf("[%0d] Got try_event or try_event2\n", get_time(LO) );
33 // ORDER event trigger and wait
34 fork {
35 delay(10);
36 trigger(try_event);
37 printf("[%0d] Triggering try_event\n", get_time(LO) );
38 delay(10);
39 trigger(try_event2);
40 printf("[%0d] Triggering try_event2\n", get_time(LO) );
41 } join none
42 sync(ORDER, try_event, try_event2);
43 printf("[%0d] Got try_event followed by try_event2\n", get_time(LO) );
44
45 }
You could download file event_sync.vr here
|
|
|
|
|
|
Simulation : event sync methods
|
|
|
|
|
|
[10] Triggering try_event
[10] Got try_event
[20] Triggering try_event2
[30] Triggering try_event
[30] Got try_event and try_event2
[40] Triggering try_event2
[40] Got try_event or try_event2
[50] Triggering try_event
[60] Triggering try_event2
[60] Got try_event followed by try_event2
|
|
|
|
|
|
Trigger
|
|
|
This task is used to change the state of an event. Triggering an event unblocks waiting syncs, or blocks subsequent syncs. By default, all events are OFF. |
|
|
|
|
|
|
|
|
task trigger([ONE_SHOT | ONE_BLAST| HAND_SHAKE | ON |
OFF,] event event_name1 , ... ,event event_nameN);
|
|
|
|
|
|
Where |
|
|
- event_name : Is the event variable name on which the sync is activated.
- ONE_SHOT : The ONE_SHOT trigger is the default trigger type. If you use a ONE_SHOT trigger, any process waiting for a trigger receives it. If there are no processes waiting for the trigger, the trigger is discarded.
- ONE_BLAST : ONE_BLAST triggers work just as ONE_SHOT triggers do with the exception that they trigger any sync called within the same simulation delta cycle, regardless of whether or not it was called before the trigger was executed. If a ONE_BLAST trigger is used for the situation diagrammed previously, all the processes are unblocked regardless of execution order.
- HAND_SHAKE : HAND_SHAKE triggers unblock only one sync, even if multiple syncs are waiting for triggers. It triggers the most recent pending sync, or queues requests. If the order of triggering the unblocking of a sync is important, use a semaphore_get() and semaphore_put() around the sync to maintain order.
- ON : The ON trigger is used to turn on an event. When an event is turned on, all syncs waiting for that event immediately trigger. Also, all future sync operations on that event will immediately trigger until there is a trigger (OFF) call.
- OFF : The OFF trigger is used to turn off an event. An event cannot be used to synchronize concurrent processes if it is turned off.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|