public void Run() { VCDSignalsSnapshot topLevelSnapshot = new VCDSignalsSnapshot("TOP"); var controlScope = topLevelSnapshot.Scope("Control"); var clockSignal = controlScope.Add(new VCDVariable("Clock", true, 1)); _topLevel.PopulateSnapshot(topLevelSnapshot); _vcdBuilder?.Init(topLevelSnapshot); var clock = 0; var stageIteration = 0; while (clock < MaxClockCycles && (IsRunning?.Invoke(_topLevel) ?? true)) { var currentTime = clock * 2 * MaxStageIterations; clockSignal.Value = true; stageIteration = 0; do { currentTime++; var modified = _topLevel.Stage(stageIteration); _topLevel.PopulateSnapshot(topLevelSnapshot); _vcdBuilder?.Snapshot(currentTime, topLevelSnapshot); // no modules were modified during stage iteration, all converged if (!modified) { break; } }while (++stageIteration < MaxStageIterations); if (stageIteration >= MaxStageIterations) { throw new MaxStageIterationReachedException(); } OnPostStage?.Invoke(_topLevel); currentTime = clock * 2 * MaxStageIterations + MaxStageIterations; clockSignal.Value = false; _topLevel.PopulateSnapshot(topLevelSnapshot); _vcdBuilder?.Snapshot(currentTime, topLevelSnapshot); _topLevel.Commit(); clock++; } }
public virtual void ClockCycle() { _simulatorContext.DeltaCycle = 0; do { _simulatorContext.CurrentTime++; var stageResult = _topLevel.DeltaCycle(_simulatorContext.DeltaCycle); _simulatorContext.TotalDeltaCycles++; TraceSignals(); // no modules were modified during stage iteration, all converged if (stageResult == RTLModuleStageResult.Stable) { break; } }while (++_simulatorContext.DeltaCycle < _simulatorContext.MaxDeltaCycles); if (_simulatorContext.DeltaCycle >= _simulatorContext.MaxDeltaCycles) { throw new MaxStageIterationReachedException(); } OnPostStage?.Invoke(_topLevel); _simulatorContext.CurrentTime = _simulatorContext.Clock * 2 * _simulatorContext.MaxDeltaCycles + _simulatorContext.MaxDeltaCycles; // clock fall is not handled in RTL module, all sync is done of clock rise at the moment _simulatorContext.ClockSignal?.SetValue(false); TraceSignals(); // clock rise will commit all changes _simulatorContext.Clock++; _simulatorContext.CurrentTime = _simulatorContext.Clock * 2 * _simulatorContext.MaxDeltaCycles; _simulatorContext.ClockSignal?.SetValue(true); _topLevel.Commit(); TraceSignals(); OnPostCommit?.Invoke(_topLevel); }
public void ClockCycle() { _simulatorContext.CurrentTime = _simulatorContext.Clock * 2 * _simulatorContext.MaxStageIterations; _simulatorContext.ClockSignal?.SetValue(true); _simulatorContext.Iteration = 0; do { _simulatorContext.CurrentTime++; var modified = _topLevel.Stage(_simulatorContext.Iteration); TraceSignals(); // no modules were modified during stage iteration, all converged if (!modified) { break; } }while (++_simulatorContext.Iteration < _simulatorContext.MaxStageIterations); if (_simulatorContext.Iteration >= _simulatorContext.MaxStageIterations) { throw new MaxStageIterationReachedException(); } OnPostStage?.Invoke(_topLevel); _simulatorContext.CurrentTime = _simulatorContext.Clock * 2 * _simulatorContext.MaxStageIterations + _simulatorContext.MaxStageIterations; _simulatorContext.ClockSignal?.SetValue(false); TraceSignals(); _topLevel.Commit(); OnPostCommit?.Invoke(_topLevel); _simulatorContext.Clock++; }