struct State
{
TimeMs lastUpdateTime;
};
{{ GENERATED_CODE }}
void evaluate(Context ctx)
{
State* state = getState(ctx);
TimeMs tus = micros();
if (isInputDirty<input_RST>(ctx))
emitValue<output_Tus>(ctx, 0);
else if (getValue<input_EN>(ctx) && isInputDirty<input_UPD>(ctx))
emitValue<output_Tus>(ctx, getValue<output_Tus>(ctx) + (tus - state->lastUpdateTime));
state->lastUpdateTime = tus;
}