-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logic_Probe.cs
71 lines (58 loc) · 1.55 KB
/
Logic_Probe.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Copyright (c) 2023 Aaron Keith
// Copyright (c) 2010-2020 Antmicro
// Copyright (c) 2011-2015 Realtime Embedded
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using Antmicro.Renode.Core;
using Antmicro.Renode.Logging;
using Antmicro.Migrant;
namespace Antmicro.Renode.Peripherals.Miscellaneous
{
public class Logic_Probe : IGPIOReceiver, ILed
{
public Logic_Probe(bool invert = false)
{
inverted = invert;
state = invert;
sync = new object();
}
public void OnGPIO(int number, bool value)
{
if(number != 0)
{
throw new ArgumentOutOfRangeException();
}
State = inverted ? !value : value;
}
public void Reset()
{
state = inverted;
}
[field: Transient]
public event Action<ILed, bool> StateChanged;
public bool State
{
get => state;
private set
{
lock(sync)
{
if(value == state)
{
return;
}
state = value;
StateChanged?.Invoke(this, state);
this.Log(LogLevel.Info, "Logic state changed to {0}", state);
}
}
}
private bool state;
private readonly bool inverted;
private readonly object sync;
}
}