public BaseDoubleWordVerilatedPeripheral(Machine machine, long frequency, string simulationFilePathLinux = null, string simulationFilePathWindows = null, string simulationFilePathMacOS = null, ulong limitBuffer = LimitBuffer, int timeout = DefaultTimeout) { this.machine = machine; this.msTimeout = timeout; pauseMRES = new ManualResetEventSlim(initialState: true); allTicksProcessedARE = new AutoResetEvent(initialState: false); mainSocket = new CommunicationChannel(this, msTimeout); asyncEventsSocket = new CommunicationChannel(this, Timeout.Infinite); receiveThread = new Thread(ReceiveLoop) { IsBackground = true, Name = "Verilated.Receiver" }; timer = new LimitTimer(machine.ClockSource, frequency, this, LimitTimerName, limitBuffer, enabled: false, eventEnabled: true, autoUpdate: true); timer.LimitReached += () => { Send(ActionType.TickClock, 0, limitBuffer); this.NoisyLog("Tick: TickClock sent, waiting for the verilated peripheral..."); allTicksProcessedARE.WaitOne(); this.NoisyLog("Tick: Verilated peripheral finished evaluating the model."); }; SimulationFilePathLinux = simulationFilePathLinux; SimulationFilePathWindows = simulationFilePathWindows; SimulationFilePathMacOS = simulationFilePathMacOS; }
// the default moduleRevision/moduleId are correct for Zynq with GEM p23 public CadenceGEM(Machine machine, ushort moduleRevision = 0x118, ushort moduleId = 0x2) : base(machine) { ModuleId = moduleId; ModuleRevision = moduleRevision; IRQ = new GPIO(); MAC = EmulationManager.Instance.CurrentEmulation.MACRepository.GenerateUniqueMAC(); sync = new object(); interruptManager = new InterruptManager <Interrupts>(this); nanoTimer = new LimitTimer(machine.ClockSource, NanosPerSecond, this, "PTP nanos", limit: NanosPerSecond, direction: Direction.Ascending, workMode: WorkMode.Periodic, eventEnabled: true); nanoTimer.LimitReached += () => secTimer.Value++; var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.NetworkControl, new DoubleWordRegister(this) .WithFlag(2, out receiveEnabled, name: "RXEN") .WithFlag(9, FieldMode.Write, name: "STARTTX", writeCallback: (_, value) => { if (value) { SendFrames(); } }) },
public PicoRV32(Core.Machine machine, string cpuType, bool latchedIrqs = true, uint hartId = 0, uint resetVectorAddress = 0x10) : base(null, cpuType, machine, hartId, PrivilegeArchitecture.Priv1_09, Endianess.LittleEndian) { this.latchedIrqs = latchedIrqs; // the frequency value is picked at random and not tested internalTimer = new LimitTimer(machine.ClockSource, 1000000, this, nameof(internalTimer), workMode: WorkMode.OneShot, eventEnabled: true); internalTimer.LimitReached += () => { lock (irqLock) { pendingInterrupts |= (1u << TimerInterruptSource); TlibSetReturnRequest(); } }; qRegisters = new uint[NumberOfQRegisters]; // this will enable handling interrupts locally TlibSetReturnOnException(1); this.resetVectorAddress = resetVectorAddress; InstallCustomInstruction(pattern: "0000000-----000ss---ddddd0001011", handler: HandleGetqInstruction); InstallCustomInstruction(pattern: "0000001-----sssss---000dd0001011", handler: HandleSetqInstruction); InstallCustomInstruction(pattern: "0000010-----00000---000000001011", handler: HandleRetirqInstruction); InstallCustomInstruction(pattern: "0000011-----sssss---ddddd0001011", handler: HandleMaskirqInstruction); InstallCustomInstruction(pattern: "0000100-----00000---ddddd0001011", handler: HandleWaitirqInstruction); InstallCustomInstruction(pattern: "0000101-----sssss---ddddd0001011", handler: HandleTimerInstruction); Reset(); }
// Start is called before the first frame update void Start() { _player = FindObjectOfType <Player>(); _limitTimer = FindObjectOfType <LimitTimer>(); _canvasController = FindObjectOfType <CanvasController>(); StartCoroutine(_readyState()); }
private void InitTimer(IClockSource clockSource, long frequency, ulong limit) { var timer = new LimitTimer(clockSource, frequency, this, LimitTimerName, limit, enabled: true, eventEnabled: true, autoUpdate: true); timer.LimitReached += () => { Send(ActionType.TickClock, 0, limit); }; }
public void ShouldNotFireAlarmWhenInterruptsAreDisabled() { var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 1, null, String.Empty, 10, Direction.Descending, true); var ticked = false; timer.LimitReached += () => ticked = true; manualClockSource.AdvanceBySeconds(11); Assert.IsFalse(ticked); }
public SweRV_EH1(Machine machine, IRiscVTimeProvider timeProvider = null, uint hartId = 0, PrivilegeArchitecture privilegeArchitecture = PrivilegeArchitecture.Priv1_10, string cpuType = "rv32imc") : base(timeProvider, cpuType, machine, hartId, privilegeArchitecture) { timer = new LimitTimer(machine.ClockSource, 1000000, this, nameof(timer), uint.MaxValue, Direction.Descending, false, autoUpdate: true); TlibSetCsrValidationLevel((uint)CSRValidationLevel.None); // register custom CSRs RegisterCSR((ulong)0xBC8, () => 0u, _ => {}); //meivt RegisterCSR((ulong)0xBC9, () => 0u, _ => {}); //meipt RegisterCSR((ulong)0xBCA, () => 0u, _ => {}); //meicpct RegisterCSR((ulong)0xBCB, () => 0u, _ => {}); //meicidpl RegisterCSR((ulong)0xBCC, () => 0u, _ => {}); //meicurpl RegisterCSR((ulong)0xFC8, () => 0u, _ => {}); //meihap }
public void ShouldFireAlarmWhenInterruptsAreEnabled() { var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 1, null, String.Empty, 10, Direction.Descending, true); timer.EventEnabled = true; var ticked = false; timer.LimitReached += () => ticked = true; // var val =timer.Value; manualClockSource.AdvanceBySeconds(10); Assert.IsTrue(ticked); }
public void ShouldSwitchDirectionProperly() { var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 100, null, String.Empty, 100000, Direction.Ascending, true); timer.EventEnabled = true; var ticked = false; timer.LimitReached += () => ticked = true; manualClockSource.AdvanceBySeconds(2); timer.Direction = Direction.Descending; // and then change the direction manualClockSource.AdvanceBySeconds(2); Assert.IsTrue(ticked); }
public void ShouldBeDescending() { var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 100, null, String.Empty, 100000, Direction.Descending, true); var oldValue = timer.Limit; for (var i = 0; i < 100; i++) { manualClockSource.AdvanceBySeconds(1); var value = timer.Value; Assert.Less(value, oldValue, "Timer is not monotonic."); oldValue = value; } }
public NVIC(Machine machine, int systickFrequency = 50 * 0x800000) { priorities = new byte[IRQCount]; activeIRQs = new Stack <int>(); systick = new LimitTimer(machine.ClockSource, systickFrequency, this, nameof(systick), uint.MaxValue, Direction.Descending, false, autoUpdate: true); irqs = new IRQState[IRQCount]; IRQ = new GPIO(); systick.LimitReached += () => { SetPendingIRQ(15); }; InitInterrupts(); Init(); }
public void ShouldBeAscending() { var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 100, 100000, Direction.Ascending, true); var oldValue = 0UL; for (var i = 0; i < 100; i++) { manualClockSource.AdvanceBySeconds(1); var value = timer.Value; Assert.Greater(value, oldValue, "Timer is not monotonic."); oldValue = value; } }
public void ShouldNotExceedLimitDescending() { var limit = 100UL; var manualClockSource = new ManualClockSource(); var timer = new LimitTimer(manualClockSource, 1, null, String.Empty, limit, Direction.Ascending, true); manualClockSource.AdvanceBySeconds(limit - 1); for (var i = 0; i < 3; i++) { var value = timer.Value; Assert.LessOrEqual(value, limit, "Timer exceeded given limit."); Assert.GreaterOrEqual(value, 0, "Timer returned negative value."); manualClockSource.AdvanceBySeconds(1); } }
public BaseDoubleWordVerilatedPeripheral(Machine machine, long frequency, string simulationFilePath = null, ulong limitBuffer = LimitBuffer, double timeout = DefaultTimeout) { mainSocket = new CommunicationChannel(timeout); asyncEventsSocket = new CommunicationChannel(timeout); receiveThread = new Thread(ReceiveLoop) { IsBackground = true, Name = "Verilated.Receiver" }; timer = new LimitTimer(machine.ClockSource, frequency, this, LimitTimerName, limitBuffer, enabled: false, eventEnabled: true, autoUpdate: true); timer.LimitReached += () => { Send(ActionType.TickClock, 0, limitBuffer); }; SimulationFilePath = simulationFilePath; }
public void ShouldFireAlarmWhenInterruptsAreEnabled() { using (var machine = new Machine()) { var timer = new LimitTimer(machine, 1, 10, Direction.Descending, true); var manualClockSource = new ManualClockSource(); machine.SetClockSource(manualClockSource); timer.EventEnabled = true; var ticked = false; timer.LimitReached += () => ticked = true; machine.Start(); // var val =timer.Value; manualClockSource.AdvanceBySeconds(110); Assert.IsTrue(ticked); } }
//Recording stop and sleep and start async Task ReRecord() { BeginInvoke((MethodInvoker) async delegate { //stop _obs.Api.ToggleRecording(); LimitTimer.Stop(); ReloadAddTime(); while (IsRecording) { //IsRecording await Task.Delay(1000); } _obs.Api.ToggleRecording(); }); }
public NVIC(Machine machine, int systickFrequency = 50 * 0x800000) { priorities = new byte[IRQCount]; activeIRQs = new Stack <int>(); systick = new LimitTimer(machine, systickFrequency, limit: uint.MaxValue, direction: Direction.Descending, enabled: false); systick.EventEnabled = false; systick.AutoUpdate = true; irqs = new IRQState[IRQCount]; IRQ = new GPIO(); systick.LimitReached += () => { SetPendingIRQ(15); }; InitInterrupts(); Init(); }
/*------------------------------------ * Update * * summary:更新 * param :なし(void) * return :なし(void) * ------------------------------------*/ void Update() { m_text.text = m_score.ToString(); /* ポーズとタイムアップのときはグレーになる処理 */ PauseController pc = GameObject.FindGameObjectWithTag("PlayManager").GetComponent <PauseController>(); LimitTimer lt = GameObject.FindGameObjectWithTag("LimitTime").GetComponent <LimitTimer>(); if (pc.IsPause() || lt.IsUpTime()) { m_text.color = new Color(1.0f, 1.0f, 1.0f, 0.5f); // グレー } else { m_text.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // ふつー } }
public STM32_ADC(Machine machine) : base(machine) { channels = Enumerable.Range(0, NumberOfChannels).Select(x => new ADCChannel(this, x)).ToArray(); DefineRegisters(); // Sampling time fixed samplingTimer = new LimitTimer( machine.ClockSource, 1000000, this, "samplingClock", limit: 100, eventEnabled: true, direction: Direction.Ascending, enabled: false, autoUpdate: false, workMode: WorkMode.OneShot); samplingTimer.LimitReached += OnConversionFinished; }
public NVIC(Machine machine, long systickFrequency = 50 * 0x800000, byte priorityMask = 0xFF) { priorities = new byte[IRQCount]; activeIRQs = new Stack <int>(); pendingIRQs = new SortedSet <int>(); systick = new LimitTimer(machine.ClockSource, systickFrequency, this, nameof(systick), uint.MaxValue, Direction.Descending, false, autoUpdate: true); this.priorityMask = priorityMask; irqs = new IRQState[IRQCount]; IRQ = new GPIO(); resetMachine = machine.RequestReset; systick.LimitReached += () => { countFlag = true; SetPendingIRQ(15); }; InitInterrupts(); }
/*------------------------------------ * StartGame * * summary:ゲームスタート処理 * param :なし(void) * return :なし(void) * ------------------------------------*/ void StartGame() { /* スタートしてから生成 */ m_enemy_creater = Instantiate(m_EnemyCreater, m_EnemyCreater.transform.position, Quaternion.identity); m_player = Instantiate(m_Player, m_Player.transform.position, Quaternion.identity); m_ui = Instantiate(m_UI, m_UI.transform.position, Quaternion.identity); /* インフォ背景削除 */ SpriteRenderer sr = GetComponent <SpriteRenderer>(); m_info_bg = sr.sprite; // 画像を保存 sr.sprite = null; /* 制限時間管理用取得(※UI生成後に行うこと!) */ m_limit_time = GameObject.FindGameObjectWithTag("LimitTime").GetComponent <LimitTimer>(); m_is_start = true; }
/// <summary> /// Logs the initial conditions of the object. /// </summary> protected override void Start() { base.Start(); mainCollider = GetComponent <Collider>(); _body = GetComponent <Rigidbody>(); forwardOffset = mainCollider.bounds.extents.x; sideOffset = mainCollider.bounds.extents.z; heightOffset = mainCollider.bounds.extents.y; _height = heightOffset * 2; blockDistance = forwardOffset * 1.5f; animator = GetComponentInChildren <Animator>(); renderers = transform.FindChild("Model").GetComponentsInChildren <MeshRenderer>(); jumpTimer = new LimitTimer(0.25f); ResetFields(); }
public Quark_PWM(Machine machine) : base(machine, NumberOfInternalTimers) { IRQ = new GPIO(); internalLock = new object(); interruptStatus = new bool[NumberOfInternalTimers]; timers = new LimitTimer[NumberOfInternalTimers]; interruptMask = new bool[NumberOfInternalTimers]; alternativeLoadCount = new uint[NumberOfInternalTimers]; operationMode = new OperationMode[NumberOfInternalTimers]; runningMode = new RunningMode[NumberOfInternalTimers]; for (int i = 0; i < timers.Length; i++) { timers[i] = new LimitTimer(machine, 32000000, eventEnabled: true); var j = i; timers[i].LimitReached += () => HandleLimitReached(j); } PrepareRegisters(); }
public void ShouldBeDescending() { using (var machine = new Machine()) { var timer = new LimitTimer(machine, 100, 100000, Direction.Descending, true); var manualClockSource = new ManualClockSource(); machine.SetClockSource(manualClockSource); machine.Start(); var oldValue = timer.Limit; for (var i = 0; i < 100; i++) { manualClockSource.AdvanceBySeconds(1); var value = timer.Value; Assert.Less(value, oldValue, "Timer is not monotonic."); oldValue = value; } machine.Pause(); } }
public LAPIC(Machine machine) { // frequency guessed from driver and zephyr code localTimer = new LimitTimer(machine.ClockSource, 32000000, this, nameof(localTimer), direction: Direction.Descending, workMode: WorkMode.OneShot, eventEnabled: true, divider: 2); localTimer.LimitReached += () => { if (localTimerMasked.Value || !lapicEnabled.Value) { return; } lock (sync) { interrupts[(int)localTimerVector.Value] |= IRQState.Pending; FindPendingInterrupt(); } }; IRQ = new GPIO(); DefineRegisters(); Reset(); }
public BaseDoubleWordVerilatedPeripheral(Machine machine, long frequency, string simulationFilePathLinux = null, string simulationFilePathWindows = null, string simulationFilePathMacOS = null, ulong limitBuffer = LimitBuffer, int timeout = DefaultTimeout) { this.machine = machine; pauseMRES = new ManualResetEventSlim(initialState: true); mainSocket = new CommunicationChannel(this, timeout); asyncEventsSocket = new CommunicationChannel(this, Timeout.Infinite); receiveThread = new Thread(ReceiveLoop) { IsBackground = true, Name = "Verilated.Receiver" }; timer = new LimitTimer(machine.ClockSource, frequency, this, LimitTimerName, limitBuffer, enabled: false, eventEnabled: true, autoUpdate: true); timer.LimitReached += () => { Send(ActionType.TickClock, 0, limitBuffer); }; SimulationFilePathLinux = simulationFilePathLinux; SimulationFilePathWindows = simulationFilePathWindows; SimulationFilePathMacOS = simulationFilePathMacOS; }
public void ShouldNotExceedLimitDescending() { var limit = 100; using (var machine = new Machine()) { var timer = new LimitTimer(machine, 1, limit, Direction.Descending, true); var manualClockSource = new ManualClockSource(); machine.SetClockSource(manualClockSource); machine.Start(); manualClockSource.AdvanceBySeconds(limit - 1); for (var i = 0; i < 3; i++) { var value = timer.Value; Assert.LessOrEqual(value, limit, "Timer exceeded given limit."); Assert.GreaterOrEqual(value, 0, "Timer returned negative value."); manualClockSource.AdvanceBySeconds(1); } machine.Pause(); } }
/*------------------------------------ * Update * * summary:更新 * param :なし(void) * return :なし(void) * ------------------------------------*/ void Update() { LimitTimer lt = GameObject.FindGameObjectWithTag("LimitTime").GetComponent <LimitTimer>(); PauseController pc = GameObject.FindGameObjectWithTag("PlayManager").GetComponent <PauseController>(); /* キー入力 */ if (!(pc.IsPause())) // ポーズ中はだめ { float rev = Input.GetAxisRaw("Horizontal"); // 入力補正値 float speed_x = transform.position.x + (rev * m_SpeedX); // 移動量 Move(speed_x, transform.position.y); if ((Input.GetButtonDown("Shot")) && (!(lt.IsUpTime()))) { Shot(); // ゲーム終了後は撃てない } } /* 浮遊処理 */ m_passage_time_ms += Time.deltaTime; if (m_passage_time_ms >= m_FloatIntervalSecond) { if (m_is_float) { MoveDown(); // 上がってるなら下がる } else { MoveUp(); // 下がってるなら上げる } m_passage_time_ms = 0.0f; } /* 画面内の弾の数更新 */ GameObject[] obj = GameObject.FindGameObjectsWithTag("Bullet"); m_bullet_num = obj.Length; }
/*------------------------------------ * Update * * summary:更新 * param :なし(void) * return :なし(void) * ------------------------------------*/ void Update() { m_total_time = (Mathf.Max(0.0f, m_total_time - Time.deltaTime)); m_text.text = ((int)m_total_time).ToString(); /* ポーズ処理 */ PauseController pc = GameObject.FindGameObjectWithTag("PlayManager").GetComponent <PauseController>(); LimitTimer lt = GameObject.FindGameObjectWithTag("LimitTime").GetComponent <LimitTimer>(); if (pc.IsPause() || lt.IsUpTime()) { m_text.color = new Color(1.0f, 1.0f, 1.0f, 0.5f); // グレー } else { m_text.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // ふつー } /* 10秒切ったら赤にする */ if (m_total_time <= 10.0f) { m_text.color *= Color.red; // 上のポーズ中も色が反映されるように(*=) } }
/// <summary> /// Sets the level to be spawned and cause all of the mobiles/items /// in the list to be spawned /// </summary> public void Spawn() { TimeSpan limit; m_Count = 0; if (m_Levels.Count != 0 && m_Levels.Count >= CurrentLevel) { m_CreaturesName = m_Levels[CurrentLevel - 1].Mobs; for (int i = 0; i < m_Levels[CurrentLevel - 1].MobAmts.Count; i++) { m_Count += m_Levels[CurrentLevel - 1].MobAmts[i]; } limit = m_Levels[CurrentLevel - 1].TimeLimit; if (limit.TotalSeconds > 0) { m_TimeLimit = new LimitTimer(limit, this); m_TimeLimit.Start(); } } else { return; } for (int i = 0; i < m_CreaturesName.Count; i++) { for (int j = 0; j < m_Levels[CurrentLevel - 1].MobAmts[i]; j++) { Spawn(i); } } }
/// <summary> /// Loads the object /// </summary> /// <param name="reader"></param> public override void Deserialize(GenericReader reader) { base.Deserialize(reader); m_Active = reader.ReadBool(); m_CurrLvl = reader.ReadInt(); m_HomeRange = reader.ReadInt(); m_LevelAmt = reader.ReadInt(); m_PlayerRange = reader.ReadInt(); m_RechargeDelay = reader.ReadDateTime(); m_RechargeTime = reader.ReadTimeSpan(); m_SpawnStarted = reader.ReadBool(); m_UseRitual = reader.ReadBool(); m_WalkingRange = reader.ReadInt(); m_WaveStarted = reader.ReadBool(); int size = reader.ReadInt(); m_CreaturesName = new List<string>(); for (int i = 0; i < size; ++i) { string typeName = reader.ReadString(); m_CreaturesName.Add(typeName); } int count = reader.ReadInt(); m_Creatures = new List<IEntity>(); for (int i = 0; i < count; ++i) { IEntity e = World.FindEntity(reader.ReadInt()); if (e != null) m_Creatures.Add(e); } // Hack to load the progression level info m_Levels = new List<ProgressionLevel>(); int amt = reader.ReadInt(); for (int i = 0; i < amt; i++) { ProgressionLevel lvl = new ProgressionLevel(); lvl.Load(reader); m_Levels.Add(lvl); } m_Timer = new SpawnerTimer(this); if (m_Active && !m_UseRitual) m_Timer.Start(); DateTime recupe = reader.ReadDateTime(); if (recupe > DateTime.Now) m_RecupeTimer = new RecupeTimer(recupe.Subtract(DateTime.Now),this); DateTime limit = reader.ReadDateTime(); if (limit > DateTime.Now) m_TimeLimit = new LimitTimer(limit.Subtract(DateTime.Now), this); }
/// <summary> /// Saves the object /// </summary> /// <param name="writer"></param> public override void Serialize(GenericWriter writer) { base.Serialize(writer); writer.Write((bool)m_Active); writer.Write((int)m_CurrLvl); writer.Write((int)m_HomeRange); writer.Write((int)m_LevelAmt); writer.Write((int)m_PlayerRange); writer.Write((DateTime)m_RechargeDelay); writer.Write((TimeSpan)m_RechargeTime); writer.Write((bool)m_SpawnStarted); writer.Write((bool)m_UseRitual); writer.Write((int)m_WalkingRange); writer.Write((bool)m_WaveStarted); writer.Write(m_CreaturesName.Count); for (int i = 0; i < m_CreaturesName.Count; ++i) writer.Write((string)m_CreaturesName[i]); writer.Write(m_Creatures.Count); for (int i = 0; i < m_Creatures.Count; ++i) { object o = m_Creatures[i]; if (o is Item) writer.Write((Item)o); else if (o is Mobile) writer.Write((Mobile)o); else writer.Write(Serial.MinusOne); } // Hack to save the progression level info writer.Write((int)m_Levels.Count); foreach (ProgressionLevel l in m_Levels) { l.Save(writer); } if (m_RecupeTimer != null) m_RecupeTimer.Save(writer); else { m_RecupeTimer = new RecupeTimer(TimeSpan.FromSeconds(0.0), this); m_RecupeTimer.Save(writer); } if (m_TimeLimit != null) m_TimeLimit.Save(writer); else { m_TimeLimit = new LimitTimer(TimeSpan.FromSeconds(0.0), this); m_TimeLimit.Save(writer); } }
/// <summary> /// Sets the level to be spawned and cause all of the mobiles/items /// in the list to be spawned /// </summary> public void Spawn() { TimeSpan limit; m_Count = 0; if (m_Levels.Count != 0 && m_Levels.Count >= CurrentLevel) { m_CreaturesName = m_Levels[CurrentLevel - 1].Mobs; for (int i = 0; i < m_Levels[CurrentLevel - 1].MobAmts.Count; i++) m_Count += m_Levels[CurrentLevel - 1].MobAmts[i]; limit = m_Levels[CurrentLevel - 1].TimeLimit; if (limit.TotalSeconds > 0) { m_TimeLimit = new LimitTimer(limit, this); m_TimeLimit.Start(); } } else return; for(int i = 0; i < m_CreaturesName.Count; i++) { for (int j = 0; j < m_Levels[CurrentLevel - 1].MobAmts[i]; j++) Spawn(i); } }