The triggering of events is called event emission. Events can be emitted explicitly or implicitly. Events are emitted explicitly with the emit action. When events are emitted, threads that were blocked, awaiting the emission of this event, are unblocked and scheduled for execution. How ever, they do not execute until the thread which emitted the event itself blocks. The emit event does not consume time. The syntax for the emit action is shown below:
emit [struct-exp.]event-type ;
The components of an emit action are shown in Table 7-2 below:
struct-exp | An expression referring to the struct instance in which the event is defined. |
event-type | The type of event to emit. |
Example 7-2 shows explicit event emission.
Example shows how the emit action can be used for explicit event emission. There is some syntax in this example that will be covered later in the book. Look at the comments for the portions that are relevant. <' struct xmit_recv { //Define struct xmit_recv event rec_ev; transmit() @sys.clk is { wait cycle; //Wait for the next emission of sys.clk event emit rec_ev; //Emit the rec_ev event out("rec_ev emitted"); }; receive() @sys.clk is { wait @rec_ev; //Wait for the next emission of rec_ev event. //This will happen when the rec_ev event is //triggered by the "emit rec_ev action" in the //transmit() method. out("rec_ev occurred"); //Print after the rec_ev event has //been emitted. stop_run(); //Finish the run }; run() is also { start transmit(); //Start two processes transmit and start receive(); //receive in parallel at the beginning //of simulation. }; }; extend sys { //Define struct sys event clk is @sys.any; //Create a clk event xmtrcv_i: xmit_recv; //Instantiate the xmit_recv struct }; '>
Events can also be emitted implicitly when they are attached to @sim or another temporal expression. There is no need to manually emit these events. 7-3 shows automatic event emission.
Example shows implicit event emission when various temporal expressions succeed in SpecmanElite or the HDL simulator. <' struct m_str { event s_event is rise('~/top/start') @sim; //s_event is implicitly triggered when //the ~/top/start HDL signal rises. //@sim is the sampling event //that initiates a callback from the HDL simulator //to Specman Elite. event e_event is rise('~/top/end') @sim; //e_event is implicitly triggered when //the ~/top/end HDL signal rises. event clk is rise('~/top/clk') @sim; //When a posedge of the HDL signal ~/top/r_clk //occurs, an event top_clk is triggered (emitted) //implicitly in Specman Elite. event t_event is {@s_event; [5]; @e_event} @clk; //The event t_event is emitted implicitly //when s_event is followed by 5 posedges of clk //and then an e_event occurs. Thus the t_event //is emitted when a temporal expression succeeds. }; '>