0

I have stumbled upon e code written like that:

event a is cycle @b;

Removing the 'cycle' from this event, made no difference in behavior.

What is the meaning of cycle here?

Thanks

2 Answers2

4

From the e LRM:

"Represents one cycle of an event. With no explicit sampling event specified, this represents one cycle of the default sampling event. With a sampling event specified, cycle is equivalent to “@sampling-event @any”. You can use the cycle expression to override the default sampling event taken from the context."

A use for it is the following:

some_tcm() @clk is {
  message(LOW, "This is synced at clock");
  wait @rise_async;
  message(LOW, "This is synced at the first clk after rise_async");
  wait cycle @rise_async;
  message(LOW, "This is synced exactly at rise_async");
  stop_run();
};

some_tcm() specifies @clk as a sampling event. Say you have another asynchronous event @rise_async which will get triggered in between clock edges. If you do a simple wait @rise_async the TCM will wait until the first trigger of @clk after @rise_async (effectively a @rise_async @clk). If you do a wait cycle @rise_async, then you have overridden the sampling event and the TCM will wait exactly until @rise_async happens.

Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • So according to this, in this tcm, there is no difference if I write "wait [2];" or if I write "wait [2]*cycle;", correct? If I specify no event then 'cycle' will refer to the sampling event, same as if I leave it out? – user3488810 Apr 07 '14 at 08:06
0

"event a is cycle @b;" is a trick to respond to event triggering, but do so at the end of the current tick. For example, the following code would print "hello world", instead of "world hello" if we did "on b".

event b;
event a is cycle @b;

foo() is {
  emit b;
  message(NONE, "hello");
};

on a {
    message(NONE, "world");
};
Ayalo
  • 1
  • 3