1 // 2 // Copyright (c) 2010-2022 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using Antmicro.Renode.Core; 9 using Antmicro.Renode.Logging; 10 11 namespace Antmicro.Renode.Peripherals.Miscellaneous 12 { 13 public class ResetPin : IGPIOReceiver 14 { ResetPin(IMachine machine, bool invert = true)15 public ResetPin(IMachine machine, bool invert = true) 16 { 17 inverted = invert; 18 this.machine = machine; 19 state = false; 20 sync = new object(); 21 } 22 OnGPIO(int number, bool value)23 public void OnGPIO(int number, bool value) 24 { 25 if(number != 0) 26 { 27 this.Log(LogLevel.Error, "Tried to set pin {0} to value {1}, but only pin 0 is supported in this model", number, value); 28 return; 29 } 30 31 State = inverted ? !value : value; 32 } 33 Reset()34 public void Reset() 35 { 36 state = false; 37 } 38 39 public bool State 40 { 41 get => state; 42 43 private set 44 { 45 lock(sync) 46 { 47 if(value == state) 48 { 49 return; 50 } 51 52 state = value; 53 54 if(state) 55 { 56 machine.RequestReset(); 57 } 58 } 59 } 60 } 61 62 private bool state; 63 64 private readonly bool inverted; 65 private readonly IMachine machine; 66 private readonly object sync; 67 } 68 } 69